/** * Instantiates a new jSON request. */ public JSONRequest() { init(null, null, null, null); }
/** * Inits the. * * @param id * the id * @param method * the method * @param params * the params */ private <T> void init(final JsonNode id, final String method, final ObjectNode params, final AsyncCallback<T> callback) { this.setRequest(true); setVersion(); if (callback != null && (id == null || id.isNull())) { setId(JOM.getInstance().valueToTree(new UUID().toString())); } else { setId(id); } setMethod(method); setParams(params); setCallback(callback); }
@Override public <T> void call(final URI url, final Method method, final Object[] params, final AsyncCallback<T> callback) throws IOException { final JSONRequest message = new JSONRequest(method, params, callback); transport.send(url, protocolStack.outbound(message, url).result, null); }
final JSONRequest request, final RequestParams requestParams, final Authorizor auth) { final JSONResponse resp = new JSONResponse(request.getId(), null); try { final CallTuple tuple = NamespaceUtil.get(destination, request.getMethod()); JSONRPCException.CODE.METHOD_NOT_FOUND, "Method '" + request.getMethod() + "' not found. The method does not exist or you are not authorized."); if (Defines.HASMETHODHANDLES) { final Object[] params = castParams(realDest, request.getParams(), annotatedMethod.getParams(), requestParams); result = methodHandle.invokeExact(params);
+ "' is missing the @Name annotation."); } else if (isRequired(annotatedParam)) { throw new IllegalArgumentException("Required parameter " + i + " in method '" + method.getName() + "' is null."); LOG.log(Level.SEVERE, "Failed to generate UUID for request", e); init(id, method.getName(), params, callback);
public Meta outbound(final Object msg, final URI recipientUrl) { if (msg instanceof JSONRequest) { final JSONRequest request = (JSONRequest) msg; addCallback(request, request.getCallback()); } return new Meta(msg); }
@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); } }
@Override public <T> void call(final URI url, final String method, final ObjectNode params, final AsyncCallback<T> callback) throws IOException { final JSONRequest message = new JSONRequest(method, params, callback); transport.send(url, protocolStack.outbound(message, url).result, null); }
/** * Schedule an RPC call at a specified due time. * * @param method * the method * @param params * the params * @param delay * the delay * @return the string */ @Access(AccessType.UNAVAILABLE) protected String schedule(final String method, final ObjectNode params, final long delay) { final Scheduler scheduler = this.scheduler; if (scheduler == null) return ""; return scheduler.schedule(new JSONRequest(method, params), delay); }
/** * Instantiates a new JSON request. * * @param request * the request */ public JSONRequest(final JsonNode request) { init(request); }
/** * Schedule an RPC call at a specified due time. * * @param method * the method * @param params * the params * @param delay * the delay * @return the string */ @Access(AccessType.UNAVAILABLE) protected String schedule(final String method, final ObjectNode params, final int delay) { final Scheduler scheduler = this.scheduler; if (scheduler == null) return ""; return scheduler.schedule(new JSONRequest(method, params), delay); }
/** * Instantiates a new JSON request. * * @param method * the method * @param params * the params */ public JSONRequest(final String method, final ObjectNode params) { init(null, method, params, null); }
/** * Schedule an RPC call at a specified due time. * * @param method * the method * @param params * the params * @param due * the due * @return the string */ @Access(AccessType.UNAVAILABLE) protected String schedule(final String method, final ObjectNode params, final DateTime due) { final Scheduler scheduler = this.scheduler; if (scheduler == null) return ""; return scheduler.schedule(new JSONRequest(method, params), due); }
/** * Instantiates a new JSON request. * * @param method * the method * @param params * the params * @param callback * the callback */ public <T> JSONRequest(final String method, final ObjectNode params, final AsyncCallback<T> callback) { if (callback != null) { } init(null, method, params, callback); }
@Override public <T> T callSync(final URI url, final String method, final ObjectNode params, final TypeUtil<T> type) throws IOException { final SyncCallback<T> callback = new SyncCallback<T>(type) {}; final JSONRequest message = new JSONRequest(method, params, callback); transport.send(url, protocolStack.outbound(message, url).result, null); try { return callback.get(); } catch (final Exception e) { throw new IOException(e); } } }
/** * Instantiates a new jSON request. * * @param id * the id * @param method * the method * @param params * the params * @param callback * the callback */ public <T> JSONRequest(final JsonNode id, final String method, final ObjectNode params, final AsyncCallback<T> callback) { init(id, method, params, callback); }
jsonMsg = response; } else if (JSONRpc.isRequest(json)) { final JSONRequest request = new JSONRequest(json); jsonMsg = request; } else {
/** * Instantiates a new JSON request. * * @param json * the json * @throws IOException * Signals that an I/O exception has occurred. */ public JSONRequest(final String json) throws IOException { final ObjectMapper mapper = JOM.getInstance(); init(mapper.readTree(json)); }
/** * 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(); }