Package org.codehaus.jackson.node

Examples of org.codehaus.jackson.node.ObjectNode


        // bail on invalid response
        if (!response.isObject()) {
            throw new Exception("Invalid JSON-RPC response");
        }
        ObjectNode jsonObject = ObjectNode.class.cast(response);

        // detect errors
        if (jsonObject.has("error") && jsonObject.get("error")!=null) {
            ObjectNode errorObject = ObjectNode.class.cast(jsonObject.get("error"));
            throw new Exception(
                "JSON-RPC Error "+errorObject.get("code")+": "+errorObject.get("message"));
        }

        // convert it to a return object
        if (jsonObject.has("result")) {
            return mapper.readValue(
View Full Code Here


        throws IOException,
        JsonGenerationException,
        JsonMappingException {

        // create the request
        ObjectNode request = mapper.createObjectNode();
        request.put("id", id);
        request.put("jsonrpc", JSON_RPC_VERSION);
        request.put("method", methodName);
        request.put("params", mapper.valueToTree(arguments));

        // post the json data;
        mapper.writeValue(ops, request);
    }
View Full Code Here

      }
    }

    // invoke the method
    JsonNode result = null;
    ObjectNode error = null;
    Throwable thrown = null;
    try {
      result = invoke(method, paramNodes);
    } catch (Throwable e) {
      thrown = e;
      if (InvocationTargetException.class.isInstance(e)) {
        e = InvocationTargetException.class.cast(e).getTargetException();
      }
      error = mapper.createObjectNode();

      // use error
      boolean errorMapped = false;
      for (JsonRpcError em : errorMappings) {
        if (em.exception().isInstance(e)) {
          error.put("code", em.code());
          error.put("message", em.message());

          // get data from annotation
          String data = em.data();

          // default to exception message
          if("".equals(data)) {
            data = e.getMessage();
          }

          // only add the data if we have a value
          if (data != null && !"".equals(data)) {
            error.put("data", data);
          }

          // we used an annotation for the exception
          errorMapped = true;
          break;
        }
      }

      // generate generic error response
      if (!errorMapped) {
        error.put("code", 0);
        error.put("message", e.getMessage());
        error.put("data", e.getClass().getName());
      }
    }

    // bail if notification request
    if (id==null) {
      return;
    }

    // create response
    ObjectNode response = mapper.createObjectNode();
    response.put("jsonrpc", jsonRpc);
    response.put("id", id);
    if (error==null) {
      response.put("result", result);
    } else if (error!=null) {
      response.put("error", error);
    }

    // write it
    mapper.writeValue(ops, response);
View Full Code Here

   * @param data the error data (if any)
   * @return the error response
   */
  private ObjectNode createErrorResponse(
    String jsonRpc, String id, int code, String message, Object data) {
    ObjectNode response = mapper.createObjectNode();
    ObjectNode error = mapper.createObjectNode();
    error.put("code", code);
    error.put("message", message);
    if (data!=null) {
      error.put("data",  mapper.valueToTree(data));
    }
    response.put("jsonrpc", jsonRpc);
    response.put("id", id);
    response.put("error", error);
    return response;
View Full Code Here

    String basemap = rootNode.path("basemap").getTextValue();
    String bbox = rootNode.path("extent").getTextValue();
    String username = rootNode.path("username").getTextValue();
    String password = rootNode.path("password").getTextValue();
   
    ObjectNode responseJson = mapper.createObjectNode();
    //response json format
    //{"status": "", "message": "", mapUrl: "", "layers": []}
    //status  where in the process
    //statusMessage text
    //mapUrl:
View Full Code Here

        addFormParameter(proxy, "sortOrder", "score");
        addFormParameter(proxy, "maxNum", "10");
        proxy.execute();

        assertResultOK(proxy);
        ObjectNode json = getJSON(proxy);
        assertPublicEventsAreFound(json);
        assertThat(json.has("reason"), equalTo(false));
    }
View Full Code Here

        addFormParameter(proxy, "sortOrder", "score");
        addFormParameter(proxy, "maxNum", "10");
        proxy.execute();

        assertResultOK(proxy);
        ObjectNode json = getJSON(proxy);
        assertPublicEventsAreFound(json);
        assertThat(json.has("reason"), equalTo(false));
    }
View Full Code Here

        addFormParameter(proxy, "sortOrder", "score");
        addFormParameter(proxy, "maxNum", "10");
        proxy.execute();

        assertResultOK(proxy);
        ObjectNode json = getJSON(proxy);
        assertPublicEventsAreFound(json);
        assertThat(json.has("reason"), equalTo(false));

    }
View Full Code Here

        addFormParameter(proxy, "sortOrder", "score");
        addFormParameter(proxy, "maxNum", "10");
        proxy.execute();

        assertResultOK(proxy);
        ObjectNode json = getJSON(proxy);
        assertThat(json.has("reason"), equalTo(false));
        assertPublicEventsAreFound(json);
    }
View Full Code Here

        addFormParameter(proxy, "sortOrder", "score");
        addFormParameter(proxy, "maxNum", "10");
        proxy.execute();

        assertResultOK(proxy);
        ObjectNode json = getJSON(proxy);
        assertOnlyBeforeDeadlineAreFound(json);
    }
View Full Code Here

TOP

Related Classes of org.codehaus.jackson.node.ObjectNode

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.