use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class MockDispatchDocproc method process.
@Override
public Progress process(Processing processing) {
for (DocumentOperation op : processing.getDocumentOperations()) {
PutDocumentMessage message = new PutDocumentMessage((DocumentPut) op);
ListenableFuture<Response> future = createRequest(message).dispatch();
try {
responses.add(future.get());
} catch (ExecutionException | InterruptedException e) {
throw new RuntimeException(e);
}
}
return Progress.DONE;
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class ProcessingHandlerTestCase method testProcessorSetsResponseHeaders.
@Test
public void testProcessorSetsResponseHeaders() throws InterruptedException {
ProcessingTestDriver.MockResponseHandler responseHandler = null;
try {
Map<String, List<String>> responseHeaders = new HashMap<>();
responseHeaders.put("foo", Collections.singletonList("fooValue"));
responseHeaders.put("bar", Arrays.asList(new String[] { "barValue", "bazValue" }));
Map<String, List<String>> otherResponseHeaders = new HashMap<>();
otherResponseHeaders.put("foo", Collections.singletonList("fooValue2"));
otherResponseHeaders.put("bax", Collections.singletonList("baxValue"));
List<Chain<Processor>> chains = new ArrayList<>();
chains.add(new Chain<Processor>("default", new ResponseHeaderSetter(responseHeaders), new ResponseHeaderSetter(otherResponseHeaders)));
driver = new ProcessingTestDriver(chains);
responseHandler = driver.sendRequest("http://localhost/?chain=default").awaitResponse();
Response response = responseHandler.getResponse();
assertEquals("[fooValue2, fooValue]", response.headers().get("foo").toString());
assertEquals("[barValue, bazValue]", response.headers().get("bar").toString());
assertEquals("[baxValue]", response.headers().get("bax").toString());
assertEquals("ResponseHeaders are not rendered", "{\"datalist\":[]}", responseHandler.read());
} finally {
if (responseHandler != null)
responseHandler.readAll();
}
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class StateHandlerTest method requestAsString.
private String requestAsString(String requestUri) throws Exception {
final BufferedContentChannel content = new BufferedContentChannel();
Response response = driver.dispatchRequest(requestUri, new ResponseHandler() {
@Override
public ContentChannel handleResponse(Response response) {
return content;
}
}).get(60, TimeUnit.SECONDS);
assertNotNull(response);
assertEquals(Response.Status.OK, response.getStatus());
StringBuilder str = new StringBuilder();
Reader in = new InputStreamReader(content.toStream(), StandardCharsets.UTF_8);
for (int c; (c = in.read()) != -1; ) {
str.append((char) c);
}
return str.toString();
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class SecurityFilterUtils method sendErrorResponse.
public static void sendErrorResponse(ResponseHandler responseHandler, int statusCode, String message) {
Response response = new Response(statusCode);
response.headers().put("Content-Type", "application/json");
ObjectNode errorMessage = mapper.createObjectNode();
errorMessage.put("message", message);
try (FastContentWriter writer = ResponseDispatch.newInstance(response).connectFastWriter(responseHandler)) {
writer.write(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorMessage));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class MbusRequestHandlerTestCase method requireThatHandlerCanRespondInSameThread.
@Test
public void requireThatHandlerCanRespondInSameThread() throws Exception {
TestDriver driver = newTestDriver(SameThreadReplier.INSTANCE);
Response response = dispatchMessage(driver, new SimpleMessage("msg")).get(60, TimeUnit.SECONDS);
assertTrue(response instanceof MbusResponse);
assertEquals(Response.Status.OK, response.getStatus());
Reply reply = ((MbusResponse) response).getReply();
assertTrue(reply instanceof EmptyReply);
assertFalse(reply.hasErrors());
assertTrue(driver.close());
}
Aggregations