diff options
Diffstat (limited to 'bpmn')
11 files changed, 136 insertions, 72 deletions
diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy index 3438c7957c..235b6219d1 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy @@ -22,7 +22,6 @@ package org.onap.so.bpmn.common.scripts import static org.mockito.Mockito.* - import org.camunda.bpm.engine.ProcessEngineServices import org.camunda.bpm.engine.RepositoryService import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity @@ -48,10 +47,10 @@ public class SDNCAdapterTest { } - String workflowResponse = """<sdncadapterworkflow:SDNCAdapterWorkflowResponse xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1" + String workflowResponse = """<sdncadapterworkflow:SDNCAdapterWorkflowResponse xmlns="com:att:sdnctl:l3api" + xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1" xmlns:tag0="http://org.onap/workflow/sdnc/adapter/schema/v1" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="com:att:sdnctl:l3api"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <sdncadapterworkflow:response-data> <tag0:CallbackHeader> <tag0:RequestId>testRequestId</tag0:RequestId> diff --git a/bpmn/MSOCommonBPMN/src/test/resources/logback-test.xml b/bpmn/MSOCommonBPMN/src/test/resources/logback-test.xml index 9088d1a844..90f73dc419 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/logback-test.xml +++ b/bpmn/MSOCommonBPMN/src/test/resources/logback-test.xml @@ -24,7 +24,7 @@ <root level="WARN"> <appender-ref ref="STDOUT" /> </root> - + <logger name="org.reflections" level="ERROR" /> <logger name="wiremock.org" level="ERROR" /> </configuration>
\ No newline at end of file diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/xml/XmlTool.java b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/xml/XmlTool.java index da096e5461..79a4c54e23 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/xml/XmlTool.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/xml/XmlTool.java @@ -49,6 +49,7 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import org.apache.commons.lang3.StringEscapeUtils; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -87,44 +88,47 @@ public final class XmlTool { * @throws SAXException * @throws XPathExpressionException */ - public static String normalize(Object xml) throws IOException, TransformerException, ParserConfigurationException, - SAXException, XPathExpressionException { + public static String normalize(final Object xml) throws IOException, TransformerException, + ParserConfigurationException, SAXException, XPathExpressionException { if (xml == null) { return null; } - Source xsltSource = new StreamSource(new StringReader(readResourceFile("normalize-namespaces.xsl"))); + final Source xsltSource = new StreamSource(new StringReader(readResourceFile("normalize-namespaces.xsl"))); - DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); dbFactory.setNamespaceAware(true); dbFactory.setFeature("http://xml.org/sax/features/external-general-entities", false); dbFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); - DocumentBuilder db = dbFactory.newDocumentBuilder(); - InputSource source = new InputSource(new StringReader(String.valueOf(xml))); - Document doc = db.parse(source); + final DocumentBuilder db = dbFactory.newDocumentBuilder(); + final InputSource source = new InputSource(new StringReader(String.valueOf(xml))); + final Document doc = db.parse(source); // Start of code to remove whitespace outside of tags - XPath xPath = XPathFactory.newInstance().newXPath(); - NodeList nodeList = (NodeList) xPath.evaluate("//text()[normalize-space()='']", doc, XPathConstants.NODESET); + final XPath xPath = XPathFactory.newInstance().newXPath(); + final NodeList nodeList = + (NodeList) xPath.evaluate("//text()[normalize-space()='']", doc, XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); ++i) { - Node node = nodeList.item(i); + final Node node = nodeList.item(i); node.getParentNode().removeChild(node); } // End of code to remove whitespace outside of tags // the factory pattern supports different XSLT processors - TransformerFactory transformerFactory = TransformerFactory.newInstance(); + final TransformerFactory transformerFactory = TransformerFactory.newInstance(); + transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, StringUtils.EMPTY); + transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, StringUtils.EMPTY); transformerFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); - Transformer transformer = transformerFactory.newTransformer(xsltSource); + final Transformer transformer = transformerFactory.newTransformer(xsltSource); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); - StringWriter writer = new StringWriter(); + final StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(doc), new StreamResult(writer)); return writer.toString().trim(); } @@ -220,7 +224,7 @@ public final class XmlTool { * @return the contents of the modified XML document as a String or null/empty if the modification failed. * @throws IOException, TransformerException, ParserConfigurationException, SAXException */ - public static Optional<String> modifyElement(String xml, String elementTag, String newValue) + public static Optional<String> modifyElement(final String xml, final String elementTag, final String newValue) throws IOException, TransformerException, ParserConfigurationException, SAXException { if (xml == null || xml.isEmpty()) { @@ -228,15 +232,15 @@ public final class XmlTool { return Optional.empty(); } - DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); dbFactory.setNamespaceAware(true); dbFactory.setFeature("http://xml.org/sax/features/external-general-entities", false); dbFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); - DocumentBuilder db = dbFactory.newDocumentBuilder(); - InputSource source = new InputSource(new StringReader(xml)); - Document doc = db.parse(source); + final DocumentBuilder db = dbFactory.newDocumentBuilder(); + final InputSource source = new InputSource(new StringReader(xml)); + final Document doc = db.parse(source); - Node modNode = doc.getElementsByTagName(elementTag).item(0); + final Node modNode = doc.getElementsByTagName(elementTag).item(0); if (modNode == null) { // did not find the specified element to be modified, return empty // System.out.println("Did not find element tag " + elementTag + " in XML"); @@ -245,9 +249,12 @@ public final class XmlTool { modNode.setTextContent(newValue); } - TransformerFactory transformerFactory = TransformerFactory.newInstance(); - Transformer transformer = transformerFactory.newTransformer(); - StringWriter writer = new StringWriter(); + final TransformerFactory transformerFactory = TransformerFactory.newInstance(); + transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, StringUtils.EMPTY); + transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, StringUtils.EMPTY); + + final Transformer transformer = transformerFactory.newTransformer(); + final StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(doc), new StreamResult(writer)); // return the modified String representation of the XML return Optional.of(writer.toString().trim()); diff --git a/bpmn/MSOCoreBPMN/src/test/resources/logback-test.xml b/bpmn/MSOCoreBPMN/src/test/resources/logback-test.xml index 02ac437db6..20b0dce748 100644 --- a/bpmn/MSOCoreBPMN/src/test/resources/logback-test.xml +++ b/bpmn/MSOCoreBPMN/src/test/resources/logback-test.xml @@ -18,33 +18,34 @@ ============LICENSE_END========================================================= --> -<configuration > - - - <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> - <encoder> - <pattern>%d{MM/dd-HH:mm:ss.SSS}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}||%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}||%X{Timer}|%msg%n</pattern> - </encoder> - </appender> +<configuration> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%d{MM/dd-HH:mm:ss.SSS}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}||%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}||%X{Timer}|%msg%n + </pattern> + </encoder> + </appender> - <logger name="com.att.eelf.audit" level="info" additivity="false"> - <appender-ref ref="STDOUT" /> - </logger> - - <logger name="com.att.eelf.metrics" level="info" additivity="false"> + <logger name="com.att.eelf.audit" level="info" additivity="false"> + <appender-ref ref="STDOUT" /> + </logger> + + <logger name="com.att.eelf.metrics" level="info" additivity="false"> <appender-ref ref="STDOUT" /> - </logger> + </logger> - <logger name="com.att.eelf.error" level="trace" additivity="false"> - <appender-ref ref="STDOUT" /> - </logger> - <logger name="org.onap" level="${so.log.level:-DEBUG}" additivity="false"> - <appender-ref ref="STDOUT" /> - </logger> - <root level="info"> - <appender-ref ref="STDOUT" /> - </root> - + <logger name="com.att.eelf.error" level="trace" additivity="false"> + <appender-ref ref="STDOUT" /> + </logger> + <logger name="org.onap" level="${so.log.level:-DEBUG}" additivity="false"> + <appender-ref ref="STDOUT" /> + </logger> + + <logger name="org.reflections" level="ERROR" /> + + <root level="info"> + <appender-ref ref="STDOUT" /> + </root> </configuration> diff --git a/bpmn/pom.xml b/bpmn/pom.xml index 33c0415d9d..6a61ed1df3 100644 --- a/bpmn/pom.xml +++ b/bpmn/pom.xml @@ -15,7 +15,7 @@ <camunda.bpm.assert.version>1.2</camunda.bpm.assert.version> <h2.version>1.4.196</h2.version> <groovy.version>2.5.3</groovy.version> - <saxon.version>9.5.1-8</saxon.version> + <saxon.version>10.5</saxon.version> <xmlunit.version>2.4.0</xmlunit.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> diff --git a/bpmn/so-bpmn-building-blocks/src/test/resources/logback-test.xml b/bpmn/so-bpmn-building-blocks/src/test/resources/logback-test.xml index c080bc90f8..c0b24d9680 100644 --- a/bpmn/so-bpmn-building-blocks/src/test/resources/logback-test.xml +++ b/bpmn/so-bpmn-building-blocks/src/test/resources/logback-test.xml @@ -27,5 +27,6 @@ </root> <logger name="wiremock.org" level="DEBUG" /> + <logger name="org.reflections" level="ERROR" /> </configuration>
\ No newline at end of file diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/resources/logback-test.xml b/bpmn/so-bpmn-infrastructure-common/src/test/resources/logback-test.xml index 38a2ef6ef5..7a8d2a122c 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/resources/logback-test.xml +++ b/bpmn/so-bpmn-infrastructure-common/src/test/resources/logback-test.xml @@ -1,7 +1,5 @@ <configuration> - - <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] |%X{RequestId}| %-5level @@ -10,7 +8,6 @@ </encoder> </appender> - <logger name="com.att.ecomp.audit" level="info" additivity="false"> <appender-ref ref="STDOUT" /> </logger> @@ -26,19 +23,19 @@ <logger name="org.onap" level="${so.log.level:-DEBUG}" additivity="false"> <appender-ref ref="STDOUT" /> </logger> - <logger name="ch.vorburger" level="WARN" additivity="false"> <appender-ref ref="STDOUT" /> </logger> - - <logger name="AUDIT" level="info" additivity="true"> + + <logger name="AUDIT" level="info" additivity="true"> <appender-ref ref="STDOUT" /> </logger> + <logger name="org.reflections" level="ERROR" /> + <root level="WARN"> <appender-ref ref="STDOUT" /> </root> - </configuration>
\ No newline at end of file diff --git a/bpmn/so-bpmn-infrastructure-flows/src/test/resources/logback-test.xml b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/logback-test.xml index 3b0bdb252f..6fbf09ec4a 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/test/resources/logback-test.xml +++ b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/logback-test.xml @@ -45,6 +45,8 @@ <logger name="AUDIT" level="info" additivity="true"> <appender-ref ref="STDOUT"/> </logger> + + <logger name="org.reflections" level="ERROR" /> <!-- suppress the amount of org.apache.tomcat.util.net.NioEndpoint log--> <logger name="org.apache.tomcat" level="WARN" /> diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImpl.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImpl.java index 8e6e8678ed..7c6473f79d 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImpl.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImpl.java @@ -2,12 +2,15 @@ package org.onap.so.bpmn.infrastructure.adapter.network.tasks; import java.io.ByteArrayInputStream; import java.io.StringReader; +import java.nio.charset.StandardCharsets; import java.util.Optional; +import javax.xml.XMLConstants; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; +import org.apache.commons.lang3.StringUtils; import org.onap.so.adapters.nwrest.CreateNetworkResponse; import org.onap.so.adapters.nwrest.DeleteNetworkResponse; import org.onap.so.adapters.nwrest.UpdateNetworkResponse; @@ -22,6 +25,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.w3c.dom.Document; @Component public class NetworkAdapterImpl { @@ -80,14 +84,16 @@ public class NetworkAdapterImpl { return unmarshaller.unmarshal(reader); } - protected Optional<String> findResponseType(String xmlString) { + protected Optional<String> findResponseType(final String xmlString) { try { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - org.w3c.dom.Document doc; - doc = builder.parse(new ByteArrayInputStream(xmlString.getBytes("UTF-8"))); + final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, StringUtils.EMPTY); + factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, StringUtils.EMPTY); + + final DocumentBuilder builder = factory.newDocumentBuilder(); + final Document doc = builder.parse(new ByteArrayInputStream(xmlString.getBytes(StandardCharsets.UTF_8))); return Optional.of(doc.getDocumentElement().getNodeName()); - } catch (Exception e) { + } catch (final Exception e) { logger.error("Error Finding Response Type", e); return Optional.empty(); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java index e55fa9e24b..7ed8447fa6 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java @@ -22,6 +22,7 @@ package org.onap.so.bpmn.infrastructure.sdnc.tasks; import java.io.StringReader; import java.io.StringWriter; +import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Transformer; @@ -30,14 +31,15 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathFactory; +import org.apache.commons.lang3.StringUtils; import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.logging.filter.base.ONAPComponents; import org.onap.so.bpmn.infrastructure.sdnc.exceptions.SDNCErrorResponseException; import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.exception.MapperException; import org.onap.so.client.sdnc.SDNCClient; import org.onap.so.client.sdnc.beans.SDNCRequest; -import org.onap.logging.filter.base.ONAPComponents; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -47,10 +49,17 @@ import org.w3c.dom.Document; import org.xml.sax.InputSource; import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.PathNotFoundException; +import net.sf.saxon.lib.NamespaceConstant; +import net.sf.saxon.xpath.XPathFactoryImpl; @Component public class SDNCRequestTasks { + private static final String NET_SF_SAXON_XPATH_IMPL = "net.sf.saxon.xpath.XPathFactoryImpl"; + + private static final String XPATH_FACTORY_PROPERTY_NAME = + "javax.xml.xpath.XPathFactory:" + NamespaceConstant.OBJECT_MODEL_SAXON; + private static final Logger logger = LoggerFactory.getLogger(SDNCRequestTasks.class); private static final String SDNC_REQUEST = "SDNCRequest"; @@ -143,14 +152,20 @@ public class SDNCRequestTasks { return "Y".equals(finalMessageIndicator); } - protected String getXmlElement(Document doc, String exp) throws Exception { - TransformerFactory tf = TransformerFactory.newInstance(); - Transformer transformer = tf.newTransformer(); - StringWriter writer = new StringWriter(); + protected String getXmlElement(final Document doc, final String exp) throws Exception { + final TransformerFactory factory = TransformerFactory.newInstance(); + factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, StringUtils.EMPTY); + factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, StringUtils.EMPTY); + + final Transformer transformer = factory.newTransformer(); + final StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(doc), new StreamResult(writer)); logger.debug(writer.getBuffer().toString()); - XPath xPath = XPathFactory.newInstance().newXPath(); - String result = xPath.evaluate(exp, doc); + + System.setProperty(XPATH_FACTORY_PROPERTY_NAME, NET_SF_SAXON_XPATH_IMPL); + final XPathFactory xPathFactory = XPathFactoryImpl.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON); + final XPath xPath = xPathFactory.newXPath(); + final String result = xPath.evaluate(exp, doc); if (result == null || result.isEmpty()) { throw new Exception("XPath Failed to find element expression: " + exp); } diff --git a/bpmn/so-bpmn-tasks/src/test/resources/logback-test.xml b/bpmn/so-bpmn-tasks/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..bb4aee6e05 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/logback-test.xml @@ -0,0 +1,36 @@ +<!-- + ============LICENSE_START======================================================= + ONAP - SO + ================================================================================ + Copyright (C) 2021 Nordix Foundation. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + SPDX-License-Identifier: Apache-2.0 + ============LICENSE_END========================================================= +--> +<configuration> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{1024} - %msg%n + </pattern> + </encoder> + </appender> + + <logger name="org.reflections" level="ERROR" /> + <logger name="org.onap" level="DEBUG" /> + + <root level="INFO"> + <appender-ref ref="STDOUT" /> + </root> +</configuration> |