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.adapters.sdnc.sdncrest;
23 import javax.servlet.http.HttpServletResponse;
24 import javax.ws.rs.Consumes;
25 import javax.ws.rs.POST;
26 import javax.ws.rs.Path;
27 import javax.ws.rs.PathParam;
28 import javax.ws.rs.Produces;
29 import javax.ws.rs.core.MediaType;
30 import javax.ws.rs.core.Response;
32 import org.onap.so.adapters.sdnc.impl.Constants;
33 import org.onap.so.logger.MessageEnum;
34 import org.onap.so.logger.MsoAlarmLogger;
35 import org.onap.so.logger.MsoLogger;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.core.env.Environment;
38 import org.springframework.stereotype.Component;
41 * A temporary interface to support notifications from SNIRO to BPMN.
42 * We added this to the SDNC adapter because we didn't have time to
43 * develop a SNIRO adapter in 1702.
47 public class SNIROResponse {
48 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA,SNIROResponse.class);
49 private static final MsoAlarmLogger ALARMLOGGER = new MsoAlarmLogger();
52 private Environment env;
55 private BPRestCallback callback;
58 @Path("/SDNCNotify/SNIROResponse/{correlator}")
60 @Produces({MediaType.TEXT_PLAIN})
61 public Response serviceNotification(@PathParam("correlator") String correlator, String content) {
62 LOGGER.info(MessageEnum.RA_RECEIVE_SDNC_NOTIF, content, "SDNC", "SDNCNotify/SNIROResponse");
64 long startTime = System.currentTimeMillis();
66 String bpUrl = env.getProperty(Constants.BPEL_REST_URL_PROP, "");
68 if (bpUrl == null || bpUrl.equals("")) {
69 String error = "Missing configuration for: " + Constants.BPEL_REST_URL_PROP;
70 LOGGER.error(MessageEnum.RA_SDNC_MISS_CONFIG_PARAM, Constants.BPEL_REST_URL_PROP, "SDNC", "",
71 MsoLogger.ErrorCode.DataError, "Missing config param");
72 ALARMLOGGER.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
73 return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity(error).build();
76 long bpStartTime = System.currentTimeMillis();
77 boolean callbackSuccess = callback.send(bpUrl, "SNIROResponse", correlator, content);
79 if (callbackSuccess) {
80 LOGGER.recordMetricEvent(bpStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
81 "Sent notification", "BPMN", bpUrl, null);
82 LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful");
84 LOGGER.recordMetricEvent(bpStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError,
85 "Failed to send notification", "BPMN", bpUrl, null);
86 LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError,
87 "Failed to send notification");
90 return Response.status(204).build();