Search in sources :

Example 31 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project open-kilda by telstra.

the class TopologyTest method verifyEmittedValues.

@Test
public void verifyEmittedValues() {
    MkClusterParam clusterParam = new MkClusterParam();
    clusterParam.setSupervisors(1);
    withSimulatedTimeLocalCluster(clusterParam, new TestJob() {

        @Override
        public void run(ILocalCluster cluster) throws JsonProcessingException {
            MockedSources mockedSources = new MockedSources();
            mockedSources.addMockData(builder.getSpoutId(), new Values(SWITCH_ID));
            Config config = new Config();
            config.setDebug(true);
            CompleteTopologyParam topologyParam = new CompleteTopologyParam();
            topologyParam.setMockedSources(mockedSources);
            topologyParam.setStormConf(config);
            Map<?, ?> result = completeTopology(cluster, builder.build(), topologyParam);
            assertTrue(multiseteq(new Values(new Values(SWITCH_ID)), readTuples(result, builder.getSpoutId())));
            assertTrue(multiseteq(new Values(new Values(SWITCH_ID)), readTuples(result, builder.getConfirmationBoltId())));
        }
    });
}
Also used : ILocalCluster(org.apache.storm.ILocalCluster) MockedSources(org.apache.storm.testing.MockedSources) TestJob(org.apache.storm.testing.TestJob) Config(org.apache.storm.Config) CompleteTopologyParam(org.apache.storm.testing.CompleteTopologyParam) Values(org.apache.storm.tuple.Values) MkClusterParam(org.apache.storm.testing.MkClusterParam) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Map(java.util.Map) Test(org.junit.Test)

Example 32 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project open-kilda by telstra.

the class KafkaMessageProducer method send.

/**
 * Sends messages to WorkFlowManager.
 *
 * @param topic  kafka topic
 * @param object object to serialize and send
 */
public void send(final String topic, final Object object) {
    String message;
    try {
        message = MAPPER.writeValueAsString(object);
    } catch (JsonProcessingException exception) {
        logger.error("Unable to serialize object: object={}", object, exception);
        throw new MessageException(DATA_INVALID, System.currentTimeMillis());
    }
    kafkaTemplate.send(topic, message).addCallback(new ListenableFutureCallback<SendResult<String, String>>() {

        @Override
        public void onSuccess(SendResult<String, String> result) {
            logger.debug("Message sent: topic={}, message={}", topic, message);
        }

        @Override
        public void onFailure(Throwable exception) {
            logger.error("Unable to send message: topic={}, message={}", topic, message, exception);
        }
    });
}
Also used : MessageException(org.openkilda.messaging.error.MessageException) SendResult(org.springframework.kafka.support.SendResult) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 33 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project airlift by airlift.

the class SmileMapper method readFrom.

@Override
public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream inputStream) throws IOException {
    Object object;
    try {
        JsonParser jsonParser = new SmileFactory().createParser(inputStream);
        // Important: we are NOT to close the underlying stream after
        // mapping, so we need to instruct parser:
        jsonParser.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
        object = objectMapper.readValue(jsonParser, objectMapper.getTypeFactory().constructType(genericType));
    } catch (Exception e) {
        // we want to return a 400 for bad JSON but not for a real IO exception
        if (e instanceof IOException && !(e instanceof JsonProcessingException) && !(e instanceof EOFException)) {
            throw (IOException) e;
        }
        // log the exception at debug so it can be viewed during development
        // Note: we are not logging at a higher level because this could cause a denial of service
        log.debug(e, "Invalid json for Java type %s", type);
        // Invalid json request. Throwing exception so the response code can be overridden using a mapper.
        throw new JsonMapperParsingException(type, e);
    }
    return object;
}
Also used : SmileFactory(com.fasterxml.jackson.dataformat.smile.SmileFactory) EOFException(java.io.EOFException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) EOFException(java.io.EOFException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 34 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project connect-utils by jcustenborder.

the class RstTemplateHelper method jsonExample.

public String jsonExample(ConnectorTemplate template) {
    StringWriter writer = new StringWriter();
    final ObjectNode outputNode = createJsonNode(template);
    final String json;
    try {
        json = this.objectMapper.writeValueAsString(outputNode);
    } catch (JsonProcessingException e) {
        throw new IllegalStateException(e);
    }
    writer.write(".. code-block:: json");
    writer.write('\n');
    writer.write("    :name: connector.json");
    writer.write('\n');
    List<Integer> emphasizeLines = emphasizeLines(json);
    if (!emphasizeLines.isEmpty()) {
        writer.write("    :emphasize-lines: ");
        writer.write(Joiner.on(',').join(emphasizeLines));
        writer.write('\n');
    }
    writer.write('\n');
    writer.write(indent(json));
    writer.write('\n');
    return writer.toString();
}
Also used : StringWriter(java.io.StringWriter) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 35 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project indy by Commonjava.

the class AutoProxCalculatorResource method eval.

@ApiOperation(value = "Calculate the effects of referencing a store with the given type and name to determine what AutoProx will auto-create", response = AutoProxCalculation.class)
@ApiResponse(code = 200, message = "Result of calculation")
@Path("/{packageType}/{type: (hosted|group|remote)}/{name}")
@GET
@Produces(ApplicationContent.application_json)
public Response eval(@PathParam("packageType") final String packageType, @PathParam("type") final String type, @PathParam("name") final String remoteName) {
    Response response = checkEnabled();
    if (response != null) {
        return response;
    }
    try {
        StoreKey key = new StoreKey(packageType, StoreType.get(type), remoteName);
        final AutoProxCalculation calc = controller.eval(key);
        response = formatOkResponseWithJsonEntity(serializer.writeValueAsString(calc == null ? Collections.singletonMap("error", "Nothing was created") : calc));
    } catch (final IndyWorkflowException e) {
        logger.error(String.format("Failed to create demo RemoteRepository for: '%s'. Reason: %s", remoteName, e.getMessage()), e);
        response = formatResponse(e);
    } catch (final JsonProcessingException e) {
        logger.error(String.format("Failed to create demo RemoteRepository for: '%s'. Reason: %s", remoteName, e.getMessage()), e);
        response = formatResponse(e);
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) AutoProxCalculation(org.commonjava.indy.autoprox.rest.dto.AutoProxCalculation) StoreKey(org.commonjava.indy.model.core.StoreKey) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponse(io.swagger.annotations.ApiResponse)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)741 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)241 IOException (java.io.IOException)174 HashMap (java.util.HashMap)108 Map (java.util.Map)83 ArrayList (java.util.ArrayList)74 JsonNode (com.fasterxml.jackson.databind.JsonNode)73 Test (org.junit.Test)65 List (java.util.List)56 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)36 Collectors (java.util.stream.Collectors)30 InputStream (java.io.InputStream)26 Json (com.sequenceiq.cloudbreak.domain.json.Json)21 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)20 File (java.io.File)20 Function (java.util.function.Function)20 Logger (org.slf4j.Logger)20 Optional (java.util.Optional)19 Date (java.util.Date)18 Test (org.testng.annotations.Test)18