use of io.knotx.dataobjects.KnotContext in project knotx by Cognifide.
the class ActionKnotProxyVerticleTest method callGetWithActionFragmentActionHandlerNotExists_expectStatusCode500.
@Test
@KnotxConfiguration("knotx-test.json")
public void callGetWithActionFragmentActionHandlerNotExists_expectStatusCode500(TestContext context) throws Exception {
KnotContext knotContext = createKnotContext("fragment_form_actionhandler_not_exists_in.txt");
knotContext.getClientRequest().setMethod(HttpMethod.GET);
callActionKnotWithAssertions(context, knotContext, clientResponse -> {
context.assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR.code(), clientResponse.getClientResponse().getStatusCode());
context.assertFalse(clientResponse.getTransition() != null);
context.assertFalse(clientResponse.getFragments() != null);
}, error -> context.fail(error.getMessage()));
}
use of io.knotx.dataobjects.KnotContext in project knotx by Cognifide.
the class FragmentAssemblerKnotProxyImpl method createSuccessResponse.
private KnotContext createSuccessResponse(KnotContext inputContext, String renderedContent) {
ClientResponse clientResponse = inputContext.getClientResponse();
if (StringUtils.isBlank(renderedContent)) {
clientResponse.setStatusCode(HttpResponseStatus.NO_CONTENT.code());
} else {
MultiMap headers = clientResponse.getHeaders();
headers.add(HttpHeaders.CONTENT_LENGTH.toString().toLowerCase(), Integer.toString(renderedContent.length()));
clientResponse.setBody(Buffer.buffer(renderedContent)).setHeaders(headers);
clientResponse.setStatusCode(HttpResponseStatus.OK.code());
}
return new KnotContext().setClientRequest(inputContext.getClientRequest()).setClientResponse(clientResponse);
}
use of io.knotx.dataobjects.KnotContext in project knotx by Cognifide.
the class KnotxServerRoutingTest method createSimpleGatewayKnot.
private void createSimpleGatewayKnot(final String address, final String transition) {
Action1<KnotContext> simpleKnot = knotContext -> {
ClientResponse clientResponse = new ClientResponse();
clientResponse.setBody(Buffer.buffer());
clientResponse.setStatusCode(200);
knotContext.setClientResponse(clientResponse);
knotContext.setTransition(transition);
};
MockKnotProxy.register(vertx.vertx(), address, simpleKnot);
}
use of io.knotx.dataobjects.KnotContext 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.knotx.dataobjects.KnotContext in project knotx by Cognifide.
the class HandlebarsKnotProxyImpl method processError.
@Override
protected KnotContext processError(KnotContext knotContext, Throwable error) {
LOGGER.error("Error happened during Template processing", error);
ClientResponse errorResponse = new ClientResponse().setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code());
return new KnotContext().setClientRequest(knotContext.getClientRequest()).setClientResponse(errorResponse);
}
Aggregations