Example usage for com.fasterxml.jackson.databind JsonMappingException getMessage

List of usage examples for com.fasterxml.jackson.databind JsonMappingException getMessage

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonMappingException getMessage.

Prototype

public String getMessage() 

Source Link

Usage

From source file:org.apache.streams.builders.threaded.BaseStreamsTask.java

/**
 * In order for our data streams to ported to other data flow frame works(Storm, Hadoop, Spark, etc) we need to be able to
 * enforce the serialization required by each framework.  This needs some thought and design before a final solution is
 * made./*w w  w .  j a  va  2  s.c  o  m*/
 * <p/>
 * The object must be either marked as serializable OR be of instance ObjectNode in order to be cloned
 *
 * @param datum The datum you wish to clone
 * @return A Streams datum
 * @throws SerializationException (runtime) if the serialization fails
 */
private StreamsDatum cloneStreamsDatum(StreamsDatum datum) throws SerializationException {
    // this is difficult to clone due to it's nature. To clone it we will use the "deepCopy" function available.
    if (datum.document instanceof ObjectNode)
        return copyMetaData(datum, new StreamsDatum(((ObjectNode) datum.getDocument()).deepCopy(),
                datum.getTimestamp(), datum.getSequenceid()));
    else {
        try {
            // Try to serialize the document using standard serialization methods
            return (StreamsDatum) org.apache.commons.lang.SerializationUtils.clone(datum);
        } catch (SerializationException ser) {
            try {
                // Use the bruce force method for serialization.
                String value = StreamsJacksonMapper.getInstance().writeValueAsString(datum.document);
                Object object = StreamsJacksonMapper.getInstance().readValue(value,
                        datum.getDocument().getClass());
                return copyMetaData(datum,
                        new StreamsDatum(object, datum.getId(), datum.timestamp, datum.sequenceid));
            } catch (JsonMappingException e) {
                LOGGER.warn("Unable to clone datum Mapper Error: {} - {}", e.getMessage(), datum);
            } catch (JsonParseException e) {
                LOGGER.warn("Unable to clone datum Parser Error: {} - {}", e.getMessage(), datum);
            } catch (JsonProcessingException e) {
                LOGGER.warn("Unable to clone datum Processing Error: {} - {}", e.getMessage(), datum);
            } catch (IOException e) {
                LOGGER.warn("Unable to clone datum IOException Error: {} - {}", e.getMessage(), datum);
            }
            throw new SerializationException("Unable to clone datum");
        }
    }
}

From source file:net.fischboeck.discogs.BaseOperations.java

<T> T doGetRequest(String url, JavaType type) throws ClientException {

    log.debug("[doGetRequest] Requesting URL {}", url);

    CloseableHttpResponse response = null;

    try {/*from  w  ww . j  av  a2 s.com*/
        response = doHttpRequest(new HttpGet(url));
        HttpEntity entity = response.getEntity();

        BufferedInputStream in2 = new BufferedInputStream(entity.getContent());

        return mapper.readValue(in2, type);
    } catch (EntityNotFoundException ex) {
        return null;
    } catch (JsonMappingException jme) {
        throw new ClientException(jme.getMessage());
    } catch (JsonParseException jpe) {
        throw new ClientException(jpe.getMessage());
    } catch (IOException ioe) {
        throw new ClientException(ioe.getMessage());
    } finally {
        closeSafe(response);
    }
}

From source file:org.apache.streams.threaded.tasks.BaseStreamsTask.java

/**
 * In order for our data streams to ported to other data flow frame works(Storm, Hadoop, Spark, etc) we need to be able to
 * enforce the serialization required by each framework.  This needs some thought and design before a final solution is
 * made./*from   w  w  w.  j  ava 2s. c o m*/
 * <p/>
 * The object must be either marked as serializable OR be of instance ObjectNode in order to be cloned
 *
 * @param datum The datum you wish to clone
 * @return A Streams datum
 * @throws SerializationException (runtime) if the serialization fails
 */
