use of io.vertx.reactivex.core.Vertx 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);
}
use of io.vertx.reactivex.core.Vertx 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());
}
}
use of io.vertx.reactivex.core.Vertx in project knotx by Cognifide.
the class ActionKnotProxyVerticleTest method callActionKnotWithAssertions.
private void callActionKnotWithAssertions(TestContext context, KnotContext knotContext, Action1<KnotContext> onSuccess, Consumer<Throwable> onError) {
Async async = context.async();
KnotProxy actionKnot = KnotProxy.createProxy(new Vertx(vertx.vertx()), ADDRESS);
actionKnot.rxProcess(knotContext).doOnSuccess(onSuccess::call).subscribe(success -> async.complete(), onError);
}
use of io.vertx.reactivex.core.Vertx 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);
});
}
use of io.vertx.reactivex.core.Vertx in project knotx by Cognifide.
the class TestVertxDeployer method apply.
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
KnotxConfiguration knotxConfig = description.getAnnotation(KnotxConfiguration.class);
if (knotxConfig == null || knotxConfig.value().isEmpty()) {
throw new IllegalArgumentException("Missing @KnotxConfiguration annotation with the path to configuration JSON");
}
Vertx vertx = Vertx.newInstance(vertxContext.vertx());
CompletableFuture<Void> toComplete = new CompletableFuture<>();
vertx.deployVerticle(KnotxStarterVerticle.class.getName(), new DeploymentOptions().setConfig(readJson(knotxConfig.value())), ar -> {
if (ar.succeeded()) {
toComplete.complete(null);
} else {
toComplete.completeExceptionally(ar.cause());
}
});
try {
toComplete.get();
} catch (ExecutionException ignore) {
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw e;
}
base.evaluate();
}
};
}
Aggregations