2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.bpmn.common.workflow.service;
\r
23 import java.util.HashMap;
\r
24 import java.util.Map;
\r
26 import javax.ws.rs.Consumes;
\r
27 import javax.ws.rs.HeaderParam;
\r
28 import javax.ws.rs.POST;
\r
29 import javax.ws.rs.Path;
\r
30 import javax.ws.rs.PathParam;
\r
31 import javax.ws.rs.Produces;
\r
32 import javax.ws.rs.core.MediaType;
\r
33 import javax.ws.rs.core.Response;
\r
35 import org.openecomp.mso.logger.MessageEnum;
\r
36 import org.openecomp.mso.logger.MsoLogger;
\r
39 * Generalized REST interface that injects a message event into a waiting BPMN process.
\r
42 * /WorkflowMessage/SDNCAResponse/6d10d075-100c-42d0-9d84-a52432681cae-1478486185286
\r
43 * /WorkflowMessage/SDNCAEvent/USOSTCDALTX0101UJZZ01
\r
47 public class WorkflowMessageResource extends AbstractCallbackService {
\r
48 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
\r
49 private static final String LOGMARKER = "[WORKFLOW-MESSAGE]";
\r
52 @Path("/WorkflowMessage/{messageType}/{correlator}")
\r
54 @Produces(MediaType.TEXT_PLAIN)
\r
55 public Response deliver(
\r
56 @HeaderParam("Content-Type") String contentType,
\r
57 @PathParam("messageType") String messageType,
\r
58 @PathParam("correlator") String correlator,
\r
61 String method = "receiveWorkflowMessage";
\r
62 MsoLogger.setServiceName("MSO." + method);
\r
63 MsoLogger.setLogContext(correlator, "N/A");
\r
65 LOGGER.debug(LOGMARKER + " Received workflow message"
\r
66 + " type='" + messageType + "'"
\r
67 + " correlator='" + correlator + "'"
\r
68 + (contentType == null ? "" : " contentType='" + contentType + "'")
\r
69 + " message=" + System.lineSeparator() + message);
\r
71 if (messageType == null || messageType.isEmpty()) {
\r
72 String msg = "Missing message type";
\r
73 LOGGER.debug(LOGMARKER + " " + msg);
\r
74 LOGGER.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
\r
75 MsoLogger.ErrorCode.DataError, LOGMARKER + ":" + msg);
\r
76 return Response.status(400).entity(msg).build();
\r
79 if (correlator == null || correlator.isEmpty()) {
\r
80 String msg = "Missing correlator";
\r
81 LOGGER.debug(LOGMARKER + " " + msg);
\r
82 LOGGER.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
\r
83 MsoLogger.ErrorCode.DataError, LOGMARKER + ":" + msg);
\r
84 return Response.status(400).entity(msg).build();
\r
87 String messageEventName = "WorkflowMessage";
\r
88 String messageVariable = messageType + "_MESSAGE";
\r
89 String correlationVariable = messageType + "_CORRELATOR";
\r
90 String correlationValue = correlator;
\r
91 String contentTypeVariable = messageType + "_CONTENT_TYPE";
\r
93 Map<String, Object> variables = new HashMap<>();
\r
95 if (contentType != null) {
\r
96 variables.put(contentTypeVariable, contentType);
\r
99 CallbackResult result = handleCallback(method, message, messageEventName,
\r
100 messageVariable, correlationVariable, correlationValue, LOGMARKER, variables);
\r
102 if (result instanceof CallbackError) {
\r
103 return Response.status(500).entity(((CallbackError)result).getErrorMessage()).build();
\r
105 return Response.status(204).build();
\r