1
1
// Copyright (c) 2019, 2020, Oracle Corporation and/or its affiliates.
2
2
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3
3
4
- package com .oracle .weblogic .imagetool .util ;
4
+ package com .oracle .weblogic .imagetool .aru ;
5
5
6
6
import java .io .IOException ;
7
- import javax .xml .XMLConstants ;
8
- import javax .xml .parsers .DocumentBuilder ;
9
- import javax .xml .parsers .DocumentBuilderFactory ;
10
7
import javax .xml .parsers .ParserConfigurationException ;
11
8
import javax .xml .xpath .XPathExpressionException ;
12
9
13
- import com .oracle .weblogic .imagetool .installer .AruProduct ;
10
+ import com .oracle .weblogic .imagetool .util .HttpUtil ;
11
+ import com .oracle .weblogic .imagetool .util .XPathUtil ;
14
12
import org .w3c .dom .Document ;
15
13
import org .w3c .dom .Element ;
16
14
import org .w3c .dom .Node ;
@@ -171,7 +169,7 @@ AruHttpHelper execValidation(String url, String payload) throws IOException {
171
169
AruHttpHelper validation () throws IOException {
172
170
NodeList conflictSets ;
173
171
try {
174
- conflictSets = XPathUtil .applyXPathReturnNodeList (results (),
172
+ conflictSets = XPathUtil .nodelist (results (),
175
173
"/conflict_check/conflict_sets/set" );
176
174
} catch (XPathExpressionException xee ) {
177
175
throw new IOException (xee );
@@ -181,7 +179,7 @@ AruHttpHelper validation() throws IOException {
181
179
success = false ;
182
180
String expression = "/conflict_check/conflict_sets/set/merge_patches" ;
183
181
184
- NodeList nodeList = XPathUtil .applyXPathReturnNodeList (results (), expression );
182
+ NodeList nodeList = XPathUtil .nodelist (results (), expression );
185
183
186
184
createResultDocument (nodeList );
187
185
@@ -203,15 +201,7 @@ AruHttpHelper validation() throws IOException {
203
201
*/
204
202
AruHttpHelper createResultDocument (NodeList nodeList ) throws IOException {
205
203
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 ();
215
205
Element element = doc .createElement ("results" );
216
206
217
207
for (int i = 0 ; i < nodeList .getLength (); i ++) {
@@ -242,11 +232,11 @@ private String parsePatchValidationError() {
242
232
Node conflictsResultNode = results ();
243
233
if (conflictsResultNode != null ) {
244
234
try {
245
- NodeList patchSets = XPathUtil .applyXPathReturnNodeList (conflictsResultNode , "//merge_patches" );
235
+ NodeList patchSets = XPathUtil .nodelist (conflictsResultNode , "//merge_patches" );
246
236
stringBuilder .append ("patch conflicts detected: " );
247
237
for (int i = 0 ; i < patchSets .getLength (); i ++) {
248
238
stringBuilder .append ("[" );
249
- NodeList bugNumbers = XPathUtil .applyXPathReturnNodeList (patchSets .item (i ), "patch/bug/number"
239
+ NodeList bugNumbers = XPathUtil .nodelist (patchSets .item (i ), "patch/bug/number"
250
240
+ "/text()" );
251
241
for (int j = 0 ; j < bugNumbers .getLength (); j ++) {
252
242
stringBuilder .append (bugNumbers .item (j ).getNodeValue ());
@@ -267,10 +257,10 @@ private String parsePatchValidationError() {
267
257
private void searchResult (Document result ) throws IOException {
268
258
success = true ;
269
259
try {
270
- NodeList nodeList = XPathUtil .applyXPathReturnNodeList (result , "/results/error" );
260
+ NodeList nodeList = XPathUtil .nodelist (result , "/results/error" );
271
261
if (nodeList .getLength () > 0 ) {
272
262
success = false ;
273
- errorMessage = XPathUtil .applyXPathReturnString (result , "/results/error/message" );
263
+ errorMessage = XPathUtil .string (result , "/results/error/message" );
274
264
} else {
275
265
results = result ;
276
266
}
0 commit comments