annotate content/Java/jetty-as-proxy.md @ 24:a8c68c6bbf9c

new blog post
author Dirk Olmes <dirk@xanthippe.ping.de>
date Fri, 24 Jan 2014 03:15:15 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24
a8c68c6bbf9c new blog post
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
1 Title: Proxying requests with Jetty
a8c68c6bbf9c new blog post
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
2 Date: 2014-01-24
a8c68c6bbf9c new blog post
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
3 Tags: Jetty
a8c68c6bbf9c new blog post
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
4 Lang: en
a8c68c6bbf9c new blog post
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
5
a8c68c6bbf9c new blog post
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
6 At 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.
a8c68c6bbf9c new blog post
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
7
a8c68c6bbf9c new blog post
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
8 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](http://en.wikipedia.org/wiki/Same-origin_policy) quickly.
a8c68c6bbf9c new blog post
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
9
a8c68c6bbf9c new blog post
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
10 For the deployment setup we mess around with [Apache](http://httpd.apache.org)'s [mod_proxy](http://httpd.apache.org/docs/2.2/mod/mod_proxy.html). This works but is not really manageable for our development machines.
a8c68c6bbf9c new blog post
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
11
a8c68c6bbf9c new blog post
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
12 For development I wrote a couple of simple servlets that accept the request, use the JDK's [HttpURLConnection](http://docs.oracle.com/javase/7/docs/api/java/net/HttpURLConnection.html) to retrieve the content from the VM and pass the resuld back. While this works it was really ugly code.
a8c68c6bbf9c new blog post
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
13
a8c68c6bbf9c new blog post
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
14 A bit of googling came up with Jetty's [ProxyServlet](http://www.eclipse.org/jetty/documentation/current/proxy-servlet.html) which looked promising. The real time saver was [Alan Hohn's blog post](http://blog.anvard.org/articles/2013/10/06/jetty-proxy-servlet.html) 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!