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