use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class CallableRequestDispatchTestCase method requireThatDispatchIsCalled.
@Test
public void requireThatDispatchIsCalled() throws Exception {
final TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
Response response = new Response(Response.Status.OK);
builder.serverBindings().bind("http://host/path", new MyRequestHandler(response));
driver.activateContainer(builder);
assertSame(response, new CallableRequestDispatch() {
@Override
protected Request newRequest() {
return new Request(driver, URI.create("http://host/path"));
}
}.call());
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class RequestDeniedTestCase method requireThatRequestDeniedIsThrown.
@Test
public void requireThatRequestDeniedIsThrown() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
RequestHandler requestHandler = new MyRequestHandler();
builder.serverBindings().bind("http://host/path", requestHandler);
driver.activateContainer(builder);
Request request = new Request(driver, URI.create("http://host/path"));
try {
request.connect(new MyResponseHandler());
fail();
} catch (RequestDeniedException e) {
assertSame(request, e.request());
}
request.release();
driver.close();
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class RequestDeniedTestCase method requireThatAccessorsWork.
@Test
public void requireThatAccessorsWork() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
driver.activateContainer(driver.newContainerBuilder());
Request request = new Request(driver, URI.create("http://host/path"));
RequestDeniedException e = new RequestDeniedException(request);
assertSame(request, e.request());
request.release();
driver.close();
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class ThreadedRequestHandlerTestCase method requireThatRequestAndResponseReachHandlers.
@Test
public void requireThatRequestAndResponseReachHandlers() throws InterruptedException {
MyRequestHandler requestHandler = new MyRequestHandler(newExecutor());
TestDriver driver = newTestDriver("http://localhost/", requestHandler);
MyResponseHandler responseHandler = new MyResponseHandler();
Request request = new Request(driver, URI.create("http://localhost/"));
ContentChannel requestContent = request.connect(responseHandler);
ByteBuffer buf = ByteBuffer.allocate(69);
requestContent.write(buf, null);
requestContent.close(null);
request.release();
requestHandler.entryLatch.countDown();
assertTrue(requestHandler.exitLatch.await(600, TimeUnit.SECONDS));
assertSame(request, requestHandler.request);
assertSame(buf, requestHandler.content.read());
assertNull(requestHandler.content.read());
assertTrue(responseHandler.latch.await(600, TimeUnit.SECONDS));
assertSame(requestHandler.response, responseHandler.response);
assertNull(responseHandler.content.read());
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class HttpRequest method createRequest.
/**
* Create a new HTTP request from an URI.
*
* @param container the current container instance
* @param uri the request parameters
* @param method GET, POST, etc
* @param requestData the associated data stream, may be null
* @param properties a set of properties to set in the request in addition to the implicit ones from the URI
* @return a new HTTP request
*/
public static HttpRequest createRequest(CurrentContainer container, URI uri, Method method, InputStream requestData, Map<String, String> properties) {
com.yahoo.jdisc.http.HttpRequest clientRequest = com.yahoo.jdisc.http.HttpRequest.newClientRequest(new Request(container, uri), uri, method);
setProperties(clientRequest, properties);
return new HttpRequest(clientRequest, requestData);
}
Aggregations