/** * Instantiates a new jSON response. */ public JSONResponse() { init(null, null, null); }
/** * Inits the. * * @param id * the id * @param result * the result * @param error * the error */ private void init(final JsonNode id, final Object result, final JSONRPCException error) { this.setRequest(false); setVersion(); setId(id); setResult(result); setError(error); }
final JSONRequest request, final RequestParams requestParams, final Authorizor auth) { final JSONResponse resp = new JSONResponse(request.getId(), null); try { final CallTuple tuple = NamespaceUtil.get(destination, resp.setResult(result); } catch (final JSONRPCException err) { resp.setError(err); } catch (final Throwable err) { final Throwable cause = err.getCause(); if (cause instanceof JSONRPCException) { resp.setError((JSONRPCException) cause); } else { if (err instanceof InvocationTargetException && cause != null) { getMessage(cause), cause); jsonError.setData(cause); resp.setError(jsonError); } else { LOG.log(Level.WARNING, getMessage(err), err); jsonError.setData(err); resp.setError(jsonError); if (resp.getId() == null || resp.getId().isNull()) { return null; } else {
if (callback != null) { final JSONResponse response = (JSONResponse) jsonMsg; final JSONRPCException error = response.getError(); if (error != null) { callback.onFailure(error); LOG.log(Level.WARNING, "Exception in receiving message", jsonError); if (id != null){ final JSONResponse response = new JSONResponse(jsonError); response.setId(id); return response;
/** * Invoke a method on an object. * * @param destination * the destination * @param request * A request in JSON-RPC format * @param requestParams * Optional request parameters * @param auth * the auth * @return the string * @throws IOException * Signals that an I/O exception has occurred. */ public static String invoke(final Object destination, final String request, final RequestParams requestParams, final Authorizor auth) throws IOException { JSONRequest jsonRequest = null; JSONResponse jsonResponse = null; try { jsonRequest = new JSONRequest(request); jsonResponse = invoke(destination, jsonRequest, requestParams, auth); } catch (final JSONRPCException err) { jsonResponse = new JSONResponse(err); } return jsonResponse.toString(); }
@Override public void onSuccess(final JSONResponse response) { final Exception err = response.getError(); if (err != null) { asyncCallback.onFailure(err); } if (asyncCallback.getType() != null && !asyncCallback.getType().getJavaType().getRawClass() .equals(Void.class)) { try { final T res = asyncCallback.getType().inject( response.getResult()); asyncCallback.onSuccess(res); } catch (final ClassCastException cce) { asyncCallback.onFailure(new JSONRPCException( "Incorrect return type received for JSON-RPC call:" + request.getMethod(), cce)); } } else { asyncCallback.onSuccess(null); } }
/** * Sets the result. * * @param result * the new result */ public void setResult(final Object result) { if (result != null) { final ObjectMapper mapper = JOM.getInstance(); resp.set(RESULT, (JsonNode) mapper.convertValue(result, JSONNODETYPE)); setError(null); } else { if (resp.has(RESULT)) { resp.remove(RESULT); } } }
/** * Sets the error. * * @param error * the new error */ public void setError(final JSONRPCException error) { if (error != null) { resp.set(ERROR, error.getJsonNode()); setResult(null); } else { if (resp.has(ERROR)) { resp.remove(ERROR); } } }
final JSONResponse response = new JSONResponse(json); jsonMsg = response; } else if (JSONRpc.isRequest(json)) {
/** * Instantiates a new jSON response. * * @param response * the response */ public JSONResponse(final ObjectNode response) { init(response); }
/** * Instantiates a new jSON response. * * @param error * the error */ public JSONResponse(final JSONRPCException error) { init(null, null, error); }
/** * Instantiates a new jSON response. * * @param id * the id * @param result * the result */ public JSONResponse(final JsonNode id, final Object result) { init(id, result, null); }
/** * Instantiates a new jSON response. * * @param result * the result */ public JSONResponse(final Object result) { init(null, result, null); }
/** * Instantiates a new jSON response. * * @param id * the id * @param error * the error */ public JSONResponse(final JsonNode id, final JSONRPCException error) { init(id, null, error); }
/** * Instantiates a new jSON response. * * @param json * the json * @throws IOException * Signals that an I/O exception has occurred. */ public JSONResponse(final String json) throws IOException { final ObjectMapper mapper = JOM.getInstance(); init(mapper.valueToTree(json)); }
init(id, result, error);