コード例 #1
0
  // call the an appropriate request dispatcher
  private JSONObject callRequestDispatcher(JmxRequest pJmxReq)
      throws InstanceNotFoundException, AttributeNotFoundException, ReflectionException,
          MBeanException, IOException {
    Object retValue = null;
    boolean useValueWithPath = false;
    boolean found = false;
    for (RequestDispatcher dispatcher : requestDispatchers) {
      if (dispatcher.canHandle(pJmxReq)) {
        retValue = dispatcher.dispatchRequest(pJmxReq);
        useValueWithPath = dispatcher.useReturnValueWithPath(pJmxReq);
        found = true;
        break;
      }
    }
    if (!found) {
      throw new IllegalStateException(
          "Internal error: No dispatcher found for handling " + pJmxReq);
    }

    JsonConvertOptions opts = getJsonConvertOptions(pJmxReq);

    Object jsonResult =
        converters
            .getToJsonConverter()
            .convertToJson(retValue, useValueWithPath ? pJmxReq.getPathParts() : null, opts);

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("value", jsonResult);
    jsonObject.put("request", pJmxReq.toJSON());
    return jsonObject;
  }
コード例 #2
0
 private JsonConvertOptions getJsonConvertOptions(JmxRequest pJmxReq) {
   return convertOptionsBuilder
       .maxDepth(pJmxReq.getParameterAsInt(ConfigKey.MAX_DEPTH))
       .maxCollectionSize(pJmxReq.getParameterAsInt(ConfigKey.MAX_COLLECTION_SIZE))
       .maxObjects(pJmxReq.getParameterAsInt(ConfigKey.MAX_OBJECTS))
       .faultHandler(pJmxReq.getValueFaultHandler())
       .build();
 }
コード例 #3
0
ファイル: JmxRequestTest.java プロジェクト: kinow/jolokia
 private void verify(JmxRequest pReq, String pKey, String pValue) {
   JSONObject json = pReq.toJSON();
   assertEquals(json.get(pKey), pValue);
   String info = pReq.toString();
   if (pKey.equals("type")) {
     String val = pValue.substring(0, 1).toUpperCase() + pValue.substring(1);
     assertTrue(info.contains(val));
   } else {
     assertTrue(info.contains(pValue));
   }
 }