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;
}
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));
}
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);
}
Aggregations