Subscribe

  • Subscribe  

Use JSP Page to Bypass Crossdomain File for Flex

Posted by Charles | February 22, 2008 .

When you write a Flex application or any application in Flash or Actionscript, and when you are accessing remote hosts for services you have no control of, then you find out there is no cross domain file and Flex app will bump. What you can do?

By the way, the cross domain file is to allow a server to give access to a Flash based application that is originated from different server. You will run into this situation when you are doing mashup. So, here is a help.

Marco Casario at RIAvolutionize wrote a post that utilizing a JSP as a proxy to give your Flash based application an access to other services. Of cause, with his solution, you need to have an access to a server that runs a JEE application server so that this JSP can be deployed there.

The main logic in the JSP file is like this:

url = new URL(contentURL);
URLConnection urlConn = url.openConnection();
// show the client the content type:
String contentType = urlConn.getContentType();
response.setContentType(contentType);
// get the input stream
InputStream in = urlConn.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
char[] buffer = new char[1024];
String contentString = "";
String tmp = br.readLine();
 
do
{
   contentString += tmp + "\n";
   tmp = br.readLine();
}
while (tmp != null);
   out.flush();
   out.close();
}

Where, the contentURL is the service URL passed in.

Then at the Flex application you define the HTTPConnection like this:

<mx:HTTPService id="myHS"
   url="http://the.jspurl.com/proxy.jsp"
   method="GET"?
   result="aFunction()">
   <mx:request xmlns="">
      <url>{myURL}</url>
   </mx:request>
</mx:HTTPService>

That’s it.

Leave a Comment

If you would like to make a comment, please fill out the form below.


Name

Email

Website

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Comments

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word


Related Posts

3 Comments so far
  1. Beadle Fox  February 22, 2008 9:19 am

    Great– let’s just throw anonymous and open proxies all over the place without even posting a caveat about the security implications of this. I’m sure the rogue individuals out there will have a blast downloading porn and copyrighted content from your open proxy in production. Maybe after a while you’ll even start scratching your head as to why your bandwidth is nearly non-existent.

    If you’re going to post a tip like this, at least show some responsibility and encourage people to require authentication and/or explicitly limit what URL(s) the proxy can get to!

    Beadle

  2. Charles  February 22, 2008 10:29 am

    Beadle,
    I agree with you about the social responsibility when dealing with technologies. But that’s a hard nut to crack because it’s a complicate issue. Even anonymous proxy can be used in a noble way such as by pass government imposed blockages online in other side of the world. So, I’ll leave that to a social focused blog. Here just for some bits and bytes.

    Charles

  3. Tom Van den Eynde  February 23, 2008 1:29 am

    Other detail: all traffic has to go through your own site which probably ruines your business case if you’re talking about a high-volume website.

<

Direct TV Offers - usdirect has the best directtv deals