List of usage examples for com.fasterxml.jackson.core JsonProcessingException toString
@Override
public String toString()
From source file:watchtower.common.automation.JobUtils.java
public static String toJson(Job job) { try {// w w w . j a v a 2 s . c o m return OBJECT_MAPPER.writeValueAsString(job); } catch (JsonProcessingException e) { logger.error("Failed to convert job to json: {}", e.toString()); } return null; }
From source file:watchtower.common.event.EventUtils.java
public static String toJson(Event event) { try {/*from w w w . j a va 2 s . co m*/ return OBJECT_MAPPER.writeValueAsString(event); } catch (JsonProcessingException e) { logger.error("Failed to convert event to json: {}", e.toString()); } return null; }
From source file:watchtower.common.automation.CommandUtils.java
public static String toJson(Command command) { try {// www . jav a2 s .c om return OBJECT_MAPPER.writeValueAsString(command); } catch (JsonProcessingException e) { logger.error("Failed to convert command to json: {}", e.toString()); } return null; }
From source file:watchtower.common.incident.IncidentUtils.java
public static String toJson(Incident incident) { try {/*from www. j a v a 2 s . c o m*/ return OBJECT_MAPPER.writeValueAsString(incident); } catch (JsonProcessingException e) { logger.error("Failed to convert incident to json: {}", e.toString()); } return null; }
From source file:automenta.knowtention.Core.java
public static String toJSON(Object o) { try {/*from ww w.j a va 2 s . c o m*/ return json.writeValueAsString(o); } catch (JsonProcessingException ex) { System.out.println(ex.toString()); try { return json.writeValueAsString(o.toString()); } catch (JsonProcessingException ex1) { return null; } } }
From source file:com.rusticisoftware.tincan.json.JSONBase.java
@Override public String toJSON(TCAPIVersion version, Boolean pretty) { ObjectWriter writer = Mapper.getWriter(pretty); try {/* w w w . j a v a2 s.c om*/ return writer.writeValueAsString(this.toJSONNode(version)); } catch (JsonProcessingException ex) { return "Exception in JSONBase Class: " + ex.toString(); } }
From source file:nz.co.acme.spike.rest.resource.Entity.java
/** * Create a JSON string representation of this object. * * @return String in JSON format or null if an exception is caught. *//*from w w w.j av a 2 s.c o m*/ @Override public String toString() { String string = null; try { string = new ObjectMapper().writer().writeValueAsString(this); } catch (JsonProcessingException e) { logger.severe(e.toString()); } return string; }
From source file:com.streamsets.datacollector.execution.store.FilePipelineStateStore.java
private void persistPipelineState(PipelineState pipelineState) throws PipelineStoreException { // write to /runInfo/<pipelineName>/pipelineState.json as well as /runInfo/<pipelineName>/pipelineStateHistory.json PipelineStateJson pipelineStateJson = BeanHelper.wrapPipelineState(pipelineState); String pipelineString;//from w w w. j a v a 2 s . c om try { pipelineString = ObjectMapperFactory.get().writeValueAsString(pipelineStateJson); } catch (JsonProcessingException e) { throw new PipelineStoreException(ContainerError.CONTAINER_0210, e.toString(), e); } DataStore dataStore = new DataStore( getPipelineStateFile(pipelineState.getPipelineId(), pipelineState.getRev())); try (OutputStream os = dataStore.getOutputStream()) { os.write(pipelineString.getBytes()); dataStore.commit(os); } catch (IOException e) { throw new PipelineStoreException(ContainerError.CONTAINER_0100, e.toString(), e); } finally { dataStore.release(); } // In addition, append the state of the pipeline to the pipelineState.json present in the directory of that // pipeline LogUtil.log(pipelineState.getPipelineId(), pipelineState.getRev(), STATE, pipelineString); }
From source file:io.github.retz.web.Client.java
public int getBinaryFile(int id, String file, OutputStream out) throws IOException { String date = TimestampHelper.now(); String resource = "/job/" + id + "/download?path=" + file; AuthHeader header = authenticator.header("GET", "", date, resource); URL url = new URL(uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + resource); // TODO url-encode! LOG.info("Fetching {}", url); HttpURLConnection conn;/*w w w . j a v a2 s .c o m*/ conn = (HttpURLConnection) url.openConnection(); //LOG.info("classname> {}", conn.getClass().getName()); if (uri.getScheme().equals("https") && !checkCert && conn instanceof HttpsURLConnection) { if (verboseLog) { LOG.warn( "DANGER ZONE: TLS certificate check is disabled. Set 'retz.tls.insecure = false' at config file to supress this message."); } HttpsURLConnection sslCon = (HttpsURLConnection) conn; if (socketFactory != null) { sslCon.setSSLSocketFactory(socketFactory); } if (hostnameVerifier != null) { sslCon.setHostnameVerifier(hostnameVerifier); } } conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "application/octet-stream"); conn.setRequestProperty("Authorization", header.buildHeader()); conn.setRequestProperty("Date", date); conn.setRequestProperty("Content-md5", ""); conn.setDoInput(true); String s2s = authenticator.string2sign("GET", "", date, resource); LOG.debug("Authorization: {} / S2S={}", header.buildHeader(), s2s); if (conn.getResponseCode() != 200) { if (verboseLog) { LOG.warn("HTTP Response:", conn.getResponseMessage()); } if (conn.getResponseCode() < 200) { throw new AssertionError(conn.getResponseMessage()); } else if (conn.getResponseCode() == 404) { throw new FileNotFoundException(url.toString()); } else { String message; try { Response response = MAPPER.readValue(conn.getErrorStream(), Response.class); message = response.status(); LOG.error(message, response); } catch (JsonProcessingException e) { message = e.toString(); LOG.error(message, e); } throw new UnknownError(message); } } int size = conn.getContentLength(); if (size < 0) { throw new IOException("Illegal content length:" + size); } else if (size == 0) { // not bytes to save; return 0; } try { return IOUtils.copy(conn.getInputStream(), out); } finally { conn.disconnect(); } }
From source file:com.yahoo.elide.Elide.java
protected ElideResponse buildResponse(Pair<Integer, JsonNode> response) { try {//from w w w. jav a 2 s .c o m JsonNode responseNode = response.getRight(); Integer responseCode = response.getLeft(); String body = mapper.writeJsonApiDocument(responseNode); return new ElideResponse(responseCode, body); } catch (JsonProcessingException e) { return new ElideResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.toString()); } }