use of com.linkedin.parseq.trace.codec.json.JsonTraceCodec in project rest.li by linkedin.
the class ParseqTraceDebugRequestHandler method sendTraceRawAsResponse.
private void sendTraceRawAsResponse(final RequestExecutionCallback<RestResponse> callback, final RequestExecutionReport executionReport) {
String mediaType = HEADER_VALUE_APPLICATION_JSON;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
Trace trace = executionReport.getParseqTrace();
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), null, null, null);
}
sendByteArrayAsResponse(callback, outputStream.toByteArray(), mediaType);
}
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, RequestExecutionCallback<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
public void handleRequest(RestRequest request, RequestContext requestContext, RequestExecutionCallback<RestResponse> callback) {
RestResponse response = EasyMock.createMock(RestResponse.class);
RequestExecutionReportBuilder executionReportBuilder = new RequestExecutionReportBuilder();
JsonTraceCodec jsonTraceCodec = new JsonTraceCodec();
Trace t = null;
try {
t = jsonTraceCodec.decode(TEST_TRACE);
executionReportBuilder.setParseqTrace(t);
} catch (IOException exc) {
//test will fail later
}
callback.onSuccess(response, executionReportBuilder.build(), null);
}
}, null, callback);
}
use of com.linkedin.parseq.trace.codec.json.JsonTraceCodec in project rest.li by linkedin.
the class ParseqTraceDebugRequestHandler method sendTracevisEntryPageAsResponse.
private void sendTracevisEntryPageAsResponse(final Callback<RestResponse> callback, final Trace trace) {
String mediaType = HEADER_VALUE_TEXT_HTML;
ClassLoader currentClassLoader = getClass().getClassLoader();
InputStream resourceStream = currentClassLoader.getResourceAsStream(ENTRY_PATH_SEGMENT_TRACEVIS + PATH_SEP + ENTRY_PAGE);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
IOUtils.copy(resourceStream, outputStream);
if (trace != null) {
// Serialize the Parseq trace into JSON and then inject a javascript into the response
// which will call the corresponding render function on the entry page html with the JSON
// string.
JsonTraceCodec traceCodec = new JsonTraceCodec();
IOUtils.write(createTraceRenderScript(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 parseq by linkedin.
the class ExampleUtil method printTracingResults.
public static void printTracingResults(final Task<?> task) {
final Trace trace = task.getTrace();
System.out.println();
System.out.println();
System.out.println("JSON Trace:");
try {
System.out.println(new JsonTraceCodec().encode(trace));
} catch (IOException e) {
System.err.println("Failed to encode JSON");
e.printStackTrace();
}
System.out.println();
}
use of com.linkedin.parseq.trace.codec.json.JsonTraceCodec in project rest.li by linkedin.
the class ParseqTraceDebugRequestHandler method sendTracevisEntryPageAsResponse.
private void sendTracevisEntryPageAsResponse(final RequestExecutionCallback<RestResponse> callback, final RequestExecutionReport executionReport) {
String mediaType = HEADER_VALUE_TEXT_HTML;
ClassLoader currentClassLoader = getClass().getClassLoader();
InputStream resourceStream = currentClassLoader.getResourceAsStream(ENTRY_PATH_SEGMENT_TRACEVIS + PATH_SEP + ENTRY_PAGE);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
IOUtils.copy(resourceStream, outputStream);
Trace trace = executionReport.getParseqTrace();
if (trace != null) {
//Serialize the Parseq trace into JSON and then inject a javascript into the response
//which will call the corresponding render function on the entry page html with the JSON
//string.
JsonTraceCodec traceCodec = new JsonTraceCodec();
IOUtils.write(createTraceRenderScript(traceCodec.encode(trace)), outputStream);
}
} catch (IOException exception) {
callback.onError(new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, exception), null, null, null);
}
sendByteArrayAsResponse(callback, outputStream.toByteArray(), mediaType);
}
Aggregations