public static KnotContext empty(List<Fragment> fragments) { return empty("").setFragments(fragments); }
public static KnotContext create(List<Pair<List<String>, String>> fragments) { return new KnotContext() .setFragments( fragments != null ? fragments.stream().map(data -> Fragment.snippet(data.getKey(), data.getValue())).collect(Collectors.toList()) : null) .setClientRequest(new ClientRequest()) .setClientResponse( new ClientResponse() .setHeaders(MultiMap.caseInsensitiveMultiMap())); }
public static KnotContext empty(List<Fragment> fragments) { return empty("").setFragments(fragments); }
private KnotContext createSuccessResponse(KnotContext inputContext) { return new KnotContext() .setClientRequest(inputContext.getClientRequest()) .setClientResponse(inputContext.getClientResponse()) .setFragments( Optional.ofNullable(inputContext.getFragments()).orElse(Collections.emptyList())) .setTransition(DEFAULT_TRANSITION); }
private KnotContext createSuccessResponse(KnotContext inputContext) { return new KnotContext() .setClientRequest(inputContext.getClientRequest()) .setClientResponse(inputContext.getClientResponse()) .setFragments( Optional.ofNullable(inputContext.getFragments()).orElse(Collections.emptyList())) .setTransition(DEFAULT_TRANSITION); }
@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); } ); } }
@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); } ); } }
@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); } ); } }
@Override protected Single<KnotContext> processRequest(KnotContext knotContext) { try { knotContext .setFragments(splitter.split(knotContext.getClientResponse().getBody().toString())); knotContext.getClientResponse().setStatusCode(HttpResponseStatus.OK.code()).clearBody(); return Single.just(knotContext); } catch (Exception ex) { LOGGER.error("Exception happened during HTML splitting.", ex); return Single.just(processError(knotContext, ex)); } }
@Override protected Single<KnotContext> processRequest(KnotContext knotContext) { try { knotContext .setFragments(splitter.split(knotContext.getClientResponse().getBody().toString())); knotContext.getClientResponse().setStatusCode(HttpResponseStatus.OK.code()).clearBody(); return Single.just(knotContext); } catch (Exception ex) { LOGGER.error("Exception happened during HTML splitting.", ex); return Single.just(processError(knotContext, ex)); } }
@Override protected Single<KnotContext> processRequest(KnotContext knotContext) { try { knotContext .setFragments(splitter.split(knotContext.getClientResponse().getBody().toString())); knotContext.getClientResponse().setStatusCode(HttpResponseStatus.OK.code()).clearBody(); return Single.just(knotContext); } catch (Exception ex) { LOGGER.error("Exception happened during HTML splitting.", ex); return Single.just(processError(knotContext, ex)); } }
public static void fromJson(JsonObject json, KnotContext obj) { if (json.getValue("clientRequest") instanceof JsonObject) { obj.setClientRequest(new io.knotx.dataobjects.ClientRequest((JsonObject)json.getValue("clientRequest"))); } if (json.getValue("clientResponse") instanceof JsonObject) { obj.setClientResponse(new io.knotx.dataobjects.ClientResponse((JsonObject)json.getValue("clientResponse"))); } if (json.getValue("fragments") instanceof JsonArray) { java.util.ArrayList<io.knotx.dataobjects.Fragment> list = new java.util.ArrayList<>(); json.getJsonArray("fragments").forEach( item -> { if (item instanceof JsonObject) list.add(new io.knotx.dataobjects.Fragment((JsonObject)item)); }); obj.setFragments(list); } if (json.getValue("transition") instanceof String) { obj.setTransition((String)json.getValue("transition")); } }
public static KnotContext create(List<Triple<List<String>, String, String>> fragments) { return new KnotContext() .setFragments( fragments != null ? fragments.stream().map(data -> { Fragment fragment = Fragment.snippet(data.getLeft(), data.getRight(), data.getMiddle()); if (data.getMiddle() != null) { fragment.failure(data.getLeft().get(0), new RuntimeException("knot failure")); } if ("_fallback".equals(data.getLeft().get(0))) { fragment.setAttribute(FragmentConstants.FALLBACK_ID, getAttribute(fragment, "data-knotx-fallback-id")); } return fragment; }).collect(Collectors.toList()) : null) .setClientRequest(new ClientRequest()) .setClientResponse( new ClientResponse() .setHeaders(MultiMap.caseInsensitiveMultiMap())); }