Package sunlabs.brazil.handler
Class ProxyPropertiesHandler
- java.lang.Object
-
- sunlabs.brazil.handler.GenericProxyHandler
-
- sunlabs.brazil.handler.ProxyPropertiesHandler
-
- All Implemented Interfaces:
Handler
public class ProxyPropertiesHandler extends GenericProxyHandler implements Handler
Obtain properties format content from remote websites, and add it to the current request properties. Many of the handlers are designed to produce side effects, by inserting values into the request properties (seePropertiesHandler
). If they are instead configured to produce the properties in java properties format, then this handler will read their output, and place the result in the request object on their behalf. This capability allows certain handlers to be run on other web sites, yet behave as if they are in the handler chain. The following request properties are used:- type
- The document type for files to process as java properties (defaults to text/plain)
- prepend
- The prefix that should be prepended to each property before it is inserted into the request properties
- url
- The url that should be used to fetch the remote content. If not specified, the curent url is used instead. Any ${...} constructs in the url are evaluated at each request.
- Version:
- 2.2, 04/08/30
- Author:
- Stephen Uhler
-
-
Field Summary
-
Fields inherited from class sunlabs.brazil.handler.GenericProxyHandler
host, HOST, mapper, NL, noErrorReturn, passHost, port, PORT, prefix, PREFIX, PROXY_HOST, PROXY_PORT, proxyHost, proxyPort, requestPrefix, tokens, urlPrefix
-
-
Constructor Summary
Constructors Constructor Description ProxyPropertiesHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
init(Server server, java.lang.String prefix)
Do one-time setup.byte[]
modifyContent(Request request, byte[] content)
Rewrite the links in an html file so they resolve correctly in proxy mode.boolean
respond(Request request)
If this is one of "our" url's, fetch the document from the destination server, and return it as if it was local.protected boolean
shouldFilter(MimeHeaders headers)
See if the content needs to be filtered Return "true" if "modifyContent" should be called-
Methods inherited from class sunlabs.brazil.handler.GenericProxyHandler
getMapper, isMine
-
-
-
-
Method Detail
-
init
public boolean init(Server server, java.lang.String prefix)
Description copied from class:GenericProxyHandler
Do one-time setup. get and process the handler properties. we can contact the server identified by the host parameter.- Specified by:
init
in interfaceHandler
- Overrides:
init
in classGenericProxyHandler
- Parameters:
server
- The HTTP server that created thisHandler
. TypicalHandler
s will useServer.props
to obtain run-time configuration information.prefix
- The handlers name. The string thisHandler
may prepend to all of the keys that it uses to extract configuration information fromServer.props
. This is set (by theServer
andChainHandler
) to help avoid configuration parameter namespace collisions.- Returns:
true
if thisHandler
initialized successfully,false
otherwise. Iffalse
is returned, thisHandler
should not be used.
-
respond
public boolean respond(Request request) throws java.io.IOException
Description copied from class:GenericProxyHandler
If this is one of "our" url's, fetch the document from the destination server, and return it as if it was local.- Specified by:
respond
in interfaceHandler
- Overrides:
respond
in classGenericProxyHandler
- Parameters:
request
- TheRequest
object that represents the HTTP request.- Returns:
true
if the request was handled. A request was handled if a response was supplied to the client, typically by callingRequest.sendResponse()
orRequest.sendError
.- Throws:
java.io.IOException
- if there was an I/O error while sending the response to the client. Typically, in that case, theServer
will (try to) send an error message to the client and then close the client's connection.The
IOException
should not be used to silently ignore problems such as being unable to access some server-side resource (for example getting aFileNotFoundException
due to not being able to open a file). In that case, theHandler
's duty is to turn thatIOException
into a HTTP response indicating, in this case, that a file could not be found.
-
shouldFilter
protected boolean shouldFilter(MimeHeaders headers)
See if the content needs to be filtered Return "true" if "modifyContent" should be called- Overrides:
shouldFilter
in classGenericProxyHandler
- Parameters:
headers
- mime headers for data to proxy
-
modifyContent
public byte[] modifyContent(Request request, byte[] content)
Description copied from class:GenericProxyHandler
Rewrite the links in an html file so they resolve correctly in proxy mode.- Overrides:
modifyContent
in classGenericProxyHandler
- Parameters:
request
- The original request to this "proxy"- Returns:
- true if the headers and content should be sent to the client, false otherwise Modifies "headers" as a side effect
-
-