To handle the encoding problem, you can always craft a JSP specifically to wrap each URL you need to call and change the <%page charset directive at the bottom accordingly.
 
I was thinking that there's probably some way to directly connect the input stream from the URL connection to the output stream of the JSP like a crude pipe of some sort but I couldn't figure out how to do it. I ended up reading data in a loop.
 
To pass the data as raw bytes, you can probably use this code in the JSP...
 
    BufferedInputStream in = null;
    BufferedOutputStream out = null;
    try {
      in = new BufferedInputStream(new FileInputStream(srcFile));
      out = new BufferedOutputStream(new FileOutputStream(dstFile));
      byte[] buffer = new byte[8 * 1024];
      int count;
      while ( (count = in.read(buffer)) >= 0) {
        out.write(buffer, 0, count);
      }
    }
    catch (IOException ex) {
      // handle exceptions here
    }
    finally {
      if (in != null)
        try { in.close(); } catch (IOException e) {}
      if (out != null)
        try { out.close(); } catch (IOException e) {}
    }
 
-----Original Message-----
From: Henry Minsky [mailto:[EMAIL PROTECTED]
Sent: Wednesday, April 05, 2006 12:39 PM
To: William Krick
Cc: Benjamin Shine; Matt Hubbard; [email protected]
Subject: Re: [Laszlo-user] Using PHP to proxy content

That is handy.. there is an issue if the data source for the  XML is not using an encoding of UTF-8, of course.


You could either forward the data as a byte stream, or else try to parse out the
encoding  in the <?xml ...?> declaration and convert it to UTF-8, which would be doing a favor for clients that
don't have a wide range of charset encodings that they understand. I found that emprically the Flash player seems to have a lot fewer encodings it understands than does the Java VM we are using on the server.

The LPS server proxy attempts to read the encoding from the XML declaration, but there have been some bugs reported recently from Chinese users, so that functionality needs to be have more unit testing written for it at some point.

As of release 3.2, the LPS server proxies XML as text data, rather than encoding it as swf (the Flash XML parser is finally fast enough, and the server code is a lot easier to maintain). The LPS server wraps the data inside an XML wrapper which contains HTTP header data. I have been working in my spare time on making an optimization to the server which would notice whether the app is requesting HTTP header info, and if it does not, to just proxy the XML data as a byte stream. That would improve throughput because the server would have to do the very minimum scanning and string manipulation of the data as it flows by.







On 4/5/06, William Krick <[EMAIL PROTECTED]> wrote:
I don't know if this is useful in this case or not but it's possible to wrap
a call to a URL on a different server in a local JSP like this example
"getdata.jsp" that I use for calling a web service that returns XML...

<%
  try {
    String urlstring = "http://www.domain.com/webapp/getxmldata";
    URL url = "" URL(urlstring);
    URLConnection con = url.openConnection();
    BufferedReader br = new BufferedReader(new
InputStreamReader(con.getInputStream()));
    String line = "";
    while ((line = br.readLine()) != null)
      out.println(line);
    br.close();
  }
  catch (Exception e) {
    // handle exceptions here
  }
%>
<[EMAIL PROTECTED] import="java.io.*"%>
<[EMAIL PROTECTED] import="java.net.*"%>
<[EMAIL PROTECTED] contentType="text/xml; charset=UTF-8" %>



...You can also relay parameters by using request.getQueryString() for GET
requests or request.getParameter() for POST requests to get at the data.

And if you really want to get fancy, you could "genericize" the whole thing
by passing the URL to call as the first parameter, followed by the
parameters to relay.

Note that you have to put the "import" and whatnot at the bottom when
dealing with XML otherwise they cause newlines to appear at the beginning of
the output which breaks stuff since the <xml> directive isn't the first line
in the document.



-----Original Message-----
From: Benjamin Shine [mailto:[EMAIL PROTECTED] ]
Sent: Wednesday, April 05, 2006 11:53 AM
To: Matt Hubbard
Cc: [email protected]
Subject: Re: [Laszlo-user] Using PHP to proxy content


This sounds like a crossdomain.xml problem. Flash doesn't let you
load content from another domain than the one that served up the swf
unless the other domain has crossdomain.xml on it and includes your
domain in the list of allowed domains.
In this example, you own example.com, right? So you could put your
own crossdomain.xml on it, which should take care of it.

-ben

On Apr 5, 2006, at 5:37 AM, Matt Hubbard wrote:

> Hello,
>
> My environment:
> Linux
> lps-3.1.1
> Flash 7 plugin
> SOLO deployment
>
> I am attempting to proxy an swf from another domain into an openlaszlo
> text view using a server-side proxy written in php.  In lzx I create a
> URL to that points to the proxy script passing several parameters
> (session id, action to be executed, and a urlencoded filename).
>
> var asset = '<img src=""/>';
>
> Then I add the resulting <img> tag to a text view called content:
>
> content.addText(asset);
>
> I don't get an error, but nothing shows up.  If I write  the asset var
> to the Debugger it reads correctly and if I visit that same url
> with my
> browser directly it returns and plays the animation just fine, so I
> think the php works.  I notice that if I change my proxy call from:
>
> http://www.example.com/proxy.php?x=y&a=b
>
> to
>
> http://www.example.com/proxy.swf
> (here proxy.swf is my php proxy script with a hardcoded url to
> retrieve
> )
>
> Suddenly it works.  However, I need to be able to pass the resource to
> retrieve to the proxy.  Can anyone shed some light on what I need
> to do
> to get the text view to recognize my url as a call for flash?
>
> Many thanks,
>
> Matt Hubbard
>
>
>
>
> _______________________________________________
> Laszlo-user mailing list
> [email protected]
> http://www.openlaszlo.org/mailman/listinfo/laszlo-user

benjamin shine
software engineer
[EMAIL PROTECTED]



_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user


_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user



--
Henry Minsky
Software Architect
[EMAIL PROTECTED]

_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user

Reply via email to