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=========================================================
22 package org.openecomp.mso.adapters.sdnc.notify;
25 import java.io.StringReader;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29 import javax.ws.rs.Consumes;
30 import javax.ws.rs.GET;
31 import javax.ws.rs.POST;
32 import javax.ws.rs.Path;
33 import javax.ws.rs.PathParam;
34 import javax.ws.rs.Produces;
35 import javax.ws.rs.core.Context;
36 import javax.ws.rs.core.Response;
37 import javax.xml.XMLConstants;
38 import javax.xml.parsers.DocumentBuilder;
39 import javax.xml.parsers.DocumentBuilderFactory;
40 import javax.xml.parsers.ParserConfigurationException;
41 import javax.xml.xpath.XPath;
42 import javax.xml.xpath.XPathConstants;
43 import javax.xml.xpath.XPathFactory;
46 import org.openecomp.mso.utils.UUIDChecker;
47 import org.w3c.dom.Document;
48 import org.w3c.dom.NodeList;
49 import org.xml.sax.InputSource;
51 import org.openecomp.mso.adapters.sdnc.impl.Constants;
52 import org.openecomp.mso.adapters.sdnc.impl.SDNCAdapterPortTypeImpl;
53 import org.openecomp.mso.adapters.sdnc.impl.SDNCResponse;
54 import org.openecomp.mso.adapters.sdnc.impl.SDNCRestClient;
55 import org.openecomp.mso.adapters.sdnc.util.SDNCRequestIdUtil;
56 import org.openecomp.mso.logger.MsoLogger;
57 import org.openecomp.mso.properties.MsoPropertiesFactory;
58 import org.openecomp.mso.logger.MessageEnum;
60 //SDNC to SDNC Async Notifcations
62 public class SDNCNotifyResource {
64 private MsoPropertiesFactory msoPropertiesFactory=new MsoPropertiesFactory();
66 private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
69 public Response printMessage () {
70 long startTime = System.currentTimeMillis ();
71 UUIDChecker.generateUUID (msoLogger);
72 String result = "SDNCAdapter Rest services";
73 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful");
74 return Response.status (HttpServletResponse.SC_OK).entity (result).build ();
80 public Response printMessageParam (@PathParam("param") String msg) {
81 long startTime = System.currentTimeMillis ();
82 UUIDChecker.generateUUID (msoLogger);
83 String result = "SDNCAdapter Rest services : " + msg;
84 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful");
85 return Response.status (HttpServletResponse.SC_OK).entity (result).build ();
91 @Consumes("application/xml")
92 @Produces("application/xml")
93 public Response SDNCNotify (String reqXML, @Context HttpServletRequest request) {
95 XPathFactory xpathFactory = XPathFactory.newInstance ();
96 XPath xpath = xpathFactory.newXPath ();
97 long startTime = System.currentTimeMillis ();
99 msoLogger.info (MessageEnum.RA_RECEIVE_SDNC_NOTIF, reqXML, "SDNC", "SDNCNotify");
101 InputSource source = new InputSource (new StringReader (reqXML));
103 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance ();
108 dbf.setFeature (XMLConstants.FEATURE_SECURE_PROCESSING, true);
109 db = dbf.newDocumentBuilder ();
110 } catch (ParserConfigurationException e) {
111 msoLogger.error (MessageEnum.RA_PARSING_REQUEST_ERROR, "SDNC", "SDNCNotify", MsoLogger.ErrorCode.SchemaError, "Exception - Invalid XML request format", e);
112 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, "Invalid XML request format");
113 return Response.status (HttpServletResponse.SC_BAD_REQUEST).entity ("Invalid XML request format").build ();
118 doc = db.parse (source);
119 } catch (Exception e) {
120 msoLogger.error (MessageEnum.RA_PARSING_REQUEST_ERROR, "SDNC", "SDNCNotify", MsoLogger.ErrorCode.SchemaError, "Exception - Invalid XML request format", e);
121 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, "Invalid XML request format");
122 return Response.status (HttpServletResponse.SC_BAD_REQUEST).entity ("Invalid XML request format").build ();
126 NodeList nl = (NodeList) xpath.evaluate (Constants.SDNC_SVCCFGRESP_ROOT, doc, XPathConstants.NODESET);
127 if (nl.getLength () <= 0) {
128 msoLogger.error (MessageEnum.RA_MISSING_PARAM, Constants.SDNC_SVCCFGRESP_ROOT, "SDNC", "SDNCNotify", MsoLogger.ErrorCode.DataError, "Missing param");
129 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, "Missing" + Constants.SDNC_SVCCFGRESP_ROOT);
130 return Response.status (HttpServletResponse.SC_BAD_REQUEST)
131 .entity ("Missing " + Constants.SDNC_SVCCFGRESP_ROOT)
134 } catch (Exception e) {
135 msoLogger.error (MessageEnum.RA_MISSING_PARAM, Constants.SDNC_SVCCFGRESP_ROOT, "SDNC", "SDNCNotify", MsoLogger.ErrorCode.DataError, "Exception - Missing param", e);
136 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, "Missing" + Constants.SDNC_SVCCFGRESP_ROOT);
137 return Response.status (HttpServletResponse.SC_BAD_REQUEST)
138 .entity ("Missing " + Constants.SDNC_SVCCFGRESP_ROOT)
144 reqId = xpath.evaluate (Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_REQ_ID, doc);
145 } catch (Exception e) {
146 msoLogger.error (MessageEnum.RA_MISSING_PARAM, Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_REQ_ID, "SDNC", "SDNCNotify", MsoLogger.ErrorCode.DataError, "Exception - Missing param", e);
147 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, "Missing" + Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_REQ_ID);
148 return Response.status (HttpServletResponse.SC_BAD_REQUEST)
149 .entity ("Missing " + Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_REQ_ID)
153 MsoLogger.setLogContext (SDNCRequestIdUtil.getSDNCOriginalRequestId (reqId), "");
157 respCode = xpath.evaluate (Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_RESP_CODE, doc);
158 } catch (Exception e) {
159 msoLogger.error (MessageEnum.RA_MISSING_PARAM,
160 Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_RESP_CODE, "SDNC", "SDNCNotify", MsoLogger.ErrorCode.DataError, "Exception - Missing param",
162 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, "Missing" + Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_RESP_CODE);
163 return Response.status (HttpServletResponse.SC_BAD_REQUEST)
164 .entity ("Missing" + Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_RESP_CODE)
170 respMsg = xpath.evaluate (Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_RESP_MSG, doc);
171 } catch (Exception e) {
172 msoLogger.error (MessageEnum.RA_MISSING_PARAM, Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_RESP_MSG, "SDNC", "SDNCNotify", MsoLogger.ErrorCode.DataError, "Exception - Missing param", e);
179 * bpelUrl = RequestsDatabase.getBpelUrl(reqId);
181 * catch (Exception e)
183 * logger.error("Unable to get SDNC_CALLBACK_URL from ActiveRequests, using default for reqid:" + reqId, e);
187 bpelUrl = SDNCAdapterPortTypeImpl.getProperty (Constants.BPEL_URL_PROP, Constants.DEFAULT_BPEL_URL,msoPropertiesFactory);
188 if (bpelUrl == null) {
189 msoLogger.debug("bpelUrl is NULL:");
192 SDNCResponse sdncResp = new SDNCResponse (reqId);
193 sdncResp.setRespCode (Integer.parseInt (respCode));
194 sdncResp.setRespMsg (respMsg);
195 sdncResp.setSdncRespXml (reqXML);
196 long subStartTime = System.currentTimeMillis ();
197 SDNCRestClient.sendRespToBpel (bpelUrl, sdncResp,msoPropertiesFactory);
198 msoLogger.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully send request to BPMN", "BPMN", bpelUrl, null);
200 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful");
201 return Response.ok ().build ();