private StreamsDatum cloneStreamsDatum(StreamsDatum datum) throws SerializationException {
    // this is difficult to clone due to it's nature. To clone it we will use the "deepCopy" function available.
    if (datum.document instanceof ObjectNode) {
        return copyMetaData(datum, new StreamsDatum(((ObjectNode) datum.getDocument()).deepCopy(),
                datum.getTimestamp(), datum.getSequenceid()));
    } else {
        try {
            // Try to serialize the document using standard serialization methods
            return (StreamsDatum) org.apache.commons.lang.SerializationUtils.clone(datum);
        } catch (SerializationException ser) {
            try {
                // Use the bruce force method for serialization.
                String value = StreamsJacksonMapper.getInstance().writeValueAsString(datum.document);
                Object object = StreamsJacksonMapper.getInstance().readValue(value,
                        datum.getDocument().getClass());
                return copyMetaData(datum,
                        new StreamsDatum(object, datum.getId(), datum.timestamp, datum.sequenceid));
            } catch (JsonMappingException e) {
                LOGGER.warn("Unable to clone datum Mapper Error: {} - {}", e.getMessage(), datum);
            } catch (JsonParseException e) {
                LOGGER.warn("Unable to clone datum Parser Error: {} - {}", e.getMessage(), datum);
            } catch (JsonProcessingException e) {
                LOGGER.warn("Unable to clone datum Processing Error: {} - {}", e.getMessage(), datum);
            } catch (IOException e) {
                LOGGER.warn("Unable to clone datum IOException Error: {} - {}", e.getMessage(), datum);
            }
            throw new SerializationException("Unable to clone datum");
        }
    }
}

From source file:net.fischboeck.discogs.BaseOperations.java

<T> T doGetRequest(String url, Class<T> type) throws ClientException {

    log.debug("[doRequest] Requesting URL {}", url);

    CloseableHttpResponse response = null;

    try {/*from  ww  w  .j av a2  s. c  om*/
        response = doHttpRequest(new HttpGet(url));
        HttpEntity entity = response.getEntity();

        BufferedInputStream in2 = new BufferedInputStream(entity.getContent());

        return mapper.readValue(in2, type);

    } catch (EntityNotFoundException ex) {
        return null;
    } catch (JsonMappingException jme) {
        throw new ClientException(jme.getMessage());
    } catch (JsonParseException jpe) {
        throw new ClientException(jpe.getMessage());
    } catch (IOException ioe) {
        throw new ClientException(ioe.getMessage());
    } finally {
        closeSafe(response);
    }
}

From source file:com.hpcloud.mon.resource.exception.JsonMappingExceptionManager.java

@Override
public Response toResponse(JsonMappingException exception) {
    return Response.status(FaultType.BAD_REQUEST.statusCode).type(MediaType.APPLICATION_JSON)
            .entity(Exceptions.buildLoggedErrorMessage(FaultType.BAD_REQUEST,
                    "Unable to process the provided JSON",
                    Exceptions.stripLocationFromStacktrace(exception.getMessage()), null))
            .build();/*from  ww w  . ja va 2 s .  com*/
}

From source file:monasca.api.resource.exception.JsonMappingExceptionManager.java

@Override
public Response toResponse(JsonMappingException exception) {
    return Response.status(FaultType.UNPROCESSABLE_ENTITY.statusCode).type(MediaType.APPLICATION_JSON)
            .entity(Exceptions.buildLoggedErrorMessage(FaultType.UNPROCESSABLE_ENTITY,
                    "Unable to process the provided JSON",
                    Exceptions.stripLocationFromStacktrace(exception.getMessage()), null))
            .build();//w w w  .  j a  va2  s  .  co  m
}

From source file:org.jaqpot.core.service.filter.excmappers.JsonMappingExceptionMapper.java

@Override
public Response toResponse(JsonMappingException exception) {
    LOG.log(Level.INFO, "JaqpotNotAuthorizedExceptionMapper exception caught", exception);
    StringWriter sw = new StringWriter();
    exception.printStackTrace(new PrintWriter(sw));
    String details = sw.toString();
    ErrorReport error = ErrorReportBuilder.builderRandomId().setCode("JsonMappingError")
            .setMessage(exception.getMessage()).setDetails(details).setHttpStatus(400).build();
    return Response.ok(error, MediaType.APPLICATION_JSON).status(Response.Status.BAD_REQUEST).build();
}

From source file:org.primeframework.mvc.content.json.JacksonContentHandler.java

/**
 * Adds a field error using the information stored in the JsonMappingException.
 *
 * @param e The exception./*w  ww  . ja  va 2 s .c o  m*/
 */
