use of io.knotx.dataobjects.KnotContext in project knotx by Cognifide.
the class ActionKnotProxyVerticleTest method callPostWithActionFragmentWithIncorrectSnippetId_expectStatusCode500.
@Test
@KnotxConfiguration("knotx-test.json")
public void callPostWithActionFragmentWithIncorrectSnippetId_expectStatusCode500(TestContext context) throws Exception {
KnotContext knotContext = createKnotContext("fragment_form_redirect_in.txt");
knotContext.getClientRequest().setMethod(HttpMethod.POST).setFormAttributes(MultiMap.caseInsensitiveMultiMap().add(HIDDEN_INPUT_TAG_NAME, "snippet_id_not_exists"));
callActionKnotWithAssertions(context, knotContext, clientResponse -> {
context.assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR.code(), clientResponse.getClientResponse().getStatusCode());
context.assertFalse(clientResponse.getFragments() != null);
context.assertFalse(clientResponse.getTransition() != null);
}, error -> context.fail(error.getMessage()));
}
use of io.knotx.dataobjects.KnotContext in project knotx by Cognifide.
the class ActionKnotProxyVerticleTest method callGetWithNoActionFragments_expectResponseOkNoFragmentChanges.
@Test
@KnotxConfiguration("knotx-test.json")
public void callGetWithNoActionFragments_expectResponseOkNoFragmentChanges(TestContext context) throws Exception {
String expectedTemplatingFragment = FileReader.readText("fragment_templating_out.txt");
KnotContext knotContext = createKnotContext(FIRST_FRAGMENT, LAST_FRAGMENT, "fragment_templating_in.txt");
knotContext.getClientRequest().setMethod(HttpMethod.GET);
callActionKnotWithAssertions(context, knotContext, clientResponse -> {
context.assertEquals(HttpResponseStatus.OK.code(), clientResponse.getClientResponse().getStatusCode());
context.assertTrue(clientResponse.getTransition() != null);
context.assertEquals(KNOT_TRANSITION, clientResponse.getTransition());
context.assertTrue(clientResponse.getFragments() != null);
List<Fragment> fragments = clientResponse.getFragments();
context.assertEquals(FIRST_FRAGMENT.content(), fragments.get(0).content());
context.assertEquals(expectedTemplatingFragment, fragments.get(1).content());
context.assertEquals(LAST_FRAGMENT.content(), fragments.get(2).content());
}, error -> context.fail(error.getMessage()));
}
use of io.knotx.dataobjects.KnotContext in project knotx by Cognifide.
the class ActionKnotProxyVerticleTest method callGetWithTwoActionFragments_expectResponseOkTwoFragmentChanges.
@Test
@KnotxConfiguration("knotx-test.json")
public void callGetWithTwoActionFragments_expectResponseOkTwoFragmentChanges(TestContext context) throws Exception {
String expectedRedirectFormFragment = FileReader.readText("fragment_form_redirect_out.txt");
String expectedSelfFormFragment = FileReader.readText("fragment_form_self_out.txt");
KnotContext knotContext = createKnotContext(FIRST_FRAGMENT, LAST_FRAGMENT, "fragment_form_redirect_in.txt", "fragment_form_self_in.txt");
knotContext.getClientRequest().setMethod(HttpMethod.GET);
callActionKnotWithAssertions(context, knotContext, clientResponse -> {
context.assertEquals(HttpResponseStatus.OK.code(), clientResponse.getClientResponse().getStatusCode());
context.assertTrue(clientResponse.getTransition() != null);
context.assertEquals(KNOT_TRANSITION, clientResponse.getTransition());
context.assertTrue(clientResponse.getFragments() != null);
List<Fragment> fragments = clientResponse.getFragments();
context.assertEquals(FIRST_FRAGMENT.content(), fragments.get(0).content());
context.assertEquals(clean(expectedRedirectFormFragment), clean(fragments.get(1).content()));
context.assertEquals(clean(expectedSelfFormFragment), clean(fragments.get(2).content()));
context.assertEquals(LAST_FRAGMENT.content(), fragments.get(3).content());
}, error -> context.fail(error.getMessage()));
}
use of io.knotx.dataobjects.KnotContext in project knotx by Cognifide.
the class KnotxAssemblerHandler method handle.
@Override
public void handle(RoutingContext context) {
KnotContext knotContext = context.get(KnotContext.KEY);
if (isOkClientResponse(knotContext.getClientResponse())) {
assembler.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.getDefaultFlow().splitterAddress());
context.fail(error);
});
} else {
sendResponse(context, knotContext.getClientResponse());
}
}
use of io.knotx.dataobjects.KnotContext in project knotx by Cognifide.
the class KnotxEngineHandler method handleRoute.
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 -> OptionalAction.of(Optional.ofNullable(ctx.getTransition())).ifPresent(on -> {
RoutingEntry entry = routing.get(on);
if (entry != null) {
handleRoute(context, entry.address(), entry.onTransition());
} else {
LOGGER.debug("Received transition '{}' from '{}'. No further routing available for the transition. Go to the response generation.", on, address);
// last knot can return default transition
context.put(KnotContext.KEY, ctx);
context.next();
}
}).ifNotPresent(() -> {
LOGGER.debug("Request processing finished by {} Knot. Go to the response generation", address);
context.put(KnotContext.KEY, ctx);
context.next();
}), error -> {
LOGGER.error("Error happened while communicating with {} engine", error, address);
context.fail(error);
});
}
Aggregations