2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.adapters.workflowmessage;
23 import javax.servlet.http.HttpServletResponse;
24 import javax.ws.rs.Consumes;
25 import javax.ws.rs.GET;
26 import javax.ws.rs.HEAD;
27 import javax.ws.rs.POST;
28 import javax.ws.rs.Path;
29 import javax.ws.rs.HeaderParam;
30 import javax.ws.rs.PathParam;
31 import javax.ws.rs.Produces;
32 import javax.ws.rs.QueryParam;
33 import javax.ws.rs.core.Context;
34 import javax.ws.rs.core.HttpHeaders;
35 import javax.ws.rs.core.MediaType;
36 import javax.ws.rs.core.Response;
38 import org.apache.http.entity.ContentType;
40 import org.openecomp.mso.HealthCheckUtils;
41 import org.openecomp.mso.logger.MessageEnum;
42 import org.openecomp.mso.logger.MsoAlarmLogger;
43 import org.openecomp.mso.logger.MsoLogger;
44 import org.openecomp.mso.utils.UUIDChecker;
47 * Workflow Message Adapter interface added in 1707. Supports delivery of
48 * callbacks from external systems to waiting BPMN workflows.
51 public class WMAdapterRest {
52 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
53 private static final MsoAlarmLogger ALARMLOGGER = new MsoAlarmLogger();
58 @Produces(MediaType.TEXT_HTML)
59 public Response healthcheck(@QueryParam("requestId") String requestId) {
60 long startTime = System.currentTimeMillis();
61 MsoLogger.setServiceName("Healthcheck");
62 UUIDChecker.verifyOldUUID(requestId, LOGGER);
63 HealthCheckUtils healthCheck = new HealthCheckUtils();
65 if (!healthCheck.siteStatusCheck(LOGGER, startTime)) {
66 return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
69 if (!healthCheck.configFileCheck(LOGGER, startTime, WMAdapterConstants.MSO_PROPERTIES_ID)) {
70 return HealthCheckUtils.NOT_STARTED_RESPONSE;
73 LOGGER.debug("healthcheck - Successful");
74 return HealthCheckUtils.HEALTH_CHECK_RESPONSE;
78 * Receives a message from a remote system.
79 * @param content the message content
82 @Path("/message/{messageType}/{correlator}")
84 @Produces({MediaType.TEXT_PLAIN})
85 public Response receiveWorkflowMessage(
86 @HeaderParam("Content-Type") String contentTypeHeader,
87 @PathParam("messageType") String messageType,
88 @PathParam("correlator") String correlator,
91 String path= "workflow/" + messageType + "/" + correlator;
92 LOGGER.info(MessageEnum.RA_RECEIVE_WORKFLOW_MESSAGE, content, "WorkflowMessageAdapter", path);
94 long startTime = System.currentTimeMillis();
96 ContentType contentType = null;
98 if (contentTypeHeader != null) {
100 contentType = ContentType.parse(contentTypeHeader);
101 } catch (Exception e) {
102 // If we don't get a valid one, we handle it below.
103 LOGGER.debug("Exception :",e);
107 if (contentType == null && content != null) {
108 String error = "Missing or Invalid Content-Type";
109 LOGGER.error(MessageEnum.RA_PARSING_REQUEST_ERROR, error, "WorkflowMessageAdapter", path,
110 MsoLogger.ErrorCode.DataError, "Bad Request");
111 ALARMLOGGER.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
112 return Response.status(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE).entity(error).build();
115 String bpUrl = WMAdapterProperties.getProperty(WMAdapterConstants.BPEL_URL_PROP, null);
118 String error = "Missing configuration for: " + WMAdapterConstants.BPEL_URL_PROP;
119 LOGGER.error(MessageEnum.RA_CONFIG_EXC, error, "WorkflowMessageAdapter", path,
120 MsoLogger.ErrorCode.DataError, "Configuration Error");
121 ALARMLOGGER.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
122 return Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).entity(error).build();
125 long bpStartTime = System.currentTimeMillis();
126 BPRestCallback callback = new BPRestCallback();
127 boolean callbackSuccess = callback.send(bpUrl, messageType, correlator, contentType, content);
129 if (callbackSuccess) {
130 LOGGER.recordMetricEvent(bpStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
131 "Sent notification", "BPMN", bpUrl, null);
132 LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful");
134 LOGGER.recordMetricEvent(bpStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError,
135 "Failed to send notification", "BPMN", bpUrl, null);
136 LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError,
137 "Failed to send notification");
140 return Response.status(204).build();