List of usage examples for com.fasterxml.jackson.core JsonProcessingException getMessage
@Override
public String getMessage()
From source file:org.resthub.web.converter.MappingJackson2JsonHttpMessageConverter.java
@Override protected void writeInternal(Object object, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType()); JsonGenerator jsonGenerator = this.objectMapper.getJsonFactory() .createJsonGenerator(outputMessage.getBody(), encoding); // A workaround for JsonGenerators not applying serialization features // https://github.com/FasterXML/jackson-databind/issues/12 if (this.objectMapper.isEnabled(SerializationFeature.INDENT_OUTPUT)) { jsonGenerator.useDefaultPrettyPrinter(); }// www .ja v a 2s . com try { if (this.prefixJson) { jsonGenerator.writeRaw("{} && "); } this.objectMapper.writeValue(jsonGenerator, object); } catch (JsonProcessingException ex) { throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex); } }
From source file:net.fischboeck.discogs.BaseOperations.java
<T> T doPostRequest(String url, Object body, Class<T> type) throws ClientException { log.debug("[doPostRequest] url={}", url); CloseableHttpResponse response = null; try {// ww w . j a v a 2 s . c o m HttpPost request = new HttpPost(url); request.setEntity(new ByteArrayEntity(mapper.writeValueAsBytes(body), ContentType.APPLICATION_JSON)); response = doHttpRequest(request); HttpEntity entity = response.getEntity(); return mapper.readValue(entity.getContent(), type); } catch (JsonProcessingException jpe) { throw new ClientException(jpe.getMessage()); } catch (IOException ioe) { throw new ClientException(ioe.getMessage()); } catch (EntityNotFoundException enfe) { return null; } finally { closeSafe(response); } }
From source file:org.apache.streams.elasticsearch.ElasticsearchQuery.java
public void execute(Object o) { // If we haven't already set up the search, then set up the search. if (search == null) { search = elasticsearchClientManager.getClient().prepareSearch(indexes.toArray(new String[0])) .setSearchType(SearchType.SCAN).setExplain(true).addField("*").setFetchSource(true) .setSize(batchSize).setScroll(scrollTimeout).addField("_timestamp"); String searchJson;//from ww w . jav a 2 s .co m if (config.getSearch() != null) { LOGGER.debug("Have config in Reader: " + config.getSearch().toString()); try { searchJson = mapper.writeValueAsString(config.getSearch()); LOGGER.debug("Setting source: " + searchJson); search = search.setExtraSource(searchJson); } catch (JsonProcessingException e) { LOGGER.warn("Could not apply _search supplied by config", e.getMessage()); } LOGGER.debug("Search Source is now " + search.toString()); } if (this.queryBuilder != null) search = search.setQuery(this.queryBuilder); // If the types are null, then don't specify a type if (this.types != null && this.types.size() > 0) search = search.setTypes(types.toArray(new String[0])); // TODO: Replace when all clusters are upgraded past 0.90.4 so we can implement a RANDOM scroll. if (this.random) search = search.addSort(SortBuilders.scriptSort("random()", "number")); } // We don't have a scroll, we need to create a scroll if (scrollResp == null) { scrollResp = search.execute().actionGet(); LOGGER.trace(search.toString()); } }
From source file:com.hp.mqm.atrf.octane.services.OctaneEntityService.java
private boolean loginInternal() { boolean ret = false; restConnector.clearAll();/*w w w. java 2s. co m*/ ObjectMapper mapper = new ObjectMapper(); String jsonString = null; try { jsonString = mapper.writeValueAsString(authData); } catch (JsonProcessingException e) { throw new RuntimeException("Fail in generating json for login data : " + e.getMessage()); } //Get LWSSO COOKIE Map<String, String> headers = new HashMap<>(); headers.put(HTTPUtils.HEADER_CONTENT_TYPE, HTTPUtils.HEADER_APPLICATION_JSON); Response authResponse = restConnector.httpPost(OctaneRestConstants.AUTHENTICATION_URL, jsonString, headers); if (authResponse.getStatusCode() == HttpStatus.SC_OK) { ret = true; } return ret; }
From source file:com.jivesoftware.os.routing.bird.deployable.TenantRoutingBirdProviderBuilder.java
public ConnectionDescriptorsProvider build(OAuthSigner signer) { HttpClientConfig httpClientConfig = HttpClientConfig.newBuilder().build(); final HttpClient httpClient = new HttpClientFactoryProvider() .createHttpClientFactory(Collections.singletonList(httpClientConfig), false) .createClient(signer, routesHost, routesPort); AtomicLong activeCount = new AtomicLong(); final ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationFeature.INDENT_OUTPUT, true); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); ConnectionDescriptorsProvider connectionsProvider = (connectionsRequest, expectedReleaseGroup) -> { activeCount.incrementAndGet();/*from w w w . ja v a 2 s .c o m*/ try { LOG.debug("Requesting connections:{}", connectionsRequest); String postEntity; try { postEntity = mapper.writeValueAsString(connectionsRequest); } catch (JsonProcessingException e) { LOG.error("Error serializing request parameters object to a string. Object " + "was " + connectionsRequest + " " + e.getMessage()); return null; } HttpResponse response; try { response = httpClient.postJson(routesPath, postEntity, null); } catch (HttpClientException e) { LOG.error( "Error posting query request to server. The entity posted was {} and the endpoint posted to was {}", new Object[] { postEntity, routesPath }, e); return null; } int statusCode = response.getStatusCode(); if (statusCode >= 200 && statusCode < 300) { byte[] responseBody = response.getResponseBody(); try { ConnectionDescriptorsResponse connectionDescriptorsResponse = mapper.readValue(responseBody, ConnectionDescriptorsResponse.class); if (!connectionsRequest.getRequestUuid() .equals(connectionDescriptorsResponse.getRequestUuid())) { LOG.warn("Request UUIDs are misaligned, request:{} response:{}", connectionsRequest, connectionDescriptorsResponse); } if (connectionDescriptorsResponse.getReturnCode() >= 0 && expectedReleaseGroup != null && !expectedReleaseGroup.equals(connectionDescriptorsResponse.getReleaseGroup())) { String responseEntity = new String(responseBody, StandardCharsets.UTF_8); LOG.warn( "Release group changed, active:{} request:{} requestEntity:{} responseEntity:{} response:{}", activeCount.get(), connectionsRequest, postEntity, responseEntity, connectionDescriptorsResponse); } LOG.debug("Request:{} ConnectionDescriptors:{}", connectionsRequest, connectionDescriptorsResponse); return connectionDescriptorsResponse; } catch (IOException x) { LOG.error("Failed to deserialize response:" + new String(responseBody) + " " + x.getMessage()); return null; } } return null; } finally { activeCount.decrementAndGet(); } }; return connectionsProvider; }
From source file:org.thingsplode.synapse.serializers.jackson.JacksonSerializer.java
@Override public byte[] marshall(Object object) throws SerializationException { if (object == null) { return new byte[0]; }/*from ww w. j ava2 s. c o m*/ try { return mapper.writeValueAsBytes(object); } catch (JsonProcessingException ex) { throw new SerializationException("Could not serialize object of type [" + object.getClass().getName() + "] due to: " + ex.getMessage(), ex); } }
From source file:com.reprezen.swagedit.validation.SwaggerError.java
public SwaggerError(JsonProcessingException exception) { this.level = IMarker.SEVERITY_ERROR; this.message = exception.getMessage(); if (exception.getLocation() != null) { this.line = exception.getLocation().getLineNr(); } else {/*from ww w .j a va2 s . c o m*/ this.line = 1; } }
From source file:org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.java
@SuppressWarnings("deprecation") @Override/*from w w w . j a v a2 s .com*/ protected void writeInternal(Object object, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType()); JsonGenerator jsonGenerator = this.objectMapper.getJsonFactory() .createJsonGenerator(outputMessage.getBody(), encoding); // A workaround for JsonGenerators not applying serialization features // https://github.com/FasterXML/jackson-databind/issues/12 if (this.objectMapper.isEnabled(SerializationFeature.INDENT_OUTPUT)) { jsonGenerator.useDefaultPrettyPrinter(); } try { if (this.jsonPrefix != null) { jsonGenerator.writeRaw(this.jsonPrefix); } this.objectMapper.writeValue(jsonGenerator, object); } catch (JsonProcessingException ex) { throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex); } }
From source file:org.o3project.ocnrm.rest.GUIRestApi.java
/** * Data acquisition API of NW component. * Flow information, topology information, * and boundary information (Layerized nw is only specified) are acquired. * * GET /demo/info?NWCID=\<NW component name\> * <br>Example<br>/*from w ww . ja v a 2 s . com*/ * http://localhost:44444/demo/info?NWCID=networkcomponent012,networkcomponent01 * @return Representation */ @Get public Representation getNWComponentInfo() { seqNo = SEQNO_PREFIX + mf.requestNoToString(); logger.info(seqNo + "\t" + "getNWComponentInfo Start"); logger.info(seqNo + "\t" + "getQueryValue(\"NWCID\") : " + getQueryValue("NWCID")); JSONObject result = new JSONObject(); String nwcIdQuery = getQueryValue("NWCID"); if (nwcIdQuery == null) { return new JsonRepresentation(result); } String[] nwcIds = getQueryValue("NWCID").split(","); try { for (String nwcId : nwcIds) { JSONObject json = new JSONObject(); json.put("flow", makeFlows(nwcId)); json.put("topology", makeTopology(nwcId)); String objectId = sender.getConnections(nwcId); if (objectId != null) { json.put("boundaries", makeBoundary(nwcId, objectId)); } result.put(nwcId, json); } } catch (JsonProcessingException e) { logger.error(seqNo + "\t" + "JsonProcessingException is occured: " + e.getMessage()); e.printStackTrace(); } catch (JSONException e) { logger.error(seqNo + "\t" + "JSONException is occured: " + e.getMessage()); e.printStackTrace(); } catch (ParseBodyException e) { logger.error(seqNo + "\t" + "ParseBodyException is occured: " + e.getMessage()); e.printStackTrace(); } logger.debug(seqNo + "\t" + "response to GUI : " + result); logger.info(seqNo + "\t" + "getNWComponentInfo End"); return new JsonRepresentation(result); }
From source file:org.thingsplode.synapse.serializers.jackson.JacksonSerializer.java
@Override public String marshallToWireformat(Object object) throws SerializationException { try {//from ww w . jav a 2 s . c o m if (object != null) { return mapper.writeValueAsString(object); } else { return ""; } } catch (JsonProcessingException ex) { throw new SerializationException("Could not serialize object of type [" + object.getClass().getSimpleName() + "] due to: " + ex.getMessage(), ex); } }