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.openecomp.mso.adapters.sdnc.notify;
24 import java.io.StringReader;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28 import javax.ws.rs.Consumes;
29 import javax.ws.rs.GET;
30 import javax.ws.rs.POST;
31 import javax.ws.rs.Path;
32 import javax.ws.rs.PathParam;
33 import javax.ws.rs.Produces;
34 import javax.ws.rs.core.Context;
35 import javax.ws.rs.core.Response;
36 import javax.xml.XMLConstants;
37 import javax.xml.parsers.DocumentBuilder;
38 import javax.xml.parsers.DocumentBuilderFactory;
39 import javax.xml.parsers.ParserConfigurationException;
40 import javax.xml.xpath.XPath;
41 import javax.xml.xpath.XPathConstants;
42 import javax.xml.xpath.XPathFactory;
45 import org.openecomp.mso.utils.UUIDChecker;
46 import org.w3c.dom.Document;
47 import org.w3c.dom.NodeList;
48 import org.xml.sax.InputSource;
50 import org.openecomp.mso.adapters.sdnc.impl.Constants;
51 import org.openecomp.mso.adapters.sdnc.impl.SDNCAdapterPortTypeImpl;
52 import org.openecomp.mso.adapters.sdnc.impl.SDNCResponse;
53 import org.openecomp.mso.adapters.sdnc.impl.SDNCRestClient;
54 import org.openecomp.mso.adapters.sdnc.util.SDNCRequestIdUtil;
55 import org.openecomp.mso.logger.MsoLogger;
56 import org.openecomp.mso.properties.MsoPropertiesFactory;
57 import org.openecomp.mso.logger.MessageEnum;
59 //SDNC to SDNC Async Notifcations
61 public class SDNCNotifyResource {
63 private MsoPropertiesFactory msoPropertiesFactory=new MsoPropertiesFactory();
65 private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
68 public Response printMessage () {
69 long startTime = System.currentTimeMillis ();
70 UUIDChecker.generateUUID (msoLogger);
71 String result = "SDNCAdapter Rest services";
72 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful");
73 return Response.status (HttpServletResponse.SC_OK).entity (result).build ();
79 public Response printMessageParam (@PathParam("param") String msg) {
80 long startTime = System.currentTimeMillis ();
81 UUIDChecker.generateUUID (msoLogger);
82 String result = "SDNCAdapter Rest services : " + msg;
83 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful");
84 return Response.status (HttpServletResponse.SC_OK).entity (result).build ();
90 @Consumes("application/xml")
91 @Produces("application/xml")
92 public Response SDNCNotify (String reqXML, @Context HttpServletRequest request) {
94 XPathFactory xpathFactory = XPathFactory.newInstance ();
95 XPath xpath = xpathFactory.newXPath ();
96 long startTime = System.currentTimeMillis ();
98 msoLogger.info (MessageEnum.RA_RECEIVE_SDNC_NOTIF, reqXML, "SDNC", "SDNCNotify");
100 InputSource source = new InputSource (new StringReader (reqXML));
102 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance ();
107 dbf.setFeature (XMLConstants.FEATURE_SECURE_PROCESSING, true);
108 db = dbf.newDocumentBuilder ();
109 } catch (ParserConfigurationException e) {
110 msoLogger.error (MessageEnum.RA_PARSING_REQUEST_ERROR, "SDNC", "SDNCNotify", MsoLogger.ErrorCode.SchemaError, "Exception - Invalid XML request format", e);
111 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, "Invalid XML request format");
112 return Response.status (HttpServletResponse.SC_BAD_REQUEST).entity ("Invalid XML request format").build ();
117 doc = db.parse (source);
118 } catch (Exception e) {
119 msoLogger.error (MessageEnum.RA_PARSING_REQUEST_ERROR, "SDNC", "SDNCNotify", MsoLogger.ErrorCode.SchemaError, "Exception - Invalid XML request format", e);
120 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, "Invalid XML request format");
121 return Response.status (HttpServletResponse.SC_BAD_REQUEST).entity ("Invalid XML request format").build ();
125 NodeList nl = (NodeList) xpath.evaluate (Constants.SDNC_SVCCFGRESP_ROOT, doc, XPathConstants.NODESET);
126 if (nl.getLength () <= 0) {
127 msoLogger.error (MessageEnum.RA_MISSING_PARAM, Constants.SDNC_SVCCFGRESP_ROOT, "SDNC", "SDNCNotify", MsoLogger.ErrorCode.DataError, "Missing param");
128 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, "Missing" + Constants.SDNC_SVCCFGRESP_ROOT);
129 return Response.status (HttpServletResponse.SC_BAD_REQUEST)
130 .entity ("Missing " + Constants.SDNC_SVCCFGRESP_ROOT)
133 } catch (Exception e) {
134 msoLogger.error (MessageEnum.RA_MISSING_PARAM, Constants.SDNC_SVCCFGRESP_ROOT, "SDNC", "SDNCNotify", MsoLogger.ErrorCode.DataError, "Exception - Missing param", e);
135 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, "Missing" + Constants.SDNC_SVCCFGRESP_ROOT);
136 return Response.status (HttpServletResponse.SC_BAD_REQUEST)
137 .entity ("Missing " + Constants.SDNC_SVCCFGRESP_ROOT)
143 reqId = xpath.evaluate (Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_REQ_ID, doc);
144 } catch (Exception e) {
145 msoLogger.error (MessageEnum.RA_MISSING_PARAM, Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_REQ_ID, "SDNC", "SDNCNotify", MsoLogger.ErrorCode.DataError, "Exception - Missing param", e);
146 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, "Missing" + Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_REQ_ID);
147 return Response.status (HttpServletResponse.SC_BAD_REQUEST)
148 .entity ("Missing " + Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_REQ_ID)
152 MsoLogger.setLogContext (SDNCRequestIdUtil.getSDNCOriginalRequestId (reqId), "");
156 respCode = xpath.evaluate (Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_RESP_CODE, doc);
157 } catch (Exception e) {
158 msoLogger.error (MessageEnum.RA_MISSING_PARAM,
159 Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_RESP_CODE, "SDNC", "SDNCNotify", MsoLogger.ErrorCode.DataError, "Exception - Missing param",
161 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, "Missing" + Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_RESP_CODE);
162 return Response.status (HttpServletResponse.SC_BAD_REQUEST)
163 .entity ("Missing" + Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_RESP_CODE)
169 respMsg = xpath.evaluate (Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_RESP_MSG, doc);
170 } catch (Exception e) {
171 msoLogger.error (MessageEnum.RA_MISSING_PARAM, Constants.SDNC_SVCCFGRESP_ROOT + Constants.SDNC_RESP_MSG, "SDNC", "SDNCNotify", MsoLogger.ErrorCode.DataError, "Exception - Missing param", e);
174 String bpelUrl = null;
178 * bpelUrl = RequestsDatabase.getBpelUrl(reqId);
180 * catch (Exception e)
182 * logger.error("Unable to get SDNC_CALLBACK_URL from ActiveRequests, using default for reqid:" + reqId, e);
185 if (bpelUrl == null) {
186 bpelUrl = SDNCAdapterPortTypeImpl.getProperty (Constants.BPEL_URL_PROP, Constants.DEFAULT_BPEL_URL,msoPropertiesFactory);
189 SDNCResponse sdncResp = new SDNCResponse (reqId);
190 sdncResp.setRespCode (Integer.parseInt (respCode));
191 sdncResp.setRespMsg (respMsg);
192 sdncResp.setSdncRespXml (reqXML);
193 long subStartTime = System.currentTimeMillis ();
194 SDNCRestClient.sendRespToBpel (bpelUrl, sdncResp,msoPropertiesFactory);
195 msoLogger.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully send request to BPMN", "BPMN", bpelUrl, null);
197 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful");
198 return Response.ok ().build ();