Example usage for com.fasterxml.jackson.core JsonProcessingException printStackTrace

List of usage examples for com.fasterxml.jackson.core JsonProcessingException printStackTrace

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonProcessingException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:ac.ucy.cs.spdx.service.SpdxViolationAnalysis.java

@POST
@Path("/correct/")
@Consumes(MediaType.TEXT_PLAIN)//www.j a  v  a 2s  . c  om
@Produces(MediaType.TEXT_XML)
public Response correctSpdx(String jsonString) throws Exception {

    ObjectMapper mapper = new ObjectMapper();
    JsonNode fileNode = null;
    try {
        fileNode = mapper.readTree(jsonString);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    String fileName = fileNode.get("filename").toString();
    fileName = fileName.substring(1, fileName.length() - 1);

    final String LICENSE_HTML = "http://spdx.org/licenses/";

    String contentXML = fileNode.get("content").toString();
    contentXML = StringEscapeUtils.unescapeXml(contentXML);
    contentXML = contentXML.substring(1, contentXML.length() - 1);

    String newDeclared = fileNode.get("declared").toString();
    newDeclared = newDeclared.substring(1, newDeclared.length() - 1);

    String fullpath = ParseRdf.parseToRdf(fileName, contentXML);
    setLastCorrected(fullpath);

    File xmlFile = new File(fullpath);

    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(xmlFile);

    if (doc.getElementsByTagName("licenseDeclared").item(0).getAttributes()
            .getNamedItem("rdf:resource") == null) {
        Element e = (Element) doc.getElementsByTagName("licenseDeclared").item(0);
        e.setAttribute("rdf:resource", LICENSE_HTML + newDeclared);
    } else {
        doc.getElementsByTagName("licenseDeclared").item(0).getAttributes().getNamedItem("rdf:resource")
                .setNodeValue(LICENSE_HTML + newDeclared);
    }

    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    DOMSource source = new DOMSource(doc);

    PrintWriter writer = new PrintWriter(xmlFile);
    writer.print("");
    writer.close();

    StreamResult result = new StreamResult(xmlFile);

    transformer.transform(source, result);

    ResponseBuilder response = Response.ok((Object) xmlFile);
    response.header("Content-Disposition", "attachment; filename=" + fileName);
    return response.build();// {"filename":"anomos","declared":"Apache-2.0","content":""}

}

From source file:org.venice.piazza.servicecontroller.messaging.handlers.SearchServiceHandlerTest.java

/**
 * Test that services were returned//from  w ww .j  a v  a2  s .  c o  m
 */
@Test
public void testSuccessSearchCriteria() {
    try {
        ObjectMapper mapper = new ObjectMapper();
        String responseServiceString = mapper.writeValueAsString(services);
        SearchCriteria criteria = new SearchCriteria();
        criteria.field = "animalType";
        criteria.pattern = "A*r";

        ResponseEntity<String> responseEntity = new ResponseEntity<String>(responseServiceString,
                HttpStatus.OK);
        Mockito.doReturn(services).when(accessorMock).search(criteria);
        Mockito.doNothing().when(loggerMock).log(Mockito.anyString(), Mockito.anyString());

        ResponseEntity<String> result = ssHandler.handle(criteria);

        assertEquals("The response entity result is correct", responseEntity, result);
        assertEquals("The response code is 200", responseEntity.getStatusCode(), HttpStatus.OK);
        assertEquals("The body of the response is correct", responseEntity.getBody(), responseServiceString);

    } catch (JsonProcessingException jpe) {
        jpe.printStackTrace();
    }

}

From source file:com.flipkart.ranger.model.ServiceProviderTest.java

private void registerService(String host, int port, int shardId) throws Exception {
    final ServiceProvider<TestShardInfo> serviceProvider = ServiceProviderBuilders
            .<TestShardInfo>shardedServiceProviderBuilder()
            .withConnectionString(testingCluster.getConnectString()).withNamespace("test")
            .withServiceName("test-service").withSerializer(new Serializer<TestShardInfo>() {
                @Override/*www . jav  a2  s . c om*/
                public byte[] serialize(ServiceNode<TestShardInfo> data) {
                    try {
                        return objectMapper.writeValueAsBytes(data);
                    } catch (JsonProcessingException e) {
                        e.printStackTrace();
                    }
                    return null;
                }
            }).withHostname(host).withPort(port).withNodeData(new TestShardInfo(shardId))
            .withHealthcheck(new Healthcheck() {
                @Override
                public HealthcheckStatus check() {
                    return HealthcheckStatus.healthy;
                }
            }).buildServiceDiscovery();
    serviceProvider.start();
    serviceProviders.add(serviceProvider);
}

From source file:org.hawkular.apm.api.model.trace.TraceTest.java

@Test
public void testSerialize() {
    Trace trace = example1();/*from w w  w .  j  a v  a 2s  .  c o m*/

    // Serialize
    ObjectMapper mapper = new ObjectMapper();

    try {
        mapper.writeValueAsString(trace);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
        fail("Failed to serialize");
    }
}

From source file:org.venice.piazza.servicecontroller.messaging.handlers.SearchServiceHandlerTest.java

/**
 * Test that the results throws a JSON exception
 * due to a marshalling error//w w  w. jav  a 2s  .c  om
 */
@Test
public void testThrowException() {
    ResponseEntity<String> responseEntity = new ResponseEntity<String>("Could not search for services",
            HttpStatus.NOT_FOUND);

    SearchCriteria criteria = new SearchCriteria();
    criteria.field = "animalType";
    criteria.pattern = "A*r";
    try {
        final SearchServiceHandler ssMock = Mockito.spy(ssHandler);

        Mockito.doReturn(omMock).when(ssMock).makeObjectMapper();
        Mockito.doReturn(services).when(accessorMock).search(criteria);

        Mockito.when(omMock.writeValueAsString(services)).thenThrow(new JsonMappingException("Test Exception"));
        ResponseEntity<String> result = ssMock.handle(criteria);

        assertEquals("The response entity was correct for the search request", responseEntity, result);
        assertEquals("The response code is 404", responseEntity.getStatusCode(), HttpStatus.NOT_FOUND);
        assertEquals("The body of the response is correct", responseEntity.getBody(),
                "Could not search for services");
    } catch (JsonProcessingException jpe) {
        jpe.printStackTrace();
    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:mercury.core.Deferred.java

public String mapObjectTOSJON(Object o) {
    String json = "{}";
    try {/*w w  w . java  2 s.  c o  m*/
        json = getMapper().writeValueAsString(o);
    } catch (JsonProcessingException ex) {
        logger.warning("Couldn't map Object. Returning {}");
        ImageJFX.getLogger();
        ex.printStackTrace();
    }
    return json;
}

From source file:eu.supersede.fe.application.ApplicationUtil.java

/**
 * Add an application with the given name, labels and home page.
 * @param applicationName/*from  w  w  w. j  a v  a 2  s . c  om*/
 * @param applicationLabels
 * @param homePage
 */
public void addApplication(String applicationName, Map<String, String> applicationLabels, String homePage) {
    Application app = new Application(applicationName, applicationLabels, homePage);

    try {
        template.opsForHash().put(APP_KEY, app.getId(), mapper.writeValueAsString(app));
    } catch (JsonProcessingException e) {
        log.debug(e.getMessage());
        e.printStackTrace();
    }
}

From source file:info.pancancer.arch3.beans.Job.java

public String toJSON() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    try {//from  w w  w. j  a  v a  2  s .com
        return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(this);
    } catch (JsonProcessingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }
}

From source file:org.venice.piazza.servicecontroller.messaging.handlers.SearchServiceHandlerTest.java

/**
 * Test that the search retrieves results
 *//*from  w ww . j  ava 2  s . c o m*/
@Test
public void testSearchSuccess() {
    SearchServiceJob job = new SearchServiceJob();

    SearchCriteria criteria = new SearchCriteria();
    criteria.field = "animalType";
    criteria.pattern = "A*r";

    job.data = criteria;
    try {
        ObjectMapper mapper = new ObjectMapper();
        String responseServiceString = mapper.writeValueAsString(services);

        ResponseEntity<String> responseEntity = new ResponseEntity<String>(responseServiceString,
                HttpStatus.OK);

        final SearchServiceHandler ssMock = Mockito.spy(ssHandler);

        Mockito.doReturn(responseEntity).when(ssMock).handle(criteria);
        ResponseEntity<String> result = ssMock.handle(job);

        assertEquals("The response entity is correct", responseEntity, result);
        assertEquals("The response code is 200", responseEntity.getStatusCode(), HttpStatus.OK);
        assertEquals("The body of the response is correct", responseEntity.getBody(), responseServiceString);

    } catch (JsonProcessingException jpe) {
        jpe.printStackTrace();
    }

}

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  a2  s  .c  om
 * @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();
    }
}