Example usage for com.fasterxml.jackson.core JsonProcessingException getMessage

List of usage examples for com.fasterxml.jackson.core JsonProcessingException getMessage

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonProcessingException getMessage.

Prototype

@Override
public String getMessage() 

Source Link

Document

Default method overridden so that we can add location information

Usage

From source file:org.zodiark.service.EndpointUtils.java

public String writeAsString(Object o) {
    try {//www . j av  a2  s.co m
        return mapper.writeValueAsString(o);
    } catch (JsonProcessingException e) {
        return "{\"error\":\"" + e.getMessage() + "\"}";
    }
}

From source file:AdminCollectionFunctionalTest.java

public void getCollections() {
    //get a collection
    String collectionName = routeCreateCollection();
    FakeRequest request = new FakeRequest("GET", "/admin/collection");
    request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
    request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
    Result result = routeAndCall(request);
    assertRoute(result, "getCollection 1", Status.OK,
            "{\"name\":\"" + collectionName + "\",\"records\":0,\"size\":0", true);

    //create two doc
    JsonNode document1;//from  w  ww .j av a  2s . c  o m
    try {
        document1 = new ObjectMapper().readTree("{\"total\":2,\"city\":\"rome\"}");

        request = new FakeRequest("POST", "/document/" + collectionName);
        request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
        request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
        request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
        request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
        request = request.withJsonBody(document1);
        result = routeAndCall(request);
        assertRoute(result, "getCollection 2", Status.OK, null, false);

        request = new FakeRequest("POST", "/document/" + collectionName);
        request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
        request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
        request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
        request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
        request = request.withJsonBody(document1);
        result = routeAndCall(request);
        assertRoute(result, "getCollection 3", Status.OK, null, false);

        //check the content of the collection
        request = new FakeRequest("GET", "/admin/collection");
        request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
        request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
        result = routeAndCall(request);
        assertRoute(result, "getCollection 4", Status.OK,
                "{\"name\":\"" + collectionName + "\",\"records\":2,\"size\":6", true);

    } catch (JsonProcessingException e) {
        Assert.fail(e.getMessage());
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }

}

From source file:ch.ralscha.extdirectspring.controller.RouterControllerFormPostJsonTest.java

@SuppressWarnings({ "unchecked", "null", "rawtypes" })
@Test//from ww w  .  j ava2 s .  c o m
public void testCallFormPostMethodError() throws Exception {

    FormInfo formInfo = new FormInfo("Ralph", 20, true, new BigDecimal(12.3), "theResult");

    MvcResult resultMvc = null;
    try {
        resultMvc = ControllerUtil.performRouterRequest(mockMvc, ControllerUtil
                .createEdsRequest("formInfoController3", "updateInfoJsonDirectError", 14, formInfo));
    } catch (JsonProcessingException e) {
        fail("perform post to /router" + e.getMessage());
    } catch (Exception e) {
        fail("perform post to /router" + e.getMessage());
    }

    List<ExtDirectResponse> responses = ControllerUtil
            .readDirectResponses(resultMvc.getResponse().getContentAsByteArray());
    assertThat(responses).hasSize(1);

    ExtDirectResponse edsResponse = responses.get(0);

    assertThat(edsResponse.getAction()).isEqualTo("formInfoController3");
    assertThat(edsResponse.getMethod()).isEqualTo("updateInfoJsonDirectError");
    assertThat(edsResponse.getTid()).isEqualTo(14);
    assertThat(edsResponse.getWhere()).isNull();
    assertThat(edsResponse.getType()).isEqualTo("rpc");

    Map<String, Object> result = (Map<String, Object>) edsResponse.getResult();
    assertThat(result).hasSize(2).contains(entry("success", Boolean.FALSE));
    assertThat(result).hasSize(2).containsKey("errors");
    Map age = (Map) result.get("errors");
    assertThat(age).hasSize(1).containsKey("age");
    ArrayList value = (ArrayList) age.get("age");
    assertThat(value).contains("age is wrong");
}

From source file:ch.ralscha.extdirectspring.controller.RouterControllerFormPostJsonTest.java

