2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.common.workflow.service;
25 import java.util.HashMap;
27 import javax.ws.rs.Consumes;
28 import javax.ws.rs.HeaderParam;
29 import javax.ws.rs.POST;
30 import javax.ws.rs.Path;
31 import javax.ws.rs.PathParam;
32 import javax.ws.rs.Produces;
33 import javax.ws.rs.core.MediaType;
34 import javax.ws.rs.core.Response;
35 import org.onap.so.logger.LoggingAnchor;
36 import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackError;
37 import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackResult;
38 import org.onap.so.logger.ErrorCode;
39 import org.onap.so.logger.MessageEnum;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import org.springframework.stereotype.Component;
44 import io.swagger.annotations.Api;
45 import io.swagger.annotations.ApiOperation;
48 * Generalized REST interface that injects a message event into a waiting BPMN process. Examples:
51 * /WorkflowMessage/SDNCAResponse/6d10d075-100c-42d0-9d84-a52432681cae-1478486185286
52 * /WorkflowMessage/SDNCAEvent/USOSTCDALTX0101UJZZ01
56 @Api(description = "Provides a generic service to inject messages into a waiting BPMN Proccess")
58 public class WorkflowMessageResource {
59 private static final Logger logger = LoggerFactory.getLogger(WorkflowMessageResource.class);
60 private static final String LOGMARKER = "[WORKFLOW-MESSAGE]";
63 CallbackHandlerService callback;
66 @Path("/WorkflowMessage/{messageType}/{correlator}")
67 @ApiOperation(value = "Workflow message correlator", notes = "")
69 @Produces(MediaType.TEXT_PLAIN)
70 public Response deliver(@HeaderParam("Content-Type") String contentType,
71 @PathParam("messageType") String messageType, @PathParam("correlator") String correlator, String message) {
73 String method = "receiveWorkflowMessage";
75 logger.debug(LOGMARKER + " Received workflow message" + " type='" + messageType + "'" + " correlator='"
76 + correlator + "'" + (contentType == null ? "" : " contentType='" + contentType + "'") + " message="
77 + System.lineSeparator() + message);
79 if (messageType == null || messageType.isEmpty()) {
80 String msg = "Missing message type";
81 logger.debug(LOGMARKER + " " + msg);
82 logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION.toString(), "BPMN",
83 ErrorCode.DataError.getValue(), LOGMARKER + ":" + msg);
84 return Response.status(400).entity(msg).build();
87 if (correlator == null || correlator.isEmpty()) {
88 String msg = "Missing correlator";
89 logger.debug(LOGMARKER + " " + msg);
90 logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION.toString(), "BPMN",
91 ErrorCode.DataError.getValue(), LOGMARKER + ":" + msg);
92 return Response.status(400).entity(msg).build();
95 String messageEventName = "WorkflowMessage";
96 String messageVariable = messageType + "_MESSAGE";
97 String correlationVariable = messageType + "_CORRELATOR";
98 String correlationValue = correlator;
99 String contentTypeVariable = messageType + "_CONTENT_TYPE";
101 Map<String, Object> variables = new HashMap<>();
103 if (contentType != null) {
104 variables.put(contentTypeVariable, contentType);
107 CallbackResult result = callback.handleCallback(method, message, messageEventName, messageVariable,
108 correlationVariable, correlationValue, LOGMARKER, variables);
110 if (result instanceof CallbackError) {
111 return Response.status(500).entity(((CallbackError) result).getErrorMessage()).build();
113 return Response.status(204).build();