1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.owasp.dependencycheck.utils;
19
20 import org.apache.hc.client5.http.impl.classic.AbstractHttpClientResponseHandler;
21 import org.apache.hc.core5.http.HttpEntity;
22 import org.w3c.dom.Document;
23 import org.xml.sax.SAXException;
24
25 import javax.xml.parsers.DocumentBuilder;
26 import javax.xml.parsers.ParserConfigurationException;
27 import java.io.IOException;
28 import java.io.InputStream;
29
30 public class ToXMLDocumentResponseHandler extends AbstractHttpClientResponseHandler<Document> {
31 @Override
32 public Document handleEntity(HttpEntity entity) throws IOException {
33 try (InputStream in = entity.getContent()) {
34 final DocumentBuilder builder = XmlUtils.buildSecureDocumentBuilder();
35 return builder.parse(in);
36 } catch (ParserConfigurationException | SAXException | IOException e) {
37 final String errorMessage = "Failed to parse XML Response: " + e.getMessage();
38 throw new IOException(errorMessage, e);
39 }
40 }
41 }