private void addFieldError(JsonMappingException e) {
    // Build the path so we can make the error
    String field = buildField(e);
    String code = "[couldNotConvert]" + field;

    messageStore.add(new SimpleFieldMessage(MessageType.ERROR, field, code,
            messageProvider.getMessage(code, e.getMessage())));
}

From source file:uk.dsxt.voting.client.ClientManager.java

public RequestResult vote(String votingId, String clientId, String votingChoice) {
    try {/*from  www .  ja  va2 s  .  c  om*/
        final Voting voting = assetsHolder.getVoting(votingId);
        if (voting == null) {
            log.error("vote method failed. Couldn't find voting with id [{}]", votingId);
            return new RequestResult<>(APIException.VOTING_NOT_FOUND);
        }

        BigDecimal packetSize = assetsHolder.getClientPacketSize(votingId, clientId);
        if (packetSize == null) {
            log.error("vote method failed. Client not found or can not vote. votingId [{}] clientId [{}]",
                    votingId, clientId);
            return new RequestResult<>(APIException.CLIENT_NOT_FOUND);
        }

        VotingChoice choice = mapper.readValue(votingChoice, VotingChoice.class);
        log.debug("Vote for voting [{}] from client [{}] received.", votingId, clientId);

        VoteResult result = new VoteResult(votingId, clientId, packetSize);
        for (Map.Entry<String, QuestionChoice> entry : choice.getQuestionChoices().entrySet()) {
            Optional<Question> question = Arrays.stream(voting.getQuestions())
                    .filter(q -> q.getId().equals(entry.getKey())).findAny();
            if (!question.isPresent()) {
                log.error("vote method failed. Couldn't find question with id={} in votingId={}.",
                        entry.getKey(), votingId);
                return new RequestResult<>(APIException.UNKNOWN_EXCEPTION);
            }
            for (Map.Entry<String, BigDecimal> answer : entry.getValue().getAnswerChoices().entrySet()) {
                if (answer.getValue().signum() == 0)
                    continue;
                result.setAnswer(question.get().getId(), answer.getKey(), answer.getValue());
            }
        }
        //generate xml body and get vote results
        VotingInfoWeb infoWeb = getVotingResults(result, voting, null, null);
        //serializing whole xml and put signature near xml (not using Sgnt field)
        String xmlBody = serializer.serialize(result, voting);
        signInfoByKey.put(generateKeyForDocument(clientId, votingId), new SignatureInfo(result, xmlBody));
        infoWeb.setXmlBody(xmlBody);
        return new RequestResult<>(infoWeb, null);
    } catch (JsonMappingException je) {
        log.error("vote method failed. Couldn't parse votingChoice JSON. votingId: {}, votingChoice: {}",
                votingId, votingChoice, je.getMessage());
        return new RequestResult<>(APIException.UNKNOWN_EXCEPTION);
    } catch (Exception e) {
        log.error(String.format(
                "vote method failed. Couldn't process votingChoice. votingId: %s, votingChoice: %s", votingId,
                votingChoice), e);
        return new RequestResult<>(APIException.UNKNOWN_EXCEPTION);
    }
}

From source file:com.opentok.OpenTok.java

/**
 * Returns a List of {@link Archive} objects, representing archives that are both
 * both completed and in-progress, for your API key.
 *
 * @param offset The index offset of the first archive. 0 is offset of the most recently started
 * archive./*from w  w  w  . java 2  s .co  m*/
 * 1 is the offset of the archive that started prior to the most recent archive.
 * @param count The number of archives to be returned. The maximum number of archives returned
 * is 1000.
 * @return A List of {@link Archive} objects.
 */
public ArchiveList listArchives(int offset, int count) throws OpenTokException {
    String archives = this.client.getArchives(offset, count);
    try {
        return archiveListReader.readValue(archives);

        // if we only wanted Java 7 and above, we could DRY this into one catch clause
    } catch (JsonMappingException e) {
        throw new RequestException("Exception mapping json: " + e.getMessage());
    } catch (JsonParseException e) {
        throw new RequestException("Exception mapping json: " + e.getMessage());
    } catch (JsonProcessingException e) {
        throw new RequestException("Exception mapping json: " + e.getMessage());
    } catch (IOException e) {
        throw new RequestException("Exception mapping json: " + e.getMessage());
    }
}