use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class MbusServer method handleMessage.
@Override
public void handleMessage(final Message msg) {
if (!running.get()) {
dispatchErrorReply(msg, ErrorCode.SESSION_BUSY, "Session temporarily closed.");
return;
}
if (msg.getTrace().shouldTrace(6)) {
msg.getTrace().trace(6, "Message received by MbusServer.");
}
Request request = null;
ContentChannel content = null;
try {
request = new MbusRequest(container, uri, msg);
content = request.connect(new ServerResponseHandler(msg));
} catch (final RuntimeException e) {
dispatchErrorReply(msg, ErrorCode.APP_FATAL_ERROR, e.toString());
} finally {
if (request != null) {
request.release();
}
}
if (content != null) {
content.close(IgnoredCompletionHandler.INSTANCE);
}
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class ReferenceCountingRequestHandler method handleRequest.
@Override
public ContentChannel handleRequest(Request request, ResponseHandler responseHandler) {
try (final ResourceReference requestReference = request.refer()) {
ContentChannel contentChannel;
final ReferenceCountingResponseHandler referenceCountingResponseHandler = new ReferenceCountingResponseHandler(request, new NullContentResponseHandler(responseHandler));
try {
contentChannel = delegate.handleRequest(request, referenceCountingResponseHandler);
Objects.requireNonNull(contentChannel, "contentChannel");
} catch (Throwable t) {
try {
// The response handler might never be invoked, due to the exception thrown from handleRequest().
referenceCountingResponseHandler.unrefer();
} catch (Throwable thrownFromUnrefer) {
log.log(Level.WARNING, "Unexpected problem", thrownFromUnrefer);
}
throw t;
}
return new ReferenceCountingContentChannel(request, contentChannel);
}
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class TestDriverTestCase method requireThatConnectRequestWorks.
@Test
public void requireThatConnectRequestWorks() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
MyRequestHandler requestHandler = new MyRequestHandler(new MyContentChannel());
ContainerBuilder builder = driver.newContainerBuilder();
builder.serverBindings().bind("scheme://host/path", requestHandler);
driver.activateContainer(builder);
ContentChannel content = driver.connectRequest("scheme://host/path", new MyResponseHandler());
assertNotNull(content);
content.close(null);
assertNotNull(requestHandler.handler);
requestHandler.handler.handleResponse(new Response(Response.Status.OK)).close(null);
assertTrue(driver.close());
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class FilteringRequestHandler method handleRequest.
@Override
public ContentChannel handleRequest(Request request, ResponseHandler originalResponseHandler) {
Preconditions.checkArgument(request instanceof HttpRequest, "Expected HttpRequest, got " + request);
Objects.requireNonNull(originalResponseHandler, "responseHandler");
RequestFilter requestFilter = requestFilters.resolve(request.getUri());
ResponseFilter responseFilter = responseFilters.resolve(request.getUri());
// Not using request.connect() here - it adds logic for error handling that we'd rather leave to the framework.
RequestHandler resolvedRequestHandler = request.container().resolveHandler(request);
if (resolvedRequestHandler == null) {
throw new BindingNotFoundException(request.getUri());
}
RequestHandler requestHandler = new ReferenceCountingRequestHandler(resolvedRequestHandler);
ResponseHandler responseHandler;
if (responseFilter != null) {
responseHandler = new FilteringResponseHandler(originalResponseHandler, responseFilter, request);
} else {
responseHandler = originalResponseHandler;
}
if (requestFilter != null) {
InterceptingResponseHandler interceptingResponseHandler = new InterceptingResponseHandler(responseHandler);
requestFilter.filter(HttpRequest.class.cast(request), interceptingResponseHandler);
if (interceptingResponseHandler.hasProducedResponse()) {
return COMPLETING_CONTENT_CHANNEL;
}
}
ContentChannel contentChannel = requestHandler.handleRequest(request, responseHandler);
if (contentChannel == null) {
throw new RequestDeniedException(request);
}
return contentChannel;
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class MockClient method handleRequest.
@Override
public ContentChannel handleRequest(Request request, ResponseHandler handler) {
counter.incrementAndGet();
final ContentChannel responseContentChannel = handler.handleResponse(new Response(200));
responseContentChannel.close(NOOP_COMPLETION_HANDLER);
return null;
}
Aggregations