use of io.knotx.dataobjects.ClientResponse 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.ClientResponse in project knotx by Cognifide.
the class FilesystemRepositoryConnectorProxyImpl method process.
@Override
public void process(ClientRequest request, Handler<AsyncResult<ClientResponse>> result) {
final String localFilePath = catalogue + StringUtils.stripStart(request.getPath(), "/");
final Optional<String> contentType = Optional.ofNullable(MimeMapping.getMimeTypeForFilename(localFilePath));
LOGGER.debug("Fetching file `{}` from local repository.", localFilePath);
fileSystem.rxReadFile(localFilePath).map(buffer -> new ClientResponse().setStatusCode(HttpResponseStatus.OK.code()).setHeaders(headers(contentType)).setBody(buffer.getDelegate())).subscribe(response -> result.handle(Future.succeededFuture(response)), error -> {
LOGGER.error(ERROR_MESSAGE, error);
result.handle(Future.succeededFuture(processError(error)));
});
}
use of io.knotx.dataobjects.ClientResponse in project knotx by Cognifide.
the class MockActionAdapterHandler method replyTransition.
private AdapterResponse replyTransition(ClientRequest request, JsonObject transitions) {
final Pair<Optional<String>, JsonObject> result = getTransitionResult(request, transitions);
final JsonObject resultBody = result.getRight().put("form", toJsonObject(request.getFormAttributes()));
final String data = resultBody.toString();
final ClientResponse clientResponse = new ClientResponse().setHeaders(headers(request, data)).setStatusCode(HttpResponseStatus.OK.code()).setBody(Buffer.buffer(data));
final AdapterResponse response = new AdapterResponse().setResponse(clientResponse);
final Optional<String> transition = result.getLeft();
if (transition.isPresent()) {
response.setSignal(transition.get());
}
return response;
}
use of io.knotx.dataobjects.ClientResponse 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);
}
use of io.knotx.dataobjects.ClientResponse in project knotx by Cognifide.
the class HttpClientFacadeTest method whenSupportedStaticPathServiceRequested_expectRequestExecutedAndResponseOKWithBody.
@Test
@KnotxConfiguration("knotx-action-adapter-http-test.json")
public void whenSupportedStaticPathServiceRequested_expectRequestExecutedAndResponseOKWithBody(TestContext context) throws Exception {
Async async = context.async();
// given
final WebClient mockedWebClient = PowerMockito.spy(webClient());
HttpClientFacade clientFacade = new HttpClientFacade(mockedWebClient, getConfiguration());
final JsonObject expectedResponse = new JsonObject(FileReader.readText("first-response.json"));
// when
Single<ClientResponse> result = clientFacade.process(payloadMessage(new JsonObject().put("path", REQUEST_PATH), clientRequest), HttpMethod.POST);
// then
result.doOnSuccess(response -> {
context.assertEquals(HttpResponseStatus.OK.code(), response.getStatusCode());
context.assertEquals(expectedResponse, response.getBody().toJsonObject());
Mockito.verify(mockedWebClient, Mockito.times(1)).request(HttpMethod.POST, PORT, DOMAIN, REQUEST_PATH);
}).subscribe(response -> async.complete(), error -> context.fail(error.getMessage()));
}
Aggregations