use of com.yahoo.jdisc.Request 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.Request in project vespa by vespa-engine.
the class FilterTestCase method requireThatResponseFilterChainIsRun.
@Test
public void requireThatResponseFilterChainIsRun() {
final ResponseFilter responseFilter1 = new ResponseHeaderFilter("foo", "bar");
final ResponseFilter responseFilter2 = mock(ResponseFilter.class);
final int statusCode = Response.Status.BAD_GATEWAY;
final Response response = new Response(statusCode);
final Request request = null;
ResponseFilterChain.newInstance(responseFilter1, responseFilter2).filter(response, request);
final ArgumentCaptor<Response> responseCaptor = ArgumentCaptor.forClass(Response.class);
verify(responseFilter2).filter(responseCaptor.capture(), any(Request.class));
assertThat(responseCaptor.getValue().getStatus(), is(statusCode));
assertThat(responseCaptor.getValue().headers().getFirst("foo"), is("bar"));
assertThat(response.getStatus(), is(statusCode));
assertThat(response.headers().getFirst("foo"), is("bar"));
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class HttpRequestTestCase method requireThatSimpleClientConstructorsUseReasonableDefaults.
@Test
public void requireThatSimpleClientConstructorsUseReasonableDefaults() {
final Request parent = new Request(mockContainer(), URI.create("http://localhost/"));
final URI uri = URI.create("http://remotehost/");
HttpRequest request = HttpRequest.newClientRequest(parent, uri);
assertFalse(request.isServerRequest());
assertEquals(uri, request.getUri());
assertEquals(HttpRequest.Method.GET, request.getMethod());
assertEquals(HttpRequest.Version.HTTP_1_1, request.getVersion());
request = HttpRequest.newClientRequest(parent, uri, HttpRequest.Method.POST);
assertFalse(request.isServerRequest());
assertEquals(uri, request.getUri());
assertEquals(HttpRequest.Method.POST, request.getMethod());
assertEquals(HttpRequest.Version.HTTP_1_1, request.getVersion());
request = HttpRequest.newClientRequest(parent, uri, HttpRequest.Method.POST, HttpRequest.Version.HTTP_1_0);
assertFalse(request.isServerRequest());
assertEquals(uri, request.getUri());
assertEquals(HttpRequest.Method.POST, request.getMethod());
assertEquals(HttpRequest.Version.HTTP_1_0, request.getVersion());
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class MbusClientTestCase method requireThatNonMbusRequestIsDenied.
@Test
public void requireThatNonMbusRequestIsDenied() throws InterruptedException {
ClientTestDriver driver = ClientTestDriver.newInstance();
Request serverReq = null;
Request clientReq = null;
try {
serverReq = driver.newServerRequest();
clientReq = new Request(serverReq, URI.create("mbus://host/path"));
clientReq.connect(MyResponseHandler.newInstance());
fail();
} catch (RequestDeniedException e) {
System.out.println(e.getMessage());
} finally {
if (serverReq != null) {
serverReq.release();
}
if (clientReq != null) {
clientReq.release();
}
}
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class AbstractRequestHandlerTestCase method requireThatHandleTimeoutIsImplemented.
@Test
public void requireThatHandleTimeoutIsImplemented() throws Exception {
FutureResponse handler = new FutureResponse();
new AbstractRequestHandler() {
@Override
public ContentChannel handleRequest(Request request, ResponseHandler handler) {
return null;
}
}.handleTimeout(NonWorkingRequest.newInstance("http://localhost/"), handler);
Response response = handler.get(600, TimeUnit.SECONDS);
assertNotNull(response);
assertEquals(Response.Status.GATEWAY_TIMEOUT, response.getStatus());
}
Aggregations