Package dk.netarkivet.viewerproxy
Class CommandResolver
- java.lang.Object
-
- dk.netarkivet.viewerproxy.CommandResolver
-
- All Implemented Interfaces:
URIResolver
,URIResolverHandler
- Direct Known Subclasses:
GetDataResolver
,HTTPControllerServer
,UnknownCommandResolver
public abstract class CommandResolver extends Object implements URIResolverHandler, URIResolver
An abstract superclass for URIResolvers that handle commands given to the server host (http://<>/< >/<>=< >*).
-
-
Field Summary
Fields Modifier and Type Field Description protected URIResolver
ur
The URI resolver which is wrapped, and which handles all non-command URIs.static String
VIEWERPROXY_COMMAND_NAME
Fake host used as hostname when doing commands.-
Fields inherited from interface dk.netarkivet.viewerproxy.URIResolver
NOT_FOUND
-
-
Constructor Summary
Constructors Constructor Description CommandResolver(URIResolver ur)
Constructor which sets the next resolver in the chain.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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 anUr)
Change the URI resolver which handles URIs that we don't handle here.
-
-
-
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 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 anUr)
Change the URI resolver which handles URIs that we don't handle here.- Specified by:
setURIResolver
in interfaceURIResolverHandler
- Parameters:
anUr
- 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 interfaceURIResolver
- Parameters:
request
- The HTTP request we are working onresponse
- 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 checkresponse
- 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.
-
-