List of usage examples for com.fasterxml.jackson.core JsonProcessingException getMessage
@Override
public String getMessage()
From source file:org.flockdata.search.dao.EntityChangeWriterEs.java
private String getJsonToIndex(EntitySearchChange searchChange) { ObjectMapper mapper = FdJsonObjectMapper.getObjectMapper(); Map<String, Object> index = getMapFromChange(searchChange); try {//from www. j a va 2s. c o m return mapper.writeValueAsString(index); } catch (JsonProcessingException e) { logger.error(e.getMessage()); } return null; }
From source file:org.commonjava.aprox.core.ctl.ContentController.java
public String renderListing(final String acceptHeader, final StoreKey key, final String requestPath, final String serviceUrl, final UriFormatter uriFormatter) throws AproxWorkflowException { String path = requestPath;//from www .ja va2s. co m if (path.endsWith(LISTING_HTML_FILE)) { path = normalize(parentPath(path)); } final List<StoreResource> listed = getListing(key, path); if (ApplicationContent.application_json.equals(acceptHeader)) { final DirectoryListingDTO dto = new DirectoryListingDTO(StoreResource.convertToEntries(listed)); try { return mapper.writeValueAsString(dto); } catch (final JsonProcessingException e) { throw new AproxWorkflowException("Failed to render listing to JSON: %s. Reason: %s", e, dto, e.getMessage()); } } final Map<String, Set<String>> listingUrls = new TreeMap<String, Set<String>>(); final String storeUrl = uriFormatter.formatAbsolutePathTo(serviceUrl, key.getType().singularEndpointName(), key.getName()); // first pass, process only obvious directory entries (ending in '/') // second pass, process the remainder. for (int pass = 0; pass < 2; pass++) { for (final ConcreteResource res : listed) { String p = res.getPath(); if (pass == 0 && !p.endsWith("/")) { continue; } else if (pass == 1) { if (!p.endsWith("/")) { final String dirpath = p + "/"; if (listingUrls.containsKey(normalize(storeUrl, dirpath))) { p = dirpath; } } else { continue; } } final String localUrl = normalize(storeUrl, p); Set<String> sources = listingUrls.get(localUrl); if (sources == null) { sources = new HashSet<String>(); listingUrls.put(localUrl, sources); } sources.add(normalize(res.getLocationUri(), res.getPath())); } } final List<String> sources = new ArrayList<String>(); for (final ConcreteResource res : listed) { // KeyedLocation is all we use in AProx. logger.debug("Formatting sources URL for: {}", res); final KeyedLocation kl = (KeyedLocation) res.getLocation(); final String uri = uriFormatter.formatAbsolutePathTo(serviceUrl, kl.getKey().getType().singularEndpointName(), kl.getKey().getName()); if (!sources.contains(uri)) { logger.debug("adding source URI: '{}'", uri); sources.add(uri); } } Collections.sort(sources); String parentPath = normalize(parentPath(path)); if (!parentPath.endsWith("/")) { parentPath += "/"; } final String parentUrl; if (parentPath.equals(path)) { parentPath = null; parentUrl = null; } else { parentUrl = uriFormatter.formatAbsolutePathTo(serviceUrl, key.getType().singularEndpointName(), key.getName(), parentPath); } final Map<String, Object> params = new HashMap<String, Object>(); params.put("items", listingUrls); params.put("parentUrl", parentUrl); params.put("parentPath", parentPath); params.put("path", path); params.put("storeKey", key); params.put("storeUrl", storeUrl); params.put("baseUrl", serviceUrl); params.put("sources", sources); // render... try { return templates.render(acceptHeader, "directory-listing", params); } catch (final AproxGroovyException e) { throw new AproxWorkflowException(e.getMessage(), e); } }
From source file:org.commonjava.aprox.depgraph.rest.RepositoryController.java
private String getPaths(final PathsDTO dto, final UriFormatter uriFormatter) throws AproxWorkflowException { final List<List<ProjectRelationship<ProjectVersionRef>>> paths; paths = resolvePaths(dto);/*from w w w . j av a2s .c om*/ Collections.sort(paths, new Comparator<List<ProjectRelationship<ProjectVersionRef>>>() { @Override public int compare(final List<ProjectRelationship<ProjectVersionRef>> o1, final List<ProjectRelationship<ProjectVersionRef>> o2) { int result = 0; int i = 0; ProjectVersionRefComparator cmp = new ProjectVersionRefComparator(); while (result == 0 && i < o1.size() && i < o2.size()) { ProjectRelationship<ProjectVersionRef> rel1 = o1.get(i); ProjectRelationship<ProjectVersionRef> rel2 = o2.get(i); i++; result = cmp.compare(rel1.getDeclaring(), rel2.getDeclaring()); if (result == 0) { result = cmp.compare(rel1.getTarget(), rel2.getTarget()); } } if (result == 0) { if (o1.size() < o2.size()) { result = -1; } else if (o1.size() > o2.size()) { result = 1; } } return result; } }); Map<ProjectVersionRef, List<List<ProjectRelationship<ProjectVersionRef>>>> result = new HashMap<>(); for (List<ProjectRelationship<ProjectVersionRef>> path : paths) { final ProjectVersionRef leaf = path.get(path.size() - 1).getTarget().asProjectVersionRef(); if (!result.containsKey(leaf)) { result.put(leaf, new ArrayList<List<ProjectRelationship<ProjectVersionRef>>>()); } List<List<ProjectRelationship<ProjectVersionRef>>> pathList = result.get(leaf); pathList.add(path); } try { return serializer.writeValueAsString(result); } catch (final JsonProcessingException e) { throw new AproxWorkflowException("Failed to serialize to JSON: %s", e, e.getMessage()); } }
From source file:com.servioticy.api.commons.data.SO.java
/** Update the Service Object * *///www . j a v a2s . c om public void update(String body) { JsonNode root; try { root = mapper.readTree(body); if (!root.path("customFields").isMissingNode()) { // TODO improve check jsonNode parsing ((ObjectNode) soRoot).put("customFields", root.get("customFields")); // ((ObjectNode)soRoot).put("customFields", mapper.readTree(mapper.writeValueAsString(root.get("customFields")))); } } 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()); } // Update updatedAt time ((ObjectNode) soRoot).put("updatedAt", System.currentTimeMillis()); }
From source file:org.jenkinsci.plugins.GitLabSecurityRealm.java
private String extractToken(String content) { try {//from w w w. j a v a 2 s . c o m ObjectMapper mapper = new ObjectMapper(); JsonNode jsonTree = mapper.readTree(content); JsonNode node = jsonTree.get("access_token"); if (node != null) { return node.asText(); } } catch (JsonProcessingException e) { Log.error(e.getMessage(), e); } catch (IOException e) { Log.error(e.getMessage(), e); } return null; }
From source file:org.dcache.util.histograms.HistogramModelTest.java
private void assertThatOriginalHistogramEqualsStored() { try {/*from w w w. j av a2 s .com*/ assertTrue(model.getClass().equals(originalModel.getClass())); String original = new ObjectMapper().writeValueAsString(originalModel); String restored = new ObjectMapper().writeValueAsString(model); assertEquals("object strings are not the same", original, restored); } catch (JsonProcessingException e) { assertNull(e.getMessage(), e); } }
From source file:org.commonjava.indy.core.ctl.ContentController.java
public String renderListing(final String acceptHeader, final StoreKey key, final String requestPath, final String serviceUrl, final UriFormatter uriFormatter, final EventMetadata eventMetadata) throws IndyWorkflowException { String path = requestPath;/*w w w . j a v a 2s .c o m*/ if (path.endsWith(LISTING_HTML_FILE)) { path = normalize(parentPath(path)); } final List<StoreResource> listed = getListing(key, path, eventMetadata); if (ApplicationContent.application_json.equals(acceptHeader)) { final DirectoryListingDTO dto = new DirectoryListingDTO(StoreResource.convertToEntries(listed)); try { return mapper.writeValueAsString(dto); } catch (final JsonProcessingException e) { throw new IndyWorkflowException("Failed to render listing to JSON: %s. Reason: %s", e, dto, e.getMessage()); } } final Map<String, Set<String>> listingUrls = new TreeMap<>(); final String storeUrl = uriFormatter.formatAbsolutePathTo(serviceUrl, key.getType().singularEndpointName(), key.getName()); if (listed != null) { // first pass, process only obvious directory entries (ending in '/') // second pass, process the remainder. for (int pass = 0; pass < 2; pass++) { for (final ConcreteResource res : listed) { String p = res.getPath(); if (pass == 0 && !p.endsWith("/")) { continue; } if (p.endsWith("-") || p.endsWith("-/")) { //skip npm adduser path to avoid the sensitive info showing. continue; } else if (pass == 1) { if (!p.endsWith("/")) { final String dirpath = p + "/"; if (listingUrls.containsKey(normalize(storeUrl, dirpath))) { p = dirpath; } } else { continue; } } final String localUrl = normalize(storeUrl, p); Set<String> sources = listingUrls.get(localUrl); if (sources == null) { sources = new HashSet<>(); listingUrls.put(localUrl, sources); } sources.add(normalize(res.getLocationUri(), res.getPath())); } } } final List<String> sources = new ArrayList<>(); if (listed != null) { for (final ConcreteResource res : listed) { // KeyedLocation is all we use in Indy. logger.debug("Formatting sources URL for: {}", res); final KeyedLocation kl = (KeyedLocation) res.getLocation(); final String uri = uriFormatter.formatAbsolutePathTo(serviceUrl, kl.getKey().getType().singularEndpointName(), kl.getKey().getName()); if (!sources.contains(uri)) { logger.debug("adding source URI: '{}'", uri); sources.add(uri); } } } Collections.sort(sources); String parentPath = normalize(parentPath(path)); if (!parentPath.endsWith("/")) { parentPath += "/"; } final String parentUrl; if (parentPath.equals(path)) { parentPath = null; parentUrl = null; } else { parentUrl = uriFormatter.formatAbsolutePathTo(serviceUrl, key.getType().singularEndpointName(), key.getName(), parentPath); } final Map<String, Object> params = new HashMap<>(); params.put("items", listingUrls); params.put("parentUrl", parentUrl); params.put("parentPath", parentPath); params.put("path", path); params.put("storeKey", key); params.put("storeUrl", storeUrl); params.put("baseUrl", serviceUrl); params.put("sources", sources); // render... try { return templates.render(acceptHeader, "directory-listing", params); } catch (final IndyGroovyException e) { throw new IndyWorkflowException(e.getMessage(), e); } }
From source file:org.venice.piazza.servicecontroller.async.AsynchronousServiceWorker.java
/** * Sends the cancellation status to the external User Service for the specified instance. * /*from w w w .ja va 2 s . co m*/ * @param instance * The instance to be cancelled */ @Async public void sendCancellationStatus(AsyncServiceInstance instance) { // Remove this from the Instance Table accessor.deleteAsyncServiceInstance(instance.getJobId()); // Send the DELETE request to the external User Service Service service = accessor.getServiceById(instance.getServiceId()); if (service != null) { String url = String.format("%s/%s/%s", service.getUrl(), DELETE_ENDPOINT, instance.getInstanceId()); try { restTemplate.delete(url); } catch (HttpClientErrorException | HttpServerErrorException exception) { String error = String.format( "Error Cancelling Service Instance on external User Service: HTTP Error Status %s encountered for Service ID %s Instance %s under Job ID %s. No subsequent calls will be made.", exception.getStatusCode().toString(), instance.getServiceId(), instance.getInstanceId(), instance.getJobId()); LOGGER.error(error, exception); logger.log(error, Severity.WARNING); } } // Send the Kafka Message for successful Cancellation status try { producer.send(JobMessageFactory.getUpdateStatusMessage(instance.getJobId(), new StatusUpdate(StatusUpdate.STATUS_CANCELLED), SPACE)); } catch (JsonProcessingException jsonException) { String error = String.format( "Error sending Cancelled Status from Job %s: %s. The Job was cancelled, but its status will not be updated in the Job Manager.", instance.getJobId(), jsonException.getMessage()); LOGGER.error(error, jsonException); logger.log(error, Severity.ERROR); } }