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()));
}
}
use of com.fasterxml.jackson.core.JsonProcessingException in project moco by dreamhead.
the class JsonRequestMatcher method doMatch.
private boolean doMatch(final Request request, final byte[] content) {
try {
JsonNode requestNode = mapper.readTree(content);
JsonNode resourceNode = mapper.readTree(expected.readFor(of(request)).getContent());
return requestNode.equals(resourceNode);
} catch (JsonProcessingException jpe) {
return false;
} catch (IOException e) {
throw new MocoException(e);
}
}
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 kafka by apache.
the class VerifiableSourceTask method poll.
@Override
public List<SourceRecord> poll() throws InterruptedException {
long sendStartMs = System.currentTimeMillis();
if (throttler.shouldThrottle(seqno - startingSeqno, sendStartMs))
throttler.throttle();
long nowMs = System.currentTimeMillis();
Map<String, Object> data = new HashMap<>();
data.put("name", name);
data.put("task", id);
data.put("topic", this.topic);
data.put("time_ms", nowMs);
data.put("seqno", seqno);
String dataJson;
try {
dataJson = JSON_SERDE.writeValueAsString(data);
} catch (JsonProcessingException e) {
dataJson = "Bad data can't be written as json: " + e.getMessage();
}
System.out.println(dataJson);
Map<String, Long> ccOffset = Collections.singletonMap(SEQNO_FIELD, seqno);
SourceRecord srcRecord = new SourceRecord(partition, ccOffset, topic, Schema.INT32_SCHEMA, id, Schema.INT64_SCHEMA, seqno);
List<SourceRecord> result = Arrays.asList(srcRecord);
seqno++;
return result;
}
Aggregations