Search in sources :

Example 1 with WebClient

use of io.vertx.mutiny.ext.web.client.WebClient in project smallrye-mutiny by smallrye.

the class WaitForCentral method call.

@Override
public Integer call() throws Exception {
    info("Waiting at most %d seconds for artifacts %s version %s to land in repository (%s)", timeout, artifacts, version, repository);
    List<String> urls = new ArrayList<>();
    for (String artifact : artifacts) {
        String[] segments = artifact.split(":");
        if (segments.length != 2) {
            fail("Invalid artifact (%s), must be groupId:artifactId", artifact);
        }
        String groupId = segments[0].replace(".", "/");
        String artifactId = segments[1];
        String url = String.format("%s/%s/%s/%s/%s-%s.pom", repository, groupId, artifactId, version, artifactId, version);
        urls.add(url);
        info("Url for %s: %s", artifact, url);
    }
    Vertx vertx = Vertx.vertx();
    WebClient client = WebClient.create(vertx);
    long beginning = System.currentTimeMillis();
    long max = beginning + (timeout * 1000);
    boolean done = false;
    while (!done && System.currentTimeMillis() < max) {
        try {
            if (get(client, urls)) {
                done = true;
            } else {
                info("Next attempt in 30s");
                Thread.sleep(30000);
            }
        } catch (Exception e) {
            warn("Failed to retrieve artifacts: %s", e);
        }
    }
    if (!done) {
        fail("Artifacts still not available after %d seconds", timeout);
    } else {
        info("Artifacts found on the repository!");
    }
    client.close();
    vertx.closeAndAwait();
    if (!done) {
        return -1;
    }
    return 0;
}
Also used : ArrayList(java.util.ArrayList) Vertx(io.vertx.mutiny.core.Vertx) WebClient(io.vertx.mutiny.ext.web.client.WebClient)

Example 2 with WebClient

use of io.vertx.mutiny.ext.web.client.WebClient in project reactive-systems-in-java by cescoffier.

the class UniApi method main.

public static void main(String[] args) {
    Vertx vertx = Vertx.vertx();
    WebClient client = WebClient.create(vertx);
    Uni<HttpResponse<Buffer>> uni = client.getAbs("https://httpbin.org/json").send();
    uni.onItem().transform(HttpResponse::bodyAsJsonObject).onFailure().recoverWithItem(new JsonObject().put("message", "fallback")).subscribe().with(json -> System.out.println("Got json document: " + json));
}
Also used : HttpResponse(io.vertx.mutiny.ext.web.client.HttpResponse) JsonObject(io.vertx.core.json.JsonObject) Vertx(io.vertx.mutiny.core.Vertx) WebClient(io.vertx.mutiny.ext.web.client.WebClient)

Example 3 with WebClient

use of io.vertx.mutiny.ext.web.client.WebClient in project kogito-runtimes by kiegroup.

the class RestWorkItemHandlerTest method init.

@BeforeEach
public void init() {
    WebClient webClient = mock(WebClient.class);
    ObjectMapper mapper = new ObjectMapper();
    when(webClient.request(any(HttpMethod.class), eq(8080), eq("localhost"), anyString())).thenReturn(request);
    when(request.sendJsonAndAwait(any())).thenReturn(response);
    when(request.sendAndAwait()).thenReturn(response);
    when(response.bodyAsJson(ObjectNode.class)).thenReturn(ObjectMapperFactory.get().createObjectNode().put("num", 1));
    workItem = new KogitoWorkItemImpl();
    workItem.setId("2");
    parameters = workItem.getParameters();
    parameters.put(RestWorkItemHandler.HOST, "localhost");
    parameters.put(RestWorkItemHandler.PORT, 8080);
    parameters.put(RestWorkItemHandler.URL, "/results/sum");
    parameters.put(RestWorkItemHandler.CONTENT_DATA, workflowData);
    Process process = mock(Process.class);
    ProcessInstance processInstance = mock(ProcessInstance.class);
    workItem.setProcessInstance(processInstance);
    workflowData = mapper.createObjectNode().put("id", 26).put("name", "pepe");
    when(processInstance.getProcess()).thenReturn(process);
    when(processInstance.getVariables()).thenReturn(Collections.singletonMap(DEFAULT_WORKFLOW_VAR, workflowData));
    Variable variable = new Variable();
    variable.setName(DEFAULT_WORKFLOW_VAR);
    variable.setType(new ObjectDataType(ObjectNode.class.getName()));
    variable.setValue(workflowData);
    when(process.getDefaultContext(VariableScope.VARIABLE_SCOPE)).thenReturn(variableScope);
    when(variableScope.findVariable(DEFAULT_WORKFLOW_VAR)).thenReturn(variable);
    when(node.getIoSpecification()).thenReturn(ioSpecification);
    workItem.setNodeInstance(nodeInstance);
    when(nodeInstance.getNode()).thenReturn(node);
    Map<String, String> outputMapping = Collections.singletonMap(RestWorkItemHandler.RESULT, DEFAULT_WORKFLOW_VAR);
    when(ioSpecification.getOutputMappingBySources()).thenReturn(outputMapping);
    handler = new RestWorkItemHandler(webClient);
}
Also used : Variable(org.jbpm.process.core.context.variable.Variable) Process(org.jbpm.process.core.Process) ProcessInstance(org.jbpm.process.instance.ProcessInstance) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) KogitoWorkItemImpl(org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebClient(io.vertx.mutiny.ext.web.client.WebClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpMethod(io.vertx.core.http.HttpMethod) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

WebClient (io.vertx.mutiny.ext.web.client.WebClient)3 Vertx (io.vertx.mutiny.core.Vertx)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HttpMethod (io.vertx.core.http.HttpMethod)1 JsonObject (io.vertx.core.json.JsonObject)1 HttpResponse (io.vertx.mutiny.ext.web.client.HttpResponse)1 ArrayList (java.util.ArrayList)1 Process (org.jbpm.process.core.Process)1 Variable (org.jbpm.process.core.context.variable.Variable)1 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)1 ProcessInstance (org.jbpm.process.instance.ProcessInstance)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 KogitoWorkItemImpl (org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1