You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2013/10/22 05:04:47 UTC
[9/9] git commit: merging httpclient-4.3 branch from Oleg
merging httpclient-4.3 branch from Oleg
Project: http://git-wip-us.apache.org/repos/asf/maven-wagon/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-wagon/commit/1c04f0a4
Tree: http://git-wip-us.apache.org/repos/asf/maven-wagon/tree/1c04f0a4
Diff: http://git-wip-us.apache.org/repos/asf/maven-wagon/diff/1c04f0a4
Branch: refs/heads/master
Commit: 1c04f0a4a32bc11fd5e69740f1a346d80d33d4cf
Parents: 5b987be d4a6064
Author: Olivier Lamy <ol...@apache.org>
Authored: Tue Oct 22 13:57:02 2013 +1100
Committer: Olivier Lamy <ol...@apache.org>
Committed: Tue Oct 22 13:57:02 2013 +1100
----------------------------------------------------------------------
.../providers/http/AbstractHttpClientWagon.java | 241 ++++++++-------
.../providers/http/ConfigurationUtils.java | 231 +++++++++++++++
.../wagon/providers/http/HttpConfiguration.java | 6 +-
.../providers/http/HttpMethodConfiguration.java | 297 +------------------
.../maven/wagon/providers/http/HttpWagon.java | 14 +-
.../providers/http/RelaxedTrustStrategy.java | 85 ++++++
.../providers/http/RelaxedX509TrustManager.java | 132 ---------
.../providers/http/HttpClientWagonTest.java | 4 +-
8 files changed, 467 insertions(+), 543 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/1c04f0a4/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
----------------------------------------------------------------------
diff --cc wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
index 0b683ae,fea72b4..268f2f1
--- a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
+++ b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
@@@ -227,28 -227,28 +227,28 @@@ public abstract class AbstractHttpClien
* <b>enabled by default</b>
*/
private final static boolean PERSISTENT_POOL =
-- Boolean.valueOf( System.getProperty( "maven.wagon.http.pool", "true" ) );
++ Boolean.valueOf( System.getProperty( "maven.wagon.http.pool", "true" ) );
/**
* skip failure on certificate validity checks.
* <b>disabled by default</b>
*/
private final static boolean SSL_INSECURE =
-- Boolean.valueOf( System.getProperty( "maven.wagon.http.ssl.insecure", "false" ) );
++ Boolean.valueOf( System.getProperty( "maven.wagon.http.ssl.insecure", "false" ) );
/**
* if using sslInsecure, certificate date issues will be ignored
* <b>disabled by default</b>
*/
private final static boolean IGNORE_SSL_VALIDITY_DATES =
-- Boolean.valueOf( System.getProperty( "maven.wagon.http.ssl.ignore.validity.dates", "false" ) );
++ Boolean.valueOf( System.getProperty( "maven.wagon.http.ssl.ignore.validity.dates", "false" ) );
/**
* If enabled, ssl hostname verifier does not check hostname. Disable this will use a browser compat hostname verifier
* <b>disabled by default</b>
*/
private final static boolean SSL_ALLOW_ALL =
-- Boolean.valueOf( System.getProperty( "maven.wagon.http.ssl.allowall", "false" ) );
++ Boolean.valueOf( System.getProperty( "maven.wagon.http.ssl.allowall", "false" ) );
/**
@@@ -256,14 -256,14 +256,14 @@@
* <b>20 by default</b>
*/
private final static int MAX_CONN_PER_ROUTE =
-- Integer.parseInt( System.getProperty( "maven.wagon.httpconnectionManager.maxPerRoute", "20" ) );
++ Integer.parseInt( System.getProperty( "maven.wagon.httpconnectionManager.maxPerRoute", "20" ) );
/**
* Maximum conncurrent connections in total.
* <b>40 by default</b>
*/
private final static int MAX_CONN_TOTAL =
-- Integer.parseInt( System.getProperty( "maven.wagon.httpconnectionManager.maxTotal", "40" ) );
++ Integer.parseInt( System.getProperty( "maven.wagon.httpconnectionManager.maxTotal", "40" ) );
/**
* Internal connection manager
@@@ -273,44 -273,94 +273,93 @@@
private static PoolingHttpClientConnectionManager createConnManager()
{
-- String sslProtocolsStr = System.getProperty("https.protocols");
-- String cipherSuitesStr = System.getProperty("https.cipherSuites");
-- String[] sslProtocols = sslProtocolsStr != null ? sslProtocolsStr.split(" *, *") : null;
-- String[] cipherSuites = cipherSuitesStr != null ? cipherSuitesStr.split(" *, *") : null;
++ String sslProtocolsStr = System.getProperty( "https.protocols" );
++ String cipherSuitesStr = System.getProperty( "https.cipherSuites" );
++ String[] sslProtocols = sslProtocolsStr != null ? sslProtocolsStr.split( " *, *" ) : null;
++ String[] cipherSuites = cipherSuitesStr != null ? cipherSuitesStr.split( " *, *" ) : null;
SSLConnectionSocketFactory sslConnectionSocketFactory;
if ( SSL_INSECURE )
{
- sslConnectionSocketFactory = new SSLConnectionSocketFactory(
- RelaxedX509TrustManager.createRelaxedSSLContext(IGNORE_SSL_VALIDITY_DATES),
- sslProtocols,
- cipherSuites,
- SSL_ALLOW_ALL ? SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER : SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER );
- try {
- SSLContext sslContext = new SSLContextBuilder()
- .useSSL()
- .loadTrustMaterial(null, new RelaxedTrustStrategy(IGNORE_SSL_VALIDITY_DATES))
- .build();
- sslConnectionSocketFactory = new SSLConnectionSocketFactory(
- sslContext,
- sslProtocols,
- cipherSuites,
- SSL_ALLOW_ALL ? SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER : SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER );
++ try
++ {
++ SSLContext sslContext = new SSLContextBuilder().useSSL().loadTrustMaterial( null,
++ new RelaxedTrustStrategy(
++ IGNORE_SSL_VALIDITY_DATES ) ).build();
++ sslConnectionSocketFactory = new SSLConnectionSocketFactory( sslContext, sslProtocols, cipherSuites,
++ SSL_ALLOW_ALL
++ ? SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER
++ : SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER );
+ }
- catch (Exception ex)
++ catch ( Exception ex )
+ {
- throw new SSLInitializationException(ex.getMessage(), ex);
++ throw new SSLInitializationException( ex.getMessage(), ex );
+ }
}
else
{
-- sslConnectionSocketFactory = new SSLConnectionSocketFactory(
-- HttpsURLConnection.getDefaultSSLSocketFactory(),
-- sslProtocols,
-- cipherSuites,
-- SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER );
++ sslConnectionSocketFactory =
++ new SSLConnectionSocketFactory( HttpsURLConnection.getDefaultSSLSocketFactory(), sslProtocols,
++ cipherSuites,
++ SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER );
}
-- Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
-- .register("http", PlainConnectionSocketFactory.INSTANCE)
-- .register("https", sslConnectionSocketFactory)
-- .build();
++ Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register( "http",
++ PlainConnectionSocketFactory.INSTANCE ).register(
++ "https", sslConnectionSocketFactory ).build();
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager( registry );
-- if (PERSISTENT_POOL) {
++ if ( PERSISTENT_POOL )
++ {
connManager.setDefaultMaxPerRoute( MAX_CONN_PER_ROUTE );
connManager.setMaxTotal( MAX_CONN_TOTAL );
-- } else {
++ }
++ else
++ {
connManager.setMaxTotal( 1 );
}
return connManager;
}
+ private static CloseableHttpClient CLIENT = createClient();
+
- private static CloseableHttpClient createClient() {
- return HttpClientBuilder.create()
- .useSystemProperties()
- .disableConnectionState()
- .setConnectionManager(CONN_MAN)
- .build();
++ private static CloseableHttpClient createClient()
++ {
++ return HttpClientBuilder.create().useSystemProperties().disableConnectionState().setConnectionManager(
++ CONN_MAN ).build();
+ }
+
+ private static String DEFAULT_USER_AGENT = getDefaultUserAgent();
+
+ private static String getDefaultUserAgent()
+ {
+ Properties props = new Properties();
+
- InputStream is = AbstractHttpClientWagon.class.getResourceAsStream("/META-INF/maven/org.apache.maven.wagon/wagon-http/pom.properties");
++ InputStream is = AbstractHttpClientWagon.class.getResourceAsStream(
++ "/META-INF/maven/org.apache.maven.wagon/wagon-http/pom.properties" );
+ if ( is != null )
+ {
+ try
+ {
+ props.load( is );
+ }
+ catch ( IOException ignore )
+ {
+ }
+ finally
+ {
+ IOUtil.close( is );
+ }
+ }
+
+ String ver = props.getProperty( "version", "unknown-version" );
+ return "Apache-Maven-Wagon/" + ver + " (Java " + System.getProperty( "java.version" ) + "; ";
+ }
+
+ private HttpClientContext localContext;
+
+ private Closeable closeable;
+
/**
* @plexus.configuration
* @deprecated Use httpConfiguration instead.
@@@ -341,7 -391,7 +390,7 @@@
String host = getRepository().getHost();
int port = getRepository().getPort() > -1 ? getRepository().getPort() : AuthScope.ANY_PORT;
-- credentialsProvider.setCredentials(new AuthScope(host, port), creds);
++ credentialsProvider.setCredentials( new AuthScope( host, port ), creds );
// preemptive off by default
/*
AuthCache authCache = new BasicAuthCache();
@@@ -385,27 -431,20 +430,20 @@@
int port = proxyInfo.getPort() > -1 ? proxyInfo.getPort() : AuthScope.ANY_PORT;
AuthScope authScope = new AuthScope( proxyHost, port );
-- credentialsProvider.setCredentials(authScope, creds);
++ credentialsProvider.setCredentials( authScope, creds );
}
}
}
localContext = HttpClientContext.create();
-
- client = HttpClientBuilder.create()
- .useSystemProperties()
- .disableConnectionState()
- .setConnectionManager(connManager)
- .setProxy(proxy)
- .setDefaultCredentialsProvider(credentialsProvider)
- .build();
- localContext.setCredentialsProvider(credentialsProvider);
++ localContext.setCredentialsProvider( credentialsProvider );
}
public void closeConnection()
{
-- if ( !PERSISTENT_POOL)
++ if ( !PERSISTENT_POOL )
{
- connManager.closeIdleConnections(0, TimeUnit.MILLISECONDS);
- CONN_MAN.closeIdleConnections(0, TimeUnit.MILLISECONDS);
++ CONN_MAN.closeIdleConnections( 0, TimeUnit.MILLISECONDS );
}
}
@@@ -510,7 -549,7 +548,7 @@@
{
int statusCode = response.getStatusLine().getStatusCode();
String reasonPhrase = ", ReasonPhrase: " + response.getStatusLine().getReasonPhrase() + ".";
-- fireTransferDebug(url + " - Status code: " + statusCode + reasonPhrase);
++ fireTransferDebug( url + " - Status code: " + statusCode + reasonPhrase );
// Check that we didn't run out of retries.
switch ( statusCode )
@@@ -544,7 -583,9 +582,9 @@@
}
}
-- firePutCompleted(resource, source);
++ firePutCompleted( resource, source );
+
- EntityUtils.consume(response.getEntity());
++ EntityUtils.consume( response.getEntity() );
}
finally
{
@@@ -588,9 -629,10 +628,11 @@@
try
{
CloseableHttpResponse response = execute( headMethod );
-- try {
++ try
++ {
int statusCode = response.getStatusLine().getStatusCode();
String reasonPhrase = ", ReasonPhrase: " + response.getStatusLine().getReasonPhrase() + ".";
+ boolean result;
switch ( statusCode )
{
case HttpStatus.SC_OK:
@@@ -616,6 -659,8 +659,8 @@@
"Failed to transfer file: " + url + ". Return code is: " + statusCode + reasonPhrase );
}
- EntityUtils.consume(response.getEntity());
++ EntityUtils.consume( response.getEntity() );
+ return result;
}
finally
{
@@@ -632,20 -677,32 +677,33 @@@
}
}
-- protected CloseableHttpResponse execute( HttpUriRequest httpMethod)
++ protected CloseableHttpResponse execute( HttpUriRequest httpMethod )
throws HttpException, IOException
{
setHeaders( httpMethod );
String userAgent = getUserAgent( httpMethod );
-- if (userAgent != null) {
-- httpMethod.setHeader(HTTP.USER_AGENT, userAgent);
++ if ( userAgent != null )
++ {
++ httpMethod.setHeader( HTTP.USER_AGENT, userAgent );
+ }
+
+ RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
+ // WAGON-273: default the cookie-policy to browser compatible
- requestConfigBuilder.setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY);
++ requestConfigBuilder.setCookieSpec( CookieSpecs.BROWSER_COMPATIBILITY );
+
+ ProxyInfo proxyInfo = getProxyInfo( getRepository().getProtocol(), getRepository().getHost() );
+ if ( proxyInfo != null )
+ {
+ HttpHost proxy = new HttpHost( proxyInfo.getHost(), proxyInfo.getPort() );
+ requestConfigBuilder.setProxy( proxy );
}
HttpMethodConfiguration config =
- httpConfiguration == null ? null : httpConfiguration.getMethodConfiguration(httpMethod);
+ httpConfiguration == null ? null : httpConfiguration.getMethodConfiguration( httpMethod );
+
if ( config != null )
{
- localContext.setRequestConfig( config.asRequestConfig() );
- ConfigurationUtils.copyConfig(config, requestConfigBuilder );
++ ConfigurationUtils.copyConfig( config, requestConfigBuilder );
if ( config.isUsePreemptive() && authenticationInfo != null )
{
@@@ -890,16 -912,16 +913,18 @@@
Header lastModifiedHeader = response.getFirstHeader( "Last-Modified" );
if ( lastModifiedHeader != null )
{
-- Date lastModified = DateUtils.parseDate(lastModifiedHeader.getValue());
-- if ( lastModified != null ) {
++ Date lastModified = DateUtils.parseDate( lastModifiedHeader.getValue() );
++ if ( lastModified != null )
++ {
resource.setLastModified( lastModified.getTime() );
fireTransferDebug( "last-modified = " + lastModifiedHeader.getValue() +
-- " (" + lastModified.getTime() + ")" );
++ " (" + lastModified.getTime() + ")" );
}
}
HttpEntity entity = response.getEntity();
-- if ( entity != null ) {
++ if ( entity != null )
++ {
inputData.setInputStream( entity.getContent() );
}
}
@@@ -925,7 -947,7 +950,7 @@@
{
closeable.close();
}
-- catch (IOException ignore)
++ catch ( IOException ignore )
{
}
@@@ -964,4 -986,4 +989,4 @@@
// no needed in this implementation but throw an Exception if used
throw new IllegalStateException( "this wagon http client must not use fillOutputData" );
}
--}
++}