dk.netarkivet.viewerproxy
Class CommandResolver

java.lang.Object
  extended by dk.netarkivet.viewerproxy.CommandResolver
All Implemented Interfaces:
URIResolver, URIResolverHandler
Direct Known Subclasses:
GetDataResolver, HTTPControllerServer, UnknownCommandResolver

public abstract class CommandResolver
extends java.lang.Object
implements URIResolverHandler, URIResolver

An abstract superclass for URIResolvers that handle commands given to the server host (http://<>/<>/<>=<>*


Field Summary
protected  URIResolver ur
          The URI resolver which is wrapped, and which handles all non-command URIs
static java.lang.String VIEWERPROXY_COMMAND_NAME
          Fake host used as hostname when doing commands.
 
Fields inherited from interface dk.netarkivet.viewerproxy.URIResolver
NOT_FOUND
 
Constructor Summary
CommandResolver(URIResolver ur)
          Constructor which sets the next resolver in the chain.
 
Method Summary
protected abstract  boolean executeCommand(Request request, Response response)
          Abstract method for parsing of the URL and delegating to relevant methods.
protected static boolean isCommandHostRequest(Request request)
          Returns true if the request specifies the host that we're running on.
 int lookup(Request request, Response response)
          Parses the given URI and executes commands for all command URLs.
 void setURIResolver(URIResolver ur)
          Change the URI resolver which handles URIs that we don't handle here.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ur

protected URIResolver ur
The URI resolver which is wrapped, and which handles all non-command URIs


VIEWERPROXY_COMMAND_NAME

public static final java.lang.String VIEWERPROXY_COMMAND_NAME
Fake host used as hostname when doing commands.

See Also:
Constant Field Values
Constructor Detail

CommandResolver

public CommandResolver(URIResolver ur)
Constructor which sets the next resolver in the chain.

Parameters:
ur - The URIResolver that handles URIs that are not handled by this resolver.
Method Detail

setURIResolver

public final void setURIResolver(URIResolver ur)
Change the URI resolver which handles URIs that we don't handle here.

Specified by:
setURIResolver in interface URIResolverHandler
Parameters:
ur - The URI resolver to handle unhandled URIs.
Throws:
ArgumentNotValid - if either argument is null.

lookup

public final int lookup(Request request,
                        Response response)
Parses the given URI and executes commands for all command URLs. The possible commands are of the form http://<>/<>?<>=<>* where command and param are defined in the subclass. If uri is none of these, the uri and response are forwarded to the wrapped URI resolver.

Specified by:
lookup in interface URIResolver
Parameters:
request - The HTTP request we are working on
response - HTTP response to generate effect on or to forward
Returns:
response code

executeCommand

protected abstract boolean executeCommand(Request request,
                                          Response response)
Abstract method for parsing of the URL and delegating to relevant methods. This should start by calling isCommandHostRequest.

Parameters:
request - The request to check
response - The response to give command results to if it is a command
Returns:
Whether this was a command URL

isCommandHostRequest

protected static boolean isCommandHostRequest(Request request)
Returns true if the request specifies the host that we're running on. Alternative specifications such as 'localhost' or '127.0.0.1' or an actual IP of this machine are not considered command hosts. Local hosts would only be command hosts if we happen to get a request from a browser running on this machine.

Parameters:
request - An HTTP request.
Returns:
True if the HTTP request specifies a URI that indicates this machine, false otherwise.