use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class SynchronousRequestResponseHandler method handleRequest.
Response handleRequest(Request request, TestDriver driver) {
BlockingResponseHandler responseHandler = new BlockingResponseHandler();
ContentChannel inputRequestChannel = connectRequest(request, driver, responseHandler);
writeRequestBody(request, inputRequestChannel);
return responseHandler.getResponse();
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class Request method connect.
/**
* <p>Attempts to resolve and connect to the {@link RequestHandler} appropriate for the {@link URI} of this Request.
* An exception is thrown if this operation fails at any point. This method is exception-safe.</p>
*
* @param responseHandler The handler to pass the corresponding {@link Response} to.
* @return The {@link ContentChannel} to write the Request content to.
* @throws NullPointerException If the {@link ResponseHandler} is null.
* @throws BindingNotFoundException If the corresponding call to {@link Container#resolveHandler(Request)} returns
* null.
*/
public ContentChannel connect(final ResponseHandler responseHandler) {
try {
Objects.requireNonNull(responseHandler, "responseHandler");
RequestHandler requestHandler = container().resolveHandler(this);
if (requestHandler == null) {
throw new BindingNotFoundException(uri);
}
requestHandler = new ProxyRequestHandler(requestHandler);
ContentChannel content = requestHandler.handleRequest(this, responseHandler);
if (content == null) {
throw new RequestDeniedException(this);
}
return content;
} catch (Throwable t) {
cancel();
throw t;
}
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class ProxyRequestHandler method handleRequest.
@Override
public ContentChannel handleRequest(Request request, ResponseHandler responseHandler) {
try (final ResourceReference requestReference = request.refer()) {
ContentChannel contentChannel;
final ResponseHandler proxyResponseHandler = new ProxyResponseHandler(request, new NullContentResponseHandler(responseHandler));
try {
contentChannel = delegate.handleRequest(request, proxyResponseHandler);
Objects.requireNonNull(contentChannel, "contentChannel");
} catch (Throwable t) {
try {
proxyResponseHandler.handleResponse(new Response(Response.Status.INTERNAL_SERVER_ERROR, t)).close(IGNORED_COMPLETION);
} catch (Throwable ignored) {
// empty
}
throw t;
}
return new ProxyContentChannel(request, contentChannel);
}
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class ContainerShutdownTestCase method requireThatRequestContentWriteExceptionDoesNotBlockTermination.
@Test
public void requireThatRequestContentWriteExceptionDoesNotBlockTermination() {
MyRequestHandler requestHandler = MyRequestHandler.newContentWriteExceptionWithEagerCompletion();
Context ctx = Context.newPendingRequest(requestHandler);
ContentChannel requestContent = ctx.request.connect(MyResponseHandler.newEagerCompletion());
try {
requestContent.write(ByteBuffer.allocate(69), null);
fail();
} catch (MyException e) {
// ignore
}
requestContent.close(null);
ctx.request.release();
requestHandler.respond().close(null);
assertTrue(ctx.shutdown());
assertTrue(ctx.driver.close());
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class ContainerShutdownTestCase method requireThatRequestContentCloseExceptionWithCompletionDoesNotBlockTermination.
@Test
public void requireThatRequestContentCloseExceptionWithCompletionDoesNotBlockTermination() {
MyRequestHandler requestHandler = MyRequestHandler.newContentCloseException();
Context ctx = Context.newPendingRequest(requestHandler);
ContentChannel requestContent = ctx.request.connect(MyResponseHandler.newEagerCompletion());
try {
requestContent.close(MyCompletion.newInstance());
fail();
} catch (MyException e) {
// ignore
}
ctx.request.release();
requestHandler.respond().close(null);
assertTrue(ctx.shutdown());
assertTrue(ctx.driver.close());
}
Aggregations