use of io.knotx.dataobjects.ClientRequest in project knotx by Cognifide.
the class HttpClientFacadeTest method whenServiceRequestedWithoutPathParam_expectNoServiceRequestAndBadRequest.
@Test
@KnotxConfiguration("knotx-action-adapter-http-test.json")
public void whenServiceRequestedWithoutPathParam_expectNoServiceRequestAndBadRequest(TestContext context) throws Exception {
Async async = context.async();
// given
final WebClient mockedWebClient = PowerMockito.spy(webClient());
HttpClientFacade clientFacade = new HttpClientFacade(mockedWebClient, getConfiguration());
// when
Single<ClientResponse> result = clientFacade.process(new AdapterRequest().setParams(new JsonObject()).setRequest(clientRequest), HttpMethod.POST);
// then
result.doOnError(error -> {
context.assertEquals("Parameter `path` was not defined in `params`!", error.getMessage());
Mockito.verify(mockedWebClient, Mockito.times(0)).request(Matchers.any(), Matchers.anyInt(), Matchers.anyString(), Matchers.anyString());
}).subscribe(response -> context.fail("Error should occur!"), error -> async.complete());
}
use of io.knotx.dataobjects.ClientRequest in project knotx by Cognifide.
the class ActionKnotProxyImpl method prepareAdapterRequest.
private AdapterRequest prepareAdapterRequest(KnotContext knotContext, FormEntity formEntity) {
AdapterMetadata metadata = formEntity.adapter();
ClientRequest request = new ClientRequest().setPath(knotContext.getClientRequest().getPath()).setMethod(knotContext.getClientRequest().getMethod()).setFormAttributes(knotContext.getClientRequest().getFormAttributes()).setHeaders(getFilteredHeaders(knotContext.getClientRequest().getHeaders(), metadata.getAllowedRequestHeaders()));
AdapterRequest adapterRequest = new AdapterRequest().setRequest(request).setParams(new JsonObject(metadata.getParams())).setAdapterParams(formEntity.adapterParams());
LOGGER.info("Adapter [{}] call with request [{}]", metadata.getAddress(), adapterRequest);
return adapterRequest;
}
use of io.knotx.dataobjects.ClientRequest in project knotx by Cognifide.
the class MockActionAdapterHandler method handle.
@Override
public void handle(Message<AdapterRequest> message) {
ClientRequest request = message.body().getRequest();
JsonObject params = message.body().getParams();
String resourcePath = getFilePath(params.getString("step"));
fileSystem.readFile(resourcePath, ar -> {
if (ar.succeeded()) {
final JsonObject transitions = ar.result().toJsonObject();
message.reply(replyTransition(request, transitions));
} else {
LOGGER.error("Unable to read file. {}", ar.cause());
message.reply(errorResponse());
}
});
}
use of io.knotx.dataobjects.ClientRequest in project knotx by Cognifide.
the class MockAdapterHandler method handle.
@Override
public void handle(Message<AdapterRequest> message) {
ClientRequest request = message.body().getRequest();
JsonObject params = message.body().getParams();
String resourcePath = getFilePath(params.getString("path"));
fileSystem.readFile(resourcePath, ar -> {
if (ar.succeeded()) {
String mockData = ar.result().toString();
message.reply(okResponse(request, mockData));
} else {
LOGGER.error("Unable to read file. {}", ar.cause());
message.reply(errorResponse());
}
});
}
use of io.knotx.dataobjects.ClientRequest 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)));
});
}
Aggregations