@Override public void process(KnotContext knotContext, Handler<AsyncResult<KnotContext>> result) { if (shouldProcess(knotContext)) { processRequest(knotContext) .subscribe( ctx -> result.handle(Future.succeededFuture(ctx)), error -> { LOGGER.error("Error happened during Knot Context processing", error); result.handle(Future.succeededFuture(processError(knotContext, error))); } ); } else { knotContext.setTransition(StringUtils.isBlank(knotContext.getTransition()) ? DEFAULT_TRANSITION : knotContext.getTransition()); result.handle(Future.succeededFuture(knotContext)); } }
@Override public void process(KnotContext knotContext, Handler<AsyncResult<KnotContext>> result) { if (shouldProcess(knotContext)) { processRequest(knotContext) .subscribe( ctx -> result.handle(Future.succeededFuture(ctx)), error -> { LOGGER.error("Error happened during Knot Context processing", error); result.handle(Future.succeededFuture(processError(knotContext, error))); } ); } else { knotContext.setTransition(StringUtils.isBlank(knotContext.getTransition()) ? DEFAULT_TRANSITION : knotContext.getTransition()); result.handle(Future.succeededFuture(knotContext)); } }
private void doTransition(RoutingContext context, KnotContext ctx, final Map<String, RoutingEntry> routing) { RoutingEntry entry = routing.get(ctx.getTransition()); if (entry != null) { handleRoute(context, entry.getAddress(), entry.getOnTransition()); } else { LOGGER.debug( "Received transition '{}' from '{}'. No further routing available for the transition. Go to the response generation.", ctx.getTransition(), address); // last knot can return default transition context.put(KnotContext.KEY, ctx); context.next(); } }
private void doTransition(RoutingContext context, KnotContext ctx, final Map<String, RoutingEntry> routing) { RoutingEntry entry = routing.get(ctx.getTransition()); if (entry != null) { handleRoute(context, entry.getAddress(), entry.getOnTransition()); } else { LOGGER.debug( "Received transition '{}' from '{}'. No further routing available for the transition. Go to the response generation.", ctx.getTransition(), address); // last knot can return default transition context.put(KnotContext.KEY, ctx); context.next(); } }
public static void toJson(KnotContext obj, JsonObject json) { if (obj.getClientRequest() != null) { json.put("clientRequest", obj.getClientRequest().toJson()); } if (obj.getClientResponse() != null) { json.put("clientResponse", obj.getClientResponse().toJson()); } if (obj.getFragments() != null) { JsonArray array = new JsonArray(); obj.getFragments().forEach(item -> array.add(item.toJson())); json.put("fragments", array); } if (obj.getTransition() != null) { json.put("transition", obj.getTransition()); } } }
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 -> { if (StringUtils.isNotBlank(ctx.getTransition())) { doTransition(context, ctx, routing); } else { doEndProcessing(context, ctx); } }, error -> { LOGGER.error("Error happened while communicating with {} engine", error, address); context.fail(error); } ); } private void doTransition(RoutingContext context, KnotContext ctx,
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 -> { if (StringUtils.isNotBlank(ctx.getTransition())) { doTransition(context, ctx, routing); } else { doEndProcessing(context, ctx); } }, error -> { LOGGER.error("Error happened while communicating with {} engine", error, address); context.fail(error); } ); } private void doTransition(RoutingContext context, KnotContext ctx,
.doOnSuccess(ctx -> context.put(KnotContext.KEY, ctx)) .subscribe( ctx -> OptionalAction.of(Optional.ofNullable(ctx.getTransition())) .ifPresent(on -> { RoutingEntry entry = routing.get(on);