diff options
author | Harry Huang <huangxiangyu5@huawei.com> | 2020-02-20 15:37:56 +0800 |
---|---|---|
committer | Harry Huang <huangxiangyu5@huawei.com> | 2020-02-21 10:56:13 +0800 |
commit | a2317eb2230ed472040bfff4af26cb126ce9e687 (patch) | |
tree | 57fe09f2861b44ff2bb15eafc84d6c3e29e761f0 /mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap | |
parent | 6d200a4c428c661c0e19fd2ffb1598e8f2992143 (diff) |
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 <huangxiangyu5@huawei.com>
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap')
-rw-r--r-- | mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/CamundaRequestHandler.java | 19 |
1 files changed, 19 insertions, 0 deletions
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<String> 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) { |