Configuring Jetty Servlet Proxy

Sample application can be downloaded from here

Lets say you deploy app1, app2, someotherapp to devhost:3000 and testhost:3000 then those apps can be accessed as follows

DEV instances

http://devhost:3000/app1

http://devhost:3000/app2

http://devhost:3000/someotherapp

TEST instances

http://testhost:3000/app1

http://testhost:3000/app2

http://testhost:3000/someotherapp

Many a times one application depends upon other applications with in the same server and hence, your application may contain code snippets as follows

<link title="Stylesheet" href="/someotherapp/style.css" rel="stylesheet" media="screen" type="text/css" />

further those can be directly accessed as well

http://devhost:3000/someotherapp/style.css

http://testhost:3000/someotherapp/style.css

Further Jetty is the best choice for local development either embedded or using jetty-maven-plugin

In this case it does not make sense to replicate the entire environment locally, instead those urls can be proxied in local environment such that /someotherapp/style.css would be proxied to http://devhost:3000/someotherapp/style.css

Here is how you can achieve it.

1) Map ProxyServlet.Transparent to /someotherapp/*
2) Set the Servlet init parameters as follows
ProxyTo ==> http://devhost:3000/someotherapp
Prefix ==> /someotherapp

The above two steps can be done in two ways

Configuring using Java

Configuring using maven jetty plugin

<plugin>
	<groupId>org.mortbay.jetty</groupId>
	<artifactId>jetty-maven-plugin</artifactId>
	<version>${jetty.version}</version>
	<configuration>
		<webAppConfig>
			<contextPath>/webApp</contextPath>
		</webAppConfig>
		<jettyConfig>src/main/etc/jetty.xml</jettyConfig>
		<connectors>
			<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
				<port>8080</port>
				<maxIdleTime>3600000</maxIdleTime>
			</connector>						
		</connectors>
	</configuration>
	<dependencies>
		<dependency>
			<groupId>org.eclipse.jetty.aggregate</groupId>
			<artifactId>jetty-all-server</artifactId>
			<version>${jetty.version}</version>
		</dependency>
	</dependencies>
</plugin>

src/main/etc/jetty.xml