Search in sources :

Example 1 with RequestMetadata

use of com.spotify.apollo.RequestMetadata in project apollo by spotify.

the class HttpServiceTest method shouldPopulateRequestMetadata.

@Test
public void shouldPopulateRequestMetadata() throws Exception {
    AtomicReference<RequestMetadata> metadataReference = new AtomicReference<>();
    final InstanceWaiter waiter = new InstanceWaiter();
    Future<?> future = executorService.submit(() -> {
        try {
            HttpService.boot(environment -> environment.routingEngine().registerRoute(Route.async("GET", "/meta", trackMeta(metadataReference))), "metadatatest", waiter);
        } catch (LoadingException e) {
            throw new RuntimeException(e);
        }
    });
    final Service.Instance instance = waiter.waitForInstance();
    Request httpRequest = new Request.Builder().url("http://localhost:29432/meta").build();
    new OkHttpClient().newCall(httpRequest).execute();
    assertThat(((HttpRequestMetadata) metadataReference.get()).httpVersion(), is("HTTP/1.1"));
    instance.getSignaller().signalShutdown();
    instance.waitForShutdown();
    future.get();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) Service(com.spotify.apollo.core.Service) ExecutorService(java.util.concurrent.ExecutorService) AtomicReference(java.util.concurrent.atomic.AtomicReference) HttpRequestMetadata(com.spotify.apollo.http.server.HttpRequestMetadata) RequestMetadata(com.spotify.apollo.RequestMetadata) Test(org.junit.Test)

Example 2 with RequestMetadata

use of com.spotify.apollo.RequestMetadata in project apollo by spotify.

the class ApolloRequestHandler method handle.

@Override
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
    final AsyncContext asyncContext = baseRequest.startAsync();
    RequestMetadata metadata = extractMetadata(req);
    AsyncContextOngoingRequest ongoingRequest = new AsyncContextOngoingRequest(asApolloRequest(req), asyncContext, logger, metadata);
    asyncContext.setTimeout(requestTimeout.toMillis());
    asyncContext.addListener(TimeoutListener.create(ongoingRequest));
    requestHandler.handle(ongoingRequest);
    baseRequest.setHandled(true);
}
Also used : AsyncContext(javax.servlet.AsyncContext) RequestMetadata(com.spotify.apollo.RequestMetadata)

Aggregations

RequestMetadata (com.spotify.apollo.RequestMetadata)2 Service (com.spotify.apollo.core.Service)1 HttpRequestMetadata (com.spotify.apollo.http.server.HttpRequestMetadata)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 AsyncContext (javax.servlet.AsyncContext)1 OkHttpClient (okhttp3.OkHttpClient)1 Request (okhttp3.Request)1 Test (org.junit.Test)1