14
14
package org .asynchttpclient .webdav ;
15
15
16
16
import io .netty .handler .codec .http .HttpHeaders ;
17
- import org .asynchttpclient .AsyncCompletionHandlerBase ;
18
17
import org .asynchttpclient .AsyncHandler ;
19
18
import org .asynchttpclient .HttpResponseBodyPart ;
20
19
import org .asynchttpclient .HttpResponseStatus ;
42
41
* @param <T> the result type
43
42
*/
44
43
public abstract class WebDavCompletionHandlerBase <T > implements AsyncHandler <T > {
45
- private final Logger logger = LoggerFactory .getLogger (AsyncCompletionHandlerBase .class );
44
+ private static final Logger LOGGER = LoggerFactory .getLogger (WebDavCompletionHandlerBase .class );
45
+ private static final DocumentBuilderFactory DOCUMENT_BUILDER_FACTORY ;
46
46
private final List <HttpResponseBodyPart > bodyParts = Collections .synchronizedList (new ArrayList <>());
47
47
private HttpResponseStatus status ;
48
48
private HttpHeaders headers ;
49
49
50
+ static {
51
+ DOCUMENT_BUILDER_FACTORY = DocumentBuilderFactory .newInstance ();
52
+ if (Boolean .getBoolean ("org.asynchttpclient.webdav.enableDtd" )) {
53
+ try {
54
+ DOCUMENT_BUILDER_FACTORY .setFeature ("http://apache.org/xml/features/disallow-doctype-decl" , true );
55
+ } catch (ParserConfigurationException e ) {
56
+ LOGGER .error ("Failed to disable doctype declaration" );
57
+ throw new ExceptionInInitializerError (e );
58
+ }
59
+ }
60
+ }
61
+
50
62
/**
51
63
* {@inheritDoc}
52
64
*/
@@ -75,13 +87,12 @@ public final State onHeadersReceived(final HttpHeaders headers) {
75
87
}
76
88
77
89
private Document readXMLResponse (InputStream stream ) {
78
- DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
79
90
Document document ;
80
91
try {
81
- document = factory .newDocumentBuilder ().parse (stream );
92
+ document = DOCUMENT_BUILDER_FACTORY .newDocumentBuilder ().parse (stream );
82
93
parse (document );
83
94
} catch (SAXException | IOException | ParserConfigurationException e ) {
84
- logger .error (e .getMessage (), e );
95
+ LOGGER .error (e .getMessage (), e );
85
96
throw new RuntimeException (e );
86
97
}
87
98
return document ;
@@ -94,7 +105,7 @@ private void parse(Document document) {
94
105
Node node = statusNode .item (i );
95
106
96
107
String value = node .getFirstChild ().getNodeValue ();
97
- int statusCode = Integer .valueOf (value .substring (value .indexOf (" " ), value .lastIndexOf (" " )).trim ());
108
+ int statusCode = Integer .parseInt (value .substring (value .indexOf (" " ), value .lastIndexOf (" " )).trim ());
98
109
String statusText = value .substring (value .lastIndexOf (" " ));
99
110
status = new HttpStatusWrapper (status , statusText , statusCode );
100
111
}
@@ -122,7 +133,7 @@ public final T onCompleted() throws Exception {
122
133
*/
123
134
@ Override
124
135
public void onThrowable (Throwable t ) {
125
- logger .debug (t .getMessage (), t );
136
+ LOGGER .debug (t .getMessage (), t );
126
137
}
127
138
128
139
/**
@@ -134,7 +145,7 @@ public void onThrowable(Throwable t) {
134
145
*/
135
146
abstract public T onCompleted (WebDavResponse response ) throws Exception ;
136
147
137
- private class HttpStatusWrapper extends HttpResponseStatus {
148
+ private static class HttpStatusWrapper extends HttpResponseStatus {
138
149
139
150
private final HttpResponseStatus wrapped ;
140
151
0 commit comments