use of com.yahoo.processing.request.ErrorMessage in project vespa by vespa-engine.
the class AbstractProcessingHandler method selectRenderer.
private static Renderer selectRenderer(com.yahoo.processing.Request processingRequest, ComponentRegistry<Renderer> renderers, Renderer defaultRenderer) {
Renderer renderer = null;
// TODO: Support setting a particular renderer instead of just selecting
// by name?
String rendererId = processingRequest.properties().getString("format");
if (rendererId != null && !"".equals(rendererId)) {
renderer = renderers.getComponent(ComponentSpecification.fromString(rendererId));
if (renderer == null)
processingRequest.errors().add(new ErrorMessage("Could not find renderer", "Requested '" + rendererId + "', has " + renderers.allComponents()));
}
if (renderer == null)
renderer = defaultRenderer;
return renderer;
}
use of com.yahoo.processing.request.ErrorMessage in project vespa by vespa-engine.
the class ProcessingHandlerTestCase method testProcessingHandlerTransfersErrorsToHttpStatusCodesWithData.
@Test
public void testProcessingHandlerTransfersErrorsToHttpStatusCodesWithData() throws Exception {
List<Chain<Processor>> chains = new ArrayList<>();
chains.add(simpleChain);
chains.add(new Chain<Processor>("moved_permanently", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(301, "Message"))));
chains.add(new Chain<Processor>("unauthorized", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(401, "Message"))));
chains.add(new Chain<Processor>("unauthorized_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.UNAUTHORIZED.code, "Message"))));
chains.add(new Chain<Processor>("forbidden", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(403, "Message"))));
chains.add(new Chain<Processor>("forbidden_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code, "Message"))));
chains.add(new Chain<Processor>("not_found", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(404, "Message"))));
chains.add(new Chain<Processor>("not_found_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NOT_FOUND.code, "Message"))));
chains.add(new Chain<Processor>("too_many_requests", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(429, "Message"))));
chains.add(new Chain<Processor>("bad_request", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(400, "Message"))));
chains.add(new Chain<Processor>("bad_request_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BAD_REQUEST.code, "Message"))));
chains.add(new Chain<Processor>("internal_server_error", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(500, "Message"))));
chains.add(new Chain<Processor>("internal_server_error_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.INTERNAL_SERVER_ERROR.code, "Message"))));
chains.add(new Chain<Processor>("service_unavailable", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(503, "Message"))));
chains.add(new Chain<Processor>("service_unavailable_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NO_BACKENDS_IN_SERVICE.code, "Message"))));
chains.add(new Chain<Processor>("gateway_timeout", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(504, "Message"))));
chains.add(new Chain<Processor>("gateway_timeout_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.TIMEOUT.code, "Message"))));
chains.add(new Chain<Processor>("bad_gateway", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(502, "Message"))));
chains.add(new Chain<Processor>("bad_gateway_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BACKEND_COMMUNICATION_ERROR.code, "Message"))));
chains.add(new Chain<Processor>("unknown_code", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(1234567, "Message"))));
driver = new ProcessingTestDriver(chains);
assertEqualStatus(200, "http://localhost/?chain=simple");
assertEqualStatus(301, "http://localhost/?chain=moved_permanently");
assertEqualStatus(401, "http://localhost/?chain=unauthorized");
assertEqualStatus(401, "http://localhost/?chain=unauthorized_mapped");
assertEqualStatus(403, "http://localhost/?chain=forbidden");
assertEqualStatus(403, "http://localhost/?chain=forbidden_mapped");
assertEqualStatus(404, "http://localhost/?chain=not_found");
assertEqualStatus(404, "http://localhost/?chain=not_found_mapped");
assertEqualStatus(429, "http://localhost/?chain=too_many_requests");
assertEqualStatus(400, "http://localhost/?chain=bad_request");
assertEqualStatus(400, "http://localhost/?chain=bad_request_mapped");
assertEqualStatus(500, "http://localhost/?chain=internal_server_error");
assertEqualStatus(500, "http://localhost/?chain=internal_server_error_mapped");
assertEqualStatus(503, "http://localhost/?chain=service_unavailable");
// as this didn't fail and this isn't a web service mapped code
assertEqualStatus(200, "http://localhost/?chain=service_unavailable_mapped");
assertEqualStatus(504, "http://localhost/?chain=gateway_timeout");
// as this didn't fail and this isn't a web service mapped code
assertEqualStatus(200, "http://localhost/?chain=gateway_timeout_mapped");
assertEqualStatus(502, "http://localhost/?chain=bad_gateway");
// as this didn't fail and this isn't a web service mapped code
assertEqualStatus(200, "http://localhost/?chain=bad_gateway_mapped");
// as this didn't fail and this isn't a web service mapped code
assertEqualStatus(200, "http://localhost/?chain=unknown_code");
}
use of com.yahoo.processing.request.ErrorMessage in project vespa by vespa-engine.
the class ProcessingHandlerTestCase method testProcessingHandlerTransfersErrorsToHttpStatusCodesNoData.
@Test
public void testProcessingHandlerTransfersErrorsToHttpStatusCodesNoData() throws Exception {
List<Chain<Processor>> chains = new ArrayList<>();
chains.add(simpleChain);
chains.add(new Chain<Processor>("moved_permanently", new ProcessorLibrary.ErrorAdder(new ErrorMessage(301, "Message"))));
chains.add(new Chain<Processor>("unauthorized", new ProcessorLibrary.ErrorAdder(new ErrorMessage(401, "Message"))));
chains.add(new Chain<Processor>("unauthorized_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.UNAUTHORIZED.code, "Message"))));
chains.add(new Chain<Processor>("forbidden", new ProcessorLibrary.ErrorAdder(new ErrorMessage(403, "Message"))));
chains.add(new Chain<Processor>("forbidden_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code, "Message"))));
chains.add(new Chain<Processor>("not_found", new ProcessorLibrary.ErrorAdder(new ErrorMessage(404, "Message"))));
chains.add(new Chain<Processor>("not_found_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NOT_FOUND.code, "Message"))));
chains.add(new Chain<Processor>("too_many_requests", new ProcessorLibrary.ErrorAdder(new ErrorMessage(429, "Message"))));
chains.add(new Chain<Processor>("bad_request", new ProcessorLibrary.ErrorAdder(new ErrorMessage(400, "Message"))));
chains.add(new Chain<Processor>("bad_request_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BAD_REQUEST.code, "Message"))));
chains.add(new Chain<Processor>("internal_server_error", new ProcessorLibrary.ErrorAdder(new ErrorMessage(500, "Message"))));
chains.add(new Chain<Processor>("internal_server_error_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.INTERNAL_SERVER_ERROR.code, "Message"))));
chains.add(new Chain<Processor>("service_unavailable", new ProcessorLibrary.ErrorAdder(new ErrorMessage(503, "Message"))));
chains.add(new Chain<Processor>("service_unavailable_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NO_BACKENDS_IN_SERVICE.code, "Message"))));
chains.add(new Chain<Processor>("gateway_timeout", new ProcessorLibrary.ErrorAdder(new ErrorMessage(504, "Message"))));
chains.add(new Chain<Processor>("gateway_timeout_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.TIMEOUT.code, "Message"))));
chains.add(new Chain<Processor>("bad_gateway", new ProcessorLibrary.ErrorAdder(new ErrorMessage(502, "Message"))));
chains.add(new Chain<Processor>("bad_gateway_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BACKEND_COMMUNICATION_ERROR.code, "Message"))));
chains.add(new Chain<Processor>("unknown_code", new ProcessorLibrary.ErrorAdder(new ErrorMessage(1234567, "Message"))));
driver = new ProcessingTestDriver(chains);
assertEqualStatus(200, "http://localhost/?chain=simple");
assertEqualStatus(301, "http://localhost/?chain=moved_permanently");
assertEqualStatus(401, "http://localhost/?chain=unauthorized");
assertEqualStatus(401, "http://localhost/?chain=unauthorized_mapped");
assertEqualStatus(403, "http://localhost/?chain=forbidden");
assertEqualStatus(403, "http://localhost/?chain=forbidden_mapped");
assertEqualStatus(404, "http://localhost/?chain=not_found");
assertEqualStatus(404, "http://localhost/?chain=not_found_mapped");
assertEqualStatus(429, "http://localhost/?chain=too_many_requests");
assertEqualStatus(400, "http://localhost/?chain=bad_request");
assertEqualStatus(400, "http://localhost/?chain=bad_request_mapped");
assertEqualStatus(500, "http://localhost/?chain=internal_server_error");
assertEqualStatus(500, "http://localhost/?chain=internal_server_error_mapped");
assertEqualStatus(503, "http://localhost/?chain=service_unavailable");
assertEqualStatus(503, "http://localhost/?chain=service_unavailable_mapped");
assertEqualStatus(504, "http://localhost/?chain=gateway_timeout");
assertEqualStatus(504, "http://localhost/?chain=gateway_timeout_mapped");
assertEqualStatus(502, "http://localhost/?chain=bad_gateway");
assertEqualStatus(503, "http://localhost/?chain=bad_gateway_mapped");
assertEqualStatus(500, "http://localhost/?chain=unknown_code");
}
use of com.yahoo.processing.request.ErrorMessage in project vespa by vespa-engine.
the class AsynchronousSectionedRendererTest method testProcessingRenderingWithClonedErrorRequest.
@Test
public void testProcessingRenderingWithClonedErrorRequest() throws IOException, InterruptedException {
StringDataList dataList = createDataList();
// Add errors
dataList.request().errors().add(new ErrorMessage("m1", "d1"));
dataList.request().errors().add(new ErrorMessage("m2", "d2"));
// Cloning a request which contains errors
dataList.add(new StringDataList(dataList.request().clone()));
// ... should not cause repetition of those errors
assertThat(render(dataList), equalTo("{\"errors\":[" + "\"m1: d1\"," + "\"m2: d2\"" + "]," + "\"datalist\":[" + "{\"data\":\"l1\"}," + "{\"datalist\":[" + "{\"data\":\"l11\"}," + "{\"data\":\"l12\"}" + "]}," + "{\"datalist\":[]}" + "]}"));
}
use of com.yahoo.processing.request.ErrorMessage in project vespa by vespa-engine.
the class AsynchronousSectionedRendererTest method testProcessingRenderingWithStackTraces.
@Test
public void testProcessingRenderingWithStackTraces() throws IOException, InterruptedException {
Exception exception = null;
// Create thrown exception
try {
throw new RuntimeException("Thrown");
} catch (RuntimeException e) {
exception = e;
}
StringDataList dataList = createDataList();
// Add errors
dataList.request().errors().add(new ErrorMessage("m1", "d1", exception));
dataList.request().errors().add(new ErrorMessage("m2", "d2"));
assertEquals("{\"errors\":[" + "{" + "\"error\":\"m1: d1: Thrown\"," + "\"stacktrace\":\"java.lang.RuntimeException: Thrown\\n\\tat com.yahoo.processing.rendering.AsynchronousSectionedRendererTest.", render(dataList).substring(0, 157));
}
Aggregations