use of io.knotx.dataobjects.KnotContext in project knotx by Cognifide.
the class KnotxSplitterHandler method handle.
@Override
public void handle(RoutingContext context) {
KnotContext knotContext = context.get(KnotContext.KEY);
splitter.rxProcess(knotContext).doOnSuccess(this::traceMessage).subscribe(ctx -> {
if (ctx.getClientResponse().getStatusCode() == HttpResponseStatus.OK.code()) {
context.put(KnotContext.KEY, ctx);
context.next();
} else {
context.fail(ctx.getClientResponse().getStatusCode());
}
}, error -> {
LOGGER.error("Error happened while communicating with {} engine", error, configuration.getDefaultFlow().splitterAddress());
context.fail(error);
});
}
use of io.knotx.dataobjects.KnotContext in project knotx by Cognifide.
the class ActionKnotProxyImpl method processError.
@Override
protected KnotContext processError(KnotContext context, Throwable error) {
LOGGER.error("Could not process template [{}]", error, context.getClientRequest().getPath());
KnotContext errorResponse = new KnotContext().setClientResponse(context.getClientResponse());
errorResponse.getClientResponse().setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code());
return errorResponse;
}
use of io.knotx.dataobjects.KnotContext in project knotx by Cognifide.
the class ActionKnotProxyVerticleTest method callPostWithActionFragmentWithoutRequestedFragmentIdentifier_expectStatusCode500.
@Test
@KnotxConfiguration("knotx-test.json")
public void callPostWithActionFragmentWithoutRequestedFragmentIdentifier_expectStatusCode500(TestContext context) throws Exception {
KnotContext knotContext = createKnotContext("fragment_form_incorrect_identifier_in.txt");
knotContext.getClientRequest().setMethod(HttpMethod.POST);
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 callGetWithActionFragmentWithoutIdentifier_expectResponseOkWithOneFragmentChanges.
@Test
@KnotxConfiguration("knotx-test.json")
public void callGetWithActionFragmentWithoutIdentifier_expectResponseOkWithOneFragmentChanges(TestContext context) throws Exception {
KnotContext knotContext = createKnotContext("fragment_form_no_identifier_in.txt");
String expectedFragmentHtml = FileReader.readText("fragment_form_no_identifier_out.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(fragments.size(), 1);
context.assertEquals(clean(expectedFragmentHtml), clean(fragments.get(0).content()));
}, error -> context.fail(error.getMessage()));
}
use of io.knotx.dataobjects.KnotContext in project knotx by Cognifide.
the class ActionKnotProxyVerticleTest method callPostWithTwoActionFragments_expectResponseOkWithTransitionStep2.
@Test
@KnotxConfiguration("knotx-test.json")
public void callPostWithTwoActionFragments_expectResponseOkWithTransitionStep2(TestContext context) throws Exception {
createMockAdapter("address-redirect", "", "step2");
KnotContext knotContext = createKnotContext("fragment_form_redirect_in.txt", "fragment_form_self_in.txt");
knotContext.getClientRequest().setMethod(HttpMethod.POST).setFormAttributes(MultiMap.caseInsensitiveMultiMap().add(HIDDEN_INPUT_TAG_NAME, FRAGMENT_REDIRECT_IDENTIFIER));
callActionKnotWithAssertions(context, knotContext, clientResponse -> {
context.assertEquals(HttpResponseStatus.MOVED_PERMANENTLY.code(), clientResponse.getClientResponse().getStatusCode());
context.assertEquals("/content/form/step2.html", clientResponse.getClientResponse().getHeaders().get("Location"));
context.assertFalse(clientResponse.getTransition() != null);
context.assertFalse(clientResponse.getFragments() != null);
}, error -> context.fail(error.getMessage()));
}
Aggregations