|
23 | 23 | import javax.xml.parsers.DocumentBuilderFactory;
|
24 | 24 | import javax.xml.parsers.ParserConfigurationException;
|
25 | 25 |
|
26 |
| -import org.asynchttpclient.AsyncCompletionHandlerBase; |
27 | 26 | import org.asynchttpclient.AsyncHandler;
|
28 | 27 | import org.asynchttpclient.HttpResponseBodyPart;
|
29 | 28 | import org.asynchttpclient.HttpResponseHeaders;
|
|
43 | 42 | * @param <T> the result type
|
44 | 43 | */
|
45 | 44 | public abstract class WebDavCompletionHandlerBase<T> implements AsyncHandler<T> {
|
46 |
| - private final Logger logger = LoggerFactory.getLogger(AsyncCompletionHandlerBase.class); |
| 45 | + private static final Logger LOGGER = LoggerFactory.getLogger(WebDavCompletionHandlerBase.class); |
| 46 | + private static final DocumentBuilderFactory DOCUMENT_BUILDER_FACTORY; |
| 47 | + |
| 48 | + static { |
| 49 | + DOCUMENT_BUILDER_FACTORY = DocumentBuilderFactory.newInstance(); |
| 50 | + if (Boolean.getBoolean("org.asynchttpclient.webdav.enableDtd")) { |
| 51 | + try { |
| 52 | + DOCUMENT_BUILDER_FACTORY.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); |
| 53 | + } catch (ParserConfigurationException e) { |
| 54 | + LOGGER.error("Failed to disable doctype declaration"); |
| 55 | + throw new ExceptionInInitializerError(e); |
| 56 | + } |
| 57 | + } |
| 58 | + } |
47 | 59 |
|
48 | 60 | private HttpResponseStatus status;
|
49 | 61 | private HttpResponseHeaders headers;
|
@@ -77,19 +89,18 @@ public final State onHeadersReceived(final HttpResponseHeaders headers) throws E
|
77 | 89 | }
|
78 | 90 |
|
79 | 91 | private Document readXMLResponse(InputStream stream) {
|
80 |
| - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
81 | 92 | Document document = null;
|
82 | 93 | try {
|
83 |
| - document = factory.newDocumentBuilder().parse(stream); |
| 94 | + document = DOCUMENT_BUILDER_FACTORY.newDocumentBuilder().parse(stream); |
84 | 95 | parse(document);
|
85 | 96 | } catch (SAXException e) {
|
86 |
| - logger.error(e.getMessage(), e); |
| 97 | + LOGGER.error(e.getMessage(), e); |
87 | 98 | throw new RuntimeException(e);
|
88 | 99 | } catch (IOException e) {
|
89 |
| - logger.error(e.getMessage(), e); |
| 100 | + LOGGER.error(e.getMessage(), e); |
90 | 101 | throw new RuntimeException(e);
|
91 | 102 | } catch (ParserConfigurationException e) {
|
92 |
| - logger.error(e.getMessage(), e); |
| 103 | + LOGGER.error(e.getMessage(), e); |
93 | 104 | throw new RuntimeException(e);
|
94 | 105 | }
|
95 | 106 | return document;
|
@@ -130,7 +141,7 @@ public final T onCompleted() throws Exception {
|
130 | 141 | */
|
131 | 142 | @Override
|
132 | 143 | public void onThrowable(Throwable t) {
|
133 |
| - logger.debug(t.getMessage(), t); |
| 144 | + LOGGER.debug(t.getMessage(), t); |
134 | 145 | }
|
135 | 146 |
|
136 | 147 | /**
|
|
0 commit comments