예제 #1
0
 @Test
 public void simpleGetWithQueryPath() {
   Map<String, String> params = new HashMap<String, String>();
   params.put("p", "list/java.lang/type=Memory");
   JmxListRequest req =
       JmxRequestFactory.createGetRequest(
           null, new Configuration().getProcessingParameters(params));
   assert req.getHttpMethod() == HttpMethod.GET : "GET by default";
   assert req.getPath().equals("java.lang/type=Memory") : "Path extracted";
 }
예제 #2
0
 /**
  * OPTION requests are treated as CORS preflight requests
  *
  * @param req the original request
  * @param resp the response the answer are written to
  */
 @Override
 protected void doOptions(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   Map<String, String> responseHeaders =
       requestHandler.handleCorsPreflightRequest(
           req.getHeader("Origin"), req.getHeader("Access-Control-Request-Headers"));
   for (Map.Entry<String, String> entry : responseHeaders.entrySet()) {
     resp.setHeader(entry.getKey(), entry.getValue());
   }
 }
예제 #3
0
  /**
   * Constructor used for {@link HttpMethod#POST} requests, which receive a JSON payload.
   *
   * @param pMap map containing requests parameters
   * @param pInitParams optional processing parameters (obtained as query parameters or from within
   *     the JSON request)
   */
  public JmxRequest(Map<String, ?> pMap, ProcessingParameters pInitParams) {
    this(
        RequestType.getTypeByName((String) pMap.get("type")),
        HttpMethod.POST,
        EscapeUtil.parsePath((String) pMap.get("path")),
        pInitParams);

    Map target = (Map) pMap.get("target");
    if (target != null) {
      targetConfig = new ProxyTargetConfig(target);
    }
  }
예제 #4
0
 // Get parameter map either directly from an Servlet 2.4 compliant implementation
 // or by looking it up explictely (thanks to codewax for the patch)
 private Map<String, String[]> getParameterMap(HttpServletRequest pReq) {
   try {
     // Servlet 2.4 API
     return pReq.getParameterMap();
   } catch (UnsupportedOperationException exp) {
     // Thrown by 'pseudo' 2.4 Servlet API implementations which fake a 2.4 API
     // As a service for the parameter map is build up explicitely
     Map<String, String[]> ret = new HashMap<String, String[]>();
     Enumeration params = pReq.getParameterNames();
     while (params.hasMoreElements()) {
       String param = (String) params.nextElement();
       ret.put(param, pReq.getParameterValues(param));
     }
     return ret;
   }
 }
예제 #5
0
 @Test
 public void simplePostWithMergedMaps() {
   Map config = new HashMap();
   config.put("maxDepth", "10");
   Map<String, Object> reqMap =
       createMap(
           "type", "read",
           "mbean", "java.lang:type=Memory",
           "attribute", "HeapMemoryUsage",
           "config", config);
   Map param = new HashMap();
   ;
   param.put("maxObjects", "100");
   JmxReadRequest req =
       (JmxReadRequest)
           JmxRequestFactory.createPostRequest(
               reqMap, new Configuration().getProcessingParameters(param));
   assertEquals(req.getAttributeName(), "HeapMemoryUsage");
   assertEquals(req.getParameter(ConfigKey.MAX_DEPTH), "10");
   assertEquals(req.getParameterAsInt(ConfigKey.MAX_OBJECTS), 100);
 }