diff options
Diffstat (limited to 'adapters/mso-sdnc-adapter/src/main/java/org')
33 files changed, 1984 insertions, 2091 deletions
diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/CXFConfiguration.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/CXFConfiguration.java index 2c84ed4fd0..6149f7ed25 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/CXFConfiguration.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/CXFConfiguration.java @@ -21,9 +21,7 @@ package org.onap.so.adapters.sdnc; import java.util.Arrays; - import javax.xml.ws.Endpoint; - import org.apache.cxf.Bus; import org.apache.cxf.endpoint.Server; import org.apache.cxf.feature.LoggingFeature; @@ -39,7 +37,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; - import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; @@ -47,24 +44,24 @@ import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; @Configuration("CXFConfiguration") public class CXFConfiguration { - - JAXRSServerFactoryBean endpoint; - + + JAXRSServerFactoryBean endpoint; + @Autowired private Bus bus; - - @Autowired - private JaxRsFilterLogging jaxRsFilterLogging; - - @Autowired - private SDNCAdapterPortType sdncAdapterPortImpl; - - @Autowired - private SNIROResponse sniroResponse; - - @Autowired - private ObjectMapper mapper; - + + @Autowired + private JaxRsFilterLogging jaxRsFilterLogging; + + @Autowired + private SDNCAdapterPortType sdncAdapterPortImpl; + + @Autowired + private SNIROResponse sniroResponse; + + @Autowired + private ObjectMapper mapper; + @Bean public Server rsServer() { endpoint = new JAXRSServerFactoryBean(); @@ -73,7 +70,7 @@ public class CXFConfiguration { endpoint.setServiceBeans(Arrays.<Object>asList(sniroResponse)); endpoint.setAddress("/rest"); endpoint.setFeatures(Arrays.asList(createSwaggerFeature(), new LoggingFeature())); - endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(mapper),jaxRsFilterLogging)); + endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(mapper), jaxRsFilterLogging)); return endpoint.create(); } @@ -95,8 +92,8 @@ public class CXFConfiguration { @Bean public Swagger2Feature createSwaggerFeature() { - Swagger2Feature swagger2Feature= new Swagger2Feature(); - swagger2Feature.setBasePath("/services/rest"); + Swagger2Feature swagger2Feature = new Swagger2Feature(); + swagger2Feature.setBasePath("/services/rest"); swagger2Feature.setPrettyPrint(true); swagger2Feature.setTitle("SO Orchestration Application"); swagger2Feature.setContact("The ONAP SO team"); diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/ObjectFactory.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/ObjectFactory.java index eab7d5bf6f..4a1349bfd8 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/ObjectFactory.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/ObjectFactory.java @@ -25,17 +25,13 @@ import javax.xml.bind.annotation.XmlRegistry; /** - * This object contains factory methods for each - * Java content interface and Java element interface - * generated in the org.onap.so.adapters.sdnc package. - * <p>An ObjectFactory allows you to programatically - * construct new instances of the Java representation - * for XML content. The Java representation of XML - * content can consist of schema derived interfaces - * and classes representing the binding of schema - * type definitions, element declarations and model - * groups. Factory methods for each of these are - * provided in this class. + * This object contains factory methods for each Java content interface and Java element interface generated in the + * org.onap.so.adapters.sdnc package. + * <p> + * An ObjectFactory allows you to programatically construct new instances of the Java representation for XML content. + * The Java representation of XML content can consist of schema derived interfaces and classes representing the binding + * of schema type definitions, element declarations and model groups. Factory methods for each of these are provided in + * this class. * */ @XmlRegistry @@ -43,7 +39,8 @@ public class ObjectFactory { /** - * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.onap.so.adapters.sdnc + * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: + * org.onap.so.adapters.sdnc * */ public ObjectFactory() { diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/RequestHeader.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/RequestHeader.java index 1f1b85f34b..2b255b36f6 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/RequestHeader.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/RequestHeader.java @@ -29,9 +29,11 @@ import javax.xml.bind.annotation.XmlType; /** - * <p>Java class for anonymous complex type. + * <p> + * Java class for anonymous complex type. * - * <p>The following schema fragment specifies the expected content contained within this class. + * <p> + * The following schema fragment specifies the expected content contained within this class. * * <pre> * <complexType> @@ -51,16 +53,9 @@ import javax.xml.bind.annotation.XmlType; * * */ -//BPEL to SDNCAdapter request header +// BPEL to SDNCAdapter request header @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "", propOrder = { - "requestId", - "svcInstanceId", - "svcAction", - "svcOperation", - "callbackUrl", - "msoAction" -}) +@XmlType(name = "", propOrder = {"requestId", "svcInstanceId", "svcAction", "svcOperation", "callbackUrl", "msoAction"}) @XmlRootElement(name = "RequestHeader") public class RequestHeader { @@ -80,9 +75,7 @@ public class RequestHeader { /** * Gets the value of the requestId property. * - * @return - * possible object is - * {@link String } + * @return possible object is {@link String } * */ public String getRequestId() { @@ -92,9 +85,7 @@ public class RequestHeader { /** * Sets the value of the requestId property. * - * @param value - * allowed object is - * {@link String } + * @param value allowed object is {@link String } * */ public void setRequestId(String value) { @@ -102,19 +93,17 @@ public class RequestHeader { } public String getSvcInstanceId() { - return svcInstanceId; - } + return svcInstanceId; + } - public void setSvcInstanceId(String svcInstanceId) { - this.svcInstanceId = svcInstanceId; - } + public void setSvcInstanceId(String svcInstanceId) { + this.svcInstanceId = svcInstanceId; + } - /** + /** * Gets the value of the svcAction property. * - * @return - * possible object is - * {@link String } + * @return possible object is {@link String } * */ public String getSvcAction() { @@ -124,9 +113,7 @@ public class RequestHeader { /** * Sets the value of the svcAction property. * - * @param value - * allowed object is - * {@link String } + * @param value allowed object is {@link String } * */ public void setSvcAction(String value) { @@ -136,9 +123,7 @@ public class RequestHeader { /** * Gets the value of the svcOperation property. * - * @return - * possible object is - * {@link String } + * @return possible object is {@link String } * */ public String getSvcOperation() { @@ -148,9 +133,7 @@ public class RequestHeader { /** * Sets the value of the svcOperation property. * - * @param value - * allowed object is - * {@link String } + * @param value allowed object is {@link String } * */ public void setSvcOperation(String value) { @@ -160,9 +143,7 @@ public class RequestHeader { /** * Gets the value of the callbackUrl property. * - * @return - * possible object is - * {@link String } + * @return possible object is {@link String } * */ public String getCallbackUrl() { @@ -172,9 +153,7 @@ public class RequestHeader { /** * Sets the value of the callbackUrl property. * - * @param value - * allowed object is - * {@link String } + * @param value allowed object is {@link String } * */ public void setCallbackUrl(String value) { @@ -184,9 +163,7 @@ public class RequestHeader { /** * Gets the value of the callbackUrl property. * - * @return - * possible object is - * {@link String } + * @return possible object is {@link String } * */ public String getMsoAction() { @@ -196,9 +173,7 @@ public class RequestHeader { /** * Sets the value of the callbackUrl property. * - * @param value - * allowed object is - * {@link String } + * @param value allowed object is {@link String } * */ public void setMsoAction(String value) { @@ -206,14 +181,10 @@ public class RequestHeader { } - @Override - public String toString() { - return "RequestHeader [requestId=" + requestId + - ", svcInstanceId=" + svcInstanceId + - ", svcAction=" + svcAction + - ", svcOperation=" + svcOperation + - ", callbackUrl=" + callbackUrl + - ", msoAction=" + msoAction + "]"; - } + @Override + public String toString() { + return "RequestHeader [requestId=" + requestId + ", svcInstanceId=" + svcInstanceId + ", svcAction=" + svcAction + + ", svcOperation=" + svcOperation + ", callbackUrl=" + callbackUrl + ", msoAction=" + msoAction + "]"; + } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterApplication.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterApplication.java index 2fd0a58dda..a38d057e49 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterApplication.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterApplication.java @@ -21,7 +21,6 @@ package org.onap.so.adapters.sdnc; import java.util.concurrent.Executor; - import org.onap.so.logging.jaxrs.filter.MDCTaskDecorator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -31,43 +30,43 @@ import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.context.annotation.Bean; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; -@SpringBootApplication(scanBasePackages = { "org.onap" }) +@SpringBootApplication(scanBasePackages = {"org.onap"}) public class SDNCAdapterApplication { - @Value("${mso.async.core-pool-size}") - private int corePoolSize; + @Value("${mso.async.core-pool-size}") + private int corePoolSize; - @Value("${mso.async.max-pool-size}") - private int maxPoolSize; + @Value("${mso.async.max-pool-size}") + private int maxPoolSize; - @Value("${mso.async.queue-capacity}") - private int queueCapacity; + @Value("${mso.async.queue-capacity}") + private int queueCapacity; - private static final String LOGS_DIR = "logs_dir"; + private static final String LOGS_DIR = "logs_dir"; - private static void setLogsDir() { - if (System.getProperty(LOGS_DIR) == null) { - System.getProperties().setProperty(LOGS_DIR, "./logs/sdnc/"); - } - } + private static void setLogsDir() { + if (System.getProperty(LOGS_DIR) == null) { + System.getProperties().setProperty(LOGS_DIR, "./logs/sdnc/"); + } + } - public static void main(String[] args) { - SpringApplication.run(SDNCAdapterApplication.class, args); - System.getProperties().setProperty("server.name", "Springboot"); - setLogsDir(); - } + public static void main(String[] args) { + SpringApplication.run(SDNCAdapterApplication.class, args); + System.getProperties().setProperty("server.name", "Springboot"); + setLogsDir(); + } - @Bean - public Executor asyncExecutor() { - ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); - executor.setTaskDecorator(new MDCTaskDecorator()); - executor.setCorePoolSize(corePoolSize); - executor.setMaxPoolSize(maxPoolSize); - executor.setQueueCapacity(queueCapacity); - executor.setThreadNamePrefix("SDNCAdapter-"); - executor.initialize(); - return executor; - } + @Bean + public Executor asyncExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setTaskDecorator(new MDCTaskDecorator()); + executor.setCorePoolSize(corePoolSize); + executor.setMaxPoolSize(maxPoolSize); + executor.setQueueCapacity(queueCapacity); + executor.setThreadNamePrefix("SDNCAdapter-"); + executor.initialize(); + return executor; + } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterPortType.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterPortType.java index 66f93ab87f..9c0c55f3ae 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterPortType.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterPortType.java @@ -30,24 +30,22 @@ import javax.xml.bind.annotation.XmlSeeAlso; /** - * This class was generated by Apache CXF 2.7.11.redhat-3 - * 2015-01-27T18:25:50.914-05:00 - * Generated source version: 2.7.11.redhat-3 + * This class was generated by Apache CXF 2.7.11.redhat-3 2015-01-27T18:25:50.914-05:00 Generated source version: + * 2.7.11.redhat-3 * */ -//BPEL SDNCAdapter SOAP WebService - impl class in impl pkg +// BPEL SDNCAdapter SOAP WebService - impl class in impl pkg @WebService(targetNamespace = "http://org.onap/workflow/sdnc/adapter/wsdl/v1", name = "SDNCAdapterPortType") @XmlSeeAlso({ObjectFactory.class}) @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) public interface SDNCAdapterPortType { - @WebResult(name = "SDNCAdapterResponse", targetNamespace = "http://org.onap/workflow/sdnc/adapter/schema/v1", partName = "SDNCAdapterResponse") + @WebResult(name = "SDNCAdapterResponse", targetNamespace = "http://org.onap/workflow/sdnc/adapter/schema/v1", + partName = "SDNCAdapterResponse") @WebMethod(operationName = "SDNCAdapter") - public SDNCAdapterResponse sdncAdapter( - @WebParam(partName = "SDNCAdapterRequest", name = "SDNCAdapterRequest", targetNamespace = "http://org.onap/workflow/sdnc/adapter/schema/v1") - SDNCAdapterRequest sdncAdapterRequest - ); + public SDNCAdapterResponse sdncAdapter(@WebParam(partName = "SDNCAdapterRequest", name = "SDNCAdapterRequest", + targetNamespace = "http://org.onap/workflow/sdnc/adapter/schema/v1") SDNCAdapterRequest sdncAdapterRequest); @WebMethod - public void healthCheck(); + public void healthCheck(); } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterRequest.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterRequest.java index d204f0c2dd..055d1cd031 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterRequest.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterRequest.java @@ -26,14 +26,16 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; - import org.onap.so.adapters.sdnc.impl.Utils; import org.w3c.dom.Document; import org.w3c.dom.Node; + /** - * <p>Java class for anonymous complex type. + * <p> + * Java class for anonymous complex type. * - * <p>The following schema fragment specifies the expected content contained within this class. + * <p> + * The following schema fragment specifies the expected content contained within this class. * * <pre> * <complexType> @@ -50,12 +52,9 @@ import org.w3c.dom.Node; * * */ -//BPEL to SDNCAdapter request +// BPEL to SDNCAdapter request @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "", propOrder = { - "requestHeader", - "requestData" -}) +@XmlType(name = "", propOrder = {"requestHeader", "requestData"}) @XmlRootElement(name = "SDNCAdapterRequest") public class SDNCAdapterRequest { @@ -67,9 +66,7 @@ public class SDNCAdapterRequest { /** * Gets the value of the requestHeader property. * - * @return - * possible object is - * {@link RequestHeader } + * @return possible object is {@link RequestHeader } * */ public RequestHeader getRequestHeader() { @@ -79,9 +76,7 @@ public class SDNCAdapterRequest { /** * Sets the value of the requestHeader property. * - * @param value - * allowed object is - * {@link RequestHeader } + * @param value allowed object is {@link RequestHeader } * */ public void setRequestHeader(RequestHeader value) { @@ -91,9 +86,7 @@ public class SDNCAdapterRequest { /** * Gets the value of the requestData property. * - * @return - * possible object is - * {@link Object } + * @return possible object is {@link Object } * */ public Object getRequestData() { @@ -103,26 +96,22 @@ public class SDNCAdapterRequest { /** * Sets the value of the requestData property. * - * @param value - * allowed object is - * {@link Object } + * @param value allowed object is {@link Object } * */ public void setRequestData(Object value) { this.requestData = value; } - @Override - public String toString() { + @Override + public String toString() { - String rd = ""; - if (requestData != null) - { - Node node = (Node) requestData; - Document doc = node.getOwnerDocument(); - rd = Utils.domToStr(doc); - } - return "SDNCAdapterRequest [requestHeader=" + requestHeader.toString() - + ", requestData=" + rd + "]"; - } + String rd = ""; + if (requestData != null) { + Node node = (Node) requestData; + Document doc = node.getOwnerDocument(); + rd = Utils.domToStr(doc); + } + return "SDNCAdapterRequest [requestHeader=" + requestHeader.toString() + ", requestData=" + rd + "]"; + } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterResponse.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterResponse.java index c67fbc0ae0..3f6db9b98e 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterResponse.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterResponse.java @@ -28,9 +28,11 @@ import javax.xml.bind.annotation.XmlType; /** - * <p>Java class for anonymous complex type. + * <p> + * Java class for anonymous complex type. * - * <p>The following schema fragment specifies the expected content contained within this class. + * <p> + * The following schema fragment specifies the expected content contained within this class. * * <pre> * <complexType> @@ -43,7 +45,7 @@ import javax.xml.bind.annotation.XmlType; * * */ -//SDNCAdapter to BPEL Sync Response(ACK) - async response(s) follow +// SDNCAdapter to BPEL Sync Response(ACK) - async response(s) follow @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "") @XmlRootElement(name = "SDNCAdapterResponse") diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterService.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterService.java index 26e67c8507..d48013b80d 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterService.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterService.java @@ -25,56 +25,55 @@ package org.onap.so.adapters.sdnc; import java.net.URL; - import javax.xml.namespace.QName; import javax.xml.ws.Service; import javax.xml.ws.WebEndpoint; import javax.xml.ws.WebServiceClient; import javax.xml.ws.WebServiceFeature; - import org.onap.so.logger.ErrorCode; import org.onap.so.logger.MessageEnum; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * This class was generated by Apache CXF 2.7.11.redhat-3 - * 2015-01-27T18:25:50.994-05:00 - * Generated source version: 2.7.11.redhat-3 + * This class was generated by Apache CXF 2.7.11.redhat-3 2015-01-27T18:25:50.994-05:00 Generated source version: + * 2.7.11.redhat-3 * */ -//BPEL SDNCAdapter SOAP WebService -@WebServiceClient(name = "SDNCAdapterService", - wsdlLocation = "main/resources/SDNCAdapter.wsdl", - targetNamespace = "http://org.onap/workflow/sdnc/adapter/wsdl/v1") +// BPEL SDNCAdapter SOAP WebService +@WebServiceClient(name = "SDNCAdapterService", wsdlLocation = "main/resources/SDNCAdapter.wsdl", + targetNamespace = "http://org.onap/workflow/sdnc/adapter/wsdl/v1") public class SDNCAdapterService extends Service { - private static Logger logger = LoggerFactory.getLogger(SDNCAdapterService.class); - private static final String SDNC_ADAPTER_WSDL="SDNCAdapter.wsdl"; - + private static Logger logger = LoggerFactory.getLogger(SDNCAdapterService.class); + private static final String SDNC_ADAPTER_WSDL = "SDNCAdapter.wsdl"; + public static final URL WSDL_LOCATION; - public static final QName SERVICE = new QName("http://org.onap/workflow/sdnc/adapter/wsdl/v1", "SDNCAdapterService"); - public static final QName SDNCAdapterSoapHttpPort = new QName("http://org.onap/workflow/sdnc/adapter/wsdl/v1", "SDNCAdapterSoapHttpPort"); + public static final QName SERVICE = + new QName("http://org.onap/workflow/sdnc/adapter/wsdl/v1", "SDNCAdapterService"); + public static final QName SDNCAdapterSoapHttpPort = + new QName("http://org.onap/workflow/sdnc/adapter/wsdl/v1", "SDNCAdapterSoapHttpPort"); static { URL wsdlUrl = null; try { - wsdlUrl = Thread.currentThread().getContextClassLoader().getResource("main/resources/SDNCAdapter.wsdl"); + wsdlUrl = Thread.currentThread().getContextClassLoader().getResource("main/resources/SDNCAdapter.wsdl"); } catch (Exception e) { logger.error("{} {} {} {}", MessageEnum.RA_WSDL_NOT_FOUND.toString(), SDNC_ADAPTER_WSDL, - ErrorCode.DataError.getValue(), "Exception - WSDL not found", e); + ErrorCode.DataError.getValue(), "Exception - WSDL not found", e); } - if(wsdlUrl == null) { + if (wsdlUrl == null) { logger.error("{} {} {} {}", MessageEnum.RA_WSDL_NOT_FOUND.toString(), SDNC_ADAPTER_WSDL, - ErrorCode.DataError.getValue(), "WSDL not found"); + ErrorCode.DataError.getValue(), "WSDL not found"); } else { - try { - logger.info("{} {} {}", MessageEnum.RA_PRINT_URL.toString(), SDNC_ADAPTER_WSDL, wsdlUrl.toURI().toString()); - } catch (Exception e) { - logger.error("{} {} {} {}", MessageEnum.RA_WSDL_URL_CONVENTION_EXC.toString(), SDNC_ADAPTER_WSDL, - ErrorCode.DataError.getValue(), "Exception - print URL", e); + try { + logger.info("{} {} {}", MessageEnum.RA_PRINT_URL.toString(), SDNC_ADAPTER_WSDL, + wsdlUrl.toURI().toString()); + } catch (Exception e) { + logger.error("{} {} {} {}", MessageEnum.RA_WSDL_URL_CONVENTION_EXC.toString(), SDNC_ADAPTER_WSDL, + ErrorCode.DataError.getValue(), "Exception - print URL", e); + } } - } WSDL_LOCATION = wsdlUrl; } @@ -90,31 +89,30 @@ public class SDNCAdapterService extends Service { super(WSDL_LOCATION, SERVICE); } - //This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2 - //API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1 - //compliant code instead. - public SDNCAdapterService(WebServiceFeature ... features) { + // This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2 + // API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1 + // compliant code instead. + public SDNCAdapterService(WebServiceFeature... features) { super(WSDL_LOCATION, SERVICE, features); } - //This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2 - //API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1 - //compliant code instead. - public SDNCAdapterService(URL wsdlLocation, WebServiceFeature ... features) { + // This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2 + // API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1 + // compliant code instead. + public SDNCAdapterService(URL wsdlLocation, WebServiceFeature... features) { super(wsdlLocation, SERVICE, features); } - //This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2 - //API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1 - //compliant code instead. - public SDNCAdapterService(URL wsdlLocation, QName serviceName, WebServiceFeature ... features) { + // This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2 + // API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1 + // compliant code instead. + public SDNCAdapterService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) { super(wsdlLocation, serviceName, features); } /** * - * @return - * returns SDNCAdapterPortType + * @return returns SDNCAdapterPortType */ @WebEndpoint(name = "SDNCAdapterSoapHttpPort") public SDNCAdapterPortType getSDNCAdapterSoapHttpPort() { @@ -123,10 +121,9 @@ public class SDNCAdapterService extends Service { /** * - * @param features - * A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values. - * @return - * returns SDNCAdapterPortType + * @param features A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features + * not in the <code>features</code> parameter will have their default values. + * @return returns SDNCAdapterPortType */ @WebEndpoint(name = "SDNCAdapterSoapHttpPort") public SDNCAdapterPortType getSDNCAdapterSoapHttpPort(WebServiceFeature... features) { diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/WebSecurityConfigImpl.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/WebSecurityConfigImpl.java index 60e37294b1..e1eb9ecef9 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/WebSecurityConfigImpl.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/WebSecurityConfigImpl.java @@ -31,21 +31,18 @@ import org.springframework.util.StringUtils; @EnableWebSecurity public class WebSecurityConfigImpl extends WebSecurityConfig { - @Override - protected void configure(HttpSecurity http) throws Exception { - http.csrf().disable() - .authorizeRequests() - .antMatchers("/manage/health","/manage/info","/services").permitAll() - .antMatchers("/**").hasAnyRole(StringUtils.collectionToDelimitedString(getRoles(),",").toString()) - .and() - .httpBasic(); - } - - @Override - public void configure(WebSecurity web) throws Exception { - super.configure(web); - StrictHttpFirewall firewall = new MSOSpringFirewall(); - web.httpFirewall(firewall); - } + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf().disable().authorizeRequests().antMatchers("/manage/health", "/manage/info", "/services").permitAll() + .antMatchers("/**").hasAnyRole(StringUtils.collectionToDelimitedString(getRoles(), ",").toString()) + .and().httpBasic(); + } + + @Override + public void configure(WebSecurity web) throws Exception { + super.configure(web); + StrictHttpFirewall firewall = new MSOSpringFirewall(); + web.httpFirewall(firewall); + } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/CallbackHeader.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/CallbackHeader.java index 67f5516daa..a37602d1fc 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/CallbackHeader.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/CallbackHeader.java @@ -28,9 +28,11 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; /** - * <p>Java class for anonymous complex type. + * <p> + * Java class for anonymous complex type. * - * <p>The following schema fragment specifies the expected content contained within this class. + * <p> + * The following schema fragment specifies the expected content contained within this class. * * <pre> * <complexType> @@ -48,13 +50,9 @@ import javax.xml.bind.annotation.XmlType; * * */ -//SDNCAdapter to BPEL Async response header +// SDNCAdapter to BPEL Async response header @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "", propOrder = { - "requestId", - "responseCode", - "responseMessage" -}) +@XmlType(name = "", propOrder = {"requestId", "responseCode", "responseMessage"}) @XmlRootElement(name = "CallbackHeader") public class CallbackHeader { @@ -70,17 +68,15 @@ public class CallbackHeader { } public CallbackHeader(String reqId, String respCode, String respMsg) { - this.requestId = reqId; - this.responseCode = respCode; - this.responseMessage = respMsg; + this.requestId = reqId; + this.responseCode = respCode; + this.responseMessage = respMsg; } /** * Gets the value of the requestId property. * - * @return - * possible object is - * {@link String } + * @return possible object is {@link String } * */ public String getRequestId() { @@ -90,9 +86,7 @@ public class CallbackHeader { /** * Sets the value of the requestId property. * - * @param value - * allowed object is - * {@link String } + * @param value allowed object is {@link String } * */ public void setRequestId(String value) { @@ -102,9 +96,7 @@ public class CallbackHeader { /** * Gets the value of the responseCode property. * - * @return - * possible object is - * {@link String } + * @return possible object is {@link String } * */ public String getResponseCode() { @@ -114,9 +106,7 @@ public class CallbackHeader { /** * Sets the value of the responseCode property. * - * @param value - * allowed object is - * {@link String } + * @param value allowed object is {@link String } * */ public void setResponseCode(String value) { @@ -126,9 +116,7 @@ public class CallbackHeader { /** * Gets the value of the responseMessage property. * - * @return - * possible object is - * {@link String } + * @return possible object is {@link String } * */ public String getResponseMessage() { @@ -138,18 +126,16 @@ public class CallbackHeader { /** * Sets the value of the responseMessage property. * - * @param value - * allowed object is - * {@link String } + * @param value allowed object is {@link String } * */ public void setResponseMessage(String value) { this.responseMessage = value; } - @Override - public String toString() { - return "CallbackHeader [requestId=" + requestId + ", responseCode=" - + responseCode + ", responseMessage=" + responseMessage + "]"; - } + @Override + public String toString() { + return "CallbackHeader [requestId=" + requestId + ", responseCode=" + responseCode + ", responseMessage=" + + responseMessage + "]"; + } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/ObjectFactory.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/ObjectFactory.java index 238b6a7b1c..3877195fbc 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/ObjectFactory.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/ObjectFactory.java @@ -25,17 +25,13 @@ import javax.xml.bind.annotation.XmlRegistry; /** - * This object contains factory methods for each - * Java content interface and Java element interface - * generated in the org.onap.so.adapters.sdnc.client package. - * <p>An ObjectFactory allows you to programatically - * construct new instances of the Java representation - * for XML content. The Java representation of XML - * content can consist of schema derived interfaces - * and classes representing the binding of schema - * type definitions, element declarations and model - * groups. Factory methods for each of these are - * provided in this class. + * This object contains factory methods for each Java content interface and Java element interface generated in the + * org.onap.so.adapters.sdnc.client package. + * <p> + * An ObjectFactory allows you to programatically construct new instances of the Java representation for XML content. + * The Java representation of XML content can consist of schema derived interfaces and classes representing the binding + * of schema type definitions, element declarations and model groups. Factory methods for each of these are provided in + * this class. * */ @XmlRegistry @@ -43,11 +39,11 @@ public class ObjectFactory { /** - * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.onap.so.adapters.sdnc.client + * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: + * org.onap.so.adapters.sdnc.client * */ - public ObjectFactory() { - } + public ObjectFactory() {} /** diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/SDNCAdapterCallbackRequest.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/SDNCAdapterCallbackRequest.java index 2703060761..97a6860dfe 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/SDNCAdapterCallbackRequest.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/SDNCAdapterCallbackRequest.java @@ -24,7 +24,6 @@ package org.onap.so.adapters.sdnc.client; import java.io.StringWriter; - import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; import javax.xml.bind.annotation.XmlAccessType; @@ -32,16 +31,17 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; - import org.onap.so.logger.ErrorCode; import org.onap.so.logger.MessageEnum; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * <p>Java class for anonymous complex type. + * <p> + * Java class for anonymous complex type. * - * <p>The following schema fragment specifies the expected content contained within this class. + * <p> + * The following schema fragment specifies the expected content contained within this class. * * <pre> * <complexType> @@ -58,12 +58,9 @@ import org.slf4j.LoggerFactory; * * */ -//SDNCAdapter to BPEL Async response +// SDNCAdapter to BPEL Async response @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "", propOrder = { - "callbackHeader", - "requestData" -}) +@XmlType(name = "", propOrder = {"callbackHeader", "requestData"}) @XmlRootElement(name = "SDNCAdapterCallbackRequest") public class SDNCAdapterCallbackRequest { @@ -77,9 +74,7 @@ public class SDNCAdapterCallbackRequest { /** * Gets the value of the callbackHeader property. * - * @return - * possible object is - * {@link CallbackHeader } + * @return possible object is {@link CallbackHeader } * */ public CallbackHeader getCallbackHeader() { @@ -89,9 +84,7 @@ public class SDNCAdapterCallbackRequest { /** * Sets the value of the callbackHeader property. * - * @param value - * allowed object is - * {@link CallbackHeader } + * @param value allowed object is {@link CallbackHeader } * */ public void setCallbackHeader(CallbackHeader value) { @@ -101,9 +94,7 @@ public class SDNCAdapterCallbackRequest { /** * Gets the value of the requestData property. * - * @return - * possible object is - * {@link Object } + * @return possible object is {@link Object } * */ public Object getRequestData() { @@ -113,31 +104,27 @@ public class SDNCAdapterCallbackRequest { /** * Sets the value of the requestData property. * - * @param value - * allowed object is - * {@link Object } + * @param value allowed object is {@link Object } * */ public void setRequestData(Object value) { this.requestData = value; } - @Override - public String toString() { - try { - JAXBContext ctx = JAXBContext.newInstance("org.onap.so.adapters.sdnc.client"); - Marshaller m = ctx.createMarshaller(); - m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); - StringWriter w = new StringWriter(); - m.marshal(this, w); - return w.toString(); - } - catch (Exception e) - { - logger.error("{} {} {}", MessageEnum.RA_MARSHING_ERROR.toString(), ErrorCode.DataError.getValue(), - "Exception - MARSHING_ERROR", e); + @Override + public String toString() { + try { + JAXBContext ctx = JAXBContext.newInstance("org.onap.so.adapters.sdnc.client"); + Marshaller m = ctx.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); + StringWriter w = new StringWriter(); + m.marshal(this, w); + return w.toString(); + } catch (Exception e) { + logger.error("{} {} {}", MessageEnum.RA_MARSHING_ERROR.toString(), ErrorCode.DataError.getValue(), + "Exception - MARSHING_ERROR", e); + } + return ""; } - return ""; - } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/SDNCCallbackAdapterPortType.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/SDNCCallbackAdapterPortType.java index 369610ce0f..d072a9af6d 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/SDNCCallbackAdapterPortType.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/SDNCCallbackAdapterPortType.java @@ -27,27 +27,26 @@ import javax.jws.WebResult; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.xml.bind.annotation.XmlSeeAlso; - import org.onap.so.adapters.sdnc.SDNCAdapterResponse; /** - * This class was generated by Apache CXF 2.7.11.redhat-3 - * 2015-01-28T11:07:01.997-05:00 - * Generated source version: 2.7.11.redhat-3 + * This class was generated by Apache CXF 2.7.11.redhat-3 2015-01-28T11:07:01.997-05:00 Generated source version: + * 2.7.11.redhat-3 * */ -//SDNCAdapter to BPEL Async response WEB Service -@WebService(targetNamespace = "http://org.onap/workflow/sdnc/adapter/callback/wsdl/v1", name = "SDNCCallbackAdapterPortType") +// SDNCAdapter to BPEL Async response WEB Service +@WebService(targetNamespace = "http://org.onap/workflow/sdnc/adapter/callback/wsdl/v1", + name = "SDNCCallbackAdapterPortType") @XmlSeeAlso({ObjectFactory.class}) @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) @FunctionalInterface public interface SDNCCallbackAdapterPortType { - @WebResult(name = "SDNCAdapterResponse", targetNamespace = "http://org.onap/workflow/sdnc/adapter/schema/v1", partName = "SDNCAdapterCallbackResponse") + @WebResult(name = "SDNCAdapterResponse", targetNamespace = "http://org.onap/workflow/sdnc/adapter/schema/v1", + partName = "SDNCAdapterCallbackResponse") @WebMethod(operationName = "SDNCAdapterCallback") - public SDNCAdapterResponse sdncAdapterCallback( - @WebParam(partName = "SDNCAdapterCallbackRequest", name = "SDNCAdapterCallbackRequest", targetNamespace = "http://org.onap/workflow/sdnc/adapter/schema/v1") - SDNCAdapterCallbackRequest sdncAdapterCallbackRequest - ); + public SDNCAdapterResponse sdncAdapterCallback(@WebParam(partName = "SDNCAdapterCallbackRequest", + name = "SDNCAdapterCallbackRequest", + targetNamespace = "http://org.onap/workflow/sdnc/adapter/schema/v1") SDNCAdapterCallbackRequest sdncAdapterCallbackRequest); } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/SDNCCallbackAdapterService.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/SDNCCallbackAdapterService.java index ee7a467357..72d18bd1ce 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/SDNCCallbackAdapterService.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/SDNCCallbackAdapterService.java @@ -24,55 +24,55 @@ package org.onap.so.adapters.sdnc.client; import java.net.URL; - import javax.xml.namespace.QName; import javax.xml.ws.Service; import javax.xml.ws.WebEndpoint; import javax.xml.ws.WebServiceClient; import javax.xml.ws.WebServiceFeature; - import org.onap.so.logger.ErrorCode; import org.onap.so.logger.MessageEnum; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * This class was generated by Apache CXF 2.7.11.redhat-3 - * 2015-01-28T11:07:02.074-05:00 - * Generated source version: 2.7.11.redhat-3 + * This class was generated by Apache CXF 2.7.11.redhat-3 2015-01-28T11:07:02.074-05:00 Generated source version: + * 2.7.11.redhat-3 * */ -//SDNCAdapter to BPEL Async response WEB Service -@WebServiceClient(name = "SDNCCallbackAdapterService", - wsdlLocation = "main/resources/SDNCCallbackAdapter.wsdl", - targetNamespace = "http://org.onap/workflow/sdnc/adapter/callback/wsdl/v1") +// SDNCAdapter to BPEL Async response WEB Service +@WebServiceClient(name = "SDNCCallbackAdapterService", wsdlLocation = "main/resources/SDNCCallbackAdapter.wsdl", + targetNamespace = "http://org.onap/workflow/sdnc/adapter/callback/wsdl/v1") public class SDNCCallbackAdapterService extends Service { - private static Logger logger = LoggerFactory.getLogger(SDNCCallbackAdapterService.class); - private static final String SDNC_CALLBACK_ADAPTER_WSDL="SDNCCallbackAdapter.wsdl"; + private static Logger logger = LoggerFactory.getLogger(SDNCCallbackAdapterService.class); + private static final String SDNC_CALLBACK_ADAPTER_WSDL = "SDNCCallbackAdapter.wsdl"; public static final URL WSDL_LOCATION; - public static final QName SERVICE = new QName("http://org.onap/workflow/sdnc/adapter/callback/wsdl/v1", "SDNCCallbackAdapterService"); - public static final QName SDNCCallbackAdapterSoapHttpPort = new QName("http://org.onap/workflow/sdnc/adapter/callback/wsdl/v1", "SDNCCallbackAdapterSoapHttpPort"); + public static final QName SERVICE = + new QName("http://org.onap/workflow/sdnc/adapter/callback/wsdl/v1", "SDNCCallbackAdapterService"); + public static final QName SDNCCallbackAdapterSoapHttpPort = + new QName("http://org.onap/workflow/sdnc/adapter/callback/wsdl/v1", "SDNCCallbackAdapterSoapHttpPort"); static { URL wsdlUrl = null; try { - wsdlUrl = Thread.currentThread().getContextClassLoader().getResource("main/resources/SDNCCallbackAdapter.wsdl"); + wsdlUrl = Thread.currentThread().getContextClassLoader() + .getResource("main/resources/SDNCCallbackAdapter.wsdl"); } catch (Exception e) { logger.error("{} {} {} {} {}", MessageEnum.RA_WSDL_NOT_FOUND.toString(), SDNC_CALLBACK_ADAPTER_WSDL, "SDNC", - ErrorCode.DataError.getValue(), "Exception - WSDL not found", e); + ErrorCode.DataError.getValue(), "Exception - WSDL not found", e); } - if(wsdlUrl == null) { + if (wsdlUrl == null) { logger.error("{} {} {} {} {}", MessageEnum.RA_WSDL_NOT_FOUND.toString(), SDNC_CALLBACK_ADAPTER_WSDL, "SDNC", - ErrorCode.DataError.getValue(), "WSDL not found"); + ErrorCode.DataError.getValue(), "WSDL not found"); } else { - try { - logger.info("{} {} {} {}", MessageEnum.RA_PRINT_URL.toString(), SDNC_CALLBACK_ADAPTER_WSDL, - wsdlUrl.toURI().toString(), "SDNC"); - } catch (Exception e) { - logger.error("{} {} {} {} {}", MessageEnum.RA_WSDL_URL_CONVENTION_EXC.toString(), SDNC_CALLBACK_ADAPTER_WSDL, - "SDNC", ErrorCode.DataError.getValue(), "Exception - URL convention problem", e); + try { + logger.info("{} {} {} {}", MessageEnum.RA_PRINT_URL.toString(), SDNC_CALLBACK_ADAPTER_WSDL, + wsdlUrl.toURI().toString(), "SDNC"); + } catch (Exception e) { + logger.error("{} {} {} {} {}", MessageEnum.RA_WSDL_URL_CONVENTION_EXC.toString(), + SDNC_CALLBACK_ADAPTER_WSDL, "SDNC", ErrorCode.DataError.getValue(), + "Exception - URL convention problem", e); + } } - } WSDL_LOCATION = wsdlUrl; } @@ -88,31 +88,30 @@ public class SDNCCallbackAdapterService extends Service { super(WSDL_LOCATION, SERVICE); } - //This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2 - //API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1 - //compliant code instead. - public SDNCCallbackAdapterService(WebServiceFeature ... features) { + // This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2 + // API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1 + // compliant code instead. + public SDNCCallbackAdapterService(WebServiceFeature... features) { super(WSDL_LOCATION, SERVICE, features); } - //This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2 - //API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1 - //compliant code instead. - public SDNCCallbackAdapterService(URL wsdlLocation, WebServiceFeature ... features) { + // This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2 + // API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1 + // compliant code instead. + public SDNCCallbackAdapterService(URL wsdlLocation, WebServiceFeature... features) { super(wsdlLocation, SERVICE, features); } - //This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2 - //API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1 - //compliant code instead. - public SDNCCallbackAdapterService(URL wsdlLocation, QName serviceName, WebServiceFeature ... features) { + // This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2 + // API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1 + // compliant code instead. + public SDNCCallbackAdapterService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) { super(wsdlLocation, serviceName, features); } /** * - * @return - * returns SDNCCallbackAdapterPortType + * @return returns SDNCCallbackAdapterPortType */ @WebEndpoint(name = "SDNCCallbackAdapterSoapHttpPort") public SDNCCallbackAdapterPortType getSDNCCallbackAdapterSoapHttpPort() { @@ -121,10 +120,9 @@ public class SDNCCallbackAdapterService extends Service { /** * - * @param features - * A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values. - * @return - * returns SDNCCallbackAdapterPortType + * @param features A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features + * not in the <code>features</code> parameter will have their default values. + * @return returns SDNCCallbackAdapterPortType */ @WebEndpoint(name = "SDNCCallbackAdapterSoapHttpPort") public SDNCCallbackAdapterPortType getSDNCCallbackAdapterSoapHttpPort(WebServiceFeature... features) { diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/package-info.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/package-info.java index 368c824caa..f5d494f40c 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/package-info.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/client/package-info.java @@ -18,6 +18,7 @@ * ============LICENSE_END========================================================= */ -@javax.xml.bind.annotation.XmlSchema(namespace = "http://org.onap/workflow/sdnc/adapter/schema/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) +@javax.xml.bind.annotation.XmlSchema(namespace = "http://org.onap/workflow/sdnc/adapter/schema/v1", + elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) package org.onap.so.adapters.sdnc.client; diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/exception/SDNCAdapterException.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/exception/SDNCAdapterException.java index e45c4ce569..3a03f454f7 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/exception/SDNCAdapterException.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/exception/SDNCAdapterException.java @@ -22,9 +22,9 @@ package org.onap.so.adapters.sdnc.exception; public class SDNCAdapterException extends Exception { - private static final long serialVersionUID = -7913634772004514998L; + private static final long serialVersionUID = -7913634772004514998L; - public SDNCAdapterException(String message) { - super(message); - } + public SDNCAdapterException(String message) { + super(message); + } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/Constants.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/Constants.java index 09597b26b7..91c7c7c65f 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/Constants.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/Constants.java @@ -23,21 +23,21 @@ package org.onap.so.adapters.sdnc.impl; public interface Constants { - public static final String BPEL_REST_URL_PROP = "org.onap.so.adapters.sdnc.rest.bpelurl"; - public static final String BPEL_URL_PROP = "org.onap.so.adapters.sdnc.bpelurl"; - public static final String DEFAULT_BPEL_URL = "http://localhost:8080//active-bpel/services/SDNCAdapterCallbackV1"; + public static final String BPEL_REST_URL_PROP = "org.onap.so.adapters.sdnc.rest.bpelurl"; + public static final String BPEL_URL_PROP = "org.onap.so.adapters.sdnc.bpelurl"; + public static final String DEFAULT_BPEL_URL = "http://localhost:8080//active-bpel/services/SDNCAdapterCallbackV1"; - public static final String MY_URL_PROP = "org.onap.so.adapters.sdnc.myurl"; - public static final String SDNC_AUTH_PROP = "org.onap.so.adapters.sdnc.sdncauth"; - public static final String BPEL_AUTH_PROP = "org.onap.so.adapters.sdnc.bpelauth"; + public static final String MY_URL_PROP = "org.onap.so.adapters.sdnc.myurl"; + public static final String SDNC_AUTH_PROP = "org.onap.so.adapters.sdnc.sdncauth"; + public static final String BPEL_AUTH_PROP = "org.onap.so.adapters.sdnc.bpelauth"; - public static final String SDNC_SVCCFGRESP_ROOT = "input"; - public static final String SDNC_REQ_ID = "/svc-request-id"; - public static final String SDNC_RESP_CODE = "/response-code"; - public static final String SDNC_RESP_MSG = "/response-message"; - public static final String SDNC_CONNECTTIME_PROP = "org.onap.so.adapters.sdnc.sdncconnecttime"; - public static final String ENCRYPTION_KEY_PROP = "org.onap.so.adapters.network.encryptionKey"; + public static final String SDNC_SVCCFGRESP_ROOT = "input"; + public static final String SDNC_REQ_ID = "/svc-request-id"; + public static final String SDNC_RESP_CODE = "/response-code"; + public static final String SDNC_RESP_MSG = "/response-message"; + public static final String SDNC_CONNECTTIME_PROP = "org.onap.so.adapters.sdnc.sdncconnecttime"; + public static final String ENCRYPTION_KEY_PROP = "org.onap.so.adapters.network.encryptionKey"; - public static final String REQUEST_TUNABLES = "org.onap.so.adapters.sdnc"; + public static final String REQUEST_TUNABLES = "org.onap.so.adapters.sdnc"; } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/MapRequestTunables.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/MapRequestTunables.java index 401f5c5b2b..2d43385700 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/MapRequestTunables.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/MapRequestTunables.java @@ -33,77 +33,82 @@ import org.springframework.stereotype.Component; @Component public class MapRequestTunables { - - private static Logger logger = LoggerFactory.getLogger(MapRequestTunables.class); - public static final String GENERATED_KEY = "Generated key: "; - - @Autowired - private Environment env; - public RequestTunables setTunables(RequestTunables reqTunableOriginal) - { - RequestTunables reqTunable = new RequestTunables(reqTunableOriginal); - String error = null; - String key; - if ("query".equals(reqTunable.getAction())) { //due to variable format for reqTunable.getOperation() eg services/layer3-service-list/8fe4ba4f-35cf-4d9b-a04a-fd3f5d4c5cc9 - key = Constants.REQUEST_TUNABLES + "." + reqTunable.getMsoAction() + ".." + reqTunable.getAction(); - logger.debug(GENERATED_KEY + key); - } - else if ("put".equals(reqTunable.getAction()) || "restdelete".equals(reqTunable.getAction())) { //due to variable format for reqTunable.getOperation() eg services/layer3-service-list/8fe4ba4f-35cf-4d9b-a04a-fd3f5d4c5cc9 - key = Constants.REQUEST_TUNABLES + "..." + reqTunable.getAction(); - logger.debug(GENERATED_KEY + key); - } else { - key = Constants.REQUEST_TUNABLES + "." + reqTunable.getMsoAction() + "." + reqTunable.getOperation() +"." + reqTunable.getAction(); - logger.debug(GENERATED_KEY + key); - } + private static Logger logger = LoggerFactory.getLogger(MapRequestTunables.class); + public static final String GENERATED_KEY = "Generated key: "; - String value; - value = env.getProperty(key, ""); + @Autowired + private Environment env; - if (value != null && value.length() > 0) { + public RequestTunables setTunables(RequestTunables reqTunableOriginal) { + RequestTunables reqTunable = new RequestTunables(reqTunableOriginal); + String error = null; + String key; + if ("query".equals(reqTunable.getAction())) { // due to variable format for reqTunable.getOperation() eg + // services/layer3-service-list/8fe4ba4f-35cf-4d9b-a04a-fd3f5d4c5cc9 + key = Constants.REQUEST_TUNABLES + "." + reqTunable.getMsoAction() + ".." + reqTunable.getAction(); + logger.debug(GENERATED_KEY + key); + } else if ("put".equals(reqTunable.getAction()) || "restdelete".equals(reqTunable.getAction())) { // due to + // variable + // format for + // reqTunable.getOperation() + // eg + // services/layer3-service-list/8fe4ba4f-35cf-4d9b-a04a-fd3f5d4c5cc9 + key = Constants.REQUEST_TUNABLES + "..." + reqTunable.getAction(); + logger.debug(GENERATED_KEY + key); + } else { + key = Constants.REQUEST_TUNABLES + "." + reqTunable.getMsoAction() + "." + reqTunable.getOperation() + "." + + reqTunable.getAction(); + logger.debug(GENERATED_KEY + key); + } - String[] parts = value.split("\\|"); //escape pipe - if (parts.length < 3) { - logger.warn("{} {} {} {} {} {}", MessageEnum.RA_SDNC_INVALID_CONFIG.toString(), key, value, "SDNC", - ErrorCode.DataError.getValue(), "Invalid config"); - } + String value; + value = env.getProperty(key, ""); - for (int i = 0; i < parts.length; i++) { - if (i == 0) { - reqTunable.setReqMethod(parts[i]) ; - logger.debug("Request Method is set to: {}", reqTunable.getReqMethod()); - } else if (i == 1) { - reqTunable.setTimeout( parts[i]); - logger.debug("Timeout is set to: {}", reqTunable.getTimeout()); - } else if (i == 2) { - reqTunable.setSdncUrl(env.getProperty(Constants.REQUEST_TUNABLES + "." + parts[i],"")); - if (reqTunable.getOperation() != null && reqTunable.getSdncUrl() != null) { - reqTunable.setSdncUrl(reqTunable.getSdncUrl() + reqTunable.getOperation()); - } - logger.debug("SDNC Url is set to: {}", reqTunable.getSdncUrl()); - } else if (i == 3) { - reqTunable.setHeaderName(parts[i]); - logger.debug("HeaderName is set to: {}", reqTunable.getHeaderName()); - } else if (i == 4) { - reqTunable.setNamespace(parts[i]); - logger.debug("NameSpace is set to: {}", reqTunable.getNamespace()); - } else if (i == 5) { - reqTunable.setAsyncInd(parts[i]); - logger.debug("AsyncInd is set to: {}", reqTunable.getAsyncInd()); - } - } + if (value != null && value.length() > 0) { - if (reqTunable.getSdncUrl() == null || ("").equals(reqTunable.getSdncUrl())) { - error = "Invalid configuration, sdncUrl required for:" + key + " value:" + value; - } - } else { - error = "Missing configuration for:" + key; - } - if (error != null) { - logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), key, "SDNC", - ErrorCode.DataError.getValue(), "Missing config param"); - } - logger.debug("RequestTunables Key:{} Value:{} Tunables:{}", key, value, this.toString()); - return reqTunable; - } + String[] parts = value.split("\\|"); // escape pipe + if (parts.length < 3) { + logger.warn("{} {} {} {} {} {}", MessageEnum.RA_SDNC_INVALID_CONFIG.toString(), key, value, "SDNC", + ErrorCode.DataError.getValue(), "Invalid config"); + } + + for (int i = 0; i < parts.length; i++) { + if (i == 0) { + reqTunable.setReqMethod(parts[i]); + logger.debug("Request Method is set to: {}", reqTunable.getReqMethod()); + } else if (i == 1) { + reqTunable.setTimeout(parts[i]); + logger.debug("Timeout is set to: {}", reqTunable.getTimeout()); + } else if (i == 2) { + reqTunable.setSdncUrl(env.getProperty(Constants.REQUEST_TUNABLES + "." + parts[i], "")); + if (reqTunable.getOperation() != null && reqTunable.getSdncUrl() != null) { + reqTunable.setSdncUrl(reqTunable.getSdncUrl() + reqTunable.getOperation()); + } + logger.debug("SDNC Url is set to: {}", reqTunable.getSdncUrl()); + } else if (i == 3) { + reqTunable.setHeaderName(parts[i]); + logger.debug("HeaderName is set to: {}", reqTunable.getHeaderName()); + } else if (i == 4) { + reqTunable.setNamespace(parts[i]); + logger.debug("NameSpace is set to: {}", reqTunable.getNamespace()); + } else if (i == 5) { + reqTunable.setAsyncInd(parts[i]); + logger.debug("AsyncInd is set to: {}", reqTunable.getAsyncInd()); + } + } + + if (reqTunable.getSdncUrl() == null || ("").equals(reqTunable.getSdncUrl())) { + error = "Invalid configuration, sdncUrl required for:" + key + " value:" + value; + } + } else { + error = "Missing configuration for:" + key; + } + if (error != null) { + logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), key, "SDNC", + ErrorCode.DataError.getValue(), "Missing config param"); + } + logger.debug("RequestTunables Key:{} Value:{} Tunables:{}", key, value, this.toString()); + return reqTunable; + } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/RequestTunables.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/RequestTunables.java index 6947b870d7..bfd2aea33f 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/RequestTunables.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/RequestTunables.java @@ -24,136 +24,151 @@ package org.onap.so.adapters.sdnc.impl; public class RequestTunables { - - - public static final String GENERATED_KEY = "Generated key: "; - - //criteria - private String reqId = ""; - private String msoAction = ""; - private String operation = ""; - private String action = ""; - - //tunables - private String reqMethod = "POST"; - private String sdncUrl = null; - private String timeout = "60000"; - private String headerName = "sdnc-request-header"; - private String namespace = ""; - private String asyncInd = "N"; //future use - - private String sdncaNotificationUrl = null; - - public RequestTunables(String reqId, String msoAction, String operation, String action) { - super(); - if (reqId != null) { + + + public static final String GENERATED_KEY = "Generated key: "; + + // criteria + private String reqId = ""; + private String msoAction = ""; + private String operation = ""; + private String action = ""; + + // tunables + private String reqMethod = "POST"; + private String sdncUrl = null; + private String timeout = "60000"; + private String headerName = "sdnc-request-header"; + private String namespace = ""; + private String asyncInd = "N"; // future use + + private String sdncaNotificationUrl = null; + + public RequestTunables(String reqId, String msoAction, String operation, String action) { + super(); + if (reqId != null) { this.reqId = reqId; } - if (msoAction != null) { + if (msoAction != null) { this.msoAction = msoAction; } - if (operation != null) { + if (operation != null) { this.operation = operation; } - if (action != null) { + if (action != null) { this.action = action; } - } - - public RequestTunables(RequestTunables original) { - this.reqId = original.reqId; - this.action = original.action; - this.msoAction = original.msoAction; - this.operation = original.operation; - this.reqMethod = original.reqMethod; - this.sdncUrl = original.sdncUrl; - this.timeout = original.timeout; - this.headerName = original.headerName; - this.namespace = original.namespace; - this.asyncInd = original.asyncInd; - this.sdncaNotificationUrl = original.sdncaNotificationUrl; - } - - public String getReqId() { - return reqId; - } - public void setReqId(String reqId) { - this.reqId = reqId; - } - public String getReqMethod() { - return reqMethod; - } - public void setReqMethod(String reqMethod) { - this.reqMethod = reqMethod; - } - public String getMsoAction() { - return msoAction; - } - public void setMsoAction(String msoAction) { - this.msoAction = msoAction; - } - public String getAction() { - return action; - } - public void setAction(String action) { - this.action = action; - } - public String getOperation() { - return operation; - } - public void setOperation(String operation) { - this.operation = operation; - } - public String getSdncUrl() { - return sdncUrl; - } - public void setSdncUrl(String sdncUrl) { - this.sdncUrl = sdncUrl; - } - public String getTimeout() { - return timeout; - } - public void setTimeout(String timeout) { - this.timeout = timeout; - } - public String getAsyncInd() { - return asyncInd; - } - public void setAsyncInd(String asyncInd) { - this.asyncInd = asyncInd; - } - public String getHeaderName() { - return headerName; - } - public void setHeaderName(String headerName) { - this.headerName = headerName; - } - - - public String getSdncaNotificationUrl() { - return sdncaNotificationUrl; - } - - public void setSdncaNotificationUrl(String sdncaNotificationUrl) { - this.sdncaNotificationUrl = sdncaNotificationUrl; - } - - public String getNamespace() { - return namespace; - } - - public void setNamespace(String namespace) { - this.namespace = namespace; - } - - @Override - public String toString() { - return "RequestTunables [reqId=" + reqId + ", msoAction=" + msoAction - + ", operation=" + operation + ", action=" + action - + ", reqMethod=" + reqMethod + ", sdncUrl=" + sdncUrl - + ", timeout=" + timeout + ", headerName=" + headerName - + ", sdncaNotificationUrl=" + sdncaNotificationUrl - + ", namespace=" + namespace + "]"; - } - + } + + public RequestTunables(RequestTunables original) { + this.reqId = original.reqId; + this.action = original.action; + this.msoAction = original.msoAction; + this.operation = original.operation; + this.reqMethod = original.reqMethod; + this.sdncUrl = original.sdncUrl; + this.timeout = original.timeout; + this.headerName = original.headerName; + this.namespace = original.namespace; + this.asyncInd = original.asyncInd; + this.sdncaNotificationUrl = original.sdncaNotificationUrl; + } + + public String getReqId() { + return reqId; + } + + public void setReqId(String reqId) { + this.reqId = reqId; + } + + public String getReqMethod() { + return reqMethod; + } + + public void setReqMethod(String reqMethod) { + this.reqMethod = reqMethod; + } + + public String getMsoAction() { + return msoAction; + } + + public void setMsoAction(String msoAction) { + this.msoAction = msoAction; + } + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + + public String getOperation() { + return operation; + } + + public void setOperation(String operation) { + this.operation = operation; + } + + public String getSdncUrl() { + return sdncUrl; + } + + public void setSdncUrl(String sdncUrl) { + this.sdncUrl = sdncUrl; + } + + public String getTimeout() { + return timeout; + } + + public void setTimeout(String timeout) { + this.timeout = timeout; + } + + public String getAsyncInd() { + return asyncInd; + } + + public void setAsyncInd(String asyncInd) { + this.asyncInd = asyncInd; + } + + public String getHeaderName() { + return headerName; + } + + public void setHeaderName(String headerName) { + this.headerName = headerName; + } + + + public String getSdncaNotificationUrl() { + return sdncaNotificationUrl; + } + + public void setSdncaNotificationUrl(String sdncaNotificationUrl) { + this.sdncaNotificationUrl = sdncaNotificationUrl; + } + + public String getNamespace() { + return namespace; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + @Override + public String toString() { + return "RequestTunables [reqId=" + reqId + ", msoAction=" + msoAction + ", operation=" + operation + ", action=" + + action + ", reqMethod=" + reqMethod + ", sdncUrl=" + sdncUrl + ", timeout=" + timeout + + ", headerName=" + headerName + ", sdncaNotificationUrl=" + sdncaNotificationUrl + ", namespace=" + + namespace + "]"; + } + } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCAdapterPortTypeImpl.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCAdapterPortTypeImpl.java index 104b4ebcc7..3e3ec6f9bb 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCAdapterPortTypeImpl.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCAdapterPortTypeImpl.java @@ -25,63 +25,60 @@ package org.onap.so.adapters.sdnc.impl; import javax.annotation.PostConstruct; import javax.jws.WebService; import javax.servlet.http.HttpServletResponse; - import org.onap.so.adapters.sdnc.SDNCAdapterPortType; import org.onap.so.adapters.sdnc.SDNCAdapterRequest; import org.onap.so.adapters.sdnc.SDNCAdapterResponse; import org.onap.so.logger.ErrorCode; import org.onap.so.logger.MessageEnum; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -//BPEL SDNCAdapter SOAP Web Service implementation -@WebService(serviceName = "SDNCAdapterService", endpointInterface = "org.onap.so.adapters.sdnc.SDNCAdapterPortType", targetNamespace = "http://org.onap/workflow/sdnc/adapter/wsdl/v1") +// BPEL SDNCAdapter SOAP Web Service implementation +@WebService(serviceName = "SDNCAdapterService", endpointInterface = "org.onap.so.adapters.sdnc.SDNCAdapterPortType", + targetNamespace = "http://org.onap/workflow/sdnc/adapter/wsdl/v1") @Component public class SDNCAdapterPortTypeImpl implements SDNCAdapterPortType { - private static Logger logger = LoggerFactory.getLogger(SDNCAdapterPortTypeImpl.class); + private static Logger logger = LoggerFactory.getLogger(SDNCAdapterPortTypeImpl.class); + + + @Autowired + private SDNCRestClient sdncClient; - - @Autowired - private SDNCRestClient sdncClient; - - @PostConstruct - public void init () { - logger.info("{} {} {}", MessageEnum.RA_INIT_SDNC_ADAPTER.toString(), "SDNC", "SDNCAdapterPortType"); - } + @PostConstruct + public void init() { + logger.info("{} {} {}", MessageEnum.RA_INIT_SDNC_ADAPTER.toString(), "SDNC", "SDNCAdapterPortType"); + } - /** - * Health Check web method. Does nothing but return to show the adapter is deployed. - */ - @Override - public void healthCheck () - { - logger.debug("Health check call in SDNC Adapter"); - } + /** + * Health Check web method. Does nothing but return to show the adapter is deployed. + */ + @Override + public void healthCheck() { + logger.debug("Health check call in SDNC Adapter"); + } - @Override - public SDNCAdapterResponse sdncAdapter(SDNCAdapterRequest bpelRequest) { - String bpelReqId = bpelRequest.getRequestHeader().getRequestId(); - String callbackUrl = bpelRequest.getRequestHeader().getCallbackUrl(); - try { - sdncClient.executeRequest(bpelRequest); - } - catch (Exception e){ - String respMsg = "Error sending request to SDNC. Failed to start SDNC Client thread " + e.getMessage(); - logger.error("{} {} {} {}", MessageEnum.RA_SEND_REQUEST_SDNC_ERR.toString(), "SDNC", - ErrorCode.DataError.getValue(), respMsg, e); + @Override + public SDNCAdapterResponse sdncAdapter(SDNCAdapterRequest bpelRequest) { + String bpelReqId = bpelRequest.getRequestHeader().getRequestId(); + String callbackUrl = bpelRequest.getRequestHeader().getCallbackUrl(); + try { + sdncClient.executeRequest(bpelRequest); + } catch (Exception e) { + String respMsg = "Error sending request to SDNC. Failed to start SDNC Client thread " + e.getMessage(); + logger.error("{} {} {} {}", MessageEnum.RA_SEND_REQUEST_SDNC_ERR.toString(), "SDNC", + ErrorCode.DataError.getValue(), respMsg, e); - SDNCResponse sdncResp = new SDNCResponse(bpelReqId); - sdncResp.setRespCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - sdncResp.setRespMsg(respMsg); - sdncClient.sendRespToBpel(callbackUrl, sdncResp); - } - return (new SDNCAdapterResponse()); - } + SDNCResponse sdncResp = new SDNCResponse(bpelReqId); + sdncResp.setRespCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + sdncResp.setRespMsg(respMsg); + sdncClient.sendRespToBpel(callbackUrl, sdncResp); + } + return (new SDNCAdapterResponse()); + } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCResponse.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCResponse.java index c0a737cf78..df753ccfe9 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCResponse.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCResponse.java @@ -25,49 +25,57 @@ import java.io.Serializable; public class SDNCResponse implements Serializable { - private static final long serialVersionUID = 1L; - private String reqId = null; - private int respCode = 0; - private String respMsg = null; - private String sdncRespXml = null; - - public SDNCResponse(String reqId) { - this.reqId = reqId; - } - public SDNCResponse(String reqId, int respCode, String respMsg) { - this.reqId = reqId; - this.respCode = respCode; - this.respMsg = respMsg; - } - - public String getReqId() { - return reqId; - } - public void setReqId(String reqId) { - this.reqId = reqId; - } - public int getRespCode() { - return respCode; - } - public void setRespCode(int respCode) { - this.respCode = respCode; - } - public String getRespMsg() { - return respMsg; - } - public void setRespMsg(String respMsg) { - this.respMsg = respMsg; - } - public String getSdncRespXml() { - return sdncRespXml; - } - public void setSdncRespXml(String sdncRespXml) { - this.sdncRespXml = sdncRespXml; - } - - @Override - public String toString() { - return "SDNCResponse [reqId=" + reqId + ", respCode=" + respCode - + ", respMsg=" + respMsg + ", sdncRespXml=" + sdncRespXml + "]"; - } + private static final long serialVersionUID = 1L; + private String reqId = null; + private int respCode = 0; + private String respMsg = null; + private String sdncRespXml = null; + + public SDNCResponse(String reqId) { + this.reqId = reqId; + } + + public SDNCResponse(String reqId, int respCode, String respMsg) { + this.reqId = reqId; + this.respCode = respCode; + this.respMsg = respMsg; + } + + public String getReqId() { + return reqId; + } + + public void setReqId(String reqId) { + this.reqId = reqId; + } + + public int getRespCode() { + return respCode; + } + + public void setRespCode(int respCode) { + this.respCode = respCode; + } + + public String getRespMsg() { + return respMsg; + } + + public void setRespMsg(String respMsg) { + this.respMsg = respMsg; + } + + public String getSdncRespXml() { + return sdncRespXml; + } + + public void setSdncRespXml(String sdncRespXml) { + this.sdncRespXml = sdncRespXml; + } + + @Override + public String toString() { + return "SDNCResponse [reqId=" + reqId + ", respCode=" + respCode + ", respMsg=" + respMsg + ", sdncRespXml=" + + sdncRespXml + "]"; + } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCRestClient.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCRestClient.java index 80f111b570..21ce06eaf1 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCRestClient.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCRestClient.java @@ -36,7 +36,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; - import javax.xml.XMLConstants; import javax.xml.bind.DatatypeConverter; import javax.xml.parsers.DocumentBuilder; @@ -46,7 +45,6 @@ import javax.xml.ws.handler.MessageContext; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathFactory; - import org.onap.so.logger.ErrorCode; import org.onap.so.utils.CryptoUtils; import org.onap.so.adapters.sdnc.SDNCAdapterRequest; @@ -55,7 +53,6 @@ import org.onap.so.adapters.sdnc.client.SDNCAdapterCallbackRequest; import org.onap.so.adapters.sdnc.client.SDNCCallbackAdapterPortType; import org.onap.so.adapters.sdnc.client.SDNCCallbackAdapterService; import org.onap.so.logger.MessageEnum; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -69,289 +66,273 @@ import org.w3c.dom.NodeList; @Component -public class SDNCRestClient{ - - @Autowired - private Environment env; - - @Autowired - private MapRequestTunables tunablesMapper; - - private static Logger logger = LoggerFactory.getLogger(SDNCRestClient.class); - - private static final String EXCEPTION_MSG="Exception while evaluate xpath"; - private static final String MSO_INTERNAL_ERROR="MsoInternalError"; - private static final String CAMUNDA="Camunda"; - @Async - public void executeRequest(SDNCAdapterRequest bpelRequest) - { - - logger.debug("BPEL Request:" + bpelRequest.toString()); - - // Added delay to allow completion of create request to SDNC - // before executing activate of create request. - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION.toString(), "SDNC", - ErrorCode.UnknownError.getValue(), "Exception processing request to SDNC", e); - - Thread.currentThread().interrupt(); - } - - String action = bpelRequest.getRequestHeader().getSvcAction(); - String operation = bpelRequest.getRequestHeader().getSvcOperation(); - String bpelReqId = bpelRequest.getRequestHeader().getRequestId(); - String callbackUrl = bpelRequest.getRequestHeader().getCallbackUrl(); - - String sdncReqBody = null; - - RequestTunables rt = new RequestTunables(bpelReqId, - bpelRequest.getRequestHeader().getMsoAction(), - bpelRequest.getRequestHeader().getSvcOperation(), - bpelRequest.getRequestHeader().getSvcAction()); - rt = tunablesMapper.setTunables(rt); - rt.setSdncaNotificationUrl(env.getProperty(Constants.MY_URL_PROP)); - - - if ("POST".equals(rt.getReqMethod())) - { - Node node = (Node) bpelRequest.getRequestData(); - Document reqDoc = node.getOwnerDocument(); - sdncReqBody = Utils.genSdncReq(reqDoc, rt); - } - else if("PUT".equals(rt.getReqMethod())){ - Node node = (Node) bpelRequest.getRequestData(); - Document reqDoc = node.getOwnerDocument(); - sdncReqBody = Utils.genSdncPutReq(reqDoc, rt); - } - long sdncStartTime = System.currentTimeMillis(); - SDNCResponse sdncResp = getSdncResp(sdncReqBody, rt); - logger.debug ("Got the SDNC Response: {}", sdncResp.getSdncRespXml()); - long bpelStartTime = System.currentTimeMillis(); - sendRespToBpel(callbackUrl, sdncResp); - return; - } - - public SDNCResponse getSdncResp(String sdncReqBody, RequestTunables rt) - { - - URL url; - HttpURLConnection con = null; - DataOutputStream out = null; - BufferedReader in = null; - SDNCResponse sdncResp = new SDNCResponse(rt.getReqId()); - StringBuilder response = new StringBuilder(); - - logger.info("{} :\n {} {}", MessageEnum.RA_SEND_REQUEST_SDNC.name(), rt.toString(), "SDNC"); - logger.trace("SDNC Request Body:{} \n", sdncReqBody); - - try { - - url = new URL(rt.getSdncUrl()); - - con = (HttpURLConnection) url.openConnection(); - con.setConnectTimeout(Integer.parseInt(env.getProperty(Constants.SDNC_CONNECTTIME_PROP))); - con.setReadTimeout(Integer.parseInt(rt.getTimeout())); - con.setRequestProperty("Accept", "application/yang.data+xml"); //for response in xml - String userCredentials = CryptoUtils.decrypt(env.getProperty(Constants.SDNC_AUTH_PROP), env.getProperty(Constants.ENCRYPTION_KEY_PROP)); - - String basicAuth = "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes()); - con.setRequestProperty ("Authorization", basicAuth); - con.setRequestMethod(rt.getReqMethod()); - - // Add request headers - if ("POST".equals(rt.getReqMethod()) || "PUT".equals(rt.getReqMethod())) - { - con.setRequestProperty("Content-type", "application/xml"); - con.setRequestProperty("Content-length",String.valueOf(sdncReqBody.length())); - con.setDoOutput(true); - out = new DataOutputStream(con.getOutputStream()); - out.writeBytes(sdncReqBody); - out.flush(); - out.close(); - } - - //Get response - sdncResp.setRespCode(con.getResponseCode()); - sdncResp.setRespMsg(con.getResponseMessage()); - - if (con.getResponseCode()>= 200 && con.getResponseCode()<=299) { - in = new BufferedReader(new InputStreamReader(con.getInputStream())); - String inputLine; - //Not parsing the response -it contains a responseHdr section and data section - while ((inputLine = in.readLine()) != null) { - response.append(inputLine); - } - in.close(); - } - - sdncResp.setSdncRespXml(response.toString()); - logger.info("{} :\n {} {}", MessageEnum.RA_RESPONSE_FROM_SDNC.name(), sdncResp.toString(), "SDNC"); - return(sdncResp); - } - catch (Exception e) - { - logger.error("{} {} {} {}", MessageEnum.RA_EXCEPTION_COMMUNICATE_SDNC.toString(), "SDNC", - ErrorCode.BusinessProcesssError.getValue(), "Exception processing request to SDNC", e); - //default - sdncResp.setRespCode(HttpURLConnection.HTTP_INTERNAL_ERROR); - String respMsg = "Error processing request to SDNC. "; - StringBuilder sdncErrMsg = new StringBuilder(); - - if (e instanceof java.net.SocketTimeoutException ) - { - sdncResp.setRespCode(HttpURLConnection.HTTP_CLIENT_TIMEOUT); - respMsg = "Request to SDNC timed out. "; - } - if (con != null) - { - try { //e1 - if (con.getResponseCode() != HttpURLConnection.HTTP_OK) //seen in SocketException connection reset - sdncResp.setRespCode(con.getResponseCode()); - respMsg = respMsg + con.getResponseMessage() + ". "; - InputStream is = con.getErrorStream(); - if (is != null) - { - XPathFactory xpathFactory = XPathFactory.newInstance(); - XPath xpath = xpathFactory.newXPath(); - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setFeature (XMLConstants.FEATURE_SECURE_PROCESSING, true); - dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); - dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); - DocumentBuilder db; - Document doc = null; - try { //e2 - db = dbf.newDocumentBuilder(); - doc = db.parse(is); - NodeList errors = (NodeList)xpath.evaluate("errors/error", doc, XPathConstants.NODESET); - for (int i = 0; i < errors.getLength(); i++) - { - Element error = (Element) errors.item(i); - String eType = null; - try { - eType = xpath.evaluate("error-type", error); - sdncErrMsg = new StringBuilder(". SDNC Returned-[error-type:" + eType); - } catch (Exception e3) { - logger.error("{} {} {} {} {} {}", MessageEnum.RA_EVALUATE_XPATH_ERROR.toString(), "error-type", - error.toString(), "SDNC", ErrorCode.DataError.getValue(), EXCEPTION_MSG, e3); - } - - String eTag = null; - try { - eTag = xpath.evaluate( "error-tag", error); - sdncErrMsg.append(", error-tag:").append(eTag); - } catch (Exception e3) { - logger.error("{} {} {} {} {} {}", MessageEnum.RA_EVALUATE_XPATH_ERROR.toString(), "error-tag", - error.toString(), "SDNC", ErrorCode.DataError.getValue(), EXCEPTION_MSG, e3); - } - - String eMsg = null; - try { - eMsg = xpath.evaluate("error-message", error); - sdncErrMsg.append(", error-message:").append(eMsg).append("]"); - } catch (Exception e3) { - logger.error("{} {} {} {} {} {}", MessageEnum.RA_EVALUATE_XPATH_ERROR.toString(), "error-message", error.toString(), - "SDNC", ErrorCode.DataError.getValue(), EXCEPTION_MSG, e3); - } - } - } catch (Exception e2) { - logger.error("{} {} {} {}", MessageEnum.RA_ANALYZE_ERROR_EXC.toString(), "SDNC", - ErrorCode.DataError.getValue(), "Exception while analyse error", e2); - } - } //is != null - } catch (Exception e1) { - logger.error("{} {} {} {}", MessageEnum.RA_ERROR_GET_RESPONSE_SDNC.toString(), "SDNC", - ErrorCode.BusinessProcesssError.getValue(), "Exception while get SDNC response", e1); - } - } //con != null - - if (e.getMessage() != null) { +public class SDNCRestClient { + + @Autowired + private Environment env; + + @Autowired + private MapRequestTunables tunablesMapper; + + private static Logger logger = LoggerFactory.getLogger(SDNCRestClient.class); + + private static final String EXCEPTION_MSG = "Exception while evaluate xpath"; + private static final String MSO_INTERNAL_ERROR = "MsoInternalError"; + private static final String CAMUNDA = "Camunda"; + + @Async + public void executeRequest(SDNCAdapterRequest bpelRequest) { + + logger.debug("BPEL Request:" + bpelRequest.toString()); + + // Added delay to allow completion of create request to SDNC + // before executing activate of create request. + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION.toString(), "SDNC", + ErrorCode.UnknownError.getValue(), "Exception processing request to SDNC", e); + + Thread.currentThread().interrupt(); + } + + String action = bpelRequest.getRequestHeader().getSvcAction(); + String operation = bpelRequest.getRequestHeader().getSvcOperation(); + String bpelReqId = bpelRequest.getRequestHeader().getRequestId(); + String callbackUrl = bpelRequest.getRequestHeader().getCallbackUrl(); + + String sdncReqBody = null; + + RequestTunables rt = new RequestTunables(bpelReqId, bpelRequest.getRequestHeader().getMsoAction(), + bpelRequest.getRequestHeader().getSvcOperation(), bpelRequest.getRequestHeader().getSvcAction()); + rt = tunablesMapper.setTunables(rt); + rt.setSdncaNotificationUrl(env.getProperty(Constants.MY_URL_PROP)); + + + if ("POST".equals(rt.getReqMethod())) { + Node node = (Node) bpelRequest.getRequestData(); + Document reqDoc = node.getOwnerDocument(); + sdncReqBody = Utils.genSdncReq(reqDoc, rt); + } else if ("PUT".equals(rt.getReqMethod())) { + Node node = (Node) bpelRequest.getRequestData(); + Document reqDoc = node.getOwnerDocument(); + sdncReqBody = Utils.genSdncPutReq(reqDoc, rt); + } + long sdncStartTime = System.currentTimeMillis(); + SDNCResponse sdncResp = getSdncResp(sdncReqBody, rt); + logger.debug("Got the SDNC Response: {}", sdncResp.getSdncRespXml()); + long bpelStartTime = System.currentTimeMillis(); + sendRespToBpel(callbackUrl, sdncResp); + return; + } + + public SDNCResponse getSdncResp(String sdncReqBody, RequestTunables rt) { + + URL url; + HttpURLConnection con = null; + DataOutputStream out = null; + BufferedReader in = null; + SDNCResponse sdncResp = new SDNCResponse(rt.getReqId()); + StringBuilder response = new StringBuilder(); + + logger.info("{} :\n {} {}", MessageEnum.RA_SEND_REQUEST_SDNC.name(), rt.toString(), "SDNC"); + logger.trace("SDNC Request Body:{} \n", sdncReqBody); + + try { + + url = new URL(rt.getSdncUrl()); + + con = (HttpURLConnection) url.openConnection(); + con.setConnectTimeout(Integer.parseInt(env.getProperty(Constants.SDNC_CONNECTTIME_PROP))); + con.setReadTimeout(Integer.parseInt(rt.getTimeout())); + con.setRequestProperty("Accept", "application/yang.data+xml"); // for response in xml + String userCredentials = CryptoUtils.decrypt(env.getProperty(Constants.SDNC_AUTH_PROP), + env.getProperty(Constants.ENCRYPTION_KEY_PROP)); + + String basicAuth = "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes()); + con.setRequestProperty("Authorization", basicAuth); + con.setRequestMethod(rt.getReqMethod()); + + // Add request headers + if ("POST".equals(rt.getReqMethod()) || "PUT".equals(rt.getReqMethod())) { + con.setRequestProperty("Content-type", "application/xml"); + con.setRequestProperty("Content-length", String.valueOf(sdncReqBody.length())); + con.setDoOutput(true); + out = new DataOutputStream(con.getOutputStream()); + out.writeBytes(sdncReqBody); + out.flush(); + out.close(); + } + + // Get response + sdncResp.setRespCode(con.getResponseCode()); + sdncResp.setRespMsg(con.getResponseMessage()); + + if (con.getResponseCode() >= 200 && con.getResponseCode() <= 299) { + in = new BufferedReader(new InputStreamReader(con.getInputStream())); + String inputLine; + // Not parsing the response -it contains a responseHdr section and data section + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + } + + sdncResp.setSdncRespXml(response.toString()); + logger.info("{} :\n {} {}", MessageEnum.RA_RESPONSE_FROM_SDNC.name(), sdncResp.toString(), "SDNC"); + return (sdncResp); + } catch (Exception e) { + logger.error("{} {} {} {}", MessageEnum.RA_EXCEPTION_COMMUNICATE_SDNC.toString(), "SDNC", + ErrorCode.BusinessProcesssError.getValue(), "Exception processing request to SDNC", e); + // default + sdncResp.setRespCode(HttpURLConnection.HTTP_INTERNAL_ERROR); + String respMsg = "Error processing request to SDNC. "; + StringBuilder sdncErrMsg = new StringBuilder(); + + if (e instanceof java.net.SocketTimeoutException) { + sdncResp.setRespCode(HttpURLConnection.HTTP_CLIENT_TIMEOUT); + respMsg = "Request to SDNC timed out. "; + } + if (con != null) { + try { // e1 + if (con.getResponseCode() != HttpURLConnection.HTTP_OK) // seen in SocketException connection reset + sdncResp.setRespCode(con.getResponseCode()); + respMsg = respMsg + con.getResponseMessage() + ". "; + InputStream is = con.getErrorStream(); + if (is != null) { + XPathFactory xpathFactory = XPathFactory.newInstance(); + XPath xpath = xpathFactory.newXPath(); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); + dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); + DocumentBuilder db; + Document doc = null; + try { // e2 + db = dbf.newDocumentBuilder(); + doc = db.parse(is); + NodeList errors = (NodeList) xpath.evaluate("errors/error", doc, XPathConstants.NODESET); + for (int i = 0; i < errors.getLength(); i++) { + Element error = (Element) errors.item(i); + String eType = null; + try { + eType = xpath.evaluate("error-type", error); + sdncErrMsg = new StringBuilder(". SDNC Returned-[error-type:" + eType); + } catch (Exception e3) { + logger.error("{} {} {} {} {} {}", MessageEnum.RA_EVALUATE_XPATH_ERROR.toString(), + "error-type", error.toString(), "SDNC", ErrorCode.DataError.getValue(), + EXCEPTION_MSG, e3); + } + + String eTag = null; + try { + eTag = xpath.evaluate("error-tag", error); + sdncErrMsg.append(", error-tag:").append(eTag); + } catch (Exception e3) { + logger.error("{} {} {} {} {} {}", MessageEnum.RA_EVALUATE_XPATH_ERROR.toString(), + "error-tag", error.toString(), "SDNC", ErrorCode.DataError.getValue(), + EXCEPTION_MSG, e3); + } + + String eMsg = null; + try { + eMsg = xpath.evaluate("error-message", error); + sdncErrMsg.append(", error-message:").append(eMsg).append("]"); + } catch (Exception e3) { + logger.error("{} {} {} {} {} {}", MessageEnum.RA_EVALUATE_XPATH_ERROR.toString(), + "error-message", error.toString(), "SDNC", ErrorCode.DataError.getValue(), + EXCEPTION_MSG, e3); + } + } + } catch (Exception e2) { + logger.error("{} {} {} {}", MessageEnum.RA_ANALYZE_ERROR_EXC.toString(), "SDNC", + ErrorCode.DataError.getValue(), "Exception while analyse error", e2); + } + } // is != null + } catch (Exception e1) { + logger.error("{} {} {} {}", MessageEnum.RA_ERROR_GET_RESPONSE_SDNC.toString(), "SDNC", + ErrorCode.BusinessProcesssError.getValue(), "Exception while get SDNC response", e1); + } + } // con != null + + if (e.getMessage() != null) { respMsg = respMsg + e.getMessage(); } respMsg = respMsg + sdncErrMsg; - sdncResp.setRespMsg(respMsg); + sdncResp.setRespMsg(respMsg); - logger.error("{} {} {} {}", MessageEnum.RA_EXCEPTION_COMMUNICATE_SDNC.toString(), "SDNC", - ErrorCode.AvailabilityError.getValue(), "Exception while communicate with SDNC", e); + logger.error("{} {} {} {}", MessageEnum.RA_EXCEPTION_COMMUNICATE_SDNC.toString(), "SDNC", + ErrorCode.AvailabilityError.getValue(), "Exception while communicate with SDNC", e); - return sdncResp; - } - finally - { - if (con != null) { + return sdncResp; + } finally { + if (con != null) { con.disconnect(); } - } - } - - public void sendRespToBpel(String bpelUrl, SDNCResponse sdncResp) - { - String error; - try - { - SDNCAdapterCallbackRequest cbReq = new SDNCAdapterCallbackRequest(); - cbReq.setCallbackHeader(new CallbackHeader(sdncResp.getReqId(), Integer.toString(sdncResp.getRespCode()), sdncResp.getRespMsg())); - if (sdncResp.getSdncRespXml() != null) - { - cbReq.setRequestData(sdncResp.getSdncRespXml()); - } - logger.info("{} :\n {} {}", MessageEnum.RA_CALLBACK_BPEL.name(), cbReq.toString(), CAMUNDA); - - URL wsdlUrl = null; - try { - wsdlUrl = new URL (bpelUrl); - } catch (MalformedURLException e1) { - error = "Caught exception initializing Callback wsdl " + e1.getMessage(); - logger.error("{} {} {} {}", MessageEnum.RA_INIT_CALLBACK_WSDL_ERR.toString(), CAMUNDA, - ErrorCode.DataError.getValue(), "Exception initializing Callback wsdl", e1); - - } - - SDNCCallbackAdapterService cbSvc = new SDNCCallbackAdapterService(); - - SDNCCallbackAdapterPortType cbPort = cbSvc.getSDNCCallbackAdapterSoapHttpPort(); - - BindingProvider bp = (BindingProvider)cbPort; - - if(null != wsdlUrl) { - bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, wsdlUrl.toExternalForm()); - } - else { - logger.debug("wsdlUrl is NULL:"); - } - - //authentication - try - { - Map<String, Object> reqCtx = bp.getRequestContext(); - Map<String, List<String>> headers = new HashMap<>(); - String userCredentials = CryptoUtils.decrypt(env.getProperty(Constants.BPEL_AUTH_PROP), env.getProperty(Constants.ENCRYPTION_KEY_PROP)); - - String basicAuth = "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes()); - reqCtx.put(MessageContext.HTTP_REQUEST_HEADERS, headers); - headers.put ("Authorization", Collections.singletonList(basicAuth)); - } - catch (Exception e2) { - error = "Unable to set authorization in callback request " + e2.getMessage(); - logger.error("{} {} {} {}", MessageEnum.RA_SET_CALLBACK_AUTH_EXC.toString(), CAMUNDA, - ErrorCode.BusinessProcesssError.getValue(), - "Exception - Unable to set authorization in callback request", e2); - - } - - logger.debug("Invoking Bpel Callback. BpelCallbackUrl:{}", bpelUrl); - cbPort.sdncAdapterCallback(cbReq); - - } - catch (Exception e) - { - error = "Error sending BpelCallback request" + e.getMessage(); - logger.error("Error {} - {} - {}", ErrorCode.BusinessProcesssError.getValue(), - MessageEnum.RA_CALLBACK_BPEL_EXC.toString(), error, e); - } - logger.info(MessageEnum.RA_CALLBACK_BPEL_COMPLETE.name(), CAMUNDA); - return; - } + } + } + + public void sendRespToBpel(String bpelUrl, SDNCResponse sdncResp) { + String error; + try { + SDNCAdapterCallbackRequest cbReq = new SDNCAdapterCallbackRequest(); + cbReq.setCallbackHeader(new CallbackHeader(sdncResp.getReqId(), Integer.toString(sdncResp.getRespCode()), + sdncResp.getRespMsg())); + if (sdncResp.getSdncRespXml() != null) { + cbReq.setRequestData(sdncResp.getSdncRespXml()); + } + logger.info("{} :\n {} {}", MessageEnum.RA_CALLBACK_BPEL.name(), cbReq.toString(), CAMUNDA); + + URL wsdlUrl = null; + try { + wsdlUrl = new URL(bpelUrl); + } catch (MalformedURLException e1) { + error = "Caught exception initializing Callback wsdl " + e1.getMessage(); + logger.error("{} {} {} {}", MessageEnum.RA_INIT_CALLBACK_WSDL_ERR.toString(), CAMUNDA, + ErrorCode.DataError.getValue(), "Exception initializing Callback wsdl", e1); + + } + + SDNCCallbackAdapterService cbSvc = new SDNCCallbackAdapterService(); + + SDNCCallbackAdapterPortType cbPort = cbSvc.getSDNCCallbackAdapterSoapHttpPort(); + + BindingProvider bp = (BindingProvider) cbPort; + + if (null != wsdlUrl) { + bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, wsdlUrl.toExternalForm()); + } else { + logger.debug("wsdlUrl is NULL:"); + } + + // authentication + try { + Map<String, Object> reqCtx = bp.getRequestContext(); + Map<String, List<String>> headers = new HashMap<>(); + String userCredentials = CryptoUtils.decrypt(env.getProperty(Constants.BPEL_AUTH_PROP), + env.getProperty(Constants.ENCRYPTION_KEY_PROP)); + + String basicAuth = "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes()); + reqCtx.put(MessageContext.HTTP_REQUEST_HEADERS, headers); + headers.put("Authorization", Collections.singletonList(basicAuth)); + } catch (Exception e2) { + error = "Unable to set authorization in callback request " + e2.getMessage(); + logger.error("{} {} {} {}", MessageEnum.RA_SET_CALLBACK_AUTH_EXC.toString(), CAMUNDA, + ErrorCode.BusinessProcesssError.getValue(), + "Exception - Unable to set authorization in callback request", e2); + + } + + logger.debug("Invoking Bpel Callback. BpelCallbackUrl:{}", bpelUrl); + cbPort.sdncAdapterCallback(cbReq); + + } catch (Exception e) { + error = "Error sending BpelCallback request" + e.getMessage(); + logger.error("Error {} - {} - {}", ErrorCode.BusinessProcesssError.getValue(), + MessageEnum.RA_CALLBACK_BPEL_EXC.toString(), error, e); + } + logger.info(MessageEnum.RA_CALLBACK_BPEL_COMPLETE.name(), CAMUNDA); + return; + } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/Utils.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/Utils.java index daa83d27f8..52164bdac7 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/Utils.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/Utils.java @@ -24,7 +24,6 @@ package org.onap.so.adapters.sdnc.impl; import java.io.StringWriter; - import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -32,7 +31,6 @@ import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; - import org.onap.so.logger.ErrorCode; import org.onap.so.logger.MessageEnum; import org.slf4j.Logger; @@ -41,167 +39,162 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; + public class Utils { - private static Logger logger = LoggerFactory.getLogger(Utils.class); - - private Utils() { - } - - public static String genSdncReq(Document reqDoc, RequestTunables rt) { - try { - - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - - //NewDoc for output - //Root - Document newdoc = db.newDocument(); - Element root = newdoc.createElementNS(rt.getNamespace(), "input"); - newdoc.appendChild(root); - - //Header - Element hdr = newdoc.createElement(rt.getHeaderName()); - root.appendChild(hdr); - - String elemData = rt.getReqId(); - Element hdrChild; - if (elemData != null && elemData.length() > 0) - { - hdrChild = newdoc.createElement("svc-request-id"); - hdrChild.appendChild(newdoc.createTextNode(elemData)); - hdr.appendChild(hdrChild); - } - - elemData = rt.getAction(); - if (elemData != null && elemData.length() > 0) - { - hdrChild = newdoc.createElement("svc-action"); - hdrChild.appendChild(newdoc.createTextNode(elemData)); - hdr.appendChild(hdrChild); - } - - elemData = rt.getSdncaNotificationUrl(); - if (elemData != null && elemData.length() > 0) - { - hdrChild = newdoc.createElement("svc-notification-url"); - hdrChild.appendChild(newdoc.createTextNode(elemData)); - hdr.appendChild(hdrChild); - } - - //RequestData - NodeList nodes = reqDoc.getDocumentElement().getChildNodes(); - for (int i = 0; i < nodes.getLength(); i++) { - Node n = nodes.item(i); - Node newNode = newdoc.importNode(n, true); - root.appendChild(newNode); - } - - String s = domToStr(newdoc); - logger.debug("Formatted SdncReq:\n", s); - return s; - - } catch (Exception e) { - logger.error("{} {} {} {}", MessageEnum.RA_ERROR_CREATE_SDNC_REQUEST.toString(), "SDNC", - ErrorCode.BusinessProcesssError.getValue(), "Exception in genSdncReq", e); - } - return null; - } - - public static String genSdncPutReq(Document reqDoc, RequestTunables rt) { - try { - - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - - //NewDoc for output - //Root - Document newdoc = db.newDocument(); - - //RequestData - NodeList nodes = reqDoc.getDocumentElement().getChildNodes(); - - Element root = newdoc.createElementNS(nodes.item(0).getNamespaceURI(), nodes.item(0).getNodeName()); - newdoc.appendChild(root); - - NodeList childNodes = nodes.item(0).getChildNodes(); - for (int i = 0; i < childNodes.getLength(); i++) { - Node n = childNodes.item(i); - Node newNode = newdoc.importNode(n, true); - root.appendChild(newNode); - } - - String s = domToStr(newdoc); - logger.debug("Formatted SdncPutReq:\n {}", s); - return s; - - } catch (Exception e) { - logger.error("{} {} {} {}", MessageEnum.RA_ERROR_CREATE_SDNC_REQUEST.toString(), "SDNC", - ErrorCode.DataError.getValue(), "Exception in genSdncPutReq", e); - } - return null; - } - - public static String genMsoFailResp(SDNCResponse resp) { - try { - - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - - //NewDoc for output - //Root - Document newdoc = db.newDocument(); - Element root = newdoc.createElement("output"); - newdoc.appendChild(root); - - Element elem1 = newdoc.createElement("svc-request-id"); - elem1.appendChild(newdoc.createTextNode(resp.getReqId())); - root.appendChild(elem1); - - Element elem2 = newdoc.createElement("response-code"); - elem2.appendChild(newdoc.createTextNode(String.valueOf(resp.getRespCode()))); - root.appendChild(elem2); - - Element elem3 = newdoc.createElement("response-message"); - elem3.appendChild(newdoc.createTextNode(String.valueOf(resp.getRespMsg()))); - root.appendChild(elem3); - - String s = domToStr(newdoc); - logger.debug("Formatted SdncReq: {}", s); - return s; - - } catch (Exception e) { - logger.error("{} {} {} {}", MessageEnum.RA_ERROR_CREATE_SDNC_RESPONSE.toString(), "SDNC", - ErrorCode.DataError.getValue(), "Exception in genMsoFailResp", e); - } - return null; - } - - - public static String domToStr(Document doc) - { - if (doc != null) - { - try { - DOMSource ds = new DOMSource(doc); - StringWriter sw = new StringWriter(); - StreamResult sr = new StreamResult(sw); - TransformerFactory tf = TransformerFactory.newInstance(); - tf.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); - tf.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, ""); - Transformer t = tf.newTransformer(); - //t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");//<?xml version="1.0" encoding="UTF-8"?> - t.transform(ds, sr); - String s = sw.toString(); - - // This is an awful fix for now but we don't want that xmlns="" to be generated - s = s.replaceAll("xmlns=\"\"", ""); - return s; - } catch (Exception e) { - logger.error("{} {} {}", MessageEnum.RA_ERROR_CONVERT_XML2STR.toString(), ErrorCode.DataError - .getValue(), "Exception - domToStr", e); - } - } - return null; - } + private static Logger logger = LoggerFactory.getLogger(Utils.class); + + private Utils() {} + + public static String genSdncReq(Document reqDoc, RequestTunables rt) { + try { + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + + // NewDoc for output + // Root + Document newdoc = db.newDocument(); + Element root = newdoc.createElementNS(rt.getNamespace(), "input"); + newdoc.appendChild(root); + + // Header + Element hdr = newdoc.createElement(rt.getHeaderName()); + root.appendChild(hdr); + + String elemData = rt.getReqId(); + Element hdrChild; + if (elemData != null && elemData.length() > 0) { + hdrChild = newdoc.createElement("svc-request-id"); + hdrChild.appendChild(newdoc.createTextNode(elemData)); + hdr.appendChild(hdrChild); + } + + elemData = rt.getAction(); + if (elemData != null && elemData.length() > 0) { + hdrChild = newdoc.createElement("svc-action"); + hdrChild.appendChild(newdoc.createTextNode(elemData)); + hdr.appendChild(hdrChild); + } + + elemData = rt.getSdncaNotificationUrl(); + if (elemData != null && elemData.length() > 0) { + hdrChild = newdoc.createElement("svc-notification-url"); + hdrChild.appendChild(newdoc.createTextNode(elemData)); + hdr.appendChild(hdrChild); + } + + // RequestData + NodeList nodes = reqDoc.getDocumentElement().getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + Node n = nodes.item(i); + Node newNode = newdoc.importNode(n, true); + root.appendChild(newNode); + } + + String s = domToStr(newdoc); + logger.debug("Formatted SdncReq:\n", s); + return s; + + } catch (Exception e) { + logger.error("{} {} {} {}", MessageEnum.RA_ERROR_CREATE_SDNC_REQUEST.toString(), "SDNC", + ErrorCode.BusinessProcesssError.getValue(), "Exception in genSdncReq", e); + } + return null; + } + + public static String genSdncPutReq(Document reqDoc, RequestTunables rt) { + try { + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + + // NewDoc for output + // Root + Document newdoc = db.newDocument(); + + // RequestData + NodeList nodes = reqDoc.getDocumentElement().getChildNodes(); + + Element root = newdoc.createElementNS(nodes.item(0).getNamespaceURI(), nodes.item(0).getNodeName()); + newdoc.appendChild(root); + + NodeList childNodes = nodes.item(0).getChildNodes(); + for (int i = 0; i < childNodes.getLength(); i++) { + Node n = childNodes.item(i); + Node newNode = newdoc.importNode(n, true); + root.appendChild(newNode); + } + + String s = domToStr(newdoc); + logger.debug("Formatted SdncPutReq:\n {}", s); + return s; + + } catch (Exception e) { + logger.error("{} {} {} {}", MessageEnum.RA_ERROR_CREATE_SDNC_REQUEST.toString(), "SDNC", + ErrorCode.DataError.getValue(), "Exception in genSdncPutReq", e); + } + return null; + } + + public static String genMsoFailResp(SDNCResponse resp) { + try { + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + + // NewDoc for output + // Root + Document newdoc = db.newDocument(); + Element root = newdoc.createElement("output"); + newdoc.appendChild(root); + + Element elem1 = newdoc.createElement("svc-request-id"); + elem1.appendChild(newdoc.createTextNode(resp.getReqId())); + root.appendChild(elem1); + + Element elem2 = newdoc.createElement("response-code"); + elem2.appendChild(newdoc.createTextNode(String.valueOf(resp.getRespCode()))); + root.appendChild(elem2); + + Element elem3 = newdoc.createElement("response-message"); + elem3.appendChild(newdoc.createTextNode(String.valueOf(resp.getRespMsg()))); + root.appendChild(elem3); + + String s = domToStr(newdoc); + logger.debug("Formatted SdncReq: {}", s); + return s; + + } catch (Exception e) { + logger.error("{} {} {} {}", MessageEnum.RA_ERROR_CREATE_SDNC_RESPONSE.toString(), "SDNC", + ErrorCode.DataError.getValue(), "Exception in genMsoFailResp", e); + } + return null; + } + + + public static String domToStr(Document doc) { + if (doc != null) { + try { + DOMSource ds = new DOMSource(doc); + StringWriter sw = new StringWriter(); + StreamResult sr = new StreamResult(sw); + TransformerFactory tf = TransformerFactory.newInstance(); + tf.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); + tf.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, ""); + Transformer t = tf.newTransformer(); + // t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");//<?xml version="1.0" encoding="UTF-8"?> + t.transform(ds, sr); + String s = sw.toString(); + + // This is an awful fix for now but we don't want that xmlns="" to be generated + s = s.replaceAll("xmlns=\"\"", ""); + return s; + } catch (Exception e) { + logger.error("{} {} {}", MessageEnum.RA_ERROR_CONVERT_XML2STR.toString(), + ErrorCode.DataError.getValue(), "Exception - domToStr", e); + } + } + return null; + } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/package-info.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/package-info.java index bd1f34eadd..3cff95727b 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/package-info.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/package-info.java @@ -18,6 +18,7 @@ * ============LICENSE_END========================================================= */ -@javax.xml.bind.annotation.XmlSchema(namespace = "http://org.onap/workflow/sdnc/adapter/schema/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) +@javax.xml.bind.annotation.XmlSchema(namespace = "http://org.onap/workflow/sdnc/adapter/schema/v1", + elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) package org.onap.so.adapters.sdnc; diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/BPRestCallback.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/BPRestCallback.java index cf52972d8f..6808230474 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/BPRestCallback.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/BPRestCallback.java @@ -25,7 +25,6 @@ package org.onap.so.adapters.sdnc.sdncrest; import javax.xml.bind.DatatypeConverter; - import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.config.RequestConfig; @@ -38,7 +37,6 @@ import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.adapters.sdnc.impl.Constants; import org.onap.so.logger.ErrorCode; import org.onap.so.logger.MessageEnum; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -52,132 +50,125 @@ import org.springframework.core.env.Environment; */ @Component public class BPRestCallback { - private static final Logger logger = LoggerFactory.getLogger(BPRestCallback.class); - - private static final String CAMUNDA="Camunda"; - private static final String MSO_INTERNAL_ERROR="MsoInternalError"; - @Autowired - private Environment env; - - /** - * Sends a message to the BPMN workflow message service. The URL path is - * constructed using the specified message type and correlator. - * @param workflowMessageUrl the base BPMN WorkflowMessage URL - * @param messageType the message type - * @param correlator the message correlator - * @param message the JSON content - * @return true if the message was consumed successfully by the endpoint - */ - public boolean send(String workflowMessageUrl, String messageType, String correlator, String message) { - logger.debug(getClass().getSimpleName() + ".send(" - + "workflowMessageUrl=" + workflowMessageUrl - + " messageType=" + messageType - + " correlator=" + correlator - + " message=" + message - + ")"); - - while (workflowMessageUrl.endsWith("/")) { - workflowMessageUrl = workflowMessageUrl.substring(0, workflowMessageUrl.length()-1); - } - - String endpoint = workflowMessageUrl + "/" + SDNCAdapterUtils.encodeURLPathSegment(messageType) - + "/" + SDNCAdapterUtils.encodeURLPathSegment(correlator); - - return send(endpoint, message); - } - - /** - * Sends a message to the BPMN workflow message service. The specified URL - * must have the message type and correlator already embedded in it. - * @param url the endpoint URL - * @param message the JSON content - * @return true if the message was consumed successfully by the endpoint - */ - public boolean send(String url, String message) { - logger.debug(getClass().getSimpleName() + ".send(" - + "url=" + url - + " message=" + message - + ")"); - - logger.info("{} {} {}", MessageEnum.RA_CALLBACK_BPEL.toString(), message == null ? "[no content]" : message, - CAMUNDA); - - HttpPost method = null; - HttpResponse httpResponse = null; - - try { - int timeout = 60 * 1000; - - RequestConfig requestConfig = RequestConfig.custom() - .setSocketTimeout(timeout) - .setConnectTimeout(timeout) - .setConnectionRequestTimeout(timeout) - .build(); - - HttpClient client = HttpClientBuilder.create().build(); - method = new HttpPost(url); - method.setConfig(requestConfig); - - if (message != null) { - method.setEntity(new StringEntity(message, ContentType.APPLICATION_JSON)); - } - - boolean error = false; - - try { - String userCredentials = CryptoUtils.decrypt(env.getProperty(Constants.BPEL_AUTH_PROP), - env.getProperty(Constants.ENCRYPTION_KEY_PROP)); - String authorization = "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes()); - method.setHeader("Authorization", authorization); - method.setHeader(ONAPLogConstants.Headers.REQUEST_ID,MDC.get(ONAPLogConstants.MDCs.REQUEST_ID)); - method.setHeader(ONAPLogConstants.Headers.INVOCATION_ID,MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); - method.setHeader(ONAPLogConstants.Headers.PARTNER_NAME,"SO-SDNCAdapter"); - } catch (Exception e) { - logger.error("{} {} {} {}", MessageEnum.RA_SET_CALLBACK_AUTH_EXC.toString(), CAMUNDA, - ErrorCode.BusinessProcesssError.getValue(), "Unable to set authorization in callback request", e); - error = true; - } - - if (!error) { - httpResponse = client.execute(method); - - @SuppressWarnings("unused") - String responseContent = null; - - if (httpResponse.getEntity() != null) { - responseContent = EntityUtils.toString(httpResponse.getEntity(), "UTF-8"); - } - - if (httpResponse.getStatusLine().getStatusCode() >= 300) { - String msg = "Received error response to callback request: " + httpResponse.getStatusLine(); - logger.error("{} {} {} {}", MessageEnum.RA_CALLBACK_BPEL_EXC.toString(), CAMUNDA, ErrorCode - .BusinessProcesssError.getValue(), msg); - - } - } - return true; - } catch (Exception e) { - logger.error("{} {} {} {}", MessageEnum.RA_CALLBACK_BPEL_EXC.toString(), CAMUNDA, - ErrorCode.BusinessProcesssError.getValue(), "Error sending callback request", e); - return false; - } finally { - if (httpResponse != null) { - try { - EntityUtils.consume(httpResponse.getEntity()); - httpResponse = null; - } catch (Exception e) { - logger.debug("Exception:", e); - } - } - - if (method != null) { - try { - method.reset(); - } catch (Exception e) { - logger.debug("Exception:", e); - } - } - logger.info("{} {}", MessageEnum.RA_CALLBACK_BPEL_COMPLETE.toString(), CAMUNDA); - } - } + private static final Logger logger = LoggerFactory.getLogger(BPRestCallback.class); + + private static final String CAMUNDA = "Camunda"; + private static final String MSO_INTERNAL_ERROR = "MsoInternalError"; + @Autowired + private Environment env; + + /** + * Sends a message to the BPMN workflow message service. The URL path is constructed using the specified message + * type and correlator. + * + * @param workflowMessageUrl the base BPMN WorkflowMessage URL + * @param messageType the message type + * @param correlator the message correlator + * @param message the JSON content + * @return true if the message was consumed successfully by the endpoint + */ + public boolean send(String workflowMessageUrl, String messageType, String correlator, String message) { + logger.debug(getClass().getSimpleName() + ".send(" + "workflowMessageUrl=" + workflowMessageUrl + + " messageType=" + messageType + " correlator=" + correlator + " message=" + message + ")"); + + while (workflowMessageUrl.endsWith("/")) { + workflowMessageUrl = workflowMessageUrl.substring(0, workflowMessageUrl.length() - 1); + } + + String endpoint = workflowMessageUrl + "/" + SDNCAdapterUtils.encodeURLPathSegment(messageType) + "/" + + SDNCAdapterUtils.encodeURLPathSegment(correlator); + + return send(endpoint, message); + } + + /** + * Sends a message to the BPMN workflow message service. The specified URL must have the message type and correlator + * already embedded in it. + * + * @param url the endpoint URL + * @param message the JSON content + * @return true if the message was consumed successfully by the endpoint + */ + public boolean send(String url, String message) { + logger.debug(getClass().getSimpleName() + ".send(" + "url=" + url + " message=" + message + ")"); + + logger.info("{} {} {}", MessageEnum.RA_CALLBACK_BPEL.toString(), message == null ? "[no content]" : message, + CAMUNDA); + + HttpPost method = null; + HttpResponse httpResponse = null; + + try { + int timeout = 60 * 1000; + + RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout) + .setConnectionRequestTimeout(timeout).build(); + + HttpClient client = HttpClientBuilder.create().build(); + method = new HttpPost(url); + method.setConfig(requestConfig); + + if (message != null) { + method.setEntity(new StringEntity(message, ContentType.APPLICATION_JSON)); + } + + boolean error = false; + + try { + String userCredentials = CryptoUtils.decrypt(env.getProperty(Constants.BPEL_AUTH_PROP), + env.getProperty(Constants.ENCRYPTION_KEY_PROP)); + String authorization = "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes()); + method.setHeader("Authorization", authorization); + method.setHeader(ONAPLogConstants.Headers.REQUEST_ID, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID)); + method.setHeader(ONAPLogConstants.Headers.INVOCATION_ID, MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); + method.setHeader(ONAPLogConstants.Headers.PARTNER_NAME, "SO-SDNCAdapter"); + } catch (Exception e) { + logger.error("{} {} {} {}", MessageEnum.RA_SET_CALLBACK_AUTH_EXC.toString(), CAMUNDA, + ErrorCode.BusinessProcesssError.getValue(), "Unable to set authorization in callback request", + e); + error = true; + } + + if (!error) { + httpResponse = client.execute(method); + + @SuppressWarnings("unused") + String responseContent = null; + + if (httpResponse.getEntity() != null) { + responseContent = EntityUtils.toString(httpResponse.getEntity(), "UTF-8"); + } + + if (httpResponse.getStatusLine().getStatusCode() >= 300) { + String msg = "Received error response to callback request: " + httpResponse.getStatusLine(); + logger.error("{} {} {} {}", MessageEnum.RA_CALLBACK_BPEL_EXC.toString(), CAMUNDA, + ErrorCode.BusinessProcesssError.getValue(), msg); + + } + } + return true; + } catch (Exception e) { + logger.error("{} {} {} {}", MessageEnum.RA_CALLBACK_BPEL_EXC.toString(), CAMUNDA, + ErrorCode.BusinessProcesssError.getValue(), "Error sending callback request", e); + return false; + } finally { + if (httpResponse != null) { + try { + EntityUtils.consume(httpResponse.getEntity()); + httpResponse = null; + } catch (Exception e) { + logger.debug("Exception:", e); + } + } + + if (method != null) { + try { + method.reset(); + } catch (Exception e) { + logger.debug("Exception:", e); + } + } + logger.info("{} {}", MessageEnum.RA_CALLBACK_BPEL_COMPLETE.toString(), CAMUNDA); + } + } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/MapTypedRequestTunablesData.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/MapTypedRequestTunablesData.java index d4c2c57510..70943c206f 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/MapTypedRequestTunablesData.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/MapTypedRequestTunablesData.java @@ -27,7 +27,6 @@ import org.onap.so.adapters.sdnc.exception.SDNCAdapterException; import org.onap.so.adapters.sdnc.impl.Constants; import org.onap.so.logger.ErrorCode; import org.onap.so.logger.MessageEnum; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -36,83 +35,83 @@ import org.springframework.stereotype.Component; @Component public class MapTypedRequestTunablesData { - - private static Logger logger = LoggerFactory.getLogger(MapTypedRequestTunablesData.class); - - private static final String MISSING_CONFIGURATION_ERROR_MSG= "Missing configuration for: "; - private static final String MISSING_CONFIG_PARAM_ERROR_MSG="Missing config param"; - private static final String MSO_INTERNAL_ERROR="MsoInternalError"; - - @Autowired - private Environment env; - - - public TypedRequestTunables setTunables(TypedRequestTunables reqTunableOriginal) throws SDNCAdapterException { - TypedRequestTunables reqTunable = new TypedRequestTunables(reqTunableOriginal); - - String error; - String value = env.getProperty(reqTunable.getKey().toLowerCase(), ""); - - if ("".equals(value)) { - error= MISSING_CONFIGURATION_ERROR_MSG + reqTunable.getKey(); - logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), reqTunable.getKey(), "SDNC", - ErrorCode.DataError.getValue(), MISSING_CONFIG_PARAM_ERROR_MSG); - - throw new SDNCAdapterException(error); - } - - String[] parts = value.split("\\|"); - - if (parts.length != 5) { - error="Invalid configuration for: " + reqTunable.getKey(); - logger.error("{} {} {} {} {} {}", MessageEnum.RA_SDNC_INVALID_CONFIG.toString(), reqTunable.getKey(), value, "SDNC", - ErrorCode.DataError.getValue(), "Invalid config"); - throw new SDNCAdapterException(error); - } - - reqTunable.setReqMethod(parts[0]); - logger.trace("Request Method is set to: {}", reqTunable.getReqMethod()); - - reqTunable.setTimeout(parts[1]); - logger.trace("Timeout is set to: {}", reqTunable.getTimeout()); - - String urlPropKey = Constants.REQUEST_TUNABLES + "." + parts[2]; - reqTunable.setSdncUrl(env.getProperty(urlPropKey, "")); - - if ("".equals(reqTunable.getSdncUrl())) { - error=MISSING_CONFIGURATION_ERROR_MSG + urlPropKey; - logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), urlPropKey, "SDNC", - ErrorCode.DataError.getValue(), MISSING_CONFIG_PARAM_ERROR_MSG); - - throw new SDNCAdapterException(error); - } - - logger.trace("SDNC Url is set to: {}", reqTunable.getSdncUrl()); - - reqTunable.setHeaderName(parts[3]); - logger.trace("Header Name is set to: {}", reqTunable.getHeaderName()); - - reqTunable.setNamespace(parts[4]); - logger.trace("Namespace is set to: {}", reqTunable.getNamespace()); - - reqTunable.setMyUrl(env.getProperty(Constants.MY_URL_PROP, "")); - - if ("".equals(reqTunable.getMyUrl())) { - error=MISSING_CONFIGURATION_ERROR_MSG + Constants.MY_URL_PROP; - logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), Constants.MY_URL_PROP, "SDNC", - ErrorCode.DataError.getValue(), MISSING_CONFIG_PARAM_ERROR_MSG); - - throw new SDNCAdapterException(error); - } - - while (reqTunable.getMyUrl().endsWith("/")) { - reqTunable.setMyUrl(reqTunable.getMyUrl().substring(0, reqTunable.getMyUrl().length()-1)); - } - - reqTunable.setMyUrl(reqTunable.getMyUrl().concat(reqTunable.getMyUrlSuffix())); - - logger.debug(reqTunable.toString()); - return reqTunable; - } + + private static Logger logger = LoggerFactory.getLogger(MapTypedRequestTunablesData.class); + + private static final String MISSING_CONFIGURATION_ERROR_MSG = "Missing configuration for: "; + private static final String MISSING_CONFIG_PARAM_ERROR_MSG = "Missing config param"; + private static final String MSO_INTERNAL_ERROR = "MsoInternalError"; + + @Autowired + private Environment env; + + + public TypedRequestTunables setTunables(TypedRequestTunables reqTunableOriginal) throws SDNCAdapterException { + TypedRequestTunables reqTunable = new TypedRequestTunables(reqTunableOriginal); + + String error; + String value = env.getProperty(reqTunable.getKey().toLowerCase(), ""); + + if ("".equals(value)) { + error = MISSING_CONFIGURATION_ERROR_MSG + reqTunable.getKey(); + logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), reqTunable.getKey(), + "SDNC", ErrorCode.DataError.getValue(), MISSING_CONFIG_PARAM_ERROR_MSG); + + throw new SDNCAdapterException(error); + } + + String[] parts = value.split("\\|"); + + if (parts.length != 5) { + error = "Invalid configuration for: " + reqTunable.getKey(); + logger.error("{} {} {} {} {} {}", MessageEnum.RA_SDNC_INVALID_CONFIG.toString(), reqTunable.getKey(), value, + "SDNC", ErrorCode.DataError.getValue(), "Invalid config"); + throw new SDNCAdapterException(error); + } + + reqTunable.setReqMethod(parts[0]); + logger.trace("Request Method is set to: {}", reqTunable.getReqMethod()); + + reqTunable.setTimeout(parts[1]); + logger.trace("Timeout is set to: {}", reqTunable.getTimeout()); + + String urlPropKey = Constants.REQUEST_TUNABLES + "." + parts[2]; + reqTunable.setSdncUrl(env.getProperty(urlPropKey, "")); + + if ("".equals(reqTunable.getSdncUrl())) { + error = MISSING_CONFIGURATION_ERROR_MSG + urlPropKey; + logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), urlPropKey, "SDNC", + ErrorCode.DataError.getValue(), MISSING_CONFIG_PARAM_ERROR_MSG); + + throw new SDNCAdapterException(error); + } + + logger.trace("SDNC Url is set to: {}", reqTunable.getSdncUrl()); + + reqTunable.setHeaderName(parts[3]); + logger.trace("Header Name is set to: {}", reqTunable.getHeaderName()); + + reqTunable.setNamespace(parts[4]); + logger.trace("Namespace is set to: {}", reqTunable.getNamespace()); + + reqTunable.setMyUrl(env.getProperty(Constants.MY_URL_PROP, "")); + + if ("".equals(reqTunable.getMyUrl())) { + error = MISSING_CONFIGURATION_ERROR_MSG + Constants.MY_URL_PROP; + logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), Constants.MY_URL_PROP, + "SDNC", ErrorCode.DataError.getValue(), MISSING_CONFIG_PARAM_ERROR_MSG); + + throw new SDNCAdapterException(error); + } + + while (reqTunable.getMyUrl().endsWith("/")) { + reqTunable.setMyUrl(reqTunable.getMyUrl().substring(0, reqTunable.getMyUrl().length() - 1)); + } + + reqTunable.setMyUrl(reqTunable.getMyUrl().concat(reqTunable.getMyUrlSuffix())); + + logger.debug(reqTunable.toString()); + return reqTunable; + } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCAdapterUtils.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCAdapterUtils.java index 8cafbda325..eaea15cf0d 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCAdapterUtils.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCAdapterUtils.java @@ -25,7 +25,6 @@ package org.onap.so.adapters.sdnc.sdncrest; import java.util.ArrayList; import java.util.List; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.util.UriUtils; @@ -38,35 +37,36 @@ import org.w3c.dom.NodeList; */ public final class SDNCAdapterUtils { private static final Logger logger = LoggerFactory.getLogger(SDNCAdapterUtils.class); + /** * Instantiation is not allowed. */ - private SDNCAdapterUtils() { - } - + private SDNCAdapterUtils() {} + /** - * Returns a node's child elements in a list. - */ - public static List<Element> childElements(Node node) { - List<Element> elements = new ArrayList<>(); + * Returns a node's child elements in a list. + */ + public static List<Element> childElements(Node node) { + List<Element> elements = new ArrayList<>(); - NodeList nodeList = node.getChildNodes(); - for (int i = 0; i < nodeList.getLength(); i++) { - Node child = nodeList.item(i); - if (child.getNodeType() == Node.ELEMENT_NODE) { - elements.add((Element) child); - } - } + NodeList nodeList = node.getChildNodes(); + for (int i = 0; i < nodeList.getLength(); i++) { + Node child = nodeList.item(i); + if (child.getNodeType() == Node.ELEMENT_NODE) { + elements.add((Element) child); + } + } - return elements; - } + return elements; + } - /** - * Encodes a URL path segment according to RFC 3986 Section 2. - * @param pathSegment the path segment to encode - * @return the encoded path segment - */ - public static String encodeURLPathSegment(String pathSegment) { - return UriUtils.encodePathSegment(pathSegment, "UTF-8"); - } + /** + * Encodes a URL path segment according to RFC 3986 Section 2. + * + * @param pathSegment the path segment to encode + * @return the encoded path segment + */ + public static String encodeURLPathSegment(String pathSegment) { + return UriUtils.encodePathSegment(pathSegment, "UTF-8"); + } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCConnector.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCConnector.java index 7cc5b8e14e..a7c65d87a4 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCConnector.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCConnector.java @@ -27,7 +27,6 @@ package org.onap.so.adapters.sdnc.sdncrest; import java.io.StringReader; import java.net.HttpURLConnection; import java.net.SocketTimeoutException; - import javax.xml.XMLConstants; import javax.xml.bind.DatatypeConverter; import javax.xml.parsers.DocumentBuilderFactory; @@ -35,7 +34,6 @@ import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; - import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.config.RequestConfig; @@ -54,7 +52,6 @@ import org.onap.so.adapters.sdncrest.SDNCErrorCommon; import org.onap.so.adapters.sdncrest.SDNCResponseCommon; import org.onap.so.logger.ErrorCode; import org.onap.so.logger.MessageEnum; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -71,263 +68,260 @@ import org.springframework.core.env.Environment; */ @Component public abstract class SDNCConnector { - private static final Logger logger = LoggerFactory.getLogger(SDNCConnector.class); - - private static final String MSO_INTERNAL_ERROR="MsoInternalError"; - private static final String XPATH_EXCEPTION="XPath Exception"; - @Autowired - private Environment env; - - public SDNCResponseCommon send(String content, TypedRequestTunables rt) { - logger.debug("SDNC URL: {}", rt.getSdncUrl()); - logger.debug("SDNC Request Body:\n {}", content); - - HttpRequestBase method = null; - HttpResponse httpResponse = null; - - try { - int timeout = Integer.parseInt(rt.getTimeout()); - - RequestConfig requestConfig = RequestConfig.custom() - .setSocketTimeout(timeout) - .setConnectTimeout(timeout) - .setConnectionRequestTimeout(timeout) - .build(); - - HttpClient client = HttpClientBuilder.create().build(); - - if ("POST".equals(rt.getReqMethod())) { - HttpPost httpPost = new HttpPost(rt.getSdncUrl()); - httpPost.setConfig(requestConfig); - httpPost.setEntity(new StringEntity(content, ContentType.APPLICATION_XML)); - method = httpPost; - } else if ("PUT".equals(rt.getReqMethod())) { - HttpPut httpPut = new HttpPut(rt.getSdncUrl()); - httpPut.setConfig(requestConfig); - httpPut.setEntity(new StringEntity(content, ContentType.APPLICATION_XML)); - method = httpPut; - } else if ("GET".equals(rt.getReqMethod())) { - HttpGet httpGet = new HttpGet(rt.getSdncUrl()); - httpGet.setConfig(requestConfig); - method = httpGet; - } else if ("DELETE".equals(rt.getReqMethod())) { - HttpDelete httpDelete = new HttpDelete(rt.getSdncUrl()); - httpDelete.setConfig(requestConfig); - method = httpDelete; - } - - - String userCredentials = CryptoUtils.decrypt(env.getProperty(Constants.SDNC_AUTH_PROP), - env.getProperty(Constants.ENCRYPTION_KEY_PROP)); - String authorization = "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes()); - if(null != method) { - method.setHeader("Authorization", authorization); - method.setHeader("Accept", "application/yang.data+xml"); - } - else { - logger.debug("method is NULL:"); - } - - - - httpResponse = client.execute(method); - - String responseContent = null; - if (httpResponse.getEntity() != null) { - responseContent = EntityUtils.toString(httpResponse.getEntity(), "UTF-8"); - } - - int statusCode = httpResponse.getStatusLine().getStatusCode(); - String statusMessage = httpResponse.getStatusLine().getReasonPhrase(); - - logger.debug("SDNC Response: {} {}", statusCode, - statusMessage + (responseContent == null ? "" : System.lineSeparator() + responseContent)); - - if (httpResponse.getStatusLine().getStatusCode() >= 300) { - String errMsg = "SDNC returned " + statusCode + " " + statusMessage; - - String errors = analyzeErrors(responseContent); - if (errors != null) { - errMsg += " " + errors; - } - - logError(errMsg); - - return createErrorResponse(statusCode, errMsg, rt); - } - - httpResponse = null; - - if(null != method) { - method.reset(); - } - else { + private static final Logger logger = LoggerFactory.getLogger(SDNCConnector.class); + + private static final String MSO_INTERNAL_ERROR = "MsoInternalError"; + private static final String XPATH_EXCEPTION = "XPath Exception"; + @Autowired + private Environment env; + + public SDNCResponseCommon send(String content, TypedRequestTunables rt) { + logger.debug("SDNC URL: {}", rt.getSdncUrl()); + logger.debug("SDNC Request Body:\n {}", content); + + HttpRequestBase method = null; + HttpResponse httpResponse = null; + + try { + int timeout = Integer.parseInt(rt.getTimeout()); + + RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout) + .setConnectionRequestTimeout(timeout).build(); + + HttpClient client = HttpClientBuilder.create().build(); + + if ("POST".equals(rt.getReqMethod())) { + HttpPost httpPost = new HttpPost(rt.getSdncUrl()); + httpPost.setConfig(requestConfig); + httpPost.setEntity(new StringEntity(content, ContentType.APPLICATION_XML)); + method = httpPost; + } else if ("PUT".equals(rt.getReqMethod())) { + HttpPut httpPut = new HttpPut(rt.getSdncUrl()); + httpPut.setConfig(requestConfig); + httpPut.setEntity(new StringEntity(content, ContentType.APPLICATION_XML)); + method = httpPut; + } else if ("GET".equals(rt.getReqMethod())) { + HttpGet httpGet = new HttpGet(rt.getSdncUrl()); + httpGet.setConfig(requestConfig); + method = httpGet; + } else if ("DELETE".equals(rt.getReqMethod())) { + HttpDelete httpDelete = new HttpDelete(rt.getSdncUrl()); + httpDelete.setConfig(requestConfig); + method = httpDelete; + } + + + String userCredentials = CryptoUtils.decrypt(env.getProperty(Constants.SDNC_AUTH_PROP), + env.getProperty(Constants.ENCRYPTION_KEY_PROP)); + String authorization = "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes()); + if (null != method) { + method.setHeader("Authorization", authorization); + method.setHeader("Accept", "application/yang.data+xml"); + } else { logger.debug("method is NULL:"); } - method = null; - - logger.info("{} {} {}", MessageEnum.RA_RESPONSE_FROM_SDNC.toString(), responseContent, "SDNC"); - return createResponseFromContent(statusCode, statusMessage, responseContent, rt); - - } catch (SocketTimeoutException | ConnectTimeoutException e) { - String errMsg = "Request to SDNC timed out"; - logError(errMsg, e); - return createErrorResponse(HttpURLConnection.HTTP_CLIENT_TIMEOUT, errMsg, rt); - - } catch (Exception e) { - String errMsg = "Error processing request to SDNC"; - logError(errMsg, e); - return createErrorResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, errMsg, rt); - - } finally { - if (httpResponse != null) { - try { - EntityUtils.consume(httpResponse.getEntity()); - } catch (Exception e) { - logger.debug("Exception:", e); - } - } - - if (method != null) { - try { - method.reset(); - } catch (Exception e) { - logger.debug("Exception:", e); - } - } - } - } - - protected void logError(String errMsg) { - logger.error("{} {} {} {}", MessageEnum.RA_EXCEPTION_COMMUNICATE_SDNC.toString(), "SDNC", - ErrorCode.AvailabilityError.getValue(), errMsg); - } - - protected void logError(String errMsg, Throwable t) { - logger.error("{} {} {} {}", MessageEnum.RA_EXCEPTION_COMMUNICATE_SDNC.toString(), "SDNC", - ErrorCode.AvailabilityError.getValue(), errMsg, t); - } - - /** - * Generates a response object from content received from SDNC. The response - * object may be a success response object or an error response object. This - * method must be overridden by the subclass to return the correct object type. - * @param statusCode the response status code from SDNC (e.g. 200) - * @param statusMessage the response status message from SDNC (e.g. "OK") - * @param responseContent the body of the response from SDNC (possibly null) - * @param rt request tunables - * @return a response object - */ - protected abstract SDNCResponseCommon createResponseFromContent(int statusCode, - String statusMessage, String responseContent, TypedRequestTunables rt); - - /** - * Generates an error response object. This method must be overridden by the - * subclass to return the correct object type. - * @param statusCode the response status code (from SDNC, or internally generated) - * @param errMsg the error message (normally a verbose explanation of the error) - * @param rt request tunables - * @return an error response object - */ - protected abstract SDNCErrorCommon createErrorResponse(int statusCode, - String errMsg, TypedRequestTunables rt); - - /** - * Called by the send() method to analyze errors that may be encoded in the - * content of non-2XX responses. By default, this method tries to parse the - * content as a restconf error. - * <pre> - * xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf" - * </pre> - * If an error (or errors) can be obtained from the content, then the result - * is a string in this format: - * <pre> - * [error-type:TYPE, error-tag:TAG, error-message:MESSAGE] ... - * </pre> - * If no error could be obtained from the content, then the result is null. - * <p> - * The subclass can override this method to provide another implementation. - */ - protected String analyzeErrors(String content) { - if (content == null || content.isEmpty()) { - return null; - } - - // Confirmed with Andrew Shen on 11/1/16 that SDNC will send content like - // this in error responses (non-2XX response codes) to "agnostic" service - // requests. - // - // <errors xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf"> - // <error> - // <error-type>protocol</error-type> - // <error-tag>malformed-message</error-tag> - // <error-message>Error parsing input: The element type "input" must be terminated by the matching end-tag "</input>".</error-message> - // </error> - // </errors> - - StringBuilder output = null; - - try { - XPathFactory xpathFactory = XPathFactory.newInstance(); - XPath xpath = xpathFactory.newXPath(); - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); - documentBuilderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false); - documentBuilderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); - InputSource source = new InputSource(new StringReader(content)); - Document doc = documentBuilderFactory.newDocumentBuilder().parse(source); - NodeList errors = (NodeList) xpath.evaluate("errors/error", doc, XPathConstants.NODESET); - - for (int i = 0; i < errors.getLength(); i++) - { - Element error = (Element) errors.item(i); - - String info = ""; - - try { - String errorType = xpath.evaluate("error-type", error); - info += "error-type:" + errorType; - } catch (XPathExpressionException e) { - logger.error("{} {} {} {} {} {}", MessageEnum.RA_EVALUATE_XPATH_ERROR.toString(), "error-type", error.toString(), - "SDNC", ErrorCode.DataError.getValue(), XPATH_EXCEPTION, e); - } - - try { - String errorTag = xpath.evaluate( "error-tag", error); - if (!info.isEmpty()) { - info += ", "; - } - info += "error-tag:" + errorTag; - } catch (XPathExpressionException e) { - logger.error("{} {} {} {} {} {}", MessageEnum.RA_EVALUATE_XPATH_ERROR.toString(), "error-tag", error.toString(), - "SDNC", ErrorCode.DataError.getValue(), XPATH_EXCEPTION, e); - } - - try { - String errorMessage = xpath.evaluate("error-message", error); - if (!info.isEmpty()) { - info += ", "; - } - info += "error-message:" + errorMessage; - } catch (Exception e) { - logger.error("{} {} {} {} {} {}", MessageEnum.RA_EVALUATE_XPATH_ERROR.toString(), "error-message", - error.toString(), "SDNC", ErrorCode.DataError.getValue(), XPATH_EXCEPTION, e); - } - - if (!info.isEmpty()) { - if (output == null) { - output = new StringBuilder("[" + info + "]"); - } else { - output.append(" [").append(info).append("]"); - } - } - } - } catch (Exception e) { - logger.error("{} {} {} {}", MessageEnum.RA_ANALYZE_ERROR_EXC.toString(), "SDNC", - ErrorCode.DataError.getValue(), "Exception while analyzing errors", e); - } - - return output.toString(); - } + + + httpResponse = client.execute(method); + + String responseContent = null; + if (httpResponse.getEntity() != null) { + responseContent = EntityUtils.toString(httpResponse.getEntity(), "UTF-8"); + } + + int statusCode = httpResponse.getStatusLine().getStatusCode(); + String statusMessage = httpResponse.getStatusLine().getReasonPhrase(); + + logger.debug("SDNC Response: {} {}", statusCode, + statusMessage + (responseContent == null ? "" : System.lineSeparator() + responseContent)); + + if (httpResponse.getStatusLine().getStatusCode() >= 300) { + String errMsg = "SDNC returned " + statusCode + " " + statusMessage; + + String errors = analyzeErrors(responseContent); + if (errors != null) { + errMsg += " " + errors; + } + + logError(errMsg); + + return createErrorResponse(statusCode, errMsg, rt); + } + + httpResponse = null; + + if (null != method) { + method.reset(); + } else { + logger.debug("method is NULL:"); + } + + method = null; + + logger.info("{} {} {}", MessageEnum.RA_RESPONSE_FROM_SDNC.toString(), responseContent, "SDNC"); + return createResponseFromContent(statusCode, statusMessage, responseContent, rt); + + } catch (SocketTimeoutException | ConnectTimeoutException e) { + String errMsg = "Request to SDNC timed out"; + logError(errMsg, e); + return createErrorResponse(HttpURLConnection.HTTP_CLIENT_TIMEOUT, errMsg, rt); + + } catch (Exception e) { + String errMsg = "Error processing request to SDNC"; + logError(errMsg, e); + return createErrorResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, errMsg, rt); + + } finally { + if (httpResponse != null) { + try { + EntityUtils.consume(httpResponse.getEntity()); + } catch (Exception e) { + logger.debug("Exception:", e); + } + } + + if (method != null) { + try { + method.reset(); + } catch (Exception e) { + logger.debug("Exception:", e); + } + } + } + } + + protected void logError(String errMsg) { + logger.error("{} {} {} {}", MessageEnum.RA_EXCEPTION_COMMUNICATE_SDNC.toString(), "SDNC", + ErrorCode.AvailabilityError.getValue(), errMsg); + } + + protected void logError(String errMsg, Throwable t) { + logger.error("{} {} {} {}", MessageEnum.RA_EXCEPTION_COMMUNICATE_SDNC.toString(), "SDNC", + ErrorCode.AvailabilityError.getValue(), errMsg, t); + } + + /** + * Generates a response object from content received from SDNC. The response object may be a success response object + * or an error response object. This method must be overridden by the subclass to return the correct object type. + * + * @param statusCode the response status code from SDNC (e.g. 200) + * @param statusMessage the response status message from SDNC (e.g. "OK") + * @param responseContent the body of the response from SDNC (possibly null) + * @param rt request tunables + * @return a response object + */ + protected abstract SDNCResponseCommon createResponseFromContent(int statusCode, String statusMessage, + String responseContent, TypedRequestTunables rt); + + /** + * Generates an error response object. This method must be overridden by the subclass to return the correct object + * type. + * + * @param statusCode the response status code (from SDNC, or internally generated) + * @param errMsg the error message (normally a verbose explanation of the error) + * @param rt request tunables + * @return an error response object + */ + protected abstract SDNCErrorCommon createErrorResponse(int statusCode, String errMsg, TypedRequestTunables rt); + + /** + * Called by the send() method to analyze errors that may be encoded in the content of non-2XX responses. By + * default, this method tries to parse the content as a restconf error. + * + * <pre> + * xmlns = "urn:ietf:params:xml:ns:yang:ietf-restconf" + * </pre> + * + * If an error (or errors) can be obtained from the content, then the result is a string in this format: + * + * <pre> + * [error-type:TYPE, error-tag:TAG, error-message:MESSAGE] ... + * </pre> + * + * If no error could be obtained from the content, then the result is null. + * <p> + * The subclass can override this method to provide another implementation. + */ + protected String analyzeErrors(String content) { + if (content == null || content.isEmpty()) { + return null; + } + + // Confirmed with Andrew Shen on 11/1/16 that SDNC will send content like + // this in error responses (non-2XX response codes) to "agnostic" service + // requests. + // + // <errors xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf"> + // <error> + // <error-type>protocol</error-type> + // <error-tag>malformed-message</error-tag> + // <error-message>Error parsing input: The element type "input" must be terminated by the matching end-tag + // "</input>".</error-message> + // </error> + // </errors> + + StringBuilder output = null; + + try { + XPathFactory xpathFactory = XPathFactory.newInstance(); + XPath xpath = xpathFactory.newXPath(); + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + documentBuilderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false); + documentBuilderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); + InputSource source = new InputSource(new StringReader(content)); + Document doc = documentBuilderFactory.newDocumentBuilder().parse(source); + NodeList errors = (NodeList) xpath.evaluate("errors/error", doc, XPathConstants.NODESET); + + for (int i = 0; i < errors.getLength(); i++) { + Element error = (Element) errors.item(i); + + String info = ""; + + try { + String errorType = xpath.evaluate("error-type", error); + info += "error-type:" + errorType; + } catch (XPathExpressionException e) { + logger.error("{} {} {} {} {} {}", MessageEnum.RA_EVALUATE_XPATH_ERROR.toString(), "error-type", + error.toString(), "SDNC", ErrorCode.DataError.getValue(), XPATH_EXCEPTION, e); + } + + try { + String errorTag = xpath.evaluate("error-tag", error); + if (!info.isEmpty()) { + info += ", "; + } + info += "error-tag:" + errorTag; + } catch (XPathExpressionException e) { + logger.error("{} {} {} {} {} {}", MessageEnum.RA_EVALUATE_XPATH_ERROR.toString(), "error-tag", + error.toString(), "SDNC", ErrorCode.DataError.getValue(), XPATH_EXCEPTION, e); + } + + try { + String errorMessage = xpath.evaluate("error-message", error); + if (!info.isEmpty()) { + info += ", "; + } + info += "error-message:" + errorMessage; + } catch (Exception e) { + logger.error("{} {} {} {} {} {}", MessageEnum.RA_EVALUATE_XPATH_ERROR.toString(), "error-message", + error.toString(), "SDNC", ErrorCode.DataError.getValue(), XPATH_EXCEPTION, e); + } + + if (!info.isEmpty()) { + if (output == null) { + output = new StringBuilder("[" + info + "]"); + } else { + output.append(" [").append(info).append("]"); + } + } + } + } catch (Exception e) { + logger.error("{} {} {} {}", MessageEnum.RA_ANALYZE_ERROR_EXC.toString(), "SDNC", + ErrorCode.DataError.getValue(), "Exception while analyzing errors", e); + } + + return output.toString(); + } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestConnector.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestConnector.java index 57051e570e..6f76ea1eab 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestConnector.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestConnector.java @@ -30,11 +30,9 @@ import java.net.HttpURLConnection; import java.text.ParseException; import java.util.ArrayList; import java.util.List; - import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; - import org.onap.so.adapters.sdncrest.SDNCErrorCommon; import org.onap.so.adapters.sdncrest.SDNCResponseCommon; import org.onap.so.adapters.sdncrest.SDNCServiceError; @@ -55,157 +53,156 @@ import org.xml.sax.SAXException; public class SDNCServiceRequestConnector extends SDNCConnector { private static final Logger logger = LoggerFactory.getLogger(SDNCServiceRequestConnector.class); - @Override - protected SDNCResponseCommon createResponseFromContent(int statusCode, String statusMessage, - String responseContent, TypedRequestTunables rt) { - try { - return parseResponseContent(responseContent); - } catch (ParseException e) { - logger.error("Error occured:", e); - return createErrorResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, e.getMessage(), rt); - }catch (Exception e) { - logger.error("Error occured:", e); - return createErrorResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, e.getMessage(), rt); - } - } - - @Override - protected SDNCErrorCommon createErrorResponse(int statusCode, String errMsg, - TypedRequestTunables rt) { - return new SDNCServiceError(rt.getReqId(), String.valueOf(statusCode), errMsg, "Y"); - } - - /** - * Parses SDNC synchronous service response content or service notification content. - * If the content can be parsed and contains all required elements, then an object - * is returned. The type of the returned object depends on the response code - * contained in the content. For 2XX response codes, an SDNCServiceResponse is - * returned. Otherwise, an SDNCServiceError is returned. If the content cannot - * be parsed, or if the content does not contain all required elements, a parse - * exception is thrown. This method performs no logging or alarming. - * @throws ParseException on error - */ - public static SDNCResponseCommon parseResponseContent(String responseContent) - throws ParseException,ParserConfigurationException, SAXException, IOException{ - - // Note: this document builder is not namespace-aware, so namespaces are ignored. - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); - documentBuilderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false); - documentBuilderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); - InputSource source = new InputSource(new StringReader(responseContent)); - Document doc = documentBuilderFactory.newDocumentBuilder().parse(source); - - // Find the configuration-response-common child under the root element. - // The root element is expected to be an "output" element, but we don't really care. - - Element root = doc.getDocumentElement(); - Element configurationResponseCommon = null; - - for (Element child : SDNCAdapterUtils.childElements(root)) { - if ("configuration-response-common".equals(child.getNodeName())) { - configurationResponseCommon = child; - break; - } - } - - if (configurationResponseCommon == null) { - throw new ParseException("No configuration-response-common element in SDNC response", 0); - } - - // Process the children of configuration-response-common. - - String responseCode = null; - String responseMessage = null; - String svcRequestId = null; - String ackFinalIndicator = null; - List<Element> responseParameters = new ArrayList<>(); - - for (Element child : SDNCAdapterUtils.childElements(configurationResponseCommon)) { - if ("response-code".equals(child.getNodeName())) { - responseCode = child.getTextContent(); - } else if ("response-message".equals(child.getNodeName())) { - responseMessage = child.getTextContent(); - } else if ("svc-request-id".equals(child.getNodeName())) { - svcRequestId = child.getTextContent(); - } else if ("ack-final-indicator".equals(child.getNodeName())) { - ackFinalIndicator = child.getTextContent(); - } else if ("response-parameters".equals(child.getNodeName())) { - responseParameters.add(child); - } - } - - // svc-request-id is mandatory. - - if (svcRequestId == null || svcRequestId.isEmpty()) { - throw new ParseException("No svc-request-id in SDNC response", 0); - } - - // response-code is mandatory. - - if (responseCode == null || responseCode.isEmpty()) { - throw new ParseException("No response-code in SDNC response", 0); - } - - // ack-final-indicator is optional: default to "Y". - - if (ackFinalIndicator == null || ackFinalIndicator.trim().isEmpty()) { - ackFinalIndicator = "Y"; - } - - if (!"Y".equals(ackFinalIndicator) && !"N".equals(ackFinalIndicator)) { - throw new ParseException("Invalid ack-final-indicator in SDNC response: '" + ackFinalIndicator + "'", 0); - } - - // response-message is optional. If the value is empty, omit it from the response object. - - if (responseMessage != null && responseMessage.isEmpty()) { - responseMessage = null; - } - - // If the response code in the message from SDNC was not 2XX, return SDNCServiceError. - - if (!responseCode.matches("2[0-9][0-9]") && !("0").equals(responseCode)) { - // Not a 2XX response. Return SDNCServiceError. - return new SDNCServiceError(svcRequestId, responseCode, responseMessage, ackFinalIndicator); - } - - // Create a success response object. - - SDNCServiceResponse response = new SDNCServiceResponse(svcRequestId, - responseCode, responseMessage, ackFinalIndicator); - - // Process any response-parameters that might be present. - - for (Element element : responseParameters) { - String tagName = null; - String tagValue = null; - - for (Element child : SDNCAdapterUtils.childElements(element)) { - if ("tag-name".equals(child.getNodeName())) { - tagName = child.getTextContent(); - } else if ("tag-value".equals(child.getNodeName())) { - tagValue = child.getTextContent(); - } - } - // tag-name is mandatory + @Override + protected SDNCResponseCommon createResponseFromContent(int statusCode, String statusMessage, String responseContent, + TypedRequestTunables rt) { + try { + return parseResponseContent(responseContent); + } catch (ParseException e) { + logger.error("Error occured:", e); + return createErrorResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, e.getMessage(), rt); + } catch (Exception e) { + logger.error("Error occured:", e); + return createErrorResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, e.getMessage(), rt); + } + } + + @Override + protected SDNCErrorCommon createErrorResponse(int statusCode, String errMsg, TypedRequestTunables rt) { + return new SDNCServiceError(rt.getReqId(), String.valueOf(statusCode), errMsg, "Y"); + } + + /** + * Parses SDNC synchronous service response content or service notification content. If the content can be parsed + * and contains all required elements, then an object is returned. The type of the returned object depends on the + * response code contained in the content. For 2XX response codes, an SDNCServiceResponse is returned. Otherwise, an + * SDNCServiceError is returned. If the content cannot be parsed, or if the content does not contain all required + * elements, a parse exception is thrown. This method performs no logging or alarming. + * + * @throws ParseException on error + */ + public static SDNCResponseCommon parseResponseContent(String responseContent) + throws ParseException, ParserConfigurationException, SAXException, IOException { + + // Note: this document builder is not namespace-aware, so namespaces are ignored. + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + documentBuilderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false); + documentBuilderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); + InputSource source = new InputSource(new StringReader(responseContent)); + Document doc = documentBuilderFactory.newDocumentBuilder().parse(source); + + // Find the configuration-response-common child under the root element. + // The root element is expected to be an "output" element, but we don't really care. + + Element root = doc.getDocumentElement(); + Element configurationResponseCommon = null; + + for (Element child : SDNCAdapterUtils.childElements(root)) { + if ("configuration-response-common".equals(child.getNodeName())) { + configurationResponseCommon = child; + break; + } + } + + if (configurationResponseCommon == null) { + throw new ParseException("No configuration-response-common element in SDNC response", 0); + } + + // Process the children of configuration-response-common. + + String responseCode = null; + String responseMessage = null; + String svcRequestId = null; + String ackFinalIndicator = null; + List<Element> responseParameters = new ArrayList<>(); + + for (Element child : SDNCAdapterUtils.childElements(configurationResponseCommon)) { + if ("response-code".equals(child.getNodeName())) { + responseCode = child.getTextContent(); + } else if ("response-message".equals(child.getNodeName())) { + responseMessage = child.getTextContent(); + } else if ("svc-request-id".equals(child.getNodeName())) { + svcRequestId = child.getTextContent(); + } else if ("ack-final-indicator".equals(child.getNodeName())) { + ackFinalIndicator = child.getTextContent(); + } else if ("response-parameters".equals(child.getNodeName())) { + responseParameters.add(child); + } + } - if (tagName == null) { - throw new ParseException("Missing tag-name in SDNC response parameter", 0); - } + // svc-request-id is mandatory. + + if (svcRequestId == null || svcRequestId.isEmpty()) { + throw new ParseException("No svc-request-id in SDNC response", 0); + } + + // response-code is mandatory. + + if (responseCode == null || responseCode.isEmpty()) { + throw new ParseException("No response-code in SDNC response", 0); + } + + // ack-final-indicator is optional: default to "Y". + + if (ackFinalIndicator == null || ackFinalIndicator.trim().isEmpty()) { + ackFinalIndicator = "Y"; + } + + if (!"Y".equals(ackFinalIndicator) && !"N".equals(ackFinalIndicator)) { + throw new ParseException("Invalid ack-final-indicator in SDNC response: '" + ackFinalIndicator + "'", 0); + } + + // response-message is optional. If the value is empty, omit it from the response object. - // tag-value is optional. If absent, make it an empty string so we don't - // end up with null values in the parameter map. + if (responseMessage != null && responseMessage.isEmpty()) { + responseMessage = null; + } - if (tagValue == null) { - tagValue = ""; + // If the response code in the message from SDNC was not 2XX, return SDNCServiceError. + + if (!responseCode.matches("2[0-9][0-9]") && !("0").equals(responseCode)) { + // Not a 2XX response. Return SDNCServiceError. + return new SDNCServiceError(svcRequestId, responseCode, responseMessage, ackFinalIndicator); + } + + // Create a success response object. + + SDNCServiceResponse response = + new SDNCServiceResponse(svcRequestId, responseCode, responseMessage, ackFinalIndicator); + + // Process any response-parameters that might be present. + + for (Element element : responseParameters) { + String tagName = null; + String tagValue = null; + + for (Element child : SDNCAdapterUtils.childElements(element)) { + if ("tag-name".equals(child.getNodeName())) { + tagName = child.getTextContent(); + } else if ("tag-value".equals(child.getNodeName())) { + tagValue = child.getTextContent(); } + } - response.addParam(tagName, tagValue); + // tag-name is mandatory + + if (tagName == null) { + throw new ParseException("Missing tag-name in SDNC response parameter", 0); + } + + // tag-value is optional. If absent, make it an empty string so we don't + // end up with null values in the parameter map. + + if (tagValue == null) { + tagValue = ""; } - return response; - - } + response.addParam(tagName, tagValue); + } + + return response; + + } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestTask.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestTask.java index a42e92db4b..7e82adf064 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestTask.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestTask.java @@ -23,7 +23,6 @@ package org.onap.so.adapters.sdnc.sdncrest; import java.io.StringWriter; - import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -32,7 +31,6 @@ import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; - import org.apache.http.HttpStatus; import org.onap.so.adapters.sdnc.exception.SDNCAdapterException; import org.onap.so.adapters.sdncrest.RequestInformation; @@ -51,171 +49,167 @@ import org.w3c.dom.Element; @Component public class SDNCServiceRequestTask { - private static final Logger logger = LoggerFactory.getLogger(SDNCServiceRequestTask.class); - - @Autowired - private SDNCServiceRequestConnector connector; - - @Autowired - MapTypedRequestTunablesData mapTunables; - - @Autowired - private BPRestCallback bpRestCallback; - - @Async - public void runRequest(SDNCServiceRequest request,String msoRequestId,String msoServiceInstanceId,String myUrlSuffix) - { - - String sdncRequestId = request.getSdncRequestId(); - String sdncService = request.getSdncService(); - String sdncOperation = request.getSdncOperation(); - - TypedRequestTunables rt = new TypedRequestTunables(sdncRequestId, myUrlSuffix); - rt.setServiceKey(sdncService, sdncOperation); - TypedRequestTunables mappedTunables; - try { - mappedTunables = mapTunables.setTunables(rt); - } catch(SDNCAdapterException e) { - bpRestCallback.send(request.getBPNotificationUrl(), e.getMessage()); - return; - } - if (!mappedTunables.getError().isEmpty()) { - // Note that the error was logged and alarmed by setTunables() - SDNCServiceError error = new SDNCServiceError(request.getSdncRequestId(), - String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR), mappedTunables.getError(), "Y"); - bpRestCallback.send(request.getBPNotificationUrl(), error.toJson()); - return; - } - - String xml = genSdncReq(request, mappedTunables); - - long sdncStartTime = System.currentTimeMillis(); - SDNCResponseCommon response = connector.send(xml, mappedTunables); - - long bpStartTime = System.currentTimeMillis(); - boolean callbackSuccess = bpRestCallback.send(request.getBPNotificationUrl(), response.toJson()); - } - - private Element addChild(Element parent, String tag) { - Element child = parent.getOwnerDocument().createElement(tag); - parent.appendChild(child); - return child; - } - - private void addTextChild(Element parent, String tag, String text) { - if (text != null) { - Element child = parent.getOwnerDocument().createElement(tag); - child.setTextContent(text); - parent.appendChild(child); - } - } - - private String genSdncReq(SDNCServiceRequest request, TypedRequestTunables rt) { - Document doc; - - try { - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); - - doc = documentBuilder.newDocument(); - Element root = doc.createElementNS(rt.getNamespace(), "input"); - doc.appendChild(root); - - Element hdr = addChild(root, rt.getHeaderName()); - addTextChild(hdr, "svc-request-id", rt.getReqId()); - addTextChild(hdr, "svc-notification-url", rt.getMyUrl()); - - RequestInformation requestInfo = request.getRequestInformation(); - Element requestInformation = addChild(root, "request-information"); - addTextChild(requestInformation, "request-id", requestInfo.getRequestId()); - - - if(requestInfo.getRequestAction()!= null) { - addTextChild(requestInformation, "request-action", - requestInfo.getRequestAction()); - } - if(requestInfo.getRequestSubAction()!= null) { - addTextChild(requestInformation, "request-sub-action", - requestInfo.getRequestSubAction()); - } - if(requestInfo.getOrderNumber() != null && - !requestInfo.getOrderNumber().isEmpty() ) { - addTextChild(requestInformation, "order-number", - requestInfo.getOrderNumber()); - } - - if(requestInfo.getOrderVersion() != null && - !requestInfo.getOrderVersion().isEmpty() ) { - addTextChild(requestInformation, "order-version", - requestInfo.getOrderVersion()); - } - - - addTextChild(requestInformation, "source", requestInfo.getSource()); - addTextChild(requestInformation, "notification-url", requestInfo.getNotificationUrl()); - - Element serviceInformation = addChild(root, "service-information"); - addTextChild(serviceInformation, "service-type", request.getServiceInformation().getServiceType()); - addTextChild(serviceInformation, "service-instance-id", request.getServiceInformation().getServiceInstanceId()); - addTextChild(serviceInformation, "subscriber-name", request.getServiceInformation().getSubscriberName()); - addTextChild(serviceInformation, "subscriber-global-id", request.getServiceInformation().getSubscriberGlobalId()); - - Element agnosticServiceInformation = addChild(root, "agnostic-service-information"); - addTextChild(agnosticServiceInformation, "operation", request.getSdncOperation()); - addTextChild(agnosticServiceInformation, "service", request.getSdncService()); - - // anydata is mandatory in the SDNC schema, so if the data we got is null, - // set use an empty string instead to ensure we generate an empty element. - - String anydata = request.getSdncServiceData(); - if (anydata == null) { - anydata = ""; - } - - // content-type is also mandatory. - - String contentType = request.getSdncServiceDataType(); - - if (contentType == null || contentType.isEmpty()) { - if (anydata.isEmpty()) { - contentType = "XML"; - } else { - if (anydata.startsWith("<")) { - contentType = "XML"; - } else { - contentType = "JSON"; - } - } - } - - addTextChild(agnosticServiceInformation, "content-type", contentType); - addTextChild(agnosticServiceInformation, "anydata", anydata); - } catch (Exception e) { - logger.error("{} {} {} {}", MessageEnum.RA_ERROR_CREATE_SDNC_REQUEST.toString(), "SDNC", - ErrorCode.BusinessProcesssError.getValue(), "Exception in genSdncReq", e); - return null; - } - - String xml; - - try { - StringWriter writer = new StringWriter(); - TransformerFactory factory = TransformerFactory.newInstance(); - factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD,""); - factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET,""); - Transformer transformer = factory.newTransformer(); - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); - transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); - transformer.transform(new DOMSource(doc), new StreamResult(writer)); - xml = writer.toString(); - } catch (Exception e) { - logger.error("{} {} {}", MessageEnum.RA_ERROR_CONVERT_XML2STR.toString(), ErrorCode.DataError.getValue(), - "Exception - domToStr", e); - return null; - } - - logger.trace("Formatted SDNC service request XML:\n {}", xml); - return xml; - } + private static final Logger logger = LoggerFactory.getLogger(SDNCServiceRequestTask.class); + + @Autowired + private SDNCServiceRequestConnector connector; + + @Autowired + MapTypedRequestTunablesData mapTunables; + + @Autowired + private BPRestCallback bpRestCallback; + + @Async + public void runRequest(SDNCServiceRequest request, String msoRequestId, String msoServiceInstanceId, + String myUrlSuffix) { + + String sdncRequestId = request.getSdncRequestId(); + String sdncService = request.getSdncService(); + String sdncOperation = request.getSdncOperation(); + + TypedRequestTunables rt = new TypedRequestTunables(sdncRequestId, myUrlSuffix); + rt.setServiceKey(sdncService, sdncOperation); + TypedRequestTunables mappedTunables; + try { + mappedTunables = mapTunables.setTunables(rt); + } catch (SDNCAdapterException e) { + bpRestCallback.send(request.getBPNotificationUrl(), e.getMessage()); + return; + } + if (!mappedTunables.getError().isEmpty()) { + // Note that the error was logged and alarmed by setTunables() + SDNCServiceError error = new SDNCServiceError(request.getSdncRequestId(), + String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR), mappedTunables.getError(), "Y"); + bpRestCallback.send(request.getBPNotificationUrl(), error.toJson()); + return; + } + + String xml = genSdncReq(request, mappedTunables); + + long sdncStartTime = System.currentTimeMillis(); + SDNCResponseCommon response = connector.send(xml, mappedTunables); + + long bpStartTime = System.currentTimeMillis(); + boolean callbackSuccess = bpRestCallback.send(request.getBPNotificationUrl(), response.toJson()); + } + + private Element addChild(Element parent, String tag) { + Element child = parent.getOwnerDocument().createElement(tag); + parent.appendChild(child); + return child; + } + + private void addTextChild(Element parent, String tag, String text) { + if (text != null) { + Element child = parent.getOwnerDocument().createElement(tag); + child.setTextContent(text); + parent.appendChild(child); + } + } + + private String genSdncReq(SDNCServiceRequest request, TypedRequestTunables rt) { + Document doc; + + try { + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); + + doc = documentBuilder.newDocument(); + Element root = doc.createElementNS(rt.getNamespace(), "input"); + doc.appendChild(root); + + Element hdr = addChild(root, rt.getHeaderName()); + addTextChild(hdr, "svc-request-id", rt.getReqId()); + addTextChild(hdr, "svc-notification-url", rt.getMyUrl()); + + RequestInformation requestInfo = request.getRequestInformation(); + Element requestInformation = addChild(root, "request-information"); + addTextChild(requestInformation, "request-id", requestInfo.getRequestId()); + + + if (requestInfo.getRequestAction() != null) { + addTextChild(requestInformation, "request-action", requestInfo.getRequestAction()); + } + if (requestInfo.getRequestSubAction() != null) { + addTextChild(requestInformation, "request-sub-action", requestInfo.getRequestSubAction()); + } + if (requestInfo.getOrderNumber() != null && !requestInfo.getOrderNumber().isEmpty()) { + addTextChild(requestInformation, "order-number", requestInfo.getOrderNumber()); + } + + if (requestInfo.getOrderVersion() != null && !requestInfo.getOrderVersion().isEmpty()) { + addTextChild(requestInformation, "order-version", requestInfo.getOrderVersion()); + } + + + addTextChild(requestInformation, "source", requestInfo.getSource()); + addTextChild(requestInformation, "notification-url", requestInfo.getNotificationUrl()); + + Element serviceInformation = addChild(root, "service-information"); + addTextChild(serviceInformation, "service-type", request.getServiceInformation().getServiceType()); + addTextChild(serviceInformation, "service-instance-id", + request.getServiceInformation().getServiceInstanceId()); + addTextChild(serviceInformation, "subscriber-name", request.getServiceInformation().getSubscriberName()); + addTextChild(serviceInformation, "subscriber-global-id", + request.getServiceInformation().getSubscriberGlobalId()); + + Element agnosticServiceInformation = addChild(root, "agnostic-service-information"); + addTextChild(agnosticServiceInformation, "operation", request.getSdncOperation()); + addTextChild(agnosticServiceInformation, "service", request.getSdncService()); + + // anydata is mandatory in the SDNC schema, so if the data we got is null, + // set use an empty string instead to ensure we generate an empty element. + + String anydata = request.getSdncServiceData(); + if (anydata == null) { + anydata = ""; + } + + // content-type is also mandatory. + + String contentType = request.getSdncServiceDataType(); + + if (contentType == null || contentType.isEmpty()) { + if (anydata.isEmpty()) { + contentType = "XML"; + } else { + if (anydata.startsWith("<")) { + contentType = "XML"; + } else { + contentType = "JSON"; + } + } + } + + addTextChild(agnosticServiceInformation, "content-type", contentType); + addTextChild(agnosticServiceInformation, "anydata", anydata); + } catch (Exception e) { + logger.error("{} {} {} {}", MessageEnum.RA_ERROR_CREATE_SDNC_REQUEST.toString(), "SDNC", + ErrorCode.BusinessProcesssError.getValue(), "Exception in genSdncReq", e); + return null; + } + + String xml; + + try { + StringWriter writer = new StringWriter(); + TransformerFactory factory = TransformerFactory.newInstance(); + factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); + factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, ""); + Transformer transformer = factory.newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); + transformer.transform(new DOMSource(doc), new StreamResult(writer)); + xml = writer.toString(); + } catch (Exception e) { + logger.error("{} {} {}", MessageEnum.RA_ERROR_CONVERT_XML2STR.toString(), ErrorCode.DataError.getValue(), + "Exception - domToStr", e); + return null; + } + + logger.trace("Formatted SDNC service request XML:\n {}", xml); + return xml; + } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SNIROResponse.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SNIROResponse.java index 96153a18fa..3921891ced 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SNIROResponse.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SNIROResponse.java @@ -31,11 +31,9 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; - import org.onap.so.adapters.sdnc.impl.Constants; import org.onap.so.logger.ErrorCode; import org.onap.so.logger.MessageEnum; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -43,39 +41,38 @@ import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; /** - * A temporary interface to support notifications from SNIRO to BPMN. - * We added this to the SDNC adapter because we didn't have time to - * develop a SNIRO adapter in 1702. + * A temporary interface to support notifications from SNIRO to BPMN. We added this to the SDNC adapter because we + * didn't have time to develop a SNIRO adapter in 1702. */ @Path("/") @Component public class SNIROResponse { - private static final Logger logger = LoggerFactory.getLogger(SNIROResponse.class); + private static final Logger logger = LoggerFactory.getLogger(SNIROResponse.class); + + + @Autowired + private Environment env; - - @Autowired - private Environment env; - - @Autowired - private BPRestCallback callback; + @Autowired + private BPRestCallback callback; - @POST - @Path("/SDNCNotify/SNIROResponse/{correlator}") - @Consumes("*/*") - @Produces({MediaType.TEXT_PLAIN}) - public Response serviceNotification(@PathParam("correlator") String correlator, String content) { - logger.info("{} {} {} {}", MessageEnum.RA_RECEIVE_SDNC_NOTIF.toString(), content, "SDNC", - "SDNCNotify/SNIROResponse"); + @POST + @Path("/SDNCNotify/SNIROResponse/{correlator}") + @Consumes("*/*") + @Produces({MediaType.TEXT_PLAIN}) + public Response serviceNotification(@PathParam("correlator") String correlator, String content) { + logger.info("{} {} {} {}", MessageEnum.RA_RECEIVE_SDNC_NOTIF.toString(), content, "SDNC", + "SDNCNotify/SNIROResponse"); - String bpUrl = env.getProperty(Constants.BPEL_REST_URL_PROP, ""); + String bpUrl = env.getProperty(Constants.BPEL_REST_URL_PROP, ""); - if (bpUrl == null || ("").equals(bpUrl)) { - String error = "Missing configuration for: " + Constants.BPEL_REST_URL_PROP; - logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), Constants.BPEL_REST_URL_PROP, - "SDNC", ErrorCode.DataError.getValue(), "Missing config param"); + if (bpUrl == null || ("").equals(bpUrl)) { + String error = "Missing configuration for: " + Constants.BPEL_REST_URL_PROP; + logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), + Constants.BPEL_REST_URL_PROP, "SDNC", ErrorCode.DataError.getValue(), "Missing config param"); - return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity(error).build(); - } - return Response.status(204).build(); - } + return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity(error).build(); + } + return Response.status(204).build(); + } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/TypedRequestTunables.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/TypedRequestTunables.java index 4ff6dbc9a6..6fb69af85a 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/TypedRequestTunables.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/TypedRequestTunables.java @@ -28,156 +28,161 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Typed Request Tunables. Each entry is identified by a TYPE in the property name. - * Different types can have different keys. + * Typed Request Tunables. Each entry is identified by a TYPE in the property name. Different types can have different + * keys. * <p> * General format: + * * <pre> * org.onap.so.adapters.sdnc.TYPE.KEY1[.KEY2...]=METHOD|TIMEOUT|URL|HEADER|NAMESPACE * </pre> + * * Currently supported type(s): service + * * <pre> - * org.onap.so.adapters.sdnc.service.SERVICE.OPERATION=METHOD|TIMEOUT|URL|HEADER|NAMESPACE + * org.onap.so.adapters.sdnc.service.SERVICE.OPERATION = METHOD | TIMEOUT | URL | HEADER | NAMESPACE * </pre> */ -public class TypedRequestTunables { - - private static final Logger logger = LoggerFactory.getLogger(TypedRequestTunables.class); - - private String reqId; - private String myUrlSuffix; - private String key = null; - private String error = ""; - - // tunables (all are required) - private String reqMethod = null; - private String timeout = null; - private String sdncUrl = null; - private String headerName = null; - private String namespace = null; - private String myUrl = null; - - public TypedRequestTunables(TypedRequestTunables reqTunableOriginal) { - this.reqId = reqTunableOriginal.getReqId(); - this.myUrlSuffix = reqTunableOriginal.getMyUrlSuffix(); - this.key = reqTunableOriginal.getKey(); - this.error = reqTunableOriginal.getError(); - this.reqMethod = reqTunableOriginal.getReqMethod(); - this.timeout = reqTunableOriginal.getTimeout(); - this.sdncUrl = reqTunableOriginal.getSdncUrl(); - this.headerName = reqTunableOriginal.getHeaderName(); - this.namespace = reqTunableOriginal.getNamespace(); - this.myUrl = reqTunableOriginal.getMyUrl(); - } - - public TypedRequestTunables(String reqId, String myUrlSuffix) { - this.reqId = reqId; - this.myUrlSuffix = myUrlSuffix; - } - - /** - * Sets the key for a service request: - * <pre> - * org.onap.so.adapters.sdnc.service.SERVICE.OPERATION - * </pre> - * @param service the sdncService - * @param operation the sdncOperation - */ - public void setServiceKey(String service, String operation) { - key = Constants.REQUEST_TUNABLES + ".service." + service + "." + operation; - logger.debug("Generated {} key: {}", getClass().getSimpleName(), key); - } - - /** - * Gets the SDNC request ID. - */ - public String getReqId() { - return reqId; - } - - /** - * Gets the generated key. - */ - public String getKey() { - return key; - } - - /** - * Gets the most recent error, or null if there was no error. - */ - public String getError() { - return error; - } - - public String getReqMethod() { - return reqMethod; - } - - public String getTimeout() { - return timeout; - } - - public String getSdncUrl() { - return sdncUrl; - } - - public String getHeaderName() { - return headerName; - } - - public String getNamespace() { - return namespace; - } - - /** - * Gets the SDNC adapter notification URL, trimmed of trailing '/' characters. - */ - public String getMyUrl() { - return myUrl; - } - - public String getMyUrlSuffix() { - return myUrlSuffix; - } - - public void setKey(String key) { - this.key = key; - } - - public void setError(String error) { - this.error = error; - } - - public void setReqMethod(String reqMethod) { - this.reqMethod = reqMethod; - } - - public void setTimeout(String timeout) { - this.timeout = timeout; - } - - public void setSdncUrl(String sdncUrl) { - this.sdncUrl = sdncUrl; - } - - public void setHeaderName(String headerName) { - this.headerName = headerName; - } - - public void setNamespace(String namespace) { - this.namespace = namespace; - } - - public void setMyUrl(String myUrl) { - this.myUrl = myUrl; - } - - @Override - public String toString() { - return new ToStringBuilder(this).append("reqId", reqId).append("myUrlSuffix", myUrlSuffix).append("key", key) - .append("error", error).append("reqMethod", reqMethod).append("timeout", timeout) - .append("sdncUrl", sdncUrl).append("headerName", headerName).append("namespace", namespace) - .append("myUrl", myUrl).toString(); - } - +public class TypedRequestTunables { + + private static final Logger logger = LoggerFactory.getLogger(TypedRequestTunables.class); + + private String reqId; + private String myUrlSuffix; + private String key = null; + private String error = ""; + + // tunables (all are required) + private String reqMethod = null; + private String timeout = null; + private String sdncUrl = null; + private String headerName = null; + private String namespace = null; + private String myUrl = null; + + public TypedRequestTunables(TypedRequestTunables reqTunableOriginal) { + this.reqId = reqTunableOriginal.getReqId(); + this.myUrlSuffix = reqTunableOriginal.getMyUrlSuffix(); + this.key = reqTunableOriginal.getKey(); + this.error = reqTunableOriginal.getError(); + this.reqMethod = reqTunableOriginal.getReqMethod(); + this.timeout = reqTunableOriginal.getTimeout(); + this.sdncUrl = reqTunableOriginal.getSdncUrl(); + this.headerName = reqTunableOriginal.getHeaderName(); + this.namespace = reqTunableOriginal.getNamespace(); + this.myUrl = reqTunableOriginal.getMyUrl(); + } + + public TypedRequestTunables(String reqId, String myUrlSuffix) { + this.reqId = reqId; + this.myUrlSuffix = myUrlSuffix; + } + + /** + * Sets the key for a service request: + * + * <pre> + * org.onap.so.adapters.sdnc.service.SERVICE.OPERATION + * </pre> + * + * @param service the sdncService + * @param operation the sdncOperation + */ + public void setServiceKey(String service, String operation) { + key = Constants.REQUEST_TUNABLES + ".service." + service + "." + operation; + logger.debug("Generated {} key: {}", getClass().getSimpleName(), key); + } + + /** + * Gets the SDNC request ID. + */ + public String getReqId() { + return reqId; + } + + /** + * Gets the generated key. + */ + public String getKey() { + return key; + } + + /** + * Gets the most recent error, or null if there was no error. + */ + public String getError() { + return error; + } + + public String getReqMethod() { + return reqMethod; + } + + public String getTimeout() { + return timeout; + } + + public String getSdncUrl() { + return sdncUrl; + } + + public String getHeaderName() { + return headerName; + } + + public String getNamespace() { + return namespace; + } + + /** + * Gets the SDNC adapter notification URL, trimmed of trailing '/' characters. + */ + public String getMyUrl() { + return myUrl; + } + + public String getMyUrlSuffix() { + return myUrlSuffix; + } + + public void setKey(String key) { + this.key = key; + } + + public void setError(String error) { + this.error = error; + } + + public void setReqMethod(String reqMethod) { + this.reqMethod = reqMethod; + } + + public void setTimeout(String timeout) { + this.timeout = timeout; + } + + public void setSdncUrl(String sdncUrl) { + this.sdncUrl = sdncUrl; + } + + public void setHeaderName(String headerName) { + this.headerName = headerName; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + public void setMyUrl(String myUrl) { + this.myUrl = myUrl; + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("reqId", reqId).append("myUrlSuffix", myUrlSuffix).append("key", key) + .append("error", error).append("reqMethod", reqMethod).append("timeout", timeout) + .append("sdncUrl", sdncUrl).append("headerName", headerName).append("namespace", namespace) + .append("myUrl", myUrl).toString(); + } + } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/util/SDNCRequestIdUtil.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/util/SDNCRequestIdUtil.java index 991126f868..ccf3c8df82 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/util/SDNCRequestIdUtil.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/util/SDNCRequestIdUtil.java @@ -22,18 +22,20 @@ package org.onap.so.adapters.sdnc.util; public class SDNCRequestIdUtil { - // Add private constructor to prevent instance creation. - private SDNCRequestIdUtil () {} + // Add private constructor to prevent instance creation. + private SDNCRequestIdUtil() {} - public static String getSDNCOriginalRequestId (String newRequestId) { - - // Camunda scripts will add postfix, such as -1, -2, on the original requestID, to make sure requestID is unique while sending request to SDNC - // In order to use the unique requestID in logging, need to remove the postfix added by the Camunda scripts - // Verify whether the requestId is a valid UUID with postfix (-1, -2). If yes, it should contain 5 times char '-', since valid UUID contains 4 times '-' - // If the requestId is not a valid UUID with postfix, we do nothing - if (newRequestId.split("-").length == 6) { - return newRequestId.substring(0, newRequestId.lastIndexOf('-')); - } - return newRequestId; + public static String getSDNCOriginalRequestId(String newRequestId) { + + // Camunda scripts will add postfix, such as -1, -2, on the original requestID, to make sure requestID is unique + // while sending request to SDNC + // In order to use the unique requestID in logging, need to remove the postfix added by the Camunda scripts + // Verify whether the requestId is a valid UUID with postfix (-1, -2). If yes, it should contain 5 times char + // '-', since valid UUID contains 4 times '-' + // If the requestId is not a valid UUID with postfix, we do nothing + if (newRequestId.split("-").length == 6) { + return newRequestId.substring(0, newRequestId.lastIndexOf('-')); + } + return newRequestId; } } |