use of com.linkedin.parseq.trace.codec.json.JsonTraceCodec in project rest.li by linkedin.
the class ParseqTraceDebugRequestHandler method sendTraceRawAsResponse.
private void sendTraceRawAsResponse(final Callback<RestResponse> callback, final Trace trace) {
String mediaType = HEADER_VALUE_APPLICATION_JSON;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
if (trace != null) {
// Serialize the Parseq trace into JSON.
JsonTraceCodec traceCodec = new JsonTraceCodec();
traceCodec.encode(trace, outputStream);
}
} catch (IOException exception) {
callback.onError(new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, exception));
}
sendByteArrayAsResponse(callback, outputStream.toByteArray(), mediaType);
}
use of com.linkedin.parseq.trace.codec.json.JsonTraceCodec in project rest.li by linkedin.
the class TestDebugRequestHandlers method sendRequestAndVerifyParseqTraceRaw.
private void sendRequestAndVerifyParseqTraceRaw(RestRequest request) throws InterruptedException, ExecutionException {
Future<RestResponse> restResponseFuture = getDefaultTransportClient().restRequest(request);
RestResponse restResponse = restResponseFuture.get();
Assert.assertEquals(restResponse.getStatus(), 200);
List<String> contentTypeValues = restResponse.getHeaderValues(RestConstants.HEADER_CONTENT_TYPE);
Assert.assertTrue(contentTypeValues.size() == 1);
Assert.assertEquals(contentTypeValues.get(0), HEADER_VALUE_APPLICATION_JSON);
InputStream traceRawStream = restResponse.getEntity().asInputStream();
JsonTraceCodec codec = new JsonTraceCodec();
try {
Trace trace = codec.decode(traceRawStream);
Assert.assertNotNull(trace);
} catch (IOException exc) {
Assert.fail("Parseq trace cannot be decoded. Details: " + exc.getMessage());
}
}
use of com.linkedin.parseq.trace.codec.json.JsonTraceCodec in project rest.li by linkedin.
the class TestParseqTraceDebugRequestHandler method executeRequestThroughParseqDebugHandler.
private void executeRequestThroughParseqDebugHandler(URI uri, Callback<RestResponse> callback) {
ParseqTraceDebugRequestHandler requestHandler = new ParseqTraceDebugRequestHandler();
RestRequestBuilder requestBuilder = new RestRequestBuilder(uri);
RestRequest request = requestBuilder.build();
RequestContext requestContext = new RequestContext();
requestHandler.handleRequest(request, requestContext, new RestLiDebugRequestHandler.ResourceDebugRequestHandler() {
@Override
@SuppressWarnings("unchecked")
public void handleRequest(RestRequest request, RequestContext requestContext, Callback<RestResponse> callback) {
RestResponse response = EasyMock.createMock(RestResponse.class);
JsonTraceCodec jsonTraceCodec = new JsonTraceCodec();
Trace t = null;
try {
t = jsonTraceCodec.decode(TEST_TRACE);
} catch (IOException exc) {
// test will fail later
}
Task<Object> task = EasyMock.createMock(Task.class);
EasyMock.expect(task.getTrace()).andReturn(t);
EasyMock.replay(task);
PromiseListener<Object> promiseListener = (PromiseListener<Object>) requestContext.getLocalAttr(RestLiMethodInvoker.ATTRIBUTE_PROMISE_LISTENER);
promiseListener.onResolved(task);
callback.onSuccess(response);
}
}, callback);
}
Aggregations