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;
28 import javax.ws.rs.Consumes;
29 import javax.ws.rs.HeaderParam;
30 import javax.ws.rs.POST;
31 import javax.ws.rs.Path;
32 import javax.ws.rs.PathParam;
33 import javax.ws.rs.Produces;
34 import javax.ws.rs.core.MediaType;
35 import javax.ws.rs.core.Response;
37 import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackError;
38 import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackResult;
39 import org.onap.so.logger.ErrorCode;
40 import org.onap.so.logger.MessageEnum;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.stereotype.Component;
46 import io.swagger.annotations.Api;
47 import io.swagger.annotations.ApiOperation;
50 * Generalized REST interface that injects a message event into a waiting BPMN process.
53 * /WorkflowMessage/SDNCAResponse/6d10d075-100c-42d0-9d84-a52432681cae-1478486185286
54 * /WorkflowMessage/SDNCAEvent/USOSTCDALTX0101UJZZ01
58 @Api(description = "Provides a generic service to inject messages into a waiting BPMN Proccess")
60 public class WorkflowMessageResource{
61 private static final Logger logger = LoggerFactory.getLogger(WorkflowMessageResource.class);
62 private static final String LOGMARKER = "[WORKFLOW-MESSAGE]";
65 CallbackHandlerService callback;
68 @Path("/WorkflowMessage/{messageType}/{correlator}")
70 value = "Workflow message correlator",
74 @Produces(MediaType.TEXT_PLAIN)
75 public Response deliver(
76 @HeaderParam("Content-Type") String contentType,
77 @PathParam("messageType") String messageType,
78 @PathParam("correlator") String correlator,
81 String method = "receiveWorkflowMessage";
83 logger.debug(LOGMARKER + " Received workflow message"
84 + " type='" + messageType + "'"
85 + " correlator='" + correlator + "'"
86 + (contentType == null ? "" : " contentType='" + contentType + "'")
87 + " message=" + System.lineSeparator() + message);
89 if (messageType == null || messageType.isEmpty()) {
90 String msg = "Missing message type";
91 logger.debug(LOGMARKER + " " + msg);
92 logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION.toString(), "BPMN",
93 ErrorCode.DataError.getValue(), LOGMARKER + ":" + msg);
94 return Response.status(400).entity(msg).build();
97 if (correlator == null || correlator.isEmpty()) {
98 String msg = "Missing correlator";
99 logger.debug(LOGMARKER + " " + msg);
100 logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION.toString(), "BPMN",
101 ErrorCode.DataError.getValue(), LOGMARKER + ":" + msg);
102 return Response.status(400).entity(msg).build();
105 String messageEventName = "WorkflowMessage";
106 String messageVariable = messageType + "_MESSAGE";
107 String correlationVariable = messageType + "_CORRELATOR";
108 String correlationValue = correlator;
109 String contentTypeVariable = messageType + "_CONTENT_TYPE";
111 Map<String, Object> variables = new HashMap<>();
113 if (contentType != null) {
114 variables.put(contentTypeVariable, contentType);
117 CallbackResult result = callback.handleCallback(method, message, messageEventName,
118 messageVariable, correlationVariable, correlationValue, LOGMARKER, variables);
120 if (result instanceof CallbackError) {
121 return Response.status(500).entity(((CallbackError)result).getErrorMessage()).build();
123 return Response.status(204).build();