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

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

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.nitsoft.ecommerce.api.APIUtil.java

protected String writeObjectToJson(Object obj) {
    try {//from  ww w . j  ava 2s .  c  o m

        return mapper.writeValueAsString(obj);

    } catch (JsonProcessingException ex) {
        // Throw our exception
        throw new ApplicationException(ex.getCause());
    }
}

From source file:com.nitsoft.ecommerce.api.APIUtil.java

protected String writeObjectToJsonRemoveNullProperty(Object obj) throws ApplicationException {
    try {/*  w w w  .  jav a2s  .com*/
        // Set setting remove NULL property
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        // map json
        String result = mapper.writeValueAsString(obj);
        // Reset default setting
        mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
        return result;

    } catch (JsonProcessingException ex) {
        // Throw our exception
        throw new ApplicationException(ex.getCause());
    }
}

From source file:com.unboundid.scim2.server.providers.JsonProcessingExceptionMapper.java

/**
 * {@inheritDoc}// w  w w.jav  a2  s.  c  o m
 */
public Response toResponse(final JsonProcessingException exception) {
    ErrorResponse errorResponse;
    if ((exception instanceof JsonParseException) || (exception instanceof JsonMappingException)) {
        StringBuilder builder = new StringBuilder();
        builder.append("Unable to parse request: ");
        builder.append(exception.getOriginalMessage());
        if (exception.getLocation() != null) {
            builder.append(" at line: ");
            builder.append(exception.getLocation().getLineNr());
            builder.append(", column: ");
            builder.append(exception.getLocation().getColumnNr());
        }
        errorResponse = BadRequestException.invalidSyntax(builder.toString()).getScimError();
    } else {
        if (exception.getCause() != null && exception.getCause() instanceof ScimException) {
            errorResponse = ((ScimException) exception.getCause()).getScimError();
        } else {
            errorResponse = new ServerErrorException(exception.getMessage()).getScimError();
        }
    }

    return ServerUtils.setAcceptableType(Response.status(errorResponse.getStatus()).entity(errorResponse),
            headers.getAcceptableMediaTypes()).build();
}

From source file:org.metis.sql.SqlJob.java

/**
 * Polls the DB and notifies clients of a change in the DB or a fatal error.
 * /*w  ww .j  a  v  a2 s . com*/
 * @return
 * @throws Exception
 */
private String pollDB() throws Exception {

    SqlResult sqlResult = null;

    try {

        // execute the sql statement. if a sqlResult was not returned,
        // then an error occurred and this job must be considered
        // defunct.
        if ((sqlResult = sqlStmnt.execute(getlParams())) == null) {
            // execute will have logged the necessary debug/error info.
            // notify all subscribed clients, that an error has occurred
            // and that this job is being stopped
            LOG.error(getThreadName() + ":ERROR, execute did not return a sqlResult object");
            sendInternalServerError("");
            throw new Exception("execute returns null sqlResult");
        }

        // sqlResult was returned, but it may not contain a result set
        List<Map<String, Object>> listMap = sqlResult.getResultSet();
        String jsonOutput = null;
        if (listMap == null || listMap.isEmpty()) {
            LOG.trace(getThreadName() + ":sqlResult did not contain a result set");
        } else {
            // convert the result set to a json object
            jsonOutput = Utils.generateJson(listMap);
            if (LOG.isTraceEnabled()) {
                if (jsonOutput.length() > 100) {
                    LOG.trace(getThreadName() + ": first 100 bytes of acquired result set = "
                            + jsonOutput.substring(0, 100));
                } else {
                    LOG.trace(getThreadName() + ": acquired this result set - " + jsonOutput);
                }
            }
        }

        // get the digital signature of the json object (if any) that
        // represents the result set
        String dSign = (jsonOutput != null) ? getHashOf(jsonOutput) : WS_DFLT_SIGNATURE;
        LOG.trace(getThreadName() + ": acquired digital signature = " + dSign);
        LOG.trace(getThreadName() + ": current  digital signature = " + getDigitalSignature());

        // determine if a change has occurred
        if (getDigitalSignature() == null) {
            // first time, so just update the current digital signature
            setDigitalSignature(dSign);
        } else if (!dSign.equals(getDigitalSignature())) {
            // update the current digital signature
            setDigitalSignature(dSign);
            // ... and send the notification
            LOG.debug(getThreadName() + ": sending notification");
            sendChangeNotification(dSign);
            return getDigitalSignature();
        }

    } catch (JsonProcessingException exc) {
        LOG.error(getThreadName() + ":ERROR, caught this " + "JsonProcessingException while trying to gen json "
                + "message: " + exc.toString());
        LOG.error(getThreadName() + ": exception stack trace follows:");
        dumpStackTrace(exc.getStackTrace());
        if (exc.getCause() != null) {
            LOG.error(getThreadName() + ": Caused by " + exc.getCause().toString());
            LOG.error(getThreadName() + ": causing exception stack trace follows:");
            dumpStackTrace(exc.getCause().getStackTrace());
        }
        sendInternalServerError("");
        throw exc;

    } catch (Exception exc) {
        LOG.error(getThreadName() + ":ERROR, caught this " + "Exception while trying to gen json " + "message: "
                + exc.toString());
        LOG.error(getThreadName() + ": exception stack trace follows:");
        dumpStackTrace(exc.getStackTrace());
        if (exc.getCause() != null) {
            LOG.error(getThreadName() + ": Caused by " + exc.getCause().toString());
            LOG.error(getThreadName() + ": causing exception stack trace follows:");
            dumpStackTrace(exc.getCause().getStackTrace());
        }
        sendInternalServerError("");
        throw exc;
    } finally {
        if (sqlResult != null) {
            SqlResult.enqueue(sqlResult);
        }
    }

    return null;
}