Examples of JSONRPCException


Examples of com.almende.eve.rpc.jsonrpc.JSONRPCException

    // check for errors
    if (task.has("error")) {
      ObjectNode error = (ObjectNode)task.get("error");
      Integer code = error.has("code") ? error.get("code").asInt() : null;
      if (code != null && code.equals(404)) {
        throw new JSONRPCException(CODE.NOT_FOUND);       
      }
     
      throw new JSONRPCException(error);
    }
   
    // check if canceled. If so, return null
    // TODO: be able to retrieve canceled events?
    if (task.has("status") && task.get("status").asText().equals("cancelled")) {
      throw new JSONRPCException(CODE.NOT_FOUND);
    }
   
    return task;
  }
View Full Code Here

Examples of com.almende.eve.rpc.jsonrpc.JSONRPCException

    ObjectNode createdTask = mapper.readValue(resp, ObjectNode.class);
       
    // check for errors
    if (createdTask.has("error")) {
      ObjectNode error = (ObjectNode)createdTask.get("error");
      throw new JSONRPCException(error);
    }
   
    logger.info("createTask=" + JOM.getInstance().writeValueAsString(createdTask));

    return createdTask;
View Full Code Here

Examples of com.almende.eve.rpc.jsonrpc.JSONRPCException

    ObjectNode updatedTask = mapper.readValue(resp, ObjectNode.class);
   
    // check for errors
    if (updatedTask.has("error")) {
      ObjectNode error = (ObjectNode)updatedTask.get("error");
      throw new JSONRPCException(error);
    }
   
    logger.info("updateTask=" + JOM.getInstance().writeValueAsString(updatedTask)); // TODO: cleanup

    return updatedTask;
View Full Code Here

Examples of com.almende.eve.rpc.jsonrpc.JSONRPCException

    ObjectNode calendars = JOM.getInstance().readValue(resp, ObjectNode.class);

    // check for errors
    if (calendars.has("error")) {
      ObjectNode error = (ObjectNode)calendars.get("error");
      throw new JSONRPCException(error);
    }

    // get items from response
    ArrayNode items = null;
    if (calendars.has("items")) {
View Full Code Here

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

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

            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

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

      } 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

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

            && !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

Examples of com.baidu.rpc.exception.JsonRpcException

        return gson.fromJson(result, method.getGenericReturnType());
      }
    } else {
      JsonElement e = res.get("error");
      if (e != null) {
        JsonRpcException jre = exceptionHandler.deserialize(e);
        if (jre instanceof ServerErrorException) {
          String msg = jre.getMessage();
          Class<?>[] exp_types = method.getExceptionTypes();
          for (Class<?> exp_type : exp_types) {
            if (msg.equals(exp_type.getSimpleName())) {
              Exception custom_exp = (Exception) exp_type
                  .newInstance();
              custom_exp.initCause(jre.getCause());
              throw custom_exp;
            }
          }
        }
        throw jre;
View Full Code Here

Examples of org.json.rpc.commons.JsonRpcException

        return locked;
    }

    public <T> void addHandler(String name, T handler, Class<T>... classes) {
        if (locked) {
            throw new JsonRpcException("executor has been locked, can't add more handlers");
        }

        synchronized (handlers) {
            HandleEntry<T> handleEntry = new HandleEntry<T>(typeChecker, handler, classes);
            if (this.handlers.containsKey(name)) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.