Search in sources :

Example 6 with KnotContext

use of io.knotx.dataobjects.KnotContext in project knotx by Cognifide.

the class KnotxGatewayResponseProviderHandler method handle.

@Override
public void handle(RoutingContext context) {
    KnotContext knotContext = context.get(KnotContext.KEY);
    if (isOkClientResponse(knotContext.getClientResponse())) {
        responseProviderProxy.rxProcess(knotContext).doOnSuccess(this::traceMessage).subscribe(ctx -> {
            if (isOkClientResponse(ctx.getClientResponse())) {
                sendResponse(context, ctx.getClientResponse());
            } else {
                context.fail(ctx.getClientResponse().getStatusCode());
            }
        }, error -> {
            LOGGER.error("Error {} happened while communicating with `{}` engine", error, configuration.getCustomFlow().responseProviderAddress());
            context.fail(error);
        });
    } else {
        sendResponse(context, knotContext.getClientResponse());
    }
}
Also used : KnotContext(io.knotx.dataobjects.KnotContext)

Example 7 with KnotContext

use of io.knotx.dataobjects.KnotContext in project knotx by Cognifide.

the class ServiceKnotProxyImpl method processError.

@Override
protected KnotContext processError(KnotContext knotContext, Throwable error) {
    LOGGER.error("Error happened during Template processing", error);
    ClientResponse errorResponse = new ClientResponse().setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code());
    return new KnotContext().setClientRequest(knotContext.getClientRequest()).setClientResponse(errorResponse);
}
Also used : ClientResponse(io.knotx.dataobjects.ClientResponse) KnotContext(io.knotx.dataobjects.KnotContext)

Example 8 with KnotContext

use of io.knotx.dataobjects.KnotContext in project knotx by Cognifide.

the class FragmentAssemblerTest method callAssemblerWithAssertions.

private void callAssemblerWithAssertions(TestContext context, List<Pair<List<String>, String>> fragments, Action1<KnotContext> testFunction) {
    Async async = context.async();
    KnotProxy service = KnotProxy.createProxy(new Vertx(vertx.vertx()), ADDRESS);
    service.rxProcess(KnotContextFactory.create(fragments)).map(ctx -> Pair.of(async, ctx)).doOnSuccess(success -> testFunction.call(success.getRight())).subscribe(success -> async.complete(), context::fail);
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) KnotContext(io.knotx.dataobjects.KnotContext) RunWith(org.junit.runner.RunWith) Logback(io.knotx.junit.rule.Logback) Action1(rx.functions.Action1) StringUtils(org.apache.commons.lang3.StringUtils) Vertx(io.vertx.reactivex.core.Vertx) FileReader(io.knotx.junit.util.FileReader) Pair(org.apache.commons.lang3.tuple.Pair) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration) TestVertxDeployer(io.knotx.junit.rule.TestVertxDeployer) KnotProxy(io.knotx.reactivex.proxy.KnotProxy) KnotContextFactory(io.knotx.junit.util.KnotContextFactory) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) IOException(java.io.IOException) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) RuleChain(org.junit.rules.RuleChain) List(java.util.List) Rule(org.junit.Rule) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Collections(java.util.Collections) Async(io.vertx.ext.unit.Async) KnotProxy(io.knotx.reactivex.proxy.KnotProxy) Vertx(io.vertx.reactivex.core.Vertx)

Example 9 with KnotContext

use of io.knotx.dataobjects.KnotContext in project knotx by Cognifide.

the class HtmlFragmentSplitterVerticleTest method callFragmentSplitterWithAssertions.

private void callFragmentSplitterWithAssertions(TestContext context, String template, Action1<KnotContext> testFunction) {
    Async async = context.async();
    KnotProxy service = KnotProxy.createProxy(new Vertx(vertx.vertx()), ADDRESS);
    service.rxProcess(KnotContextFactory.empty(template)).map(ctx -> Pair.of(async, ctx)).doOnSuccess(success -> testFunction.call(success.getRight())).subscribe(success -> async.complete(), context::fail);
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) KnotContext(io.knotx.dataobjects.KnotContext) KnotProxy(io.knotx.reactivex.proxy.KnotProxy) RunWith(org.junit.runner.RunWith) KnotContextFactory(io.knotx.junit.util.KnotContextFactory) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Test(org.junit.Test) Logback(io.knotx.junit.rule.Logback) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Action1(rx.functions.Action1) RuleChain(org.junit.rules.RuleChain) Vertx(io.vertx.reactivex.core.Vertx) Rule(org.junit.Rule) FileReader(io.knotx.junit.util.FileReader) Pair(org.apache.commons.lang3.tuple.Pair) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) TestVertxDeployer(io.knotx.junit.rule.TestVertxDeployer) Async(io.vertx.ext.unit.Async) KnotProxy(io.knotx.reactivex.proxy.KnotProxy) Vertx(io.vertx.reactivex.core.Vertx)

Example 10 with KnotContext

use of io.knotx.dataobjects.KnotContext 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)

Aggregations

KnotContext (io.knotx.dataobjects.KnotContext)21 KnotxConfiguration (io.knotx.junit.rule.KnotxConfiguration)10 Test (org.junit.Test)10 ClientResponse (io.knotx.dataobjects.ClientResponse)6 Vertx (io.vertx.reactivex.core.Vertx)6 Fragment (io.knotx.dataobjects.Fragment)4 KnotProxy (io.knotx.reactivex.proxy.KnotProxy)4 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)4 Logback (io.knotx.junit.rule.Logback)3 TestVertxDeployer (io.knotx.junit.rule.TestVertxDeployer)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 Async (io.vertx.ext.unit.Async)3 TestContext (io.vertx.ext.unit.TestContext)3 RunTestOnContext (io.vertx.ext.unit.junit.RunTestOnContext)3 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)3 MultiMap (io.vertx.reactivex.core.MultiMap)3 RoutingContext (io.vertx.reactivex.ext.web.RoutingContext)3