use of com.yahoo.jdisc.http.HttpRequest 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.http.HttpRequest in project vespa by vespa-engine.
the class VipStatusHandlerTestCase method testFileNotFound.
@Test
public final void testFileNotFound() {
final VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(true).statusfile("/VipStatusHandlerTestCaseFileThatReallyReallyShouldNotExist").noSearchBackendsImpliesOutOfService(false));
final VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric);
final NotFoundResponseHandler responseHandler = new NotFoundResponseHandler();
final HttpRequest request = createRequest();
final BufferedContentChannel requestContent = createChannel();
handler.handleRequest(request, requestContent, responseHandler);
final ByteBuffer b = responseHandler.channel.read();
final byte[] asBytes = new byte[b.remaining()];
b.get(asBytes);
assertEquals(VipStatusHandler.StatusResponse.COULD_NOT_FIND_STATUS_FILE, Utf8.toString(asBytes));
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class VipStatusHandlerTestCase method testHandleRequest.
@Test
public final void testHandleRequest() {
final VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(false).noSearchBackendsImpliesOutOfService(false));
final VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric);
final MockResponseHandler responseHandler = new MockResponseHandler();
final HttpRequest request = createRequest();
final BufferedContentChannel requestContent = createChannel();
handler.handleRequest(request, requestContent, responseHandler);
final ByteBuffer b = responseHandler.channel.read();
final byte[] asBytes = new byte[b.remaining()];
b.get(asBytes);
assertEquals(VipStatusHandler.OK_MESSAGE, Utf8.toString(asBytes));
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class VipStatusHandlerTestCase method createRequest.
public static HttpRequest createRequest(String uri) {
HttpRequest request = null;
try {
request = HttpRequest.newClientRequest(new com.yahoo.jdisc.Request(new MockCurrentContainer(), new URI(uri)), new URI(uri), HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
request.setRemoteAddress(new InetSocketAddress(0));
} catch (URISyntaxException e) {
fail("Illegal URI string in test?");
}
return request;
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterResponseTest method newRequest.
private static HttpRequest newRequest(URI uri, HttpRequest.Method method, HttpRequest.Version version) {
InetSocketAddress address = new InetSocketAddress("localhost", 69);
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
driver.activateContainer(driver.newContainerBuilder());
HttpRequest request = HttpRequest.newServerRequest(driver, uri, method, version, address);
request.release();
assertTrue(driver.close());
return request;
}
Aggregations