Search in sources :

Example 31 with Request

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

the class RequestStepdefs method sending_a_request_to.

@When("^sending a request to \"([^\"]*)\"$")
public void sending_a_request_to(String uri) throws Throwable {
    Request request = Request.forUri(uri);
    responseFuture = ServiceStepdefs.serviceHelper.request(request);
}
Also used : Request(com.spotify.apollo.Request) When(cucumber.api.java.en.When)

Example 32 with Request

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

the class ServiceSettingClientTest method decoratorShouldAddService.

@Test
public void decoratorShouldAddService() throws Exception {
    Request outgoing = Request.forUri("http://downstream");
    client.send(outgoing, Optional.empty());
    Request sent = sentRequest.getValue();
    assertEquals(TEST_SERVICE, sent.service().get());
}
Also used : Request(com.spotify.apollo.Request) Test(org.junit.Test)

Example 33 with Request

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

the class RequestRunnableImpl method matchAndRun.

private void matchAndRun(BiConsumer<OngoingRequest, RuleMatch<Endpoint>> matchContinuation) {
    final Request request = ongoingRequest.request();
    final Optional<RuleMatch<Endpoint>> match;
    try {
        match = applicationRouter.match(request);
    } catch (InvalidUriException e) {
        LOG.debug("bad uri {} {} {}", request.method(), request.uri(), BAD_REQUEST, e);
        ongoingRequest.reply(forStatus(BAD_REQUEST));
        return;
    }
    if (!match.isPresent()) {
        Collection<String> methods = applicationRouter.getMethodsForValidRules(request);
        if (methods.isEmpty()) {
            LOG.debug("not found {} {} {}", request.method(), request.uri(), NOT_FOUND);
            ongoingRequest.reply(forStatus(NOT_FOUND));
        } else {
            StatusType statusCode;
            if ("OPTIONS".equals(request.method())) {
                statusCode = NO_CONTENT;
            } else {
                statusCode = METHOD_NOT_ALLOWED;
                LOG.debug("wrong method {} {} {}", request.method(), request.uri(), statusCode);
            }
            methods = Sets.newTreeSet(methods);
            methods.add("OPTIONS");
            ongoingRequest.reply(Response.<ByteString>forStatus(statusCode).withHeader("Allow", Joiner.on(", ").join(methods)));
        }
        return;
    }
    matchContinuation.accept(ongoingRequest, match.get());
}
Also used : RuleMatch(com.spotify.apollo.route.RuleMatch) StatusType(com.spotify.apollo.StatusType) ByteString(okio.ByteString) Request(com.spotify.apollo.Request) InvalidUriException(com.spotify.apollo.route.InvalidUriException) ByteString(okio.ByteString)

Aggregations

Request (com.spotify.apollo.Request)33 Test (org.junit.Test)21 ByteString (okio.ByteString)14 Client (com.spotify.apollo.Client)3 Response (com.spotify.apollo.Response)3 IOException (java.io.IOException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 RequestContext (com.spotify.apollo.RequestContext)2 Album (com.spotify.apollo.example.data.Album)2 Artist (com.spotify.apollo.example.data.Artist)2 AsyncHandler (com.spotify.apollo.route.AsyncHandler)2 JsonSerializerMiddlewares (com.spotify.apollo.route.JsonSerializerMiddlewares)2 Route (com.spotify.apollo.route.Route)2 ArrayList (java.util.ArrayList)2 CompletionStage (java.util.concurrent.CompletionStage)2 Stream (java.util.stream.Stream)2 Before (org.junit.Before)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1