Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOXIA-576 Upgrade HttpComponents: httpclient to 4.5.8 and httpcore to 4.4.11 #12

Merged
merged 1 commit into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doxia-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ under the License.
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.0.2</version>
<version>4.5.8</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.0.1</version>
<version>4.4.11</version>
</dependency>

<!-- test -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
{
Expand All @@ -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 )
{
Expand All @@ -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 )
{
Expand Down