Friday, July 21st, 2006

A Java-based HTTP Proxy for Ajax

Category: Java, Programming

On the Java.net blog of Greg Murray, he demonstrates a method of creating a proxy client in Java for an XMLHttpRequest of your choice.

One drawback of working with AJAX is that an AJAX-based client cannot make calls to URLs outside of its domain, which means that it cannot access services located on another server. To overcome these problems, you need a generic proxy that can communicate with external services on your client’s behalf. The proxy passes a call from your client application to the service, receives the content in response from the service, and returns the content to your client. You can then use this content in your AJAX-based application.

With the brief explaination out of the way, Greg gets started with the code/application. First off, he includes a graphic (sequence diagram) to show how the flow of the application will go – in his example, a request to the geocoding interface at Yahoo. His framework of choice to work with is the Project jMaki proxy functionality.

Where the blog post gets a little sparse on the details, this doucmentation on the Project jMaki site provides the complete story – code and all. Check it out!

Posted by Chris Cornutt at 6:53 am
5 Comments

++---
2.6 rating from 41 votes

5 Comments »

Comments feed TrackBack URI

Hi Simon,

I realize that this could be an issue as if not configured correctly you could open yourself up to be a universal proxy to anyone. I have tried to address some strategies in the comments of the blog entry which matches closer to the URL you refer to. You could take the XmlHttpProxy a step further and provide a unique token to the rendered JavaScript as to prevent other web applicatons from using JSONP requests from other sites.

I plan to address these in the proxy in the next rev of the proxy. I be open to any other suggestions/advice that you have.

-Greg

Comment by Greg Murray — July 21, 2006

[…] Ajaxian » A Java-based HTTP Proxy for Ajax: couple this with a secure hash of some sort and you’ve got something interesting going. Very very interesting. […]

Pingback by Ajaxian » A Java-based HTTP Proxy for Ajax at blackrimglasses.com — July 21, 2006

There are, generally speaking, two kinds of Cross-Domain Proxy. The example here is a straight proxy that, as you say, is only useful in specialised situations, e.g. on a secure intranet. For most applications, they’ll want to use a more specialised, Facade/Mediator, style of proxy that offers only app-specific services.

Comment by Michael Mahemoff — July 22, 2006

I really dont understand why companies, schools, governments think they have the right to dicate what people do online, its essentially censorship and its wrong.

Comment by Web Proxy — September 25, 2007

Could this be done with a Java applet instead of a Java servlet? I’m trying to use AJAX within a compiled HTML help file but the peculiar protocol ms-help:// is causing “same origin policy” problems.

Comment by rsrobbins — December 12, 2007

Leave a comment

You must be logged in to post a comment.