|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.faceless.util.HttpProxyServlet
public abstract class HttpProxyServlet
A generic HTTP proxy servlet, currently handling the GET method only. Requests are received by this servlet and passed on to a remote URL. The response from that URL may then be processed and passed back to the original client. The responses may optionally be cached internally by this servlet.
Overriders must implement the following methods:
The following headers are added to the proxied request, which may be checked for.
Also, the following headers may be set in the response to control the servlets behaviour
Finally the org.faceless.util.proxytimeout initialization parameter may be set to control the timeout in milliseconds for a proxy request. The default is 30000, or 30 seconds.
| Constructor Summary | |
|---|---|
HttpProxyServlet()
|
|
| Method Summary | |
|---|---|
void |
doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
|
void |
doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Currently the POST method is unimplemented, and returns a 405 error to the browser. |
abstract HttpRequestWriter |
getRequest(HttpRequestReader reader,
javax.servlet.http.HttpServletResponse response)
Create a request to be passed on by the proxy. |
abstract HttpResponseWriter |
getResponse(HttpResponseReader response)
Creates a response for the browser, based on the response received from the proxied request. |
void |
init()
|
| Methods inherited from class javax.servlet.http.HttpServlet |
|---|
service |
| Methods inherited from class javax.servlet.GenericServlet |
|---|
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public HttpProxyServlet()
| Method Detail |
|---|
public void init()
throws javax.servlet.ServletException
init in class javax.servlet.GenericServletjavax.servlet.ServletException
public void doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException,
IOException
doPost in class javax.servlet.http.HttpServletjavax.servlet.ServletException
IOException
public void doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException,
IOException
doGet in class javax.servlet.http.HttpServletjavax.servlet.ServletException
IOException
public abstract HttpResponseWriter getResponse(HttpResponseReader response)
throws javax.servlet.ServletException,
IOException
Creates a response for the browser, based on the response received from the proxied request.
Overriders need to implement this method to pass back a response to the client. At it's simplest, this method could do something like
public HttpResponseWriter getResponse(response)
{
return new HttpResponseWriter(response);
}
which would pass the response from the proxied request directly back
to the browser.
response - the response from the request specified by getRequest()
javax.servlet.ServletException
IOException
public abstract HttpRequestWriter getRequest(HttpRequestReader reader,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException,
IOException
Create a request to be passed on by the proxy.
Overriders need to implement this method to determine what the proxy should request. At the very least this method should probably contain the following stub, or something close to it:
public HttpRequestWriter getRequest(reader, response)
{
HttpRequestWriter writer = null;
if (isInvalidRequest(reader)) {
response.sendError(404, "Invalid request to this proxy");
} else {
writer = new HttpRequestWriter(reader);
writer.setURL("/path/to/proxy/request.html");
}
return writer;
}
If an error occurs, the method should handle the error message to the response and return null as you see here. If the setURL method isn't called an endless loop will result, so don't forget it.
reader - the incoming request to this proxyresponse - the outgoing response. Should only be written to if this method
is returning null due to an error.
javax.servlet.ServletException
IOException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||