Search in sources :

Example 6 with RoutingContext

use of io.vertx.reactivex.ext.web.RoutingContext in project knotx by Cognifide.

the class KnotxRepositoryHandler method handle.

@Override
public void handle(RoutingContext context) {
    final Optional<RepositoryEntry> repositoryEntry = configuration.getDefaultFlow().repositoryForPath(context.request().path());
    final KnotContext knotContext = context.get(KnotContext.KEY);
    if (repositoryEntry.isPresent()) {
        proxies.computeIfAbsent(repositoryEntry.get().address(), adr -> RepositoryConnectorProxy.createProxyWithOptions(vertx, adr, configuration.getDeliveryOptions())).rxProcess(knotContext.getClientRequest()).doOnSuccess(this::traceMessage).subscribe(repoResponse -> handleRepositoryResponse(repoResponse, context, repositoryEntry.get(), knotContext), context::fail);
    } else {
        context.fail(HttpResponseStatus.NOT_FOUND.code());
    }
}
Also used : KnotContext(io.knotx.dataobjects.KnotContext) RepositoryConnectorProxy(io.knotx.reactivex.proxy.RepositoryConnectorProxy) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) HashMap(java.util.HashMap) HttpServerResponse(io.vertx.reactivex.core.http.HttpServerResponse) RoutingContext(io.vertx.reactivex.ext.web.RoutingContext) LoggerFactory(io.vertx.core.logging.LoggerFactory) ClientResponse(io.knotx.dataobjects.ClientResponse) RepositoryEntry(io.knotx.server.configuration.RepositoryEntry) MultiMap(io.vertx.reactivex.core.MultiMap) Vertx(io.vertx.reactivex.core.Vertx) Map(java.util.Map) Optional(java.util.Optional) Handler(io.vertx.core.Handler) Logger(io.vertx.core.logging.Logger) KnotxServerConfiguration(io.knotx.server.configuration.KnotxServerConfiguration) Buffer(io.vertx.reactivex.core.buffer.Buffer) KnotContext(io.knotx.dataobjects.KnotContext) RepositoryEntry(io.knotx.server.configuration.RepositoryEntry)

Example 7 with RoutingContext

use of io.vertx.reactivex.ext.web.RoutingContext in project knotx by Cognifide.

the class SupportedMethodsAndPathsHandlerTest method handle_whenRequestPathNotAllowedInDefaultFlowAndAllowedInCustomFlow_expectRequestAccepted.

@Test
public void handle_whenRequestPathNotAllowedInDefaultFlowAndAllowedInCustomFlow_expectRequestAccepted() throws Exception {
    RoutingContext context = mockContext("/services/feature.json", HttpMethod.GET);
    tested.handle(context);
    Mockito.verify(context, Mockito.times(1)).next();
}
Also used : RoutingContext(io.vertx.reactivex.ext.web.RoutingContext) Test(org.junit.Test)

Example 8 with RoutingContext

use of io.vertx.reactivex.ext.web.RoutingContext in project knotx by Cognifide.

the class SupportedMethodsAndPathsHandlerTest method handle_whenRequestPathAndMethodAllowedInDefaultFlow_expectRequestAccepted.

@Test
public void handle_whenRequestPathAndMethodAllowedInDefaultFlow_expectRequestAccepted() throws Exception {
    RoutingContext context = mockContext("/content/page.html", HttpMethod.GET);
    tested.handle(context);
    Mockito.verify(context, Mockito.times(1)).next();
}
Also used : RoutingContext(io.vertx.reactivex.ext.web.RoutingContext) Test(org.junit.Test)

Example 9 with RoutingContext

use of io.vertx.reactivex.ext.web.RoutingContext in project knotx by Cognifide.

the class KnotxGatewayContextHandler method handle.

@Override
public void handle(RoutingContext context) {
    KnotContext knotContext = context.get(KnotContext.KEY);
    String bodyAsString = context.getBodyAsString();
    if (StringUtils.isNotBlank(bodyAsString)) {
        knotContext.setFragments(Collections.singletonList(Fragment.raw(bodyAsString)));
    }
    LOGGER.debug("CustomFlow: Routing the traffic to '{}'", address);
    proxies.computeIfAbsent(address, adr -> KnotProxy.createProxyWithOptions(vertx, adr, configuration.getDeliveryOptions())).rxProcess(knotContext).doOnSuccess(ctx -> context.put(KnotContext.KEY, ctx)).subscribe(ctx -> {
        context.put(KnotContext.KEY, ctx);
        context.next();
    }, error -> {
        LOGGER.error("Error happened while communicating with {} engine", error, address);
        context.fail(error);
    });
}
Also used : KnotContext(io.knotx.dataobjects.KnotContext) KnotProxy(io.knotx.reactivex.proxy.KnotProxy) Fragment(io.knotx.dataobjects.Fragment) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) RoutingContext(io.vertx.reactivex.ext.web.RoutingContext) LoggerFactory(io.vertx.core.logging.LoggerFactory) Vertx(io.vertx.reactivex.core.Vertx) Map(java.util.Map) Handler(io.vertx.core.Handler) Logger(io.vertx.core.logging.Logger) KnotxServerConfiguration(io.knotx.server.configuration.KnotxServerConfiguration) Collections(java.util.Collections) KnotContext(io.knotx.dataobjects.KnotContext)

Aggregations

RoutingContext (io.vertx.reactivex.ext.web.RoutingContext)9 Test (org.junit.Test)5 KnotContext (io.knotx.dataobjects.KnotContext)3 KnotxServerConfiguration (io.knotx.server.configuration.KnotxServerConfiguration)3 Handler (io.vertx.core.Handler)3 Logger (io.vertx.core.logging.Logger)3 LoggerFactory (io.vertx.core.logging.LoggerFactory)3 Vertx (io.vertx.reactivex.core.Vertx)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 KnotProxy (io.knotx.reactivex.proxy.KnotProxy)2 Optional (java.util.Optional)2 ClientResponse (io.knotx.dataobjects.ClientResponse)1 Fragment (io.knotx.dataobjects.Fragment)1 RepositoryConnectorProxy (io.knotx.reactivex.proxy.RepositoryConnectorProxy)1 RepositoryEntry (io.knotx.server.configuration.RepositoryEntry)1 RoutingEntry (io.knotx.server.configuration.RoutingEntry)1 OptionalAction (io.knotx.util.OptionalAction)1 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)1 MultiMap (io.vertx.reactivex.core.MultiMap)1