Search in sources :

Example 1 with AdapterResponse

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;
}
Also used : AdapterResponse(io.knotx.dataobjects.AdapterResponse)

Example 2 with AdapterResponse

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));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) KnotContext(io.knotx.dataobjects.KnotContext) Fragment(io.knotx.dataobjects.Fragment) AdapterProxy(io.knotx.proxy.AdapterProxy) ServiceBinder(io.vertx.serviceproxy.ServiceBinder) RunWith(org.junit.runner.RunWith) MultiMapCollector(io.knotx.http.MultiMapCollector) Logback(io.knotx.junit.rule.Logback) Action1(rx.functions.Action1) Parser(org.jsoup.parser.Parser) ClientResponse(io.knotx.dataobjects.ClientResponse) Vertx(io.vertx.reactivex.core.Vertx) Func1(rx.functions.Func1) Lists(com.google.common.collect.Lists) AdapterRequest(io.knotx.dataobjects.AdapterRequest) FileReader(io.knotx.junit.util.FileReader) Map(java.util.Map) AsyncResult(io.vertx.core.AsyncResult) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration) TestVertxDeployer(io.knotx.junit.rule.TestVertxDeployer) KnotProxy(io.knotx.reactivex.proxy.KnotProxy) KnotContextFactory(io.knotx.junit.util.KnotContextFactory) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Consumer(io.reactivex.functions.Consumer) Future(io.vertx.core.Future) RuleChain(org.junit.rules.RuleChain) MultiMap(io.vertx.reactivex.core.MultiMap) List(java.util.List) Rule(org.junit.Rule) AdapterResponse(io.knotx.dataobjects.AdapterResponse) Buffer(io.vertx.core.buffer.Buffer) HttpMethod(io.vertx.core.http.HttpMethod) Document(org.jsoup.nodes.Document) Optional(java.util.Optional) Entities(org.jsoup.nodes.Entities) Jsoup(org.jsoup.Jsoup) Handler(io.vertx.core.Handler) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Collections(java.util.Collections) ClientResponse(io.knotx.dataobjects.ClientResponse) AdapterRequest(io.knotx.dataobjects.AdapterRequest) ServiceBinder(io.vertx.serviceproxy.ServiceBinder) AdapterResponse(io.knotx.dataobjects.AdapterResponse)

Example 3 with AdapterResponse

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;
}
Also used : ClientResponse(io.knotx.dataobjects.ClientResponse) Optional(java.util.Optional) JsonObject(io.vertx.core.json.JsonObject) AdapterResponse(io.knotx.dataobjects.AdapterResponse)

Aggregations

AdapterResponse (io.knotx.dataobjects.AdapterResponse)3 ClientResponse (io.knotx.dataobjects.ClientResponse)2 Optional (java.util.Optional)2 Lists (com.google.common.collect.Lists)1 AdapterRequest (io.knotx.dataobjects.AdapterRequest)1 Fragment (io.knotx.dataobjects.Fragment)1 KnotContext (io.knotx.dataobjects.KnotContext)1 MultiMapCollector (io.knotx.http.MultiMapCollector)1 KnotxConfiguration (io.knotx.junit.rule.KnotxConfiguration)1 Logback (io.knotx.junit.rule.Logback)1 TestVertxDeployer (io.knotx.junit.rule.TestVertxDeployer)1 FileReader (io.knotx.junit.util.FileReader)1 KnotContextFactory (io.knotx.junit.util.KnotContextFactory)1 AdapterProxy (io.knotx.proxy.AdapterProxy)1 KnotProxy (io.knotx.reactivex.proxy.KnotProxy)1 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)1 Consumer (io.reactivex.functions.Consumer)1 AsyncResult (io.vertx.core.AsyncResult)1 Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1