Class HttpRequestHandler

java.lang.Object
org.jolokia.server.core.http.HttpRequestHandler

public class HttpRequestHandler extends Object
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 Details

    • PATH_QUERY_PARAM

      public static final String PATH_QUERY_PARAM
      Alternative query parameter for providing path info.
      See Also:
  • Constructor Details

    • HttpRequestHandler

      public HttpRequestHandler(JolokiaContext pJolokiaCtx)
      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 EmptyResponseException
      Handle a GET request
      Parameters:
      pUri - URI leading to this request
      pPathInfo - path of the request
      pParameterMap - 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, EmptyResponseException
      Handle the input stream as given by a POST request
      Parameters:
      pUri - URI leading to this request
      pInputStream - input stream of the post request
      pEncoding - optional encoding for the stream. If null, the default encoding is used
      pParameterMap - additional processing parameters
      Returns:
      the JSON object containing the json results for one or more JolokiaRequest contained within the answer.
      Throws:
      IOException - if reading from the input stream fails
      EmptyResponseException
    • handleCorsPreflightRequest

      public 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).

      See the CORS specification (section 'preflight checks') for more details.

      Parameters:
      pOrigin - the origin to check. If null, no headers are returned
      pRequestHeaders - extra headers to check against
      Returns:
      headers to set
    • handleThrowable

      public org.json.simple.JSONObject handleThrowable(Throwable pThrowable)
      Utility method for handling single runtime exceptions and errors. This method is called in addition to and after executeRequest(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 of executeRequest(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 return
      pExp - the exception or error occured
      pJmxReq - request from where to get processing options
      Returns:
      the json representation
    • checkAccess

      public void checkAccess(String pRequestScheme, String pHost, String pAddress, String pOrigin)
      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 check
      pAddress - address to check
      pOrigin - (optional) origin header to check also.
    • extractCorsOrigin

      public String extractCorsOrigin(String pOrigin)
      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