use of io.knotx.dataobjects.ClientResponse 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.ClientResponse in project knotx by Cognifide.
the class ActionKnotProxyImpl method processAdapterResponse.
private KnotContext processAdapterResponse(KnotContext knotContext, List<FormEntity> forms, FormEntity form, AdapterResponse response) {
final ClientResponse clientResponse = response.getResponse();
final String signal = response.getSignal();
if (HttpResponseStatus.OK.code() != clientResponse.getStatusCode()) {
return errorKnotResponse(clientResponse, knotContext, form);
} else {
String redirectLocation = form.url(signal).orElse(FORM_NO_REDIRECT_SIGNAL);
return shouldRedirect(redirectLocation) ? redirectKnotResponse(knotContext, form, clientResponse, redirectLocation) : routeToNextKnotResponse(clientResponse, knotContext, forms, form);
}
}
use of io.knotx.dataobjects.ClientResponse in project knotx by Cognifide.
the class ActionKnotProxyVerticleTest method createMockAdapter.
private void createMockAdapter(String address, String addToBody, String signal, Map<String, List<String>> headers) {
Func1<AdapterRequest, AdapterResponse> adapter = adapterRequest -> {
ClientResponse response = new ClientResponse();
response.setStatusCode(HttpResponseStatus.OK.code());
response.setBody(Buffer.buffer().appendString(addToBody));
response.setHeaders(headers.keySet().stream().collect(MultiMapCollector.toMultiMap(o -> o, headers::get)));
return new AdapterResponse().setResponse(response).setSignal(signal);
};
new ServiceBinder(vertx.vertx()).setAddress(address).register(AdapterProxy.class, new MockAdapterImpl(adapter));
}
use of io.knotx.dataobjects.ClientResponse in project knotx by Cognifide.
the class ServiceKnotProxyImpl 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 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);
}
Aggregations