@SuppressWarnings({ "null" })
@Test/*w w w. ja v  a2 s. c om*/
public void testCallFormPostMethod() throws Exception {

    FormInfo formInfo = new FormInfo("Ralph", 20, true, new BigDecimal(12.3), "theResult");

    // Request Params are sent as part of the json content payload
    formInfo.set("p1", 1000);
    formInfo.set("p2", "2nd mandatory param");

    MvcResult resultMvc = null;
    try {
        resultMvc = ControllerUtil.performRouterRequest(mockMvc,
                ControllerUtil.createEdsRequest("formInfoController3", "updateInfoJsonDirect", 14, formInfo));
    } catch (JsonProcessingException e) {
        fail("perform post to /router" + e.getMessage());
    } catch (Exception e) {
        fail("perform post to /router" + e.getMessage());
    }

    List<ExtDirectResponse> responses = ControllerUtil
            .readDirectResponses(resultMvc.getResponse().getContentAsByteArray());
    assertThat(responses).hasSize(1);

    ExtDirectResponse edsResponse = responses.get(0);

    assertThat(edsResponse.getAction()).isEqualTo("formInfoController3");
    assertThat(edsResponse.getMethod()).isEqualTo("updateInfoJsonDirect");
    assertThat(edsResponse.getTid()).isEqualTo(14);
    assertThat(edsResponse.getWhere()).isNull();
    assertThat(edsResponse.getType()).isEqualTo("rpc");
    assertThat(edsResponse.getMessage()).isNull();

    @SuppressWarnings("unchecked")
    Map<String, Object> result = (Map<String, Object>) edsResponse.getResult();
    assertThat(result).hasSize(6).contains(entry("name", "RALPH"), entry("age", 30),
            entry("admin", Boolean.FALSE), entry("salary", 1012.3), entry("result", "theResultRESULT"),
            entry("success", Boolean.TRUE));
}

From source file:com.example.gaefirebaseeventproxy.FirebaseEventProxy.java

public void start() {
    DatabaseReference firebase = FirebaseDatabase.getInstance().getReference();

    // Subscribe to value events. Depending on use case, you may want to subscribe to child events
    // through childEventListener.
    firebase.addValueEventListener(new ValueEventListener() {
        @Override/*from  ww  w  .j  a  va 2  s  .  co  m*/
        public void onDataChange(DataSnapshot snapshot) {
            if (snapshot.exists()) {
                try {
                    // Convert value to JSON using Jackson
                    String json = new ObjectMapper().writeValueAsString(snapshot.getValue(false));

                    // Replace the URL with the url of your own listener app.
                    URL dest = new URL("http://gae-firebase-listener-python.appspot.com/log");
                    HttpURLConnection connection = (HttpURLConnection) dest.openConnection();
                    connection.setRequestMethod("POST");
                    connection.setDoOutput(true);

                    // Rely on X-Appengine-Inbound-Appid to authenticate. Turning off redirects is
                    // required to enable.
                    connection.setInstanceFollowRedirects(false);

                    // Fill out header if in dev environment
                    if (SystemProperty.environment.value() != SystemProperty.Environment.Value.Production) {
                        connection.setRequestProperty("X-Appengine-Inbound-Appid", "dev-instance");
                    }

                    // Put Firebase data into http request
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.append("&fbSnapshot=");
                    stringBuilder.append(URLEncoder.encode(json, "UTF-8"));
                    connection.getOutputStream().write(stringBuilder.toString().getBytes());
                    if (connection.getResponseCode() != 200) {
                        log.severe("Forwarding failed");
                    } else {
                        log.info("Sent: " + json);
                    }
                } catch (JsonProcessingException e) {
                    log.severe("Unable to convert Firebase response to JSON: " + e.getMessage());
                } catch (IOException e) {
                    log.severe("Error in connecting to app engine: " + e.getMessage());
                }
            }
        }

        @Override
        public void onCancelled(DatabaseError error) {
            log.severe("Firebase connection cancelled: " + error.getMessage());
        }
    });
}

From source file:org.apache.streams.json.JsonPathExtractor.java

