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:com.liato.bankdroid.banking.banks.lansforsakringar.Lansforsakringar.java

public String objectAsJson(Object value) {
    try {//from  w  w w .  j  a  v a2s.  com
        return mObjectMapper.writeValueAsString(value);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }
    return null;
}

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

/**
 * Test that a list of services could be retrieved.
 *//*from w w  w . j  a  v  a2 s. c om*/
@Test
public void testListServicesSuccessAccessor() {
    try {
        ObjectMapper mapper = new ObjectMapper();
        String responseServiceString = mapper.writeValueAsString(services);

        ResponseEntity<String> responseEntity = new ResponseEntity<String>(responseServiceString,
                HttpStatus.OK);
        Mockito.doReturn(services).when(accessorMock).list();

        ResponseEntity<String> result = lsHandler.handle();

        assertEquals("The response entity was correct for this list services request", 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:ac.ucy.cs.spdx.service.SpdxViolationAnalysis.java

@POST
@Path("/analyze/")
@Consumes(MediaType.TEXT_PLAIN)/*  w  w  w .j a  va2s .  com*/
@Produces(MediaType.APPLICATION_JSON)
public String analyzeSpdx(String jsonString) {

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

    ArrayList<SpdxLicensePairConflictError> fileNames = new ArrayList<SpdxLicensePairConflictError>();

    for (JsonNode fileNode : spdxFilesContent.get("files")) {
        String fileName = fileNode.get("filename").toString();
        fileName = fileName.substring(1, fileName.length() - 1);
        String content = fileNode.get("content").toString();
        content = StringEscapeUtils.unescapeXml(content);
        content = content.substring(1, content.length() - 1);

        try {
            fileNames.add(new SpdxLicensePairConflictError(
                    new CaptureLicense(ParseRdf.parseToRdf(fileName, content))));
        } catch (InvalidLicenseStringException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InvalidSPDXAnalysisException e) {
            e.printStackTrace();
        } catch (UnsupportedSpdxVersionException e) {
            e.printStackTrace();
        }

    }

    ViolationAnalysisInfo analysis = null;
    try {
        analysis = new ViolationAnalysisInfo(
                fileNames.toArray(new SpdxLicensePairConflictError[fileNames.size()]));
    } catch (LicenseNodeNotFoundException e) {
        e.printStackTrace();
    }

    return analysis.toJson();// {"count":"","files":[{"filename":"","content":""}]}
}

From source file:com.skubit.iab.fragments.TransactionsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_wallet_transactions, null);

    TextView balanceLabel = (TextView) view.findViewById(R.id.wallet_balance_label);
    balanceLabel.setTypeface(FontManager.CONDENSED_REGULAR);

    TextView availableLabel = (TextView) view.findViewById(R.id.wallet_available_label);
    availableLabel.setTypeface(FontManager.CONDENSED_REGULAR);

    mBalance = (TextView) view.findViewById(R.id.wallet_balance);
    mAvailable = (TextView) view.findViewById(R.id.wallet_available);

    ListView list = (ListView) view.findViewById(R.id.list);
    list.setAdapter(mAdapter);//from  w  w w  .j  a v a  2 s.co m

    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapter, View arg1, int position, long arg3) {
            TransactionDto transactionDto = (TransactionDto) adapter.getItemAtPosition(position);
            ObjectMapper mapper = new ObjectMapper();
            String value;
            try {
                value = mapper.writeValueAsString(transactionDto);
                startActivity(TransactionDetailsActivity.newIntent(value, getActivity().getPackageName()));
                getActivity().overridePendingTransition(R.anim.pull_in_right, R.anim.none);
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
        }

    });

    mSwipe = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh);

    mSwipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            refreshBalance();
            getTransactions();
        }
    });

    return view;
}

From source file:org.n52.tamis.core.test.serialize.ExecuteInputBodySerializer_Test.java

