public abstract class RequestHandler extends Object
Modifier and Type | Class and Description |
---|---|
static class |
RequestHandler.RawURLParseRequestHandler |
static class |
RequestHandler.RequestHandlerBadRequestException |
static class |
RequestHandler.RequestHandlerErrorException |
static class |
RequestHandler.RequestHandlerException |
static class |
RequestHandler.RequestHandlerForbiddenException |
Modifier and Type | Field and Description |
---|---|
protected Map<String,String> |
args
The GET request arguments
|
protected String |
content
default response
|
protected String |
contentType
default content type
|
static boolean |
globalConfirmationDefault |
static String |
globalConfirmationKey |
static boolean |
loadInNewLayerDefault |
static String |
loadInNewLayerKey |
protected String |
myCommand
will be filled with the command assigned to the subclass
|
protected String |
request
The request URL without "GET".
|
protected String |
sender
who sent the request?
the host from referer header or IP of request sender
|
Constructor and Description |
---|
RequestHandler() |
Modifier and Type | Method and Description |
---|---|
(package private) void |
checkMandatoryParams() |
void |
checkPermission()
Check permissions in preferences and display error message or ask for permission.
|
String |
getContent() |
String |
getContentType() |
abstract String[] |
getMandatoryParams() |
String[] |
getOptionalParams() |
abstract String |
getPermissionMessage()
Get a specific message to ask the user for permission for the operation
requested via remote control.
|
abstract PermissionPrefWithDefault |
getPermissionPref()
Get a PermissionPref object containing the name of a special permission
preference to individually allow the requested operation and an error
message to be displayed when a disabled operation is requested.
|
(package private) static Map<String,String> |
getRequestParameter(URI uri)
Returns the request parameters.
|
String |
getUsage() |
String[] |
getUsageExamples() |
String[] |
getUsageExamples(String cmd)
Returns usage examples for the given command.
|
void |
handle()
Check permission and parameters and handle request.
|
protected abstract void |
handleRequest()
Handle a specific command sent as remote control.
|
protected boolean |
isLoadInNewLayer() |
protected void |
parseArgs()
Parse the request parameters as key=value pairs.
|
void |
setCommand(String command)
Save command associated with this handler.
|
void |
setSender(String sender) |
void |
setUrl(String url)
Set request URL and parse args.
|
protected abstract void |
validateRequest()
Validates the request before attempting to perform it.
|
public static final String globalConfirmationKey
public static final boolean globalConfirmationDefault
public static final String loadInNewLayerKey
public static final boolean loadInNewLayerDefault
protected String contentType
public RequestHandler()
public final void handle() throws RequestHandler.RequestHandlerForbiddenException, RequestHandler.RequestHandlerBadRequestException, RequestHandler.RequestHandlerErrorException
RequestHandler.RequestHandlerForbiddenException
- if request is forbidden by preferencesRequestHandler.RequestHandlerBadRequestException
- if request is invalidRequestHandler.RequestHandlerErrorException
- if an error occurs while processing requestprotected abstract void validateRequest() throws RequestHandler.RequestHandlerBadRequestException
RequestHandler.RequestHandlerBadRequestException
- if request is invalidprotected abstract void handleRequest() throws RequestHandler.RequestHandlerErrorException, RequestHandler.RequestHandlerBadRequestException
RequestHandler.RequestHandlerErrorException
- if an error occurs while processing requestRequestHandler.RequestHandlerBadRequestException
- if request is invalidpublic abstract String getPermissionMessage()
public abstract PermissionPrefWithDefault getPermissionPref()
public abstract String[] getMandatoryParams()
public String[] getOptionalParams()
public String[] getUsageExamples()
public String[] getUsageExamples(String cmd)
cmd
- The command askedpublic final void checkPermission() throws RequestHandler.RequestHandlerForbiddenException
RequestHandler.RequestHandlerForbiddenException
- if request is forbidden by preferencespublic void setUrl(String url)
url
- The request URL.protected void parseArgs()
this.args
.
Can be overridden by subclass.static Map<String,String> getRequestParameter(URI uri)
uri
- URI as stringvoid checkMandatoryParams() throws RequestHandler.RequestHandlerBadRequestException
public void setCommand(String command)
command
- The command.public String getContent()
public String getContentType()
protected boolean isLoadInNewLayer()