diff --git a/doxia-core/pom.xml b/doxia-core/pom.xml index 867c20c77..6f675a6c7 100644 --- a/doxia-core/pom.xml +++ b/doxia-core/pom.xml @@ -62,12 +62,12 @@ under the License. org.apache.httpcomponents httpclient - 4.0.2 + 4.5.8 org.apache.httpcomponents httpcore - 4.0.1 + 4.4.11 diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java b/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java index dbeed057f..1ac62fb7e 100644 --- a/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java +++ b/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java @@ -36,16 +36,13 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.HttpRequestRetryHandler; +import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; +import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; - import org.apache.maven.doxia.macro.MacroExecutionException; import org.apache.maven.doxia.markup.XmlMarkup; import org.apache.maven.doxia.sink.Sink; @@ -811,19 +808,17 @@ private static byte[] toByteArray( URL url ) } // it is an HTTP url, using HttpClient... - DefaultHttpClient client = new DefaultHttpClient(); - HttpGet method = new HttpGet( url.toString() ); - // Set a user-agent that doesn't contain the word "java", otherwise it will be blocked by the W3C - // The default user-agent is "Apache-HttpClient/4.0.2 (java 1.5)" - method.setHeader( "user-agent", "Apache-Doxia/" + doxiaVersion() ); - - HttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler( 3, false ); - client.setHttpRequestRetryHandler( retryHandler ); - - HttpEntity entity = null; + HttpClientBuilder httpClientBuilder = HttpClientBuilder.create() + .useSystemProperties() + .setRetryHandler( new DefaultHttpRequestRetryHandler( 3, false ) ) + // Set a user-agent that doesn't contain the word "java", otherwise it will be blocked by the W3C + // The default user-agent is "Apache-HttpClient/4.5.8 (java 7)" + .setUserAgent( "Apache-Doxia/" + doxiaVersion() ); + + CloseableHttpResponse response = null; try { - HttpResponse response = client.execute( method ); + response = httpClientBuilder.build( ).execute( new HttpGet( url.toString( ) ) ); int statusCode = response.getStatusLine().getStatusCode(); if ( statusCode != HttpStatus.SC_OK ) { @@ -832,8 +827,7 @@ private static byte[] toByteArray( URL url ) + response.getStatusLine().getReasonPhrase() + "'." ); } - entity = response.getEntity(); - return EntityUtils.toByteArray( entity ); + return EntityUtils.toByteArray( response.getEntity() ); } catch ( ClientProtocolException e ) { @@ -845,11 +839,11 @@ private static byte[] toByteArray( URL url ) } finally { - if ( entity != null ) + if ( response != null ) { try { - entity.consumeContent(); + response.close(); } catch ( IOException e ) {