List of usage examples for com.fasterxml.jackson.core JsonProcessingException getMessage
@Override
public String getMessage()
From source file:com.servioticy.api.commons.datamodel.Data.java
/** Create a Data class * * @param user_id/*from ww w . j a v a 2 s . c o m*/ * @param soId * @param streamId * @param body */ public Data(SO so, String streamId, String body) { soParent = so; JsonNode stream = soParent.getStream(streamId); // Check if exists this streamId in the Service Object if (stream == null) throw new ServIoTWebApplicationException(Response.Status.NOT_FOUND, "This Service Object does not have this stream."); JsonNode root; try { root = mapper.readTree(body); // Check if exists lastUpdate if (root.path("lastUpdate").isMissingNode()) { throw new ServIoTWebApplicationException(Response.Status.BAD_REQUEST, "The lastUpdate field was not found"); } else { if (!root.path("lastUpdate").isLong() && !root.path("lastUpdate").isInt()) { throw new ServIoTWebApplicationException(Response.Status.BAD_REQUEST, "The lastUpdate has to be a long type"); } } // Check channels if (root.path("channels").isMissingNode()) { throw new ServIoTWebApplicationException(Response.Status.BAD_REQUEST, "No channels"); } else { ChannelsMapper.parsePutData(stream, root.get("channels")); } } catch (JsonProcessingException e) { LOG.error(e); throw new ServIoTWebApplicationException(Response.Status.BAD_REQUEST, e.getMessage()); } catch (IOException e) { LOG.error(e); throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage()); } ((ObjectNode) dataRoot).putAll((ObjectNode) root); dataKey = soParent.getId() + "-" + streamId + "-" + root.get("lastUpdate").asLong(); }
From source file:org.resthub.web.converter.MappingJackson2XmlHttpMessageConverter.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(); }/* ww w . j a va 2s. c o m*/ try { this.objectMapper.writeValue(jsonGenerator, object); } catch (JsonProcessingException ex) { throw new HttpMessageNotWritableException("Could not write XML: " + ex.getMessage(), ex); } }
From source file:org.eclipse.winery.repository.resources.admin.NamespacesResource.java
/** * Returns the list of all namespaces registered with his manager and used * at component instances.// w w w . ja v a2s. com * * @return a JSON list containing the non-encoded URIs of each known * namespace */ @GET @Produces(MediaType.APPLICATION_JSON) public String getNamespacesAsJSONlist() { Collection<Namespace> namespaces = NamespacesResource.getNamespaces(); // We now have all namespaces // We need to convert from Namespace to String TreeSet<String> stringNamespaces = new TreeSet<String>(); for (Namespace ns : namespaces) { stringNamespaces.add(ns.getDecoded()); } String res; try { res = Utils.mapper.writeValueAsString(stringNamespaces); } catch (JsonProcessingException e) { NamespacesResource.logger.error(e.getMessage(), e); res = "[]"; } return res; }
From source file:org.apereo.openlrs.model.xapi.Statement.java
@JsonIgnore @Override/*from w w w . j a v a2 s .c o m*/ public String toJSON() { Logger log = Logger.getLogger(Statement.class); ObjectMapper om = new ObjectMapper(); String rawJson = null; try { rawJson = om.writer().writeValueAsString(this); } catch (JsonProcessingException e) { log.error(e.getMessage(), e); } return rawJson; }
From source file:org.commonjava.maven.galley.transport.htcli.UploadMetadataGenTransferDecorator.java
private void writeMetadata(final Transfer target, final ObjectMapper mapper, final Map<String, List<String>> requestHeaders) { Transfer metaTxfr = target.getSiblingMeta(HttpExchangeMetadata.FILE_EXTENSION); if (metaTxfr == null) { if (target.isDirectory()) { logger.trace("DIRECTORY. Using HTTP exchange metadata file INSIDE directory called: {}", HttpExchangeMetadata.FILE_EXTENSION); metaTxfr = target.getChild(HttpExchangeMetadata.FILE_EXTENSION); } else {//from w w w . ja v a 2 s. c o m logger.trace("SKIP: Cannot retrieve HTTP exchange metadata Transfer instance for: {}", target); return; } } final HttpExchangeMetadata metadata = new HttpExchangeMetadataFromRequestHeader(requestHeaders); OutputStream out = null; try { final Transfer finalMeta = metaTxfr; out = metaTxfr.openOutputStream(TransferOperation.GENERATE, false); logger.trace("Writing HTTP exchange metadata:\n\n{}\n\n", new Object() { @Override public String toString() { try { return mapper.writeValueAsString(metadata); } catch (final JsonProcessingException e) { logger.warn(String.format("Failed to write HTTP exchange metadata: %s. Reason: %s", finalMeta, e.getMessage()), e); } return "ERROR RENDERING METADATA"; } }); out.write(mapper.writeValueAsBytes(metadata)); } catch (final IOException e) { if (logger.isTraceEnabled()) { logger.trace(String.format("Failed to write metadata for HTTP exchange to: %s. Reason: %s", metaTxfr, e.getMessage()), e); } else { logger.warn("Failed to write metadata for HTTP exchange to: {}. Reason: {}", metaTxfr, e.getMessage()); } } finally { IOUtils.closeQuietly(out); } }
From source file:eu.modaclouds.sla.mediator.generation.TemplateGenerator.java
private GuaranteeTerm generateGuaranteeTerm(Constraint constraint, MonitoringRule rule, IDocument<Repository> document) { logger.debug("Generate guaranteeTerm({}, {}, {}", constraint.getId(), rule.getId(), document.getJAXBNode().getId()); GuaranteeTerm gt = NULL_GUARANTEE_TERM; String outputMetric = QosModels.getOutputMetric(rule); TargetClass target = TargetClass.fromString(constraint.getTargetClass()); ServiceScope serviceScope = ServiceScoper.fromConstraint(constraint, document); if (isSuitableConstraint(constraint, rule, target, serviceScope, outputMetric)) { gt = new GuaranteeTerm(); gt.setName(constraint.getId());//from w w w . j a va 2 s . co m gt.setServiceScope(serviceScope); ServiceLevelObjective slo = new ServiceLevelObjective(); KPITarget kpi = new KPITarget(); kpi.setKpiName(constraint.getMetric()); try { kpi.setCustomServiceLevel(String.format( "{\"%s\": \"%s NOT_EXISTS\", \"qos\": %s, \"aggregation\": %s}", CONSTRAINT, outputMetric, toJson(constraint.getRange()), toJson(constraint.getMetricAggregation()))); } catch (JsonProcessingException e) { throw new GeneratorException(e.getMessage(), e); } slo.setKpitarget(kpi); gt.setServiceLevelObjetive(slo); gt = generateBusinessValueList(gt, rule); } return gt; }
From source file:org.phenotips.data.rest.internal.DefaultPatientsFetchResourceImpl.java
@Override public Response fetchPatients() { final Request request = this.container.getRequest(); // Get the internal and external IDs, if provided. final List<Object> eids = request.getProperties("eid"); final List<Object> ids = request.getProperties("id"); this.logger.debug("Retrieving patient records with external IDs [{}] and internal IDs [{}]", eids, ids); // Build a set of patients from the provided external and/or internal ID data. final ImmutableSet.Builder<PrimaryEntity> patientsBuilder = ImmutableSet.builder(); try {/*from w w w . ja v a 2s. co m*/ addEids(patientsBuilder, eids); addIds(patientsBuilder, ids); // Generate JSON for all retrieved patients. final String json = this.objectMapper.writeValueAsString(patientsBuilder.build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); } catch (final JsonProcessingException ex) { this.logger.error("Failed to serialize patients [{}] to JSON: {}", eids, ex.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } catch (final QueryException ex) { this.logger.error("Failed to retrieve patients with external ids [{}]: {}", eids, ex.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } }
From source file:de.cismet.cids.custom.utils.nas.CidsActionClient.java
/** * DOCUMENT ME!// w w w .j a va 2s. c o m * * @param actionKey DOCUMENT ME! * @param task DOCUMENT ME! * @param f DOCUMENT ME! * @param fileType DOCUMENT ME! * @param requestResultingInstance DOCUMENT ME! * * @return DOCUMENT ME! */ protected ActionTask createTask(final String actionKey, final ActionTask task, final File f, final MediaType fileType, final boolean requestResultingInstance) { try { final String formattedUrl = String.format(RESOURCE_URL, domain, actionKey, "", ""); final String url = baseURL + ACTION_URL + formattedUrl.substring(0, formattedUrl.lastIndexOf("//results")); final WebResource webResource = client.resource(url).queryParam("requestResultingInstance", Boolean.toString(requestResultingInstance)); final FormDataMultiPart form = new FormDataMultiPart(); form.field("taskparams", mapper.writeValueAsString(task), MediaType.APPLICATION_JSON_TYPE); if (f != null) { form.field("file", f, fileType); } final String responseJson = webResource.type(MediaType.MULTIPART_FORM_DATA) .accept(MediaType.APPLICATION_JSON).post(String.class, form); final ActionTask resultingInstance = mapper.readValue(responseJson, ActionTask.class); return resultingInstance; } catch (JsonProcessingException ex) { LOG.error(ex.getMessage(), ex); } catch (IOException ex) { LOG.error(ex.getMessage(), ex); } return null; }
From source file:com.miage.ws.WebServiceDomotique.java
private String getJsonFromObject(Object o) { ObjectMapper mapper = new ObjectMapper(); try {/* w w w.j av a2 s. c o m*/ return mapper.writeValueAsString(o); } catch (JsonProcessingException ex) { Logger.getLogger(WebServiceDomotique.class.getName()).log(Level.SEVERE, null, ex); return ex.getMessage(); } }
From source file:net.fischboeck.discogs.BaseOperations.java
<T> T doPutRequest(String url, Object body, Class<T> type) throws ClientException { log.debug("[doPutRequest] url={}", url); CloseableHttpResponse response = null; try {// w w w .j a v a2s . c o m HttpPut request = new HttpPut(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); } }