List of usage examples for com.fasterxml.jackson.core JsonProcessingException getMessage
@Override
public String getMessage()
From source file:eu.supersede.fe.application.ApplicationUtil.java
/** * Add the given page for the given application with the given localised labels and required profiles. * @param applicationName//ww w. j a v a 2s . co m * @param applicationPage * @param applicationPageLabels * @param profilesRequired */ public void addApplicationPage(String applicationName, String applicationPage, Map<String, String> applicationPageLabels, List<String> profilesRequired) { ApplicationPage app = new ApplicationPage(applicationName, applicationPage, applicationPageLabels, profilesRequired); try { template.opsForHash().put(PAGE_KEY, app.getId(), mapper.writeValueAsString(app)); } catch (JsonProcessingException e) { log.debug(e.getMessage()); e.printStackTrace(); } }
From source file:eu.supersede.fe.application.ApplicationUtil.java
/** * Add a gadget with the given name for the given application with the given required profiles. * @param applicationName/*from w w w . java 2 s.com*/ * @param applicationGadget * @param profilesRequired */ public void addApplicationGadget(String applicationName, String applicationGadget, List<String> profilesRequired) { ApplicationGadget gadget = new ApplicationGadget(applicationName, applicationGadget, profilesRequired); try { template.opsForHash().put(GADGET_KEY, gadget.getId(), mapper.writeValueAsString(gadget)); } catch (JsonProcessingException e) { log.debug(e.getMessage()); e.printStackTrace(); } }
From source file:org.apache.nifi.processors.standard.AttributesToJSON.java
@Override public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException { final FlowFile original = session.get(); if (original == null) { return;/*from w w w. ja va2 s .c om*/ } final Map<String, String> atrList = buildAttributesMapForFlowFile(original, attributes, attributesToRemove, nullValueForEmptyString); try { if (destinationContent) { FlowFile conFlowfile = session.write(original, (in, out) -> { try (OutputStream outputStream = new BufferedOutputStream(out)) { outputStream.write(objectMapper.writeValueAsBytes(atrList)); } }); conFlowfile = session.putAttribute(conFlowfile, CoreAttributes.MIME_TYPE.key(), APPLICATION_JSON); session.transfer(conFlowfile, REL_SUCCESS); } else { FlowFile atFlowfile = session.putAttribute(original, JSON_ATTRIBUTE_NAME, objectMapper.writeValueAsString(atrList)); session.transfer(atFlowfile, REL_SUCCESS); } } catch (JsonProcessingException e) { getLogger().error(e.getMessage()); session.transfer(original, REL_FAILURE); } }
From source file:com.blockwithme.lessobjects.schema.StructSchema.java
/** Instantiates a new struct envelope from Struct object. */ @SuppressWarnings("null") public StructSchema(final Struct theStruct) { checkNotNull(theStruct);//w ww.j ava 2 s. com final StructInfo structInfo = theStruct.structInfo(); if (structInfo != null) { createdBy = structInfo.createdBy(); createdOn = structInfo.createdOn(); schemaVersion = structInfo.schemaVersion(); } else { createdBy = DEFAULT_CREATED_BY; createdOn = new Date(); schemaVersion = DEFAULT_SCHEMA_VERSION; } jsonVersion = JSON_VERSION; struct = theStruct; binding = new StructBinding(struct); try { final ObjectMapper mapper = mapper(); final ObjectWriter writer = mapper.writerWithView(JSONViews.SignatureView.class); final String signatureStr = writer.writeValueAsString(binding); final ObjectWriter writer2 = mapper.writerWithView(JSONViews.CompleteView.class); final String fullString = writer2.writeValueAsString(binding); signature = MurmurHash.hash64(signatureStr); fullHash = MurmurHash.hash64(fullString); } catch (final JsonProcessingException e) { throw new IllegalStateException(e.getMessage(), e); } }
From source file:org.craftercms.commons.jackson.mvc.CrafterJackson2MessageConverter.java
@Override protected void writeInternal(Object object, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType()); JsonGenerator jsonGenerator = this.getObjectMapper().getFactory().createGenerator(outputMessage.getBody(), encoding);/*from w w w . ja v a 2 s . c o m*/ // A workaround for JsonGenerators not applying serialization features // https://github.com/FasterXML/jackson-databind/issues/12 if (this.getObjectMapper().isEnabled(SerializationFeature.INDENT_OUTPUT)) { jsonGenerator.useDefaultPrettyPrinter(); } try { if (this.jsonPrefix != null) { jsonGenerator.writeRaw(this.jsonPrefix); } runAnnotations(object); ObjectWriter writer = this.getObjectMapper().writer(filter); writer.writeValue(jsonGenerator, object); } catch (JsonProcessingException ex) { throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex); } }
From source file:services.bizdockapi.BizdockApiClientImpl.java
@Override public JsonNode call(String applicationKey, String secretKey, ApiMethod apiMethod, String url, JsonNode content) throws BizdockApiException { // convert the JSON content to a string String contentString = null;/* w w w .j av a 2s.c o m*/ if (content != null) { try { contentString = getMapper().writeValueAsString(content); Logger.info("contentString: " + contentString); } catch (JsonProcessingException e) { throw new BizdockApiException(e.getMessage(), 500); } } // set the timestamp as now Date timestamp = new Date(); // generate the timestamp byte[] signatureAsByte = null; try { SignatureGeneratorImpl signatureGenerator = new SignatureGeneratorImpl(secretKey, applicationKey); byte[] contentAsByte = contentString != null ? contentString.getBytes() : null; signatureAsByte = signatureGenerator.getRequestSignature(apiMethod, url, contentAsByte, timestamp.getTime()); } catch (Exception e) { throw new BizdockApiException(e.getMessage(), 500); } // construct the request WSRequest request = WS.url(url).setHeader("Content-Type", "application/json"); request.setHeader(IApiConstants.APPLICATION_KEY_HEADER, applicationKey); request.setHeader(IApiConstants.SIGNATURE_HEADER, new String(signatureAsByte)); request.setHeader(IApiConstants.TIMESTAMP_HEADER, String.valueOf(timestamp.getTime())); // process the request Promise<WSResponse> response = null; switch (apiMethod) { case GET: response = request.get(); break; case POST: response = request.post(contentString); break; case PUT: response = request.put(contentString); break; case DELETE: response = request.delete(); break; default: break; } Promise<Pair<Integer, JsonNode>> jsonPromise = response .map(new Function<WSResponse, Pair<Integer, JsonNode>>() { public Pair<Integer, JsonNode> apply(WSResponse response) { try { return Pair.of(response.getStatus(), response.asJson()); } catch (Exception e) { JsonNode error = JsonNodeFactory.instance.textNode(e.getMessage()); return Pair.of(response.getStatus(), error); } } }); Pair<Integer, JsonNode> responseContent = jsonPromise.get(WS_TIMEOUT); // treat the response if (responseContent.getLeft().equals(200) || responseContent.getLeft().equals(204)) { return responseContent.getRight(); } else { String errorMessage = "BizDock API call error / url: " + url + " / status: " + responseContent.getLeft() + " / errors: " + responseContent.getRight().toString(); throw new BizdockApiException(errorMessage, responseContent.getLeft()); } }
From source file:com.pavlovmedia.oss.osgi.gelf.impl.GelfLogSink.java
public void logged(LogEntry entry) { if (!active) { return; // We aren't running }//w ww . ja v a2s.c o m ensureConnection(); if (null == transport) { return; // Not getting connected/reconnected } GelfMessage message = GelfMessageConverter.fromOsgiMessage(entry); try { byte[] messageBytes = mapper.writeValueAsBytes(message); transport.getOutputStream().write(messageBytes); // There is a bug in GELF that requires us to end with a null byte transport.getOutputStream().write(new byte[] { '\0' }); } catch (JsonProcessingException e) { if (consoleMessages) { System.err.println("Failed serializing a GelfMessage " + e.getMessage()); e.printStackTrace(); } } catch (IOException e) { if (consoleMessages) { System.err.println("Failed writing GelfMessage " + e.getMessage()); e.printStackTrace(); } try { transport.close(); } catch (IOException e1) { /* Do nothing */ } transport = null; } }
From source file:org.apache.nifi.processors.standard.RegexAttributesToJSON.java
@Override public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException { final FlowFile original = session.get(); if (original == null) { return;//w w w . j a v a 2 s . c om } final Map<String, String> atrList = buildAttributesMapForFlowFile(original, context.getProperty(ATTRIBUTES_REGEX).getValue(), context.getProperty(INCLUDE_CORE_ATTRIBUTES).asBoolean(), context.getProperty(NULL_VALUE_FOR_EMPTY_STRING).asBoolean(), context.getProperty(ATTRIBUTES_STRIP_PREFIX).getValue()); try { switch (context.getProperty(DESTINATION).getValue()) { case DESTINATION_ATTRIBUTE: FlowFile atFlowfile = session.putAttribute(original, JSON_ATTRIBUTE_NAME, objectMapper.writeValueAsString(atrList)); session.transfer(atFlowfile, REL_SUCCESS); break; case DESTINATION_CONTENT: FlowFile conFlowfile = session.write(original, new StreamCallback() { @Override public void process(InputStream in, OutputStream out) throws IOException { try (OutputStream outputStream = new BufferedOutputStream(out)) { outputStream.write(objectMapper.writeValueAsBytes(atrList)); } } }); conFlowfile = session.putAttribute(conFlowfile, CoreAttributes.MIME_TYPE.key(), APPLICATION_JSON); session.transfer(conFlowfile, REL_SUCCESS); break; } } catch (JsonProcessingException e) { getLogger().error(e.getMessage()); session.transfer(original, REL_FAILURE); } }
From source file:tuwien.aic.crowdsourcing.util.MappingJackson2HttpMessageConverter.java
@Override protected void writeInternal(Object object, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType()); JsonGenerator jsonGenerator = this.objectMapper.getFactory().createJsonGenerator(outputMessage.getBody(), encoding);/*from w w w . j a va 2 s . c o m*/ try { if (this.prefixJson) { jsonGenerator.writeRaw("{} && "); } if (this.prettyPrint) { jsonGenerator.useDefaultPrettyPrinter(); } this.objectMapper.writeValue(jsonGenerator, object); } catch (JsonProcessingException ex) { throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex); } }
From source file:org.apache.metron.solr.dao.SolrSearchDao.java
protected SearchResponse buildSearchResponse(SearchRequest searchRequest, QueryResponse solrResponse) { SearchResponse searchResponse = new SearchResponse(); SolrDocumentList solrDocumentList = solrResponse.getResults(); searchResponse.setTotal(solrDocumentList.getNumFound()); // search hits --> search results List<SearchResult> results = solrDocumentList.stream().map(solrDocument -> SolrUtilities .getSearchResult(solrDocument, searchRequest.getFields(), accessConfig.getIndexSupplier())) .collect(Collectors.toList()); searchResponse.setResults(results);//from w w w. j a va2 s. c o m // handle facet fields List<String> facetFields = searchRequest.getFacetFields(); if (facetFields != null) { searchResponse.setFacetCounts(getFacetCounts(facetFields, solrResponse)); } if (LOG.isDebugEnabled()) { String response; try { response = JSONUtils.INSTANCE.toJSON(searchResponse, false); } catch (JsonProcessingException e) { response = e.getMessage(); } LOG.debug("Built search response; response={}", response); } return searchResponse; }