Search in sources :

Example 1 with Endpoint

use of com.spotify.apollo.dispatch.Endpoint in project apollo by spotify.

the class RouteRuleBuilderTest method shouldCreateRule.

@Theory
public void shouldCreateRule(String method) throws Exception {
    RouteProvider provider = () -> Stream.of(Route.sync(method, "/test/<arg>", newHandler1("foo")));
    Request request = request(method, "/test/" + "bar");
    ApplicationRouter<Endpoint> router = Routers.newRouterFromInspecting(provider);
    assertRequestResponse(router, "foo", "bar", request);
}
Also used : Endpoint(com.spotify.apollo.dispatch.Endpoint) Request(com.spotify.apollo.Request) Theory(org.junit.experimental.theories.Theory)

Example 2 with Endpoint

use of com.spotify.apollo.dispatch.Endpoint in project apollo by spotify.

the class RouteRuleBuilderTest method helperMethodsShouldProduceCorrectRoutes.

@Theory
public void helperMethodsShouldProduceCorrectRoutes(String method, RouteProvider provider) throws Exception {
    ApplicationRouter<Endpoint> router = Routers.newRouterFromInspecting(provider);
    String lowerCaseMethod = method.toLowerCase();
    assertRequestResponse(router, lowerCaseMethod + "-method", "a-" + lowerCaseMethod, request(method, "/test/" + "a-" + lowerCaseMethod));
}
Also used : Endpoint(com.spotify.apollo.dispatch.Endpoint) ByteString(okio.ByteString) Theory(org.junit.experimental.theories.Theory)

Example 3 with Endpoint

use of com.spotify.apollo.dispatch.Endpoint in project apollo by spotify.

the class RouteRuleBuilder method toRule.

static Rule<Endpoint> toRule(Route<? extends AsyncHandler<Response<ByteString>>> route) {
    final String uri = route.uri();
    final String requestMethod = route.method();
    final String relativeUri = STRIP_SCHEME_AUTH.matcher(uri).replaceFirst("");
    LOG.debug("Found Route with method: {}, uri: {}", requestMethod, relativeUri);
    final Endpoint endpoint = new RouteEndpoint(route);
    final Rule<Endpoint> rule = Rule.fromUri(relativeUri, requestMethod, endpoint);
    return rule;
}
Also used : Endpoint(com.spotify.apollo.dispatch.Endpoint) ByteString(okio.ByteString)

Example 4 with Endpoint

use of com.spotify.apollo.dispatch.Endpoint in project apollo by spotify.

the class RouteRuleBuilderTest method handle.

private Response<ByteString> handle(RuleMatch<Endpoint> match) throws ExecutionException, InterruptedException {
    final Endpoint endpoint = match.getRule().getTarget();
    final Map<String, String> parsedPathArguments = match.parsedPathArguments();
    return endpoint.invoke(RequestContexts.create(requestContext.request(), requestContext.requestScopedClient(), parsedPathArguments, 0L, RequestMetadataImpl.create(Instant.EPOCH, Optional.empty(), Optional.empty()))).toCompletableFuture().get();
}
Also used : Endpoint(com.spotify.apollo.dispatch.Endpoint) ByteString(okio.ByteString)

Example 5 with Endpoint

use of com.spotify.apollo.dispatch.Endpoint in project apollo by spotify.

the class RequestHandlerImpl method handleEndpointMatch.

/**
 * Continuation for the {@link RequestRunnableFactory}
 *
 * @param request  request being processed
 * @param match    the match that was made
 */
private void handleEndpointMatch(OngoingRequest request, RuleMatch<Endpoint> match) {
    final Endpoint endpoint = match.getRule().getTarget();
    final Map<String, String> parsedPathArguments = match.parsedPathArguments();
    final Client requestScopedClient = client.wrapRequest(request.request());
    final RequestContext requestContext = RequestContexts.create(request.request(), requestScopedClient, parsedPathArguments, request.arrivalTimeNanos(), request.metadata());
    erf.create(request, requestContext, endpoint).run();
}
Also used : Endpoint(com.spotify.apollo.dispatch.Endpoint) RequestContext(com.spotify.apollo.RequestContext) IncomingRequestAwareClient(com.spotify.apollo.environment.IncomingRequestAwareClient) Client(com.spotify.apollo.Client)

Aggregations

Endpoint (com.spotify.apollo.dispatch.Endpoint)5 ByteString (okio.ByteString)3 Theory (org.junit.experimental.theories.Theory)2 Client (com.spotify.apollo.Client)1 Request (com.spotify.apollo.Request)1 RequestContext (com.spotify.apollo.RequestContext)1 IncomingRequestAwareClient (com.spotify.apollo.environment.IncomingRequestAwareClient)1