use of io.knotx.dataobjects.AdapterResponse in project knotx by Cognifide.
the class HttpActionAdapterProxyImpl method prepareResponse.
private AdapterResponse prepareResponse(ClientResponse response) {
AdapterResponse result = new AdapterResponse();
if (response.getStatusCode() == HttpResponseStatus.OK.code()) {
if (isJsonBody(response.getBody()) && response.getBody().toJsonObject().containsKey("validationErrors")) {
result.setSignal("error");
} else {
result.setSignal("success");
}
}
result.setResponse(response);
return result;
}
use of io.knotx.dataobjects.AdapterResponse 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.AdapterResponse 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;
}
Aggregations