use of com.yahoo.jdisc.handler.BindingNotFoundException 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.BindingNotFoundException 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;
}
Aggregations