@Override
public List<StreamsDatum> process(StreamsDatum entry) {

    List<StreamsDatum> result = Lists.newArrayList();

    String json = null;/*from   w  w w  .j ava2 s .  c  o m*/

    LOGGER.debug("{} processing {}", STREAMS_ID);

    if (entry.getDocument() instanceof ObjectNode) {
        ObjectNode node = (ObjectNode) entry.getDocument();
        try {
            json = mapper.writeValueAsString(node);
        } catch (JsonProcessingException e) {
            LOGGER.warn(e.getMessage());
        }
    } else if (entry.getDocument() instanceof String) {
        json = (String) entry.getDocument();
    }

    if (StringUtils.isNotEmpty(json)) {

        try {
            Object readResult = jsonPath.read(json);

            if (readResult instanceof String) {
                String match = (String) readResult;
                LOGGER.info("Matched String: " + match);
                StreamsDatum matchDatum = new StreamsDatum(match);
                result.add(matchDatum);
            } else if (readResult instanceof JSONObject) {
                JSONObject match = (JSONObject) readResult;
                LOGGER.info("Matched Object: " + match);
                ObjectNode objectNode = mapper.readValue(mapper.writeValueAsString(match), ObjectNode.class);
                StreamsDatum matchDatum = new StreamsDatum(objectNode);
                result.add(matchDatum);
            } else if (readResult instanceof JSONArray) {
                LOGGER.info("Matched Array:");
                JSONArray array = (JSONArray) readResult;
                Iterator iterator = array.iterator();
                while (iterator.hasNext()) {
                    Object item = iterator.next();
                    if (item instanceof String) {
                        LOGGER.info("String Item:" + item);
                        String match = (String) item;
                        StreamsDatum matchDatum = new StreamsDatum(match);
                        result.add(matchDatum);
                    } else if (item instanceof JSONObject) {
                        LOGGER.info("Object Item:" + item);
                        JSONObject match = (JSONObject) item;
                        ObjectNode objectNode = mapper.readValue(mapper.writeValueAsString(match),
                                ObjectNode.class);
                        StreamsDatum matchDatum = new StreamsDatum(objectNode);
                        result.add(matchDatum);
                    } else {
                        LOGGER.info("Other Item:" + item.toString());
                    }
                }
            } else {
                LOGGER.info("Other Match:" + readResult.toString());
            }

        } catch (Exception e) {
            LOGGER.warn(e.getMessage());
        }

    } else {
        LOGGER.warn("result empty");
    }

    return result;

}

From source file:reactor.js.core.json.NashornJacksonJsonPathProvider.java

@Override
public String toJson(Object obj) {
    try {/*  w ww  . ja va2s . co  m*/
        return mapper.writeValueAsString(obj);
    } catch (JsonProcessingException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}

From source file:com.arpnetworking.metrics.vertx.EventBusSink.java

/**
 * {@inheritDoc}/*  ww  w .  ja v  a 2s . co m*/
 */
@Override
public void record(final Event event) {
    try {
        LOGGER.debug(String.format("Sending event to sink. Address=%s", _sinkAddress));
        _eventBus.publish(_sinkAddress, OBJECT_MAPPER.writeValueAsString(event));
    } catch (final JsonProcessingException e) {
        LOGGER.warn(String.format("Failed to send event to sink. Address=%s.", _sinkAddress), e.getMessage());
    }
}

From source file:org.commonjava.aprox.depgraph.rest.WorkspaceController.java

public String list() throws AproxWorkflowException {
    final Set<String> graph = graphFactory.listWorkspaces();
    try {/*  www  . j av  a2  s.  c o m*/
        return graph == null || graph.isEmpty() ? null
                : serializer.writeValueAsString(Collections.singletonMap("items", graph));
    } catch (final JsonProcessingException e) {
        throw new AproxWorkflowException("Failed to serialize to JSON: %s", e, e.getMessage());
    }
}

From source file:org.ccntgrid.extend.spring.http.converter.json.MappingJackson2HttpMessageConverter.java

@Override
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage)
        throws IOException, HttpMessageNotReadableException {

    JavaType javaType = getJavaType(clazz);
    try {//from w  ww  .  j a  va 2 s.  c  om
        return this.objectMapper.readValue(inputMessage.getBody(), javaType);
    } catch (JsonProcessingException ex) {
        throw new HttpMessageNotReadableException("Could not read JSON: " + ex.getMessage(), ex);
    }
}