Search in sources :

Example 16 with Request

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);
    }
}
Also used : ContentChannel(com.yahoo.jdisc.handler.ContentChannel) Request(com.yahoo.jdisc.Request)

Example 17 with Request

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"));
}
Also used : HttpResponse(com.yahoo.jdisc.http.HttpResponse) Response(com.yahoo.jdisc.Response) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) HttpRequest(com.yahoo.jdisc.http.HttpRequest) Request(com.yahoo.jdisc.Request) ResponseHeaderFilter(com.yahoo.jdisc.http.filter.ResponseHeaderFilter) Test(org.testng.annotations.Test)

Example 18 with Request

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());
}
Also used : Request(com.yahoo.jdisc.Request) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 19 with Request

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());
}
Also used : ClientTestDriver(com.yahoo.messagebus.jdisc.test.ClientTestDriver) RequestDeniedException(com.yahoo.jdisc.handler.RequestDeniedException) Request(com.yahoo.jdisc.Request) Test(org.junit.Test)

Example 20 with Request

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());
}
Also used : Response(com.yahoo.jdisc.Response) NonWorkingRequest(com.yahoo.jdisc.test.NonWorkingRequest) Request(com.yahoo.jdisc.Request) Test(org.junit.Test)

Aggregations

Request (com.yahoo.jdisc.Request)44 Test (org.junit.Test)31 TestDriver (com.yahoo.jdisc.test.TestDriver)22 Response (com.yahoo.jdisc.Response)17 ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)16 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)10 ByteBuffer (java.nio.ByteBuffer)7 NonWorkingRequest (com.yahoo.jdisc.test.NonWorkingRequest)4 RequestDispatch (com.yahoo.jdisc.handler.RequestDispatch)3 ResponseHandler (com.yahoo.jdisc.handler.ResponseHandler)3 ClientTestDriver (com.yahoo.messagebus.jdisc.test.ClientTestDriver)3 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)3 Callable (java.util.concurrent.Callable)3 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)2 HttpRequest (com.yahoo.jdisc.http.HttpRequest)2 URI (java.net.URI)2 Executor (java.util.concurrent.Executor)2 Test (org.testng.annotations.Test)2 AbstractModule (com.google.inject.AbstractModule)1 ResourceReference (com.yahoo.jdisc.ResourceReference)1