Package org.jolokia.server.core.http
Class HttpRequestHandler
java.lang.Object
org.jolokia.server.core.http.HttpRequestHandler
Request handler with no dependency on the servlet API so that it can be used in
several different environments (like for the Sun JDK 11+
HttpServer).- Since:
- Mar 3, 2010
- Author:
- roland
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringAlternative query parameter for providing path info. -
Constructor Summary
ConstructorsConstructorDescriptionHttpRequestHandler(JolokiaContext pJolokiaCtx) Request handler for parsing HTTP request and dispatching to the appropriate request handler (with help of the backend manager) -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckAccess(String pRequestScheme, String pHost, String pAddress, String pOrigin) Check whether the given host and/or address is allowed to access this agent.extractCorsOrigin(String pOrigin) Check whether for the given host is a cross-browser request allowed.org.json.simple.JSONObjectgetErrorJSON(int pErrorCode, Throwable pExp, JolokiaRequest pJmxReq) Get the JSON representation for an exception.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).org.json.simple.JSONAwareHandle a GET requestorg.json.simple.JSONAwarehandlePostRequest(String pUri, InputStream pInputStream, String pEncoding, Map<String, String[]> pParameterMap) Handle the input stream as given by a POST requestorg.json.simple.JSONObjecthandleThrowable(Throwable pThrowable) Utility method for handling single runtime exceptions and errors.
-
Field Details
-
PATH_QUERY_PARAM
Alternative query parameter for providing path info.- See Also:
-
-
Constructor Details
-
HttpRequestHandler
Request handler for parsing HTTP request and dispatching to the appropriate request handler (with help of the backend manager)- Parameters:
pJolokiaCtx- jolokia context
-
-
Method Details
-
handleGetRequest
public org.json.simple.JSONAware handleGetRequest(String pUri, String pPathInfo, Map<String, String[]> pParameterMap) throws EmptyResponseExceptionHandle a GET request- Parameters:
pUri- URI leading to this requestpPathInfo- path of the requestpParameterMap- parameters of the GET request @return the response- Throws:
EmptyResponseException
-
handlePostRequest
public org.json.simple.JSONAware handlePostRequest(String pUri, InputStream pInputStream, String pEncoding, Map<String, String[]> pParameterMap) throws IOException, EmptyResponseExceptionHandle the input stream as given by a POST request- Parameters:
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 parameters- Returns:
- the JSON object containing the json results for one or more
JolokiaRequestcontained within the answer. - Throws:
IOException- if reading from the input stream failsEmptyResponseException
-
handleCorsPreflightRequest
Handling an option request which is used for preflight checks before a CORS based browser request is sent (for certain circumstances).See the CORS specification (section 'preflight checks') for more details.
- Parameters:
pOrigin- the origin to check. Ifnull, no headers are returnedpRequestHeaders- extra headers to check against- Returns:
- headers to set
-
handleThrowable
Utility method for handling single runtime exceptions and errors. This method is called in addition to and afterexecuteRequest(JolokiaRequest)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 ofexecuteRequest(JolokiaRequest)whereas the overall handling is wrapped with this method. It is hence more coarse grained, leading typically to a 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(JolokiaRequest).- Parameters:
pThrowable- exception to handle- Returns:
- its JSON representation
-
getErrorJSON
public org.json.simple.JSONObject getErrorJSON(int pErrorCode, Throwable pExp, JolokiaRequest pJmxReq) Get the JSON representation for an exception.- Parameters:
pErrorCode- the HTTP error code to returnpExp- the exception or error occuredpJmxReq- request from where to get processing options- Returns:
- the json representation
-
checkAccess
Check whether the given host and/or address is allowed to access this agent.- Parameters:
pRequestScheme- scheme used to make the request ('http' or 'https')pHost- host to checkpAddress- address to checkpOrigin- (optional) origin header to check also.
-
extractCorsOrigin
Check whether for the given host is a cross-browser request allowed. This check is delegated to the backendmanager which is responsible for the security configuration. Also, some sanity checks are applied.- Parameters:
pOrigin- the origin URL to check against- Returns:
- the origin to put in the response header or null if none is to be set
-