Package com.almende.eve.transform.rpc.formats

Examples of com.almende.eve.transform.rpc.formats.JSONRPCException


          request.getMethod());
     
      final Object realDest = tuple.getDestination();
      final AnnotatedMethod annotatedMethod = tuple.getMethod();
      if (!isAvailable(annotatedMethod, realDest, requestParams, auth)) {
        throw new JSONRPCException(
            JSONRPCException.CODE.METHOD_NOT_FOUND,
            "Method '"
                + request.getMethod()
                + "' not found. The method does not exist or you are not authorized.");
      }
     
      final MethodHandle methodHandle = annotatedMethod.getMethodHandle();
      final Method method = annotatedMethod.getActualMethod();
     
      Object result;
      if (useMethodHandles) {
        final Object[] params = castParams(realDest,
            request.getParams(), annotatedMethod.getParams(),
            requestParams);
        result = methodHandle.invokeExact(params);
      } else {
        final Object[] params = castParams(request.getParams(),
            annotatedMethod.getParams(), requestParams);
        result = method.invoke(realDest, params);
      }
      if (result == null) {
        result = JOM.createNullNode();
      }
      resp.setResult(result);
    } catch (final JSONRPCException err) {
      resp.setError(err);
      // TODO: Can this be reduced to Exception? Which Errors do we want
      // to catch?
    } catch (final Throwable err) {
      final Throwable cause = err.getCause();
      if (cause instanceof JSONRPCException) {
        resp.setError((JSONRPCException) cause);
      } else {
        if (err instanceof InvocationTargetException && cause != null) {
          LOG.log(Level.WARNING,
              "Exception raised, returning its cause as JSONRPCException. Request:"
                  + request, cause);
         
          final JSONRPCException jsonError = new JSONRPCException(
              JSONRPCException.CODE.INTERNAL_ERROR,
              getMessage(cause), cause);
          jsonError.setData(cause);
          resp.setError(jsonError);
        } else {
          LOG.log(Level.WARNING,
              "Exception raised, returning it as JSONRPCException. Request:"
                  + request, err);
         
          final JSONRPCException jsonError = new JSONRPCException(
              JSONRPCException.CODE.INTERNAL_ERROR,
              getMessage(err), err);
          jsonError.setData(err);
          resp.setError(jsonError);
        }
      }
    }
    return resp;
View Full Code Here


            final SyncCallback<Object> callback = new SyncCallback<Object>() {
            };
            try {
              sender.call(receiverUrl, method, args, callback);
            } catch (final IOException e) {
              throw new JSONRPCException(CODE.REMOTE_EXCEPTION, e
                  .getLocalizedMessage(), e);
            }
           
            try {
              return TypeUtil.inject(callback.get(),
                  method.getGenericReturnType());
            } catch (final Exception e) {
              throw new JSONRPCException(CODE.REMOTE_EXCEPTION, e
                  .getLocalizedMessage(), e);
            }
          }
        });
    return proxy;
View Full Code Here

      } else if (jsonMsg.isResponse() && callbacks != null && id != null
          && !id.isNull()) {
        final AsyncCallback<JSONResponse> callback = callbacks.pull(id);
        if (callback != null) {
          final JSONResponse response = (JSONResponse) jsonMsg;
          final JSONRPCException error = response.getError();
          if (error != null) {
            callback.onFailure(error);
          } else {
            callback.onSuccess(response);
          }
        }
      }
    } catch (final Exception e) {
      // generate JSON error response, skipped if it was an incoming
      // notification i.s.o. request.
      final JSONRPCException jsonError = new JSONRPCException(
          JSONRPCException.CODE.INTERNAL_ERROR, e.getMessage(), e);
      LOG.log(Level.WARNING, "Exception in receiving message", jsonError);
     
      final JSONResponse response = new JSONResponse(jsonError);
      response.setId(id);
View Full Code Here

            && !type.getJavaType().getRawClass().equals(Void.class)) {
          try {
            final T res = type.inject(response.getResult());
            callback.onSuccess(res);
          } catch (final ClassCastException cce) {
            callback.onFailure(new JSONRPCException(
                "Incorrect return type received for JSON-RPC call:"
                    + request.getMethod(), cce));
          }
         
        } else {
View Full Code Here

TOP

Related Classes of com.almende.eve.transform.rpc.formats.JSONRPCException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.