Skip to content

Commit 2c86ad2

Browse files
authored
Merge pull request #257 from Esri/3.0_fixes
Reverted some security fix as it broke harvesting
2 parents 939dcea + c74b659 commit 2c86ad2

File tree

1 file changed

+12
-32
lines changed
  • geoportal-commons/geoportal-commons-csw-client/src/main/java/com/esri/geoportal/commons/csw/client/impl

1 file changed

+12
-32
lines changed

geoportal-commons/geoportal-commons-csw-client/src/main/java/com/esri/geoportal/commons/csw/client/impl/Client.java

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.time.ZonedDateTime;
3838
import java.time.format.DateTimeFormatter;
3939
import java.util.ArrayList;
40+
import java.util.Arrays;
4041
import java.util.Date;
4142
import java.util.List;
4243
import java.util.regex.Matcher;
@@ -131,8 +132,7 @@ public IRecords findRecords(int start, int max, Date from, Date to, String searc
131132
HttpPost post = createRecordsPostRequest(capabilites.get_getRecordsPostURL(), requestBody);
132133

133134
HttpClientContext context = cred!=null && !cred.isEmpty()? createHttpClientContext(baseUrl, cred): null;
134-
try (CloseableHttpResponse httpResponse = httpClient.execute(post,context);
135-
InputStream responseInputStream = httpResponse.getEntity().getContent();) {
135+
try (CloseableHttpResponse httpResponse = httpClient.execute(post,context); InputStream responseInputStream = httpResponse.getEntity().getContent();) {
136136
if (httpResponse.getStatusLine().getStatusCode()>=400) {
137137
throw new HttpResponseException(httpResponse.getStatusLine().getStatusCode(), httpResponse.getStatusLine().getReasonPhrase());
138138
}
@@ -167,16 +167,7 @@ public String readMetadata(String id) throws Exception {
167167

168168
// perform transformation
169169
StringWriter writer = new StringWriter();
170-
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
171-
builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
172-
builderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
173-
builderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
174-
builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
175-
builderFactory.setXIncludeAware(false);
176-
builderFactory.setExpandEntityReferences(false);
177-
DocumentBuilder builder = builderFactory.newDocumentBuilder();
178-
Document inputDoc = builder.parse(contentStream);
179-
transformer.transform(new DOMSource(inputDoc), new StreamResult(writer));
170+
transformer.transform(new StreamSource(contentStream), new StreamResult(writer));
180171

181172
String intermediateResult = writer.toString();
182173

@@ -316,32 +307,21 @@ private List<IRecord> readRecords(InputStream contentStream) throws IOException,
316307

317308
// perform transformation
318309
StringWriter writer = new StringWriter();
319-
320-
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
321-
builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
322-
builderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
323-
builderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
324-
builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
325-
builderFactory.setXIncludeAware(false);
326-
builderFactory.setExpandEntityReferences(false);
327-
DocumentBuilder builder = builderFactory.newDocumentBuilder();
328-
Document inputDoc = builder.parse(contentStream);
329-
330-
transformer.transform(new DOMSource(inputDoc), new StreamResult(writer));
310+
transformer.transform(new StreamSource(contentStream), new StreamResult(writer));
331311

332312
LOG.trace(String.format("Received records:\n%s", writer.toString()));
333313

334314
try (ByteArrayInputStream transformedContentStream = new ByteArrayInputStream(writer.toString().getBytes("UTF-8"))) {
335315

336316
// create internal request DOM
337-
// DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
338-
// builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
339-
// builderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
340-
// builderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
341-
// builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
342-
// builderFactory.setXIncludeAware(false);
343-
// builderFactory.setExpandEntityReferences(false);
344-
// DocumentBuilder builder = builderFactory.newDocumentBuilder();
317+
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
318+
builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
319+
builderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
320+
builderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
321+
builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
322+
builderFactory.setXIncludeAware(false);
323+
builderFactory.setExpandEntityReferences(false);
324+
DocumentBuilder builder = builderFactory.newDocumentBuilder();
345325
Document resultDom = builder.parse(new InputSource(transformedContentStream));
346326

347327
// create xpath

0 commit comments

Comments
 (0)