use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class RequestHandlerTestDriver method sendRequest.
public MockResponseHandler sendRequest(String uri, HttpRequest.Method method, ByteBuffer body) {
responseHandler = new MockResponseHandler();
Request request = HttpRequest.newServerRequest(driver, URI.create(uri), method);
// TODO: Add a method for accepting a Request instead
request.context().put("contextVariable", 37);
ContentChannel requestContent = request.connect(responseHandler);
requestContent.write(body, null);
requestContent.close(null);
request.release();
return responseHandler;
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class AccessControlRequestFilter method filter.
@Override
public void filter(DiscFilterRequest discFilterRequest, ResponseHandler responseHandler) {
String origin = discFilterRequest.getHeader("Origin");
if (!discFilterRequest.getMethod().equals(OPTIONS.name()))
return;
HttpResponse response = HttpResponse.newInstance(Response.Status.OK);
if (allowedUrls.contains(origin))
response.headers().add(ALLOW_ORIGIN_HEADER, origin);
ACCESS_CONTROL_HEADERS.forEach((name, value) -> response.headers().add(name, value));
ContentChannel cc = responseHandler.handleResponse(response);
cc.close(null);
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class ConnectToHandlerTestCase method requireThatConnectToHandlerWorks.
@Test
public void requireThatConnectToHandlerWorks() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
MyRequestHandler requestHandler = new MyRequestHandler(new MyContent());
ContainerBuilder builder = driver.newContainerBuilder();
builder.serverBindings().bind("http://host/*", requestHandler);
driver.activateContainer(builder);
Request request = new Request(driver, URI.create("http://host/path"));
MyResponseHandler responseHandler = new MyResponseHandler();
ContentChannel content = request.connect(responseHandler);
request.release();
assertNotNull(content);
content.close(null);
assertNotNull(requestHandler.handler);
assertSame(request, requestHandler.request);
requestHandler.handler.handleResponse(new Response(Response.Status.OK)).close(null);
driver.close();
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class ServerProviderConformanceTest method testRequestNondeterministicExceptionWithAsyncHandleResponse.
private <T extends ServerProvider, U, V> void testRequestNondeterministicExceptionWithAsyncHandleResponse(final Adapter<T, U, V> adapter, final Module... config) throws Throwable {
runTest(adapter, Modules.combine(config), RequestType.WITHOUT_CONTENT, new TestRequestHandler() {
@Override
public ContentChannel handle(final Request request, final ResponseHandler handler) {
callInOtherThread(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
final ContentChannel out = handler.handleResponse(new Response(Response.Status.OK));
closeResponse(out);
} catch (Throwable ignored) {
}
return null;
}
});
throw new ConformanceException();
}
});
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class ServerProviderConformanceTest method testRequestExceptionBeforeResponseWriteWithAsyncHandleResponse.
private <T extends ServerProvider, U, V> void testRequestExceptionBeforeResponseWriteWithAsyncHandleResponse(final Adapter<T, U, V> adapter, final Module... config) throws Throwable {
runTest(adapter, Modules.combine(config), RequestType.WITHOUT_CONTENT, new TestRequestHandler() {
@Override
public ContentChannel handle(final Request request, final ResponseHandler handler) {
final Event exceptionHandledByFramework = new Event();
callInOtherThread(new Callable<Void>() {
@Override
public Void call() throws Exception {
exceptionHandledByFramework.await();
try {
final ContentChannel out = handler.handleResponse(new Response(Response.Status.OK));
exceptionHandledByFramework.await();
writeResponse(out);
closeResponse(out);
} catch (Throwable ignored) {
}
return null;
}
});
throw new ConformanceException(exceptionHandledByFramework);
}
});
}
Aggregations