use of io.vertx.reactivex.ext.web.RoutingContext in project knotx by Cognifide.
the class KnotxEngineHandler method handleRoute.
private void handleRoute(final RoutingContext context, final String address, final Map<String, RoutingEntry> routing) {
KnotContext knotContext = context.get(KnotContext.KEY);
proxies.computeIfAbsent(address, adr -> KnotProxy.createProxyWithOptions(vertx, adr, configuration.getDeliveryOptions())).rxProcess(knotContext).doOnSuccess(ctx -> context.put(KnotContext.KEY, ctx)).subscribe(ctx -> OptionalAction.of(Optional.ofNullable(ctx.getTransition())).ifPresent(on -> {
RoutingEntry entry = routing.get(on);
if (entry != null) {
handleRoute(context, entry.address(), entry.onTransition());
} else {
LOGGER.debug("Received transition '{}' from '{}'. No further routing available for the transition. Go to the response generation.", on, address);
// last knot can return default transition
context.put(KnotContext.KEY, ctx);
context.next();
}
}).ifNotPresent(() -> {
LOGGER.debug("Request processing finished by {} Knot. Go to the response generation", address);
context.put(KnotContext.KEY, ctx);
context.next();
}), error -> {
LOGGER.error("Error happened while communicating with {} engine", error, address);
context.fail(error);
});
}
use of io.vertx.reactivex.ext.web.RoutingContext in project knotx by Cognifide.
the class SupportedMethodsAndPathsHandlerTest method mockContext.
private RoutingContext mockContext(String requestPath, HttpMethod method) {
RoutingContext context = Mockito.mock(RoutingContext.class);
HttpServerRequest httpRequest = Mockito.mock(HttpServerRequest.class);
Mockito.when(context.request()).thenReturn(httpRequest);
Mockito.when(httpRequest.path()).thenReturn(requestPath);
Mockito.when(httpRequest.method()).thenReturn(method);
return context;
}
use of io.vertx.reactivex.ext.web.RoutingContext in project knotx by Cognifide.
the class SupportedMethodsAndPathsHandlerTest method handle_whenRequestPathAllowedButMethodNotAllowedInCustomFlow_expectRequestFailedMethodNotAllowed.
@Test
public void handle_whenRequestPathAllowedButMethodNotAllowedInCustomFlow_expectRequestFailedMethodNotAllowed() throws Exception {
RoutingContext context = mockContext("/content/page.html", HttpMethod.POST);
tested.handle(context);
Mockito.verify(context, Mockito.times(1)).fail(405);
}
use of io.vertx.reactivex.ext.web.RoutingContext in project knotx by Cognifide.
the class SupportedMethodsAndPathsHandlerTest method handle_whenRequestPathAllowedButMethodNotAllowedInDefaultFlow_expectRequestFailedMethodNotAllowed.
@Test
public void handle_whenRequestPathAllowedButMethodNotAllowedInDefaultFlow_expectRequestFailedMethodNotAllowed() throws Exception {
RoutingContext context = mockContext("/content/page.html", HttpMethod.POST);
tested.handle(context);
Mockito.verify(context, Mockito.times(1)).fail(405);
}
use of io.vertx.reactivex.ext.web.RoutingContext in project knotx by Cognifide.
the class SupportedMethodsAndPathsHandlerTest method handle_whenRequestPathNotAllowed_expectRequestFailedNotFound.
@Test
public void handle_whenRequestPathNotAllowed_expectRequestFailedNotFound() throws Exception {
RoutingContext context = mockContext("/notallowed/page.html", HttpMethod.GET);
tested.handle(context);
Mockito.verify(context, Mockito.times(1)).fail(404);
}
Aggregations