org.clazzes.util.http
public class ReverseProxyServlet extends javax.servlet.GenericServlet
A servlet, which acts as a reverse proxy.
The following example shows how to use the servlet inside a
web.xml
configuration:
<servlet> <servlet-name>proxy-gwt-jaas-login-service</servlet-name> <servlet-class>org.clazzes.util.http.ReverseProxyServlet</servlet-class> <init-param> <param-name>targetUrl</param-name> <param-value>http://127.0.0.1:8081/gwt-jaas-login-service</param-value> </init-param> </servlet> <servlet> <servlet-name>proxy-gwt-jaas-login-service-star</servlet-name> <servlet-class>org.clazzes.util.http.ReverseProxyServlet</servlet-class> <init-param> <param-name>targetUrl</param-name> <param-value>http://127.0.0.1:8081/gwt-jaas-login-service/</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>proxy-gwt-jaas-login-service</servlet-name> <url-pattern>/gwt-jaas-login-service</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>proxy-gwt-jaas-login-service-star</servlet-name> <url-pattern>/gwt-jaas-login-service/*</url-pattern> </servlet-mapping>
Inside OGSi-containers the servlet might be configured using property tags for
the setters setConnectTimeout(int)
, setReadTimeout(int)
,
setTargetUrl(URL)
, setRewriteLocations(boolean)
and setStreamHandlerFactory(URLStreamHandlerFactory)
. The only
mandatory property is the target URL.
Constructor and Description |
---|
ReverseProxyServlet() |
Modifier and Type | Method and Description |
---|---|
void |
destroy() |
int |
getConnectTimeout() |
int |
getReadTimeout() |
String |
getServletInfo() |
URLStreamHandlerFactory |
getStreamHandlerFactory() |
URL |
getTargetUrl() |
void |
init() |
boolean |
isRewriteLocations() |
protected HttpURLConnection |
pullConnection(Long id) |
protected Long |
pushConnection(HttpURLConnection conn) |
void |
service(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse res) |
void |
setConnectTimeout(int connectTimeout) |
void |
setReadTimeout(int readTimeout) |
void |
setRewriteLocations(boolean rewriteLocations) |
void |
setStreamHandlerFactory(URLStreamHandlerFactory streamHandlerFactory) |
void |
setTargetUrl(URL targetUrl) |
protected Long pushConnection(HttpURLConnection conn)
protected HttpURLConnection pullConnection(Long id)
public void init() throws javax.servlet.ServletException
init
in class javax.servlet.GenericServlet
javax.servlet.ServletException
public void service(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res) throws javax.servlet.ServletException, IOException
service
in interface javax.servlet.Servlet
service
in class javax.servlet.GenericServlet
javax.servlet.ServletException
IOException
public String getServletInfo()
getServletInfo
in interface javax.servlet.Servlet
getServletInfo
in class javax.servlet.GenericServlet
public void destroy()
destroy
in interface javax.servlet.Servlet
destroy
in class javax.servlet.GenericServlet
public URL getTargetUrl()
public void setTargetUrl(URL targetUrl)
targetUrl
- The target URL under which all requests to the base URL
of this servlet are mapped to set.public int getReadTimeout()
public void setReadTimeout(int readTimeout)
readTimeout
- The read timeout for proxy connections
in milliseconds to set. The default value is
60000
.public int getConnectTimeout()
public void setConnectTimeout(int connectTimeout)
connectTimeout
- The connect timeout for proxy connections
in milliseconds to set. The default value is
5000
.public URLStreamHandlerFactory getStreamHandlerFactory()
null
, if the
built-in factory should be used.public void setStreamHandlerFactory(URLStreamHandlerFactory streamHandlerFactory)
streamHandlerFactory
- A custom stream handler factory to set or
null
, if the built-in factory should be used.public boolean isRewriteLocations()
Location
headers returned from
upstream, which are a sub-URL of getTargetUrl()
.public void setRewriteLocations(boolean rewriteLocations)
rewriteLocations
- Set, Whether Location-rewriting is active.Copyright © 2013 Clazzes.org. All Rights Reserved.