@Test
public void testExecuteBodySerialization() {

    try {//from w  w w  .  ja va 2  s  . c  om
        String execBodyJsonOutput = mapper.writeValueAsString(executeBody);
        System.out.println(execBodyJsonOutput);

        JsonNode parsedJsonExecBody = mapper.readTree(execBodyJsonOutput);
        JsonNode executeNode = parsedJsonExecBody.get("Execute");

        /*
         * the expected structure of the parsed JSON node looks like:
         * 
         * { "Execute": { "Identifier":
         * "org.n52.wps.server.algorithm.test.EchoProcess", "Input": [ {
         * "Reference": { "_mimeType": "text/xml", "_href":
         * "http://geoprocessing.demo.52north.org:8080/geoserver/wfs?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=topp:tasmania_roads&SRS=EPSG:4326&OUTPUTFORMAT=GML3"
         * }, "_id": "complexInput" } ], "output":[{ "_mimeType":
         * "text/xml", "_id": "complexOutput", "_transmission": "reference"
         * }], "_service": "WPS", "_version": "2.0.0"} }
         * 
         */

        Assert.assertTrue(executeNode.has("Identifier"));
        Assert.assertTrue(executeNode.has("Input"));
        Assert.assertTrue(executeNode.has("output"));
        Assert.assertTrue(executeNode.has("_service"));
        Assert.assertTrue(executeNode.has("_version"));

        Assert.assertEquals("example.processId", executeNode.get("Identifier").asText());
        Assert.assertEquals("WPS", executeNode.get("_service").asText());

        JsonNode inputs = executeNode.get("Input");

        Assert.assertTrue(inputs.isArray());
        Assert.assertTrue(inputs.size() == 2);
        /*
         * the actual structure of Input content is tested in a different
         * JUnit test case (ExecuteInputSerialier_Test)
         */

        /*
         * test output
         */
        JsonNode outputs = executeNode.get("output");
        Assert.assertTrue(outputs.isArray());

        JsonNode singleOutput = outputs.get(0);
        Assert.assertEquals("application/json", singleOutput.get("_mimeType").asText());
        Assert.assertEquals("executeOutputID", singleOutput.get("_id").asText());

    } catch (JsonProcessingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

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

/**
 * Test what happens when there are no registered user services
 *//*from  w w w.  j  a  va 2s  .c  o m*/
@Test
public void testEmptyList() {
    try {
        ObjectMapper mapper = new ObjectMapper();

        List<Service> serviceList = new ArrayList<>();
        String responseServiceString = mapper.writeValueAsString(serviceList);

        ResponseEntity<String> responseEntity = new ResponseEntity<String>(responseServiceString,
                HttpStatus.OK);
        Mockito.doReturn(serviceList).when(accessorMock).list();

        ResponseEntity<String> result = lsHandler.handle();

        assertEquals("The response entity was correct for this list services request", responseEntity, result);
        assertEquals("The response code is 200", responseEntity.getStatusCode(), HttpStatus.OK);
        assertEquals("The body of the response is correct with empty list", responseEntity.getBody(),
                responseServiceString);

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

}

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

/**
 * Test that the list of services could not be retrieved 
 * due to a marshalling error/*from   w w w . j av a2  s  .  c om*/
 */
@Test
public void testUnsuccessListServiceException() {
    ResponseEntity<String> responseEntity = new ResponseEntity<String>(
            "Could not retrieve a list of user services", HttpStatus.NOT_FOUND);
    try {
        final ListServiceHandler lsMock = Mockito.spy(lsHandler);

        Mockito.doReturn(omMock).when(lsMock).makeObjectMapper();
        Mockito.doReturn(services).when(accessorMock).list();

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

        assertEquals("The response entity was correct for this list service 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 retrieve a list of user services");
    } catch (JsonProcessingException jpe) {
        jpe.printStackTrace();
    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

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

/**
 * Test that a list of services could be retrieved.
 *///from   w w  w . j a  v  a 2s.co m
@Test
public void testListServicesSuccess() {
    ListServicesJob job = new ListServicesJob();

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

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

        final ListServiceHandler lsMock = Mockito.spy(lsHandler);

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

        assertEquals("The response entity was correct for this describe request", 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:ch.icclab.cyclops.services.iaas.openstack.resource.impl.MeterResource.java

/**
 * Returns the last persisted list of meters
 * <p/>//from   w  ww  .j  a va 2 s .c o m
 * Pseudo Code<br>
 * 1. Receive the request for the list of meters<br>
 * 2. Query the DB to get the list<br>
 * 3. Return the list of meters
 *
 * @return Representation A JSON response containing the list of meters
 */
@Get
public Representation getMeterList() {
    counter.increment(endpoint);

    JsonRepresentation responseJson = null;
    TSDBData responseObj;
    ObjectMapper mapper = new ObjectMapper();
    TSDBResource tsdbResource = new TSDBResource();
    responseObj = tsdbResource.getMeterList();

    try {
        String jsonStr = mapper.writeValueAsString(responseObj);
        responseJson = new JsonRepresentation(jsonStr);
    } catch (JsonProcessingException e) {
        logger.error("Could not parse JSON when getting meterList: " + e.getMessage());
        e.printStackTrace();
    }

    return responseJson;
}

From source file:io.github.bckfnn.reactstreams.arangodb.Result.java

public String toString() {
    ObjectMapper map = new ObjectMapper();
    try {/*w  w  w  .j  a  v a2 s  . c  o m*/
        return map.writeValueAsString(this);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
        return "error";
    }
}