/** * Converter used by JsonMBean for converting from Object to JSON representation * * @param object object to serialize * @param pConvertOptions options used for conversion * @return serialized object */ String toJson(Object object, JsonConvertOptions pConvertOptions) { try { Object ret = converters.getToJsonConverter().convertToJson(object,null,pConvertOptions); return ret.toString(); } catch (AttributeNotFoundException exp) { // Cannot happen, since we dont use a path return ""; } }
/** * Convert a Throwable to a JSON object so that it can be included in an error response * * @param pExp throwable to convert * @param pJmxReq the request from where to take the serialization options * @return the exception. */ public Object convertExceptionToJson(Throwable pExp, JmxRequest pJmxReq) { JsonConvertOptions opts = getJsonConvertOptions(pJmxReq); try { JSONObject expObj = (JSONObject) converters.getToJsonConverter().convertToJson(pExp,null,opts); return expObj; } catch (AttributeNotFoundException e) { // Cannot happen, since we dont use a path return null; } }
private JSONObject callRequestDispatcher(JmxRequest pJmxReq) throws InstanceNotFoundException, AttributeNotFoundException, ReflectionException, MBeanException, IOException, NotChangedException { 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; }
converters.getToJsonConverter().setInnerValue(pCurrentValue, newValue, pathParts) };
/** * Converter used by JsonMBean for converting from Object to JSON representation * * @param object object to serialize * @param pConvertOptions options used for conversion * @return serialized object */ String toJson(Object object, JsonConvertOptions pConvertOptions) { try { Object ret = converters.getToJsonConverter().convertToJson(object,null,pConvertOptions); return ret.toString(); } catch (AttributeNotFoundException exp) { // Cannot happen, since we dont use a path return ""; } }
public static void writeObject(Converters converters, JsonConvertOptions options, PrintWriter out, Object data) { Object result = null; try { result = converters.getToJsonConverter().convertToJson(data, null, options); } catch (AttributeNotFoundException e) { LOG.warn("Failed to convert object to json", e); } if (result != null) { out.write(result.toString()); out.flush(); out.close(); } else { writeEmpty(out); } }
public static Object toJSON(Object value) throws OpenDataException { Object result = value; try { ObjectToJsonConverter converter = converters.getToJsonConverter(); result = converter.convertToJson(value, null, JsonConvertOptions.DEFAULT); } catch (RuntimeException rte) { throw rte; } catch (Exception ex) { OpenDataException odex = new OpenDataException("Cannot convert value: " + value.getClass().getName()); odex.initCause(ex); throw odex; } return result; }
public static Object toJSON(Object value) throws OpenDataException { Object result = value; try { ObjectToJsonConverter converter = converters.getToJsonConverter(); result = converter.convertToJson(value, null, JsonConvertOptions.DEFAULT); } catch (RuntimeException rte) { throw rte; } catch (Exception ex) { OpenDataException odex = new OpenDataException("Cannot convert value: " + value.getClass().getName()); odex.initCause(ex); throw odex; } return result; }
/** * Convert a Throwable to a JSON object so that it can be included in an error response * * @param pExp throwable to convert * @param pJmxReq the request from where to take the serialization options * @return the exception. */ public Object convertExceptionToJson(Throwable pExp, JmxRequest pJmxReq) { JsonConvertOptions opts = getJsonConvertOptions(pJmxReq); try { JSONObject expObj = (JSONObject) converters.getToJsonConverter().convertToJson(pExp,null,opts); return expObj; } catch (AttributeNotFoundException e) { // Cannot happen, since we dont use a path return null; } }
/** * Convert a Throwable to a JSON object so that it can be included in an error response * * @param pExp throwable to convert * @param pJmxReq the request from where to take the serialization options * @return the exception. */ public Object convertExceptionToJson(Throwable pExp, JmxRequest pJmxReq) { JsonConvertOptions opts = getJsonConvertOptions(pJmxReq); try { JSONObject expObj = (JSONObject) converters.getToJsonConverter().convertToJson(pExp,null,opts); return expObj; } catch (AttributeNotFoundException e) { // Cannot happen, since we dont use a path return null; } }
private JSONObject callRequestDispatcher(JmxRequest pJmxReq) throws InstanceNotFoundException, AttributeNotFoundException, ReflectionException, MBeanException, IOException, NotChangedException { 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; }
private JSONObject callRequestDispatcher(JmxRequest pJmxReq) throws InstanceNotFoundException, AttributeNotFoundException, ReflectionException, MBeanException, IOException, NotChangedException { 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; }
converters.getToJsonConverter().setInnerValue(pCurrentValue, newValue, pathParts) };
converters.getToJsonConverter().setInnerValue(pCurrentValue, newValue, pathParts) };