From a2317eb2230ed472040bfff4af26cb126ce9e687 Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Thu, 20 Feb 2020 15:37:56 +0800 Subject: Add method to send message to Camunda engine Issue-ID: SO-2368 Modify CamundaRequestHandler to add method to send message to Camunda engine. Use non-blocking webclient considering workflow may take long time to finish. Change-Id: I70a8b38881ac40b4d65a3d7305f57a56829e6f1d Signed-off-by: Harry Huang --- mso-api-handlers/mso-api-handler-infra/pom.xml | 4 ++++ .../so/apihandlerinfra/CamundaRequestHandler.java | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'mso-api-handlers') diff --git a/mso-api-handlers/mso-api-handler-infra/pom.xml b/mso-api-handlers/mso-api-handler-infra/pom.xml index 84a80e6617..9944984d33 100644 --- a/mso-api-handlers/mso-api-handler-infra/pom.xml +++ b/mso-api-handlers/mso-api-handler-infra/pom.xml @@ -97,6 +97,10 @@ org.springframework.retry spring-retry + + org.springframework.boot + spring-boot-starter-webflux + commons-lang commons-lang diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/CamundaRequestHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/CamundaRequestHandler.java index 17377d881a..f30b66c6b5 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/CamundaRequestHandler.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/CamundaRequestHandler.java @@ -9,9 +9,11 @@ import javax.ws.rs.core.UriBuilder; import javax.xml.bind.DatatypeConverter; import org.camunda.bpm.engine.impl.persistence.entity.HistoricActivityInstanceEntity; import org.camunda.bpm.engine.impl.persistence.entity.HistoricProcessInstanceEntity; +import org.json.JSONObject; import org.onap.logging.filter.spring.SpringClientPayloadFilter; import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter; import org.onap.so.utils.CryptoUtils; +import org.onap.so.apihandlerinfra.exceptions.ContactCamundaException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -29,6 +31,9 @@ import org.springframework.stereotype.Component; import org.springframework.web.client.ResourceAccessException; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Flux; @Component public class CamundaRequestHandler { @@ -202,6 +207,20 @@ public class CamundaRequestHandler { return retryTemplate; } + protected void sendCamundaMessages(JSONObject msgJson) { + String url = env.getProperty("mso.camundaURL") + "/sobpmnengine/message"; + HttpHeaders headers = + setCamundaHeaders(env.getRequiredProperty("mso.camundaAuth"), env.getRequiredProperty("mso.msoKey")); + headers.setContentType(org.springframework.http.MediaType.APPLICATION_JSON); + // Workflow may take a long time so use non-blocking request + Flux flux = WebClient.create().post().uri(url).headers(httpHeaders -> { + httpHeaders.set(httpHeaders.AUTHORIZATION, headers.get(httpHeaders.AUTHORIZATION).get(0)); + httpHeaders.set(httpHeaders.ACCEPT, headers.get(httpHeaders.ACCEPT).get(0)); + httpHeaders.set(httpHeaders.CONTENT_TYPE, headers.get(httpHeaders.CONTENT_TYPE).get(0)); + }).body(BodyInserters.fromObject(msgJson.toString())).retrieve().bodyToFlux(String.class); + flux.subscribe(res -> logger.debug("Send Camunda Message: " + res)); + } + protected RestTemplate getRestTemplate(boolean retry) { int timeout; if (retry) { -- cgit 1.2.3-korg