diff options
author | waqas.ikram <waqas.ikram@est.tech> | 2021-06-25 13:21:15 +0100 |
---|---|---|
committer | waqas.ikram <waqas.ikram@est.tech> | 2021-06-28 13:04:54 +0100 |
commit | d18c3bbbdb56f2f55926e01101a570f39dbaff6a (patch) | |
tree | 316c395ba33d6cc18ce4ff638d9163d5456a9826 /bpmn/so-bpmn-tasks/src | |
parent | 6a5b05fa3b21085ef21c37db2ea3d29275b87191 (diff) |
Fixing XML parsers sonar issue
Change-Id: Id67c01bbe19057902127e8a66ba0382589789537
Issue-ID: SO-3665
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
Diffstat (limited to 'bpmn/so-bpmn-tasks/src')
-rw-r--r-- | bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java | 24 |
1 files changed, 17 insertions, 7 deletions
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..5b40768573 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 @@ -31,13 +31,13 @@ import javax.xml.transform.stream.StreamResult; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathFactory; 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 +47,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 +150,17 @@ 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 tf = TransformerFactory.newInstance(); + final Transformer transformer = tf.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); } |