11// Copyright (c) 2019, 2020, Oracle Corporation and/or its affiliates.
22// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33
4- package com .oracle .weblogic .imagetool .util ;
4+ package com .oracle .weblogic .imagetool .aru ;
55
66import java .io .IOException ;
7- import javax .xml .XMLConstants ;
8- import javax .xml .parsers .DocumentBuilder ;
9- import javax .xml .parsers .DocumentBuilderFactory ;
107import javax .xml .parsers .ParserConfigurationException ;
118import javax .xml .xpath .XPathExpressionException ;
129
13- import com .oracle .weblogic .imagetool .installer .AruProduct ;
10+ import com .oracle .weblogic .imagetool .util .HttpUtil ;
11+ import com .oracle .weblogic .imagetool .util .XPathUtil ;
1412import org .w3c .dom .Document ;
1513import org .w3c .dom .Element ;
1614import org .w3c .dom .Node ;
@@ -171,7 +169,7 @@ AruHttpHelper execValidation(String url, String payload) throws IOException {
171169 AruHttpHelper validation () throws IOException {
172170 NodeList conflictSets ;
173171 try {
174- conflictSets = XPathUtil .applyXPathReturnNodeList (results (),
172+ conflictSets = XPathUtil .nodelist (results (),
175173 "/conflict_check/conflict_sets/set" );
176174 } catch (XPathExpressionException xee ) {
177175 throw new IOException (xee );
@@ -181,7 +179,7 @@ AruHttpHelper validation() throws IOException {
181179 success = false ;
182180 String expression = "/conflict_check/conflict_sets/set/merge_patches" ;
183181
184- NodeList nodeList = XPathUtil .applyXPathReturnNodeList (results (), expression );
182+ NodeList nodeList = XPathUtil .nodelist (results (), expression );
185183
186184 createResultDocument (nodeList );
187185
@@ -203,15 +201,7 @@ AruHttpHelper validation() throws IOException {
203201 */
204202 AruHttpHelper createResultDocument (NodeList nodeList ) throws IOException {
205203 try {
206- DocumentBuilderFactory dbf = DocumentBuilderFactory .newInstance ();
207-
208- // Prevent XXE attacks
209- dbf .setFeature ("http://apache.org/xml/features/disallow-doctype-decl" , true );
210- dbf .setAttribute (XMLConstants .ACCESS_EXTERNAL_DTD , "" );
211- dbf .setAttribute (XMLConstants .ACCESS_EXTERNAL_SCHEMA , "" );
212-
213- DocumentBuilder builder = dbf .newDocumentBuilder ();
214- Document doc = builder .newDocument ();
204+ Document doc = HttpUtil .documentBuilder ().newDocument ();
215205 Element element = doc .createElement ("results" );
216206
217207 for (int i = 0 ; i < nodeList .getLength (); i ++) {
@@ -242,11 +232,11 @@ private String parsePatchValidationError() {
242232 Node conflictsResultNode = results ();
243233 if (conflictsResultNode != null ) {
244234 try {
245- NodeList patchSets = XPathUtil .applyXPathReturnNodeList (conflictsResultNode , "//merge_patches" );
235+ NodeList patchSets = XPathUtil .nodelist (conflictsResultNode , "//merge_patches" );
246236 stringBuilder .append ("patch conflicts detected: " );
247237 for (int i = 0 ; i < patchSets .getLength (); i ++) {
248238 stringBuilder .append ("[" );
249- NodeList bugNumbers = XPathUtil .applyXPathReturnNodeList (patchSets .item (i ), "patch/bug/number"
239+ NodeList bugNumbers = XPathUtil .nodelist (patchSets .item (i ), "patch/bug/number"
250240 + "/text()" );
251241 for (int j = 0 ; j < bugNumbers .getLength (); j ++) {
252242 stringBuilder .append (bugNumbers .item (j ).getNodeValue ());
@@ -267,10 +257,10 @@ private String parsePatchValidationError() {
267257 private void searchResult (Document result ) throws IOException {
268258 success = true ;
269259 try {
270- NodeList nodeList = XPathUtil .applyXPathReturnNodeList (result , "/results/error" );
260+ NodeList nodeList = XPathUtil .nodelist (result , "/results/error" );
271261 if (nodeList .getLength () > 0 ) {
272262 success = false ;
273- errorMessage = XPathUtil .applyXPathReturnString (result , "/results/error/message" );
263+ errorMessage = XPathUtil .string (result , "/results/error/message" );
274264 } else {
275265 results = result ;
276266 }
0 commit comments