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);
}
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));
}
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;
}
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();
}
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();
}
Aggregations