public class HttpRequestHandler extends Object
com.sun.net.httpserver.HttpServer
.Constructor and Description |
---|
HttpRequestHandler(Configuration pConfig,
BackendManager pBackendManager,
LogHandler pLogHandler)
Request handler for parsing HTTP request and dispatching to the appropriate
request handler (with help of the backend manager)
|
Modifier and Type | Method and Description |
---|---|
void |
checkAccess(String pHost,
String pAddress,
String pOrigin)
Check whether the given host and/or address is allowed to access this agent.
|
String |
extractCorsOrigin(String pOrigin)
Check whether for the given host is a cross-browser request allowed.
|
JSONObject |
getErrorJSON(int pErrorCode,
Throwable pExp,
JmxRequest pJmxReq)
Get the JSON representation for a an exception
|
Map<String,String> |
handleCorsPreflightRequest(String pOrigin,
String pRequestHeaders)
Handling an option request which is used for preflight checks before a CORS based browser request is
sent (for certain circumstances).
|
JSONAware |
handleGetRequest(String pUri,
String pPathInfo,
Map<String,String[]> pParameterMap)
Handle a GET request
|
JSONAware |
handlePostRequest(String pUri,
InputStream pInputStream,
String pEncoding,
Map<String,String[]> pParameterMap)
Handle the input stream as given by a POST request
|
JSONObject |
handleThrowable(Throwable pThrowable)
Utility method for handling single runtime exceptions and errors.
|
public HttpRequestHandler(Configuration pConfig, BackendManager pBackendManager, LogHandler pLogHandler)
pBackendManager
- backend manager to userpLogHandler
- log handler to where to put out loggingpublic JSONAware handleGetRequest(String pUri, String pPathInfo, Map<String,String[]> pParameterMap)
pUri
- URI leading to this requestpPathInfo
- path of the requestpParameterMap
- parameters of the GET request @return the responsepublic JSONAware handlePostRequest(String pUri, InputStream pInputStream, String pEncoding, Map<String,String[]> pParameterMap) throws IOException
pUri
- URI leading to this requestpInputStream
- input stream of the post requestpEncoding
- optional encoding for the stream. If null, the default encoding is usedpParameterMap
- additional processing parametersJmxRequest
contained
within the answer.IOException
- if reading from the input stream failspublic Map<String,String> handleCorsPreflightRequest(String pOrigin, String pRequestHeaders)
pOrigin
- the origin to check. If null
, no headers are returnedpRequestHeaders
- extra headers to check againstpublic JSONObject handleThrowable(Throwable pThrowable)
executeRequest(JmxRequest)
to catch additional errors.
They are two different methods because of bulk requests, where each individual request can
lead to an error. So, each individual request is wrapped with the error handling of
executeRequest(JmxRequest)
whereas the overall handling is wrapped with this method. It is hence more coarse grained,
leading typically to an status code of 500.
Summary: This method should be used as last security belt is some exception should escape
from a single request processing in executeRequest(JmxRequest)
.pThrowable
- exception to handlepublic JSONObject getErrorJSON(int pErrorCode, Throwable pExp, JmxRequest pJmxReq)
pErrorCode
- the HTTP error code to returnpExp
- the exception or error occuredpJmxReq
- request from where to get processing optionspublic void checkAccess(String pHost, String pAddress, String pOrigin)
pHost
- host to checkpAddress
- address to checkpOrigin
- (optional) origin header to check also.public String extractCorsOrigin(String pOrigin)
pOrigin
- the origin URL to check againstCopyright © 2018. All rights reserved.