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;
}
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);
}
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);
}
}
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;
}
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()));
}
}
Aggregations