Proxying requests with Jetty
24.01.2014 by Dirk OlmesAt work we develop a web based software for the automotive industry. On the server side we embed Jetty as HTTP server and Servlet engine. It’s easy to configure in code and performs very well.
Recently, we had to integrate a third party solution which comes as a virtual machine. This solution consists of some JavaScript APIs that need to talk to the VM. This setup gets you into problems with the same origin policy quickly.
For the deployment setup we mess around with Apache‘s mod_proxy. This works but is not really manageable for our development machines.
For development I wrote a couple of simple servlets that accept the request, use the JDK’s HttpURLConnection to retrieve the content from the VM and pass the resuld back. While this works it was really ugly code.
A bit of googling came up with Jetty’s ProxyServlet which looked promising. The real time saver was Alan Hohn’s blog post about how to use the proxy servlet. It allowed me to throw away all of our custom servlets and replace them with a single three-liner. Thanks, man!
Comments
There are no comments yet.