Search in sources :

Example 56 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project dropwizard by dropwizard.

the class DefaultLoggingFactory method configureLoggers.

private Logger configureLoggers(String name) {
    final Logger root = loggerContext.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    loggerContext.reset();
    final LevelChangePropagator propagator = new LevelChangePropagator();
    propagator.setContext(loggerContext);
    propagator.setResetJUL(true);
    loggerContext.addListener(propagator);
    root.setLevel(level);
    final LevelFilterFactory<ILoggingEvent> levelFilterFactory = new ThresholdLevelFilterFactory();
    final AsyncAppenderFactory<ILoggingEvent> asyncAppenderFactory = new AsyncLoggingEventAppenderFactory();
    final LayoutFactory<ILoggingEvent> layoutFactory = new DropwizardLayoutFactory();
    for (Map.Entry<String, JsonNode> entry : loggers.entrySet()) {
        final Logger logger = loggerContext.getLogger(entry.getKey());
        final JsonNode jsonNode = entry.getValue();
        if (jsonNode.isTextual()) {
            // Just a level as a string
            logger.setLevel(Level.valueOf(jsonNode.asText()));
        } else if (jsonNode.isObject()) {
            // A level and an appender
            final LoggerConfiguration configuration;
            try {
                configuration = Jackson.newObjectMapper().treeToValue(jsonNode, LoggerConfiguration.class);
            } catch (JsonProcessingException e) {
                throw new IllegalArgumentException("Wrong format of logger '" + entry.getKey() + "'", e);
            }
            logger.setLevel(configuration.getLevel());
            logger.setAdditive(configuration.isAdditive());
            for (AppenderFactory<ILoggingEvent> appender : configuration.getAppenders()) {
                logger.addAppender(appender.build(loggerContext, name, layoutFactory, levelFilterFactory, asyncAppenderFactory));
            }
        } else {
            throw new IllegalArgumentException("Unsupported format of logger '" + entry.getKey() + "'");
        }
    }
    return root;
}
Also used : AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) AsyncAppenderFactory(io.dropwizard.logging.async.AsyncAppenderFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) ThresholdLevelFilterFactory(io.dropwizard.logging.filter.ThresholdLevelFilterFactory) AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) LevelChangePropagator(ch.qos.logback.classic.jul.LevelChangePropagator) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 57 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project druid by druid-io.

the class AsyncQueryForwardingServlet method sendProxyRequest.

@Override
protected void sendProxyRequest(HttpServletRequest clientRequest, HttpServletResponse proxyResponse, Request proxyRequest) {
    proxyRequest.timeout(httpClientConfig.getReadTimeout().getMillis(), TimeUnit.MILLISECONDS);
    proxyRequest.idleTimeout(httpClientConfig.getReadTimeout().getMillis(), TimeUnit.MILLISECONDS);
    final Query query = (Query) clientRequest.getAttribute(QUERY_ATTRIBUTE);
    if (query != null) {
        final ObjectMapper objectMapper = (ObjectMapper) clientRequest.getAttribute(OBJECTMAPPER_ATTRIBUTE);
        try {
            proxyRequest.content(new BytesContentProvider(objectMapper.writeValueAsBytes(query)));
        } catch (JsonProcessingException e) {
            Throwables.propagate(e);
        }
    }
    super.sendProxyRequest(clientRequest, proxyResponse, proxyRequest);
}
Also used : Query(io.druid.query.Query) BytesContentProvider(org.eclipse.jetty.client.util.BytesContentProvider) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 58 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project druid by druid-io.

the class LookupCoordinatorManagerTest method testParseErrorUpdateAllOnHost.

@Test
public void testParseErrorUpdateAllOnHost() throws Exception {
    final AtomicReference<List<Map<String, Object>>> configVal = new AtomicReference<>(null);
    final URL url = LookupCoordinatorManager.getLookupsURL(HostAndPort.fromString("localhost"));
    EasyMock.reset(configManager);
    EasyMock.expect(configManager.watch(EasyMock.anyString(), EasyMock.<TypeReference>anyObject())).andReturn(configVal);
    final JsonProcessingException ex = EasyMock.createStrictMock(JsonProcessingException.class);
    final ObjectMapper mapper = EasyMock.createStrictMock(ObjectMapper.class);
    EasyMock.expect(mapper.writeValueAsBytes(EasyMock.eq(SINGLE_LOOKUP_MAP))).andThrow(ex);
    expectedException.expectCause(new BaseMatcher<Throwable>() {

        @Override
        public boolean matches(Object o) {
            return ex == o;
        }

        @Override
        public void describeTo(Description description) {
        }
    });
    EasyMock.replay(mapper);
    final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig);
    try {
        manager.updateAllOnHost(url, SINGLE_LOOKUP_MAP);
    } finally {
        EasyMock.verify(mapper);
    }
}
Also used : Description(org.hamcrest.Description) AtomicReference(java.util.concurrent.atomic.AtomicReference) URL(java.net.URL) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 59 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project buck by facebook.

the class DistBuildTargetGraphCodec method dump.

public BuildJobStateTargetGraph dump(Collection<TargetNode<?, ?>> targetNodes, Function<Path, Integer> cellIndexer) {
    BuildJobStateTargetGraph result = new BuildJobStateTargetGraph();
    for (TargetNode<?, ?> targetNode : targetNodes) {
        Map<String, Object> rawTargetNode = nodeToRawNode.apply(targetNode);
        ProjectFilesystem projectFilesystem = targetNode.getFilesystem();
        BuildJobStateTargetNode remoteNode = new BuildJobStateTargetNode();
        remoteNode.setCellIndex(cellIndexer.apply(projectFilesystem.getRootPath()));
        remoteNode.setBuildTarget(encodeBuildTarget(targetNode.getBuildTarget()));
        try {
            remoteNode.setRawNode(objectMapper.writeValueAsString(rawTargetNode));
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
        result.addToNodes(remoteNode);
    }
    return result;
}
Also used : BuildJobStateTargetNode(com.facebook.buck.distributed.thrift.BuildJobStateTargetNode) BuildJobStateTargetGraph(com.facebook.buck.distributed.thrift.BuildJobStateTargetGraph) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 60 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project buck by facebook.

the class DoctorReportHelper method uploadRequest.

public DoctorEndpointResponse uploadRequest(DoctorEndpointRequest request) {
    if (!doctorConfig.getEndpointUrl().isPresent()) {
        String errorMsg = String.format("Doctor endpoint URL is not set. Please set [%s] %s on your .buckconfig", DoctorConfig.DOCTOR_SECTION, DoctorConfig.URL_FIELD);
        return createErrorDoctorEndpointResponse(errorMsg);
    }
    byte[] requestJson;
    try {
        requestJson = objectMapper.writeValueAsBytes(request);
    } catch (JsonProcessingException e) {
        return createErrorDoctorEndpointResponse("Failed to encode request to JSON. " + "Reason: " + e.getMessage());
    }
    OkHttpClient httpClient = new OkHttpClient.Builder().connectTimeout(doctorConfig.getHttpTimeoutMs(), TimeUnit.MILLISECONDS).readTimeout(doctorConfig.getHttpTimeoutMs(), TimeUnit.MILLISECONDS).writeTimeout(doctorConfig.getHttpTimeoutMs(), TimeUnit.MILLISECONDS).build();
    Response httpResponse;
    try {
        RequestBody requestBody;
        ImmutableMap<String, String> extraArgs = doctorConfig.getExtraRequestArgs();
        if (extraArgs.isEmpty()) {
            requestBody = RequestBody.create(JSON, requestJson);
        } else {
            FormBody.Builder formBody = new FormBody.Builder();
            formBody.add("data", new String(requestJson));
            for (Map.Entry<String, String> entry : extraArgs.entrySet()) {
                formBody.add(entry.getKey(), entry.getValue());
            }
            requestBody = formBody.build();
        }
        Request httpRequest = new Request.Builder().url(doctorConfig.getEndpointUrl().get()).post(requestBody).build();
        httpResponse = httpClient.newCall(httpRequest).execute();
    } catch (IOException e) {
        return createErrorDoctorEndpointResponse("Failed to perform the request to " + doctorConfig.getEndpointUrl().get() + ". Reason: " + e.getMessage());
    }
    try {
        if (httpResponse.isSuccessful()) {
            String body = new String(httpResponse.body().bytes(), Charsets.UTF_8);
            return objectMapper.readValue(body, DoctorEndpointResponse.class);
        }
        return createErrorDoctorEndpointResponse("Request was not successful.");
    } catch (JsonProcessingException e) {
        return createErrorDoctorEndpointResponse(String.format(DECODE_FAIL_TEMPLATE, e.getMessage()));
    } catch (IOException e) {
        return createErrorDoctorEndpointResponse(String.format(DECODE_FAIL_TEMPLATE, e.getMessage()));
    }
}
Also used : OkHttpClient(okhttp3.OkHttpClient) FormBody(okhttp3.FormBody) DoctorEndpointRequest(com.facebook.buck.doctor.config.DoctorEndpointRequest) Request(okhttp3.Request) IOException(java.io.IOException) Response(okhttp3.Response) DoctorEndpointResponse(com.facebook.buck.doctor.config.DoctorEndpointResponse) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) RequestBody(okhttp3.RequestBody)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)117 IOException (java.io.IOException)28 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)26 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 InputStream (java.io.InputStream)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 ErrorResponseBody (com.nike.riposte.server.error.handler.ErrorResponseBody)6 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)6 OutputStreamWriter (java.io.OutputStreamWriter)6 Map (java.util.Map)6 Status (com.ctrip.platform.dal.daogen.domain.Status)5 TaskDTO (com.linkedin.thirdeye.datalayer.dto.TaskDTO)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 List (java.util.List)4 IncorrectRPCMethodException (com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException)3 InvalidRPCResponseException (com.exalttech.trex.remote.exceptions.InvalidRPCResponseException)3