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:39 UTC

[1/9] git commit: HttpClient never returns invalid status codes (< 200)

Updated Branches:
  refs/heads/master 5b987be4e -> 1c04f0a4a


HttpClient never returns invalid status codes (< 200)


Project: http://git-wip-us.apache.org/repos/asf/maven-wagon/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-wagon/commit/9a1b7294
Tree: http://git-wip-us.apache.org/repos/asf/maven-wagon/tree/9a1b7294
Diff: http://git-wip-us.apache.org/repos/asf/maven-wagon/diff/9a1b7294

Branch: refs/heads/master
Commit: 9a1b72942d03428de3dad0483084691619f3ba9d
Parents: e8c135d
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Sat Sep 21 13:03:28 2013 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Tue Sep 24 13:47:26 2013 +0200

----------------------------------------------------------------------
 .../providers/http/AbstractHttpClientWagon.java | 25 --------------------
 .../maven/wagon/providers/http/HttpWagon.java   |  4 ----
 2 files changed, 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/9a1b7294/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
----------------------------------------------------------------------
diff --git 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
index dd4fb8e..0b683ae 100755
--- 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
@@ -214,8 +214,6 @@ public abstract class AbstractHttpClientWagon
         }
     }
 
-    protected static final int SC_NULL = -1;
-
     private static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone( "GMT" );
 
     private CloseableHttpClient client;
@@ -529,14 +527,6 @@ public abstract class AbstractHttpClientWagon
                     case HttpStatus.SC_SEE_OTHER: // 303
                         put( resource, source, httpEntity, calculateRelocatedUrl( response ) );
                         return;
-                    case SC_NULL:
-                    {
-                        TransferFailedException e =
-                            new TransferFailedException( "Failed to transfer file: " + url + reasonPhrase );
-                        fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
-                        throw e;
-                    }
-
                     case HttpStatus.SC_FORBIDDEN:
                         fireSessionConnectionRefused();
                         throw new AuthorizationException( "Access denied to: " + url + reasonPhrase );
@@ -608,10 +598,6 @@ public abstract class AbstractHttpClientWagon
 
                     case HttpStatus.SC_NOT_MODIFIED:
                         return true;
-
-                    case SC_NULL:
-                        throw new TransferFailedException( "Failed to transfer file: " + url + reasonPhrase );
-
                     case HttpStatus.SC_FORBIDDEN:
                         throw new AuthorizationException( "Access denied to: " + url + reasonPhrase );
 
@@ -850,8 +836,6 @@ public abstract class AbstractHttpClientWagon
 
             fireTransferDebug( url + " - Status code: " + statusCode + reasonPhrase );
 
-            // TODO [BP]: according to httpclient docs, really should swallow the output on error. verify if that is
-            // required
             switch ( statusCode )
             {
                 case HttpStatus.SC_OK:
@@ -860,15 +844,6 @@ public abstract class AbstractHttpClientWagon
                 case HttpStatus.SC_NOT_MODIFIED:
                     // return, leaving last modified set to original value so getIfNewer should return unmodified
                     return;
-
-                case SC_NULL:
-                {
-                    TransferFailedException e =
-                        new TransferFailedException( "Failed to transfer file: " + url + " " + reasonPhrase );
-                    fireTransferError( resource, e, TransferEvent.REQUEST_GET );
-                    throw e;
-                }
-
                 case HttpStatus.SC_FORBIDDEN:
                     fireSessionConnectionRefused();
                     throw new AuthorizationException( "Access denied to: " + url + " " + reasonPhrase );

http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/9a1b7294/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
index 68fad2c..c06f2cc 100755
--- a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
+++ b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
@@ -59,15 +59,11 @@ public class HttpWagon
 
                 fireTransferDebug( url + " - Status code: " + statusCode );
 
-                // TODO [BP]: according to httpclient docs, really should swallow the output on error. verify if that is required
                 switch ( statusCode )
                 {
                     case HttpStatus.SC_OK:
                         break;
 
-                    case SC_NULL:
-                        throw new TransferFailedException( "Failed to transfer file: " );
-
                     case HttpStatus.SC_FORBIDDEN:
                         throw new AuthorizationException( "Access denied to: " + url );
 


[6/9] git commit: Try to make sure the connection is a consistent (re-usable) state prior to closing the response

Posted by ol...@apache.org.
Try to make sure the connection is a consistent (re-usable) state prior to closing the response


Project: http://git-wip-us.apache.org/repos/asf/maven-wagon/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-wagon/commit/70e42612
Tree: http://git-wip-us.apache.org/repos/asf/maven-wagon/tree/70e42612
Diff: http://git-wip-us.apache.org/repos/asf/maven-wagon/diff/70e42612

Branch: refs/heads/master
Commit: 70e4261277544dcc5fc40b9521bcad928dcc9607
Parents: 008accb
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Tue Sep 24 15:12:50 2013 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Tue Sep 24 15:12:50 2013 +0200

----------------------------------------------------------------------
 .../providers/http/AbstractHttpClientWagon.java    | 17 ++++++++++++-----
 .../maven/wagon/providers/http/HttpWagon.java      | 14 +++++++++++---
 2 files changed, 23 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/70e42612/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
----------------------------------------------------------------------
diff --git 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
index 0fd7ada..8df1404 100755
--- 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
@@ -78,6 +78,7 @@ import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.protocol.HTTP;
+import org.apache.http.util.EntityUtils;
 import org.apache.maven.wagon.InputData;
 import org.apache.maven.wagon.OutputData;
 import org.apache.maven.wagon.PathUtils;
@@ -561,6 +562,8 @@ public abstract class AbstractHttpClientWagon
                 }
 
                 firePutCompleted(resource, source);
+
+                EntityUtils.consume(response.getEntity());
             }
             finally
             {
@@ -607,13 +610,15 @@ public abstract class AbstractHttpClientWagon
             try {
                 int statusCode = response.getStatusLine().getStatusCode();
                 String reasonPhrase = ", ReasonPhrase: " + response.getStatusLine().getReasonPhrase() + ".";
+                boolean result;
                 switch ( statusCode )
                 {
                     case HttpStatus.SC_OK:
-                        return true;
-
+                        result = true;
+                        break;
                     case HttpStatus.SC_NOT_MODIFIED:
-                        return true;
+                        result = true;
+                        break;
                     case HttpStatus.SC_FORBIDDEN:
                         throw new AuthorizationException( "Access denied to: " + url + reasonPhrase );
 
@@ -624,14 +629,16 @@ public abstract class AbstractHttpClientWagon
                         throw new AuthorizationException( "Not authorized by proxy " + reasonPhrase );
 
                     case HttpStatus.SC_NOT_FOUND:
-                        return false;
-
+                        result = false;
+                        break;
                     //add more entries here
                     default:
                         throw new TransferFailedException(
                             "Failed to transfer file: " + url + ". Return code is: " + statusCode + reasonPhrase );
                 }
 
+                EntityUtils.consume(response.getEntity());
+                return result;
             }
             finally
             {

http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/70e42612/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
index c06f2cc..fa68341 100755
--- a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
+++ b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
@@ -21,8 +21,10 @@ package org.apache.maven.wagon.providers.http;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Collections;
 import java.util.List;
 
+import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
 import org.apache.http.HttpStatus;
 import org.apache.http.client.methods.CloseableHttpResponse;
@@ -81,10 +83,16 @@ public class HttpWagon
                         throw new TransferFailedException(
                             "Failed to transfer file: " + url + ". Return code is: " + statusCode );
                 }
+                HttpEntity entity = response.getEntity();
+                if ( entity != null )
+                {
+                    return HtmlFileListParser.parseFileList( url, entity.getContent() );
+                }
+                else
+                {
+                    return Collections.emptyList();
+                }
 
-                InputStream is = response.getEntity().getContent();
-
-                return HtmlFileListParser.parseFileList( url, is );
             } finally {
                 response.close();
             }


[7/9] git commit: Refactored configuration code; HttpClient instance is now immutable and static

Posted by ol...@apache.org.
Refactored configuration code; HttpClient instance is now immutable and static


Project: http://git-wip-us.apache.org/repos/asf/maven-wagon/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-wagon/commit/e198f011
Tree: http://git-wip-us.apache.org/repos/asf/maven-wagon/tree/e198f011
Diff: http://git-wip-us.apache.org/repos/asf/maven-wagon/diff/e198f011

Branch: refs/heads/master
Commit: e198f0110df4b7ca0cface82806624ed5ad1dcb9
Parents: 70e4261
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Tue Sep 24 20:25:12 2013 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Tue Sep 24 20:25:12 2013 +0200

----------------------------------------------------------------------
 .../providers/http/AbstractHttpClientWagon.java | 125 +++++++++----------
 .../providers/http/HttpMethodConfiguration.java |   8 +-
 .../providers/http/HttpClientWagonTest.java     |   4 +-
 3 files changed, 67 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/e198f011/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
----------------------------------------------------------------------
diff --git 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
index 8df1404..0a7e59d 100755
--- 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
@@ -54,6 +54,7 @@ import org.apache.http.auth.NTCredentials;
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.AuthCache;
 import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.config.CookieSpecs;
 import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
@@ -101,8 +102,6 @@ import org.codehaus.plexus.util.StringUtils;
 public abstract class AbstractHttpClientWagon
     extends StreamWagon
 {
-    private static String defaultUserAgent;
-
     private final class RequestEntityImplementation
         extends AbstractHttpEntity
     {
@@ -223,12 +222,6 @@ public abstract class AbstractHttpClientWagon
 
     private static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone( "GMT" );
 
-    private CloseableHttpClient client;
-
-    private HttpClientContext localContext;
-
-    private Closeable closeable;
-
     /**
      * use http(s) connection pool mechanism.
      * <b>enabled by default</b>
@@ -275,7 +268,7 @@ public abstract class AbstractHttpClientWagon
     /**
      * Internal connection manager
      */
-    private static final PoolingHttpClientConnectionManager connManager = createConnManager();
+    private static final PoolingHttpClientConnectionManager CONN_MAN = createConnManager();
 
     private static PoolingHttpClientConnectionManager createConnManager()
     {
@@ -328,6 +321,46 @@ public abstract class AbstractHttpClientWagon
         return connManager;
     }
 
+    private static CloseableHttpClient CLIENT = createClient();
+
+    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");
+        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.
@@ -373,20 +406,16 @@ public abstract class AbstractHttpClientWagon
             }
         }
 
-        HttpHost proxy = null;
         ProxyInfo proxyInfo = getProxyInfo( getRepository().getProtocol(), getRepository().getHost() );
         if ( proxyInfo != null )
         {
             String proxyUsername = proxyInfo.getUserName();
             String proxyPassword = proxyInfo.getPassword();
             String proxyHost = proxyInfo.getHost();
-            int proxyPort = proxyInfo.getPort();
             String proxyNtlmHost = proxyInfo.getNtlmHost();
             String proxyNtlmDomain = proxyInfo.getNtlmDomain();
             if ( proxyHost != null )
             {
-                proxy = new HttpHost( proxyHost, proxyPort );
-
                 if ( proxyUsername != null && proxyPassword != null )
                 {
                     Credentials creds;
@@ -408,21 +437,14 @@ public abstract class AbstractHttpClientWagon
         }
 
         localContext = HttpClientContext.create();
-
-        client = HttpClientBuilder.create()
-                .useSystemProperties()
-                .disableConnectionState()
-                .setConnectionManager(connManager)
-                .setProxy(proxy)
-                .setDefaultCredentialsProvider(credentialsProvider)
-                .build();
+        localContext.setCredentialsProvider(credentialsProvider);
     }
 
     public void closeConnection()
     {
         if ( !PERSISTENT_POOL)
         {
-            connManager.closeIdleConnections(0, TimeUnit.MILLISECONDS);
+            CONN_MAN.closeIdleConnections(0, TimeUnit.MILLISECONDS);
         }
     }
 
@@ -664,11 +686,23 @@ public abstract class AbstractHttpClientWagon
             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);
+
+        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() );
+            config.applyConfig(requestConfigBuilder);
 
             if ( config.isUsePreemptive() && authenticationInfo != null )
             {
@@ -691,13 +725,10 @@ public abstract class AbstractHttpClientWagon
         }
         else
         {
-            RequestConfig requestConfig = RequestConfig.custom()
-                    .setSocketTimeout( getReadTimeout() )
-                    .build();
-            localContext.setRequestConfig( requestConfig );
+            requestConfigBuilder.setSocketTimeout( getReadTimeout() );
         }
 
-        ProxyInfo proxyInfo = getProxyInfo( getRepository().getProtocol(), getRepository().getHost() );
+        localContext.setRequestConfig( requestConfigBuilder.build() );
 
         if ( proxyInfo != null )
         {
@@ -721,7 +752,7 @@ public abstract class AbstractHttpClientWagon
 
         }
 
-        return client.execute( httpMethod, localContext );
+        return CLIENT.execute( httpMethod, localContext );
     }
 
     protected void setHeaders( HttpUriRequest method )
@@ -736,7 +767,7 @@ public abstract class AbstractHttpClientWagon
             method.addHeader( "Pragma", "no-cache" );
             method.addHeader( "Expires", "0" );
             method.addHeader( "Accept-Encoding", "gzip" );
-            method.addHeader( "User-Agent", getDefaultUserAgent() );
+            method.addHeader( "User-Agent", DEFAULT_USER_AGENT );
         }
 
         if ( httpHeaders != null )
@@ -757,38 +788,6 @@ public abstract class AbstractHttpClientWagon
         }
     }
 
-    private String getDefaultUserAgent()
-    {
-        if ( defaultUserAgent == null )
-        {
-            defaultUserAgent =
-                "Apache-Maven-Wagon/" + getWagonVersion() + " (Java " + System.getProperty( "java.version" ) + "; "
-                    + System.getProperty( "os.name" ) + " " + System.getProperty( "os.version" ) + ")";
-        }
-        return defaultUserAgent;
-    }
-
-    private String getWagonVersion()
-    {
-        Properties props = new Properties();
-
-        InputStream is = getClass().getResourceAsStream( "/META-INF/maven/org.apache.maven.wagon/wagon-http/pom.properties" );
-        if ( is != null )
-        {
-            try
-            {
-                props.load( is );
-            }
-            catch ( IOException e )
-            {
-                // ignore
-            }
-            IOUtil.close( is );
-        }
-
-        return props.getProperty( "version", "unknown-version" );
-    }
-
     protected String getUserAgent( HttpUriRequest method )
     {
         if ( httpHeaders != null )

http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/e198f011/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpMethodConfiguration.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpMethodConfiguration.java b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpMethodConfiguration.java
index 1d10c49..a1341eb 100755
--- a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpMethodConfiguration.java
+++ b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpMethodConfiguration.java
@@ -146,15 +146,12 @@ public class HttpMethodConfiguration
 
     private static final String COERCE_PATTERN = "%(\\w+),(.+)";
 
-    public RequestConfig asRequestConfig()
+    public void applyConfig(RequestConfig.Builder builder)
     {
         if ( !hasParams() )
         {
-            return null;
+            return;
         }
-        RequestConfig.Builder builder = RequestConfig.custom();
-        // WAGON-273: default the cookie-policy to browser compatible
-        builder.setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY);
         if ( connectionTimeout > 0 )
         {
             builder.setConnectTimeout(connectionTimeout);
@@ -244,7 +241,6 @@ public class HttpMethodConfiguration
                 }
             }
         }
-        return builder.build();
     }
 
     private boolean hasParams()

http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/e198f011/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java
index 95683cd..01a130c 100755
--- a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java
+++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java
@@ -42,7 +42,9 @@ public class HttpClientWagonTest
         config.setAll(methodConfig);
 
         HttpHead method = new HttpHead();
-        RequestConfig requestConfig = config.getMethodConfiguration(method).asRequestConfig();
+        RequestConfig.Builder builder = RequestConfig.custom();
+        config.getMethodConfiguration(method).applyConfig( builder );
+        RequestConfig requestConfig = builder.build();
 
         assertEquals(2, requestConfig.getMaxRedirects());
     }


[3/9] git commit: Removed unnecessary GZIP content handling code (transparent content decoding is provided by HttpClient)

Posted by ol...@apache.org.
Removed unnecessary GZIP content handling code (transparent content decoding is provided by HttpClient)


Project: http://git-wip-us.apache.org/repos/asf/maven-wagon/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-wagon/commit/16f0f9de
Tree: http://git-wip-us.apache.org/repos/asf/maven-wagon/tree/16f0f9de
Diff: http://git-wip-us.apache.org/repos/asf/maven-wagon/diff/16f0f9de

Branch: refs/heads/master
Commit: 16f0f9de356c0c2e060148bcfea5ddb4be7fcfb2
Parents: a12972e
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Fri Sep 20 17:04:13 2013 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Tue Sep 24 13:47:26 2013 +0200

----------------------------------------------------------------------
 .../providers/http/AbstractHttpClientWagon.java | 50 ++++----------------
 1 file changed, 9 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/16f0f9de/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
----------------------------------------------------------------------
diff --git 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
index 51e0157..d195fae 100755
--- 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
@@ -35,7 +35,6 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
 import java.util.TimeZone;
-import java.util.zip.GZIPInputStream;
 
 import javax.net.ssl.HttpsURLConnection;
 import javax.net.ssl.SSLException;
@@ -61,6 +60,7 @@ import org.apache.http.client.methods.HttpHead;
 import org.apache.http.client.methods.HttpPut;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.client.utils.DateUtils;
 import org.apache.http.config.Registry;
 import org.apache.http.config.RegistryBuilder;
 import org.apache.http.conn.HttpClientConnectionManager;
@@ -76,8 +76,6 @@ import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
 import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
-import org.apache.http.impl.cookie.DateParseException;
-import org.apache.http.impl.cookie.DateUtils;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.protocol.HTTP;
 import org.apache.http.util.TextUtils;
@@ -975,8 +973,6 @@ public abstract class AbstractHttpClientWagon
                 }
             }
 
-            InputStream is;
-
             Header contentLengthHeader = response.getFirstHeader( "Content-Length" );
 
             if ( contentLengthHeader != null )
@@ -995,48 +991,20 @@ public abstract class AbstractHttpClientWagon
             }
 
             Header lastModifiedHeader = response.getFirstHeader( "Last-Modified" );
-
-            long lastModified = 0;
-
             if ( lastModifiedHeader != null )
             {
-                try
-                {
-                    lastModified = DateUtils.parseDate( lastModifiedHeader.getValue() ).getTime();
-
-                    resource.setLastModified( lastModified );
+                Date lastModified = DateUtils.parseDate(lastModifiedHeader.getValue());
+                if ( lastModified != null ) {
+                    resource.setLastModified( lastModified.getTime() );
+                    fireTransferDebug( "last-modified = " + lastModifiedHeader.getValue() +
+                            " (" + lastModified.getTime() + ")" );
                 }
-                catch ( DateParseException e )
-                {
-                    fireTransferDebug( "Unable to parse last modified header" );
-                }
-
-                fireTransferDebug( "last-modified = " + lastModifiedHeader.getValue() + " (" + lastModified + ")" );
             }
 
-            Header contentEncoding = response.getFirstHeader( "Content-Encoding" );
-            boolean isGZipped = contentEncoding == null ? false : "gzip".equalsIgnoreCase( contentEncoding.getValue() );
-
-            try
-            {
-                is = response.getEntity().getContent();
-
-                if ( isGZipped )
-                {
-                    is = new GZIPInputStream( is );
-                }
-            }
-            catch ( IOException e )
-            {
-                fireTransferError( resource, e, TransferEvent.REQUEST_GET );
-
-                String msg =
-                    "Error occurred while retrieving from remote repository " + getRepository() + ": " + e.getMessage();
-
-                throw new TransferFailedException( msg, e );
+            HttpEntity entity = response.getEntity();
+            if ( entity != null ) {
+                inputData.setInputStream( entity.getContent() );
             }
-
-            inputData.setInputStream( is );
         }
         catch ( IOException e )
         {


[4/9] git commit: Removed unnecessary private method

Posted by ol...@apache.org.
Removed unnecessary private method


Project: http://git-wip-us.apache.org/repos/asf/maven-wagon/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-wagon/commit/dc8f00ec
Tree: http://git-wip-us.apache.org/repos/asf/maven-wagon/tree/dc8f00ec
Diff: http://git-wip-us.apache.org/repos/asf/maven-wagon/diff/dc8f00ec

Branch: refs/heads/master
Commit: dc8f00ec94c2f717b3230589564943f0b69c7a0c
Parents: 9a1b729
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Tue Sep 24 14:34:57 2013 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Tue Sep 24 14:34:57 2013 +0200

----------------------------------------------------------------------
 .../providers/http/HttpMethodConfiguration.java | 99 --------------------
 1 file changed, 99 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/dc8f00ec/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpMethodConfiguration.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpMethodConfiguration.java b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpMethodConfiguration.java
index 3be9837..1d10c49 100755
--- a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpMethodConfiguration.java
+++ b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpMethodConfiguration.java
@@ -268,105 +268,6 @@ public class HttpMethodConfiguration
         return this;
     }
 
-    private void fillParams( HttpParams p )
-    {
-        if ( !hasParams() )
-        {
-            return;
-        }
-
-        if ( connectionTimeout > 0 )
-        {
-            p.setParameter( CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout );
-        }
-
-        if ( readTimeout > 0 )
-        {
-            p.setParameter( CoreConnectionPNames.SO_TIMEOUT, readTimeout );
-        }
-
-        if ( params != null )
-        {
-            Pattern coercePattern = Pattern.compile( COERCE_PATTERN );
-
-            for ( Iterator<?> it = params.entrySet().iterator(); it.hasNext(); )
-            {
-                Map.Entry<String, String> entry = (Map.Entry) it.next();
-
-                String key = entry.getKey();
-                String value = entry.getValue();
-
-                Matcher matcher = coercePattern.matcher( value );
-                if ( matcher.matches() )
-                {
-                    char type = matcher.group( 1 ).charAt( 0 );
-                    value = matcher.group( 2 );
-
-                    switch ( type )
-                    {
-                        case 'i':
-                        {
-                            p.setIntParameter( key, Integer.parseInt( value ) );
-                            break;
-                        }
-                        case 'd':
-                        {
-                            p.setDoubleParameter( key, Double.parseDouble( value ) );
-                            break;
-                        }
-                        case 'l':
-                        {
-                            p.setLongParameter( key, Long.parseLong( value ) );
-                            break;
-                        }
-                        case 'b':
-                        {
-                            p.setBooleanParameter( key, Boolean.valueOf( value ).booleanValue() );
-                            break;
-                        }
-                        case 'c':
-                        {
-                            String[] entries = value.split( "," );
-                            List<String> collection = new ArrayList<String>();
-                            for ( int i = 0; i < entries.length; i++ )
-                            {
-                                collection.add( entries[i].trim() );
-                            }
-
-                            p.setParameter( key, collection );
-                            break;
-                        }
-                        case 'm':
-                        {
-                            String[] entries = value.split( "," );
-
-                            Map<String, String> map = new LinkedHashMap<String, String>();
-                            for ( int i = 0; i < entries.length; i++ )
-                            {
-                                int idx = entries[i].indexOf( "=>" );
-                                if ( idx < 1 )
-                                {
-                                    break;
-                                }
-
-                                String mapKey = entries[i].substring( 0, idx );
-                                String mapVal = entries[i].substring( idx + 1, entries[i].length() );
-                                map.put( mapKey.trim(), mapVal.trim() );
-                            }
-
-                            p.setParameter( key, map );
-                            break;
-                        }
-                    }
-                }
-                else
-                {
-                    p.setParameter( key, value );
-                }
-            }
-        }
-    }
-
     public Header[] asRequestHeaders()
     {
         if ( headers == null )


[9/9] git commit: merging httpclient-4.3 branch from Oleg

Posted by ol...@apache.org.
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" );
      }
--}
++}


[2/9] git commit: Refactored connection initialization and management code; removed single connection mode

Posted by ol...@apache.org.
Refactored connection initialization and management code; removed single connection mode


Project: http://git-wip-us.apache.org/repos/asf/maven-wagon/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-wagon/commit/e8c135d8
Tree: http://git-wip-us.apache.org/repos/asf/maven-wagon/tree/e8c135d8
Diff: http://git-wip-us.apache.org/repos/asf/maven-wagon/diff/e8c135d8

Branch: refs/heads/master
Commit: e8c135d88e1730c068907625113d6ba116067225
Parents: 16f0f9d
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Sat Sep 21 12:36:50 2013 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Tue Sep 24 13:47:26 2013 +0200

----------------------------------------------------------------------
 .../providers/http/AbstractHttpClientWagon.java | 192 ++++++-------------
 .../providers/http/RelaxedX509TrustManager.java |  23 +--
 .../wagon/providers/http/HttpWagonTest.java     |   8 -
 3 files changed, 69 insertions(+), 154 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/e8c135d8/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
----------------------------------------------------------------------
diff --git 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
index d195fae..dd4fb8e 100755
--- 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
@@ -28,18 +28,15 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.URLEncoder;
 import java.nio.ByteBuffer;
-import java.security.cert.X509Certificate;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
 import java.util.TimeZone;
+import java.util.concurrent.TimeUnit;
 
 import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLException;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLSocket;
 
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
@@ -63,22 +60,18 @@ import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.client.utils.DateUtils;
 import org.apache.http.config.Registry;
 import org.apache.http.config.RegistryBuilder;
-import org.apache.http.conn.HttpClientConnectionManager;
 import org.apache.http.conn.socket.ConnectionSocketFactory;
 import org.apache.http.conn.socket.PlainConnectionSocketFactory;
 import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
-import org.apache.http.conn.ssl.X509HostnameVerifier;
 import org.apache.http.entity.AbstractHttpEntity;
 import org.apache.http.impl.auth.BasicScheme;
 import org.apache.http.impl.client.BasicAuthCache;
 import org.apache.http.impl.client.BasicCredentialsProvider;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
 import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.protocol.HTTP;
-import org.apache.http.util.TextUtils;
 import org.apache.maven.wagon.InputData;
 import org.apache.maven.wagon.OutputData;
 import org.apache.maven.wagon.PathUtils;
@@ -223,7 +216,7 @@ public abstract class AbstractHttpClientWagon
 
     protected static final int SC_NULL = -1;
 
-    protected static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone( "GMT" );
+    private static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone( "GMT" );
 
     private CloseableHttpClient client;
 
@@ -232,163 +225,92 @@ public abstract class AbstractHttpClientWagon
     private Closeable closeable;
 
     /**
-     * @since 2.0
-     */
-    protected static HttpClientConnectionManager connectionManagerPooled;
-
-    /**
-     * @since 2.0
-     */
-    protected HttpClientConnectionManager clientConnectionManager = new BasicHttpClientConnectionManager(
-            createSocketFactoryRegistry() );
-
-    /**
      * use http(s) connection pool mechanism.
      * <b>enabled by default</b>
-     *
-     * @since 2.0
      */
-    protected static boolean useClientManagerPooled =
-        Boolean.valueOf( System.getProperty( "maven.wagon.http.pool", "true" ) );
+    private final static boolean PERSISTENT_POOL =
+            Boolean.valueOf( System.getProperty( "maven.wagon.http.pool", "true" ) );
 
     /**
      * skip failure on certificate validity checks.
      * <b>disabled by default</b>
-     *
-     * @since 2.0
      */
-    protected static boolean sslInsecure = Boolean.valueOf( System.getProperty( "maven.wagon.http.ssl.insecure", "false" ) );
+    private final static boolean SSL_INSECURE =
+            Boolean.valueOf( System.getProperty( "maven.wagon.http.ssl.insecure", "false" ) );
 
     /**
      * if using sslInsecure, certificate date issues will be ignored
      * <b>disabled by default</b>
-     *
-     * @since 2.0
      */
-    protected static boolean IGNORE_SSL_VALIDITY_DATES =
-        Boolean.valueOf( System.getProperty( "maven.wagon.http.ssl.ignore.validity.dates", "false" ) );
+    private final static boolean IGNORE_SSL_VALIDITY_DATES =
+            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>
-     *
-     * @since 2.0
-     * @see RelaxedHostNameVerifier
      */
-    protected static boolean sslAllowAll =
-        Boolean.valueOf( System.getProperty( "maven.wagon.http.ssl.allowall", "false" ) );
+    private final static boolean SSL_ALLOW_ALL =
+            Boolean.valueOf( System.getProperty( "maven.wagon.http.ssl.allowall", "false" ) );
 
-    private static String[] split(final String s) {
-        if (TextUtils.isBlank(s)) {
-            return null;
-        }
-        return s.split(" *, *");
-    }
 
-    private static Registry<ConnectionSocketFactory> createSocketFactoryRegistry()
+    /**
+     * Maximum conncurrent connections per distinct route.
+     * <b>20 by default</b>
+     */
+    private final static int MAX_CONN_PER_ROUTE =
+            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" ) );
+
+    /**
+     * Internal connection manager
+     */
+    private static final PoolingHttpClientConnectionManager connManager = createConnManager();
+
+    private static PoolingHttpClientConnectionManager createConnManager()
     {
-        String[] sslProtocols = split(System.getProperty("https.protocols"));
-        String[] cipherSuites = split(System.getProperty("https.cipherSuites"));
-        SSLConnectionSocketFactory sslSocketFactory;
-        if ( sslInsecure )
+
+        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 )
         {
-            try
-            {
-                sslSocketFactory = new SSLConnectionSocketFactory(
-                        RelaxedX509TrustManager.createRelaxedSSLContext(),
-                        sslProtocols,
-                        cipherSuites,
-                        sslAllowAll ? new RelaxedHostNameVerifier() : SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER );
-            }
-            catch ( IOException e )
-            {
-                throw new RuntimeException( "failed to init SSLSocket Factory " + e.getMessage(), e );
-            }
+            sslConnectionSocketFactory = new SSLConnectionSocketFactory(
+                    RelaxedX509TrustManager.createRelaxedSSLContext(IGNORE_SSL_VALIDITY_DATES),
+                    sslProtocols,
+                    cipherSuites,
+                    SSL_ALLOW_ALL ? SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER : SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER );
         }
         else
         {
-            sslSocketFactory = new SSLConnectionSocketFactory(
+            sslConnectionSocketFactory = new SSLConnectionSocketFactory(
                     HttpsURLConnection.getDefaultSSLSocketFactory(),
                     sslProtocols,
                     cipherSuites,
                     SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER );
         }
-        return RegistryBuilder.<ConnectionSocketFactory>create()
+
+        Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                 .register("http", PlainConnectionSocketFactory.INSTANCE)
-                .register("https", sslSocketFactory)
+                .register("https", sslConnectionSocketFactory)
                 .build();
-    }
-
-    static
-    {
-        if ( !useClientManagerPooled )
-        {
-            System.out.println( "http connection pool disabled in wagon http" );
-        }
-        else
-        {
-            PoolingHttpClientConnectionManager poolingClientConnectionManager =
-                new PoolingHttpClientConnectionManager( createSocketFactoryRegistry() );
-            int maxPerRoute =
-                Integer.parseInt( System.getProperty( "maven.wagon.httpconnectionManager.maxPerRoute", "20" ) );
-            poolingClientConnectionManager.setDefaultMaxPerRoute( maxPerRoute );
-            int maxTotal = Integer.parseInt( System.getProperty( "maven.wagon.httpconnectionManager.maxTotal", "40" ) );
-            poolingClientConnectionManager.setDefaultMaxPerRoute( maxPerRoute );
-            poolingClientConnectionManager.setMaxTotal( maxTotal );
-
-            connectionManagerPooled = poolingClientConnectionManager;
-        }
-    }
-
-    /**
-     * disable all host name verification
-     *
-     * @since 2.0
-     */
-    private static class RelaxedHostNameVerifier
-        implements X509HostnameVerifier
-    {
-        public void verify( String s, SSLSocket sslSocket )
-            throws IOException
-        {
-            //no op
-        }
-
-        public void verify( String s, X509Certificate x509Certificate )
-            throws SSLException
-        {
-            //no op
-        }
 
-        public void verify( String s, String[] strings, String[] strings1 )
-            throws SSLException
-        {
-            //no op
+        PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager( registry );
+        if (PERSISTENT_POOL) {
+            connManager.setDefaultMaxPerRoute( MAX_CONN_PER_ROUTE );
+            connManager.setMaxTotal( MAX_CONN_TOTAL );
+        } else {
+            connManager.setMaxTotal( 1 );
         }
-
-        public boolean verify( String s, SSLSession sslSession )
-        {
-            return true;
-        }
-    }
-
-    public HttpClientConnectionManager getConnectionManager()
-    {
-        if ( !useClientManagerPooled )
-        {
-            return clientConnectionManager;
-        }
-        return connectionManagerPooled;
-    }
-
-    public static void setConnectionManagerPooled( HttpClientConnectionManager clientConnectionManager )
-    {
-        connectionManagerPooled = clientConnectionManager;
-    }
-
-    public static void setUseClientManagerPooled( boolean pooledClientManager )
-    {
-        useClientManagerPooled = pooledClientManager;
+        return connManager;
     }
 
     /**
@@ -475,7 +397,7 @@ public abstract class AbstractHttpClientWagon
         client = HttpClientBuilder.create()
                 .useSystemProperties()
                 .disableConnectionState()
-                .setConnectionManager(getConnectionManager())
+                .setConnectionManager(connManager)
                 .setProxy(proxy)
                 .setDefaultCredentialsProvider(credentialsProvider)
                 .build();
@@ -483,9 +405,9 @@ public abstract class AbstractHttpClientWagon
 
     public void closeConnection()
     {
-        if ( !useClientManagerPooled )
+        if ( !PERSISTENT_POOL)
         {
-            getConnectionManager().shutdown();
+            connManager.closeIdleConnections(0, TimeUnit.MILLISECONDS);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/e8c135d8/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/RelaxedX509TrustManager.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/RelaxedX509TrustManager.java b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/RelaxedX509TrustManager.java
index f0d14eb..6d54059 100644
--- a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/RelaxedX509TrustManager.java
+++ b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/RelaxedX509TrustManager.java
@@ -19,6 +19,8 @@ package org.apache.maven.wagon.providers.http;
  * under the License.
  */
 
+import org.apache.http.conn.ssl.SSLInitializationException;
+
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.TrustManager;
 import javax.net.ssl.TrustManagerFactory;
@@ -37,34 +39,32 @@ import java.security.cert.X509Certificate;
  *
  * @author Olivier Lamy
  * @since 2.0
- * @see AbstractHttpClientWagon.IGNORE_SSL_VALIDITY_DATES
  */
 public class RelaxedX509TrustManager
     implements X509TrustManager
 {
-    private X509TrustManager standardTrustManager = null;
+    private final X509TrustManager standardTrustManager;
+    private final boolean ignoreSSLValidityDates;
 
-    protected static SSLContext createRelaxedSSLContext()
-        throws IOException
+    public static SSLContext createRelaxedSSLContext( boolean ignoreSSLValidityDates )
     {
         try
         {
             SSLContext context = SSLContext.getInstance( "SSL" );
-            context.init( null, new TrustManager[]{ new RelaxedX509TrustManager( null ) }, null );
+            context.init( null, new TrustManager[]{
+                    new RelaxedX509TrustManager( null, ignoreSSLValidityDates ) }, null );
             return context;
         }
         catch ( Exception e )
         {
-            IOException ioe = new IOException( e.getMessage() );
-            ioe.initCause( e );
-            throw ioe;
+            throw new SSLInitializationException(e.getMessage(), e);
         }
     }
 
     /**
      * Constructor for EasyX509TrustManager.
      */
-    public RelaxedX509TrustManager( KeyStore keystore )
+    public RelaxedX509TrustManager( KeyStore keystore, boolean ignoreSSLValidityDates )
         throws NoSuchAlgorithmException, KeyStoreException
     {
         super();
@@ -76,6 +76,7 @@ public class RelaxedX509TrustManager
             throw new NoSuchAlgorithmException( "no trust manager found" );
         }
         this.standardTrustManager = (X509TrustManager) trustmanagers[0];
+        this.ignoreSSLValidityDates = ignoreSSLValidityDates;
     }
 
     /**
@@ -102,14 +103,14 @@ public class RelaxedX509TrustManager
             }
             catch ( CertificateExpiredException e )
             {
-                if ( !AbstractHttpClientWagon.IGNORE_SSL_VALIDITY_DATES )
+                if ( !ignoreSSLValidityDates )
                 {
                     throw e;
                 }
             }
             catch ( CertificateNotYetValidException e )
             {
-                if ( !AbstractHttpClientWagon.IGNORE_SSL_VALIDITY_DATES )
+                if ( !ignoreSSLValidityDates )
                 {
                     throw e;
                 }

http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/e8c135d8/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonTest.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonTest.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonTest.java
index edc7538..9552cbe 100755
--- a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonTest.java
+++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonTest.java
@@ -52,14 +52,6 @@ public class HttpWagonTest
         ( (HttpWagon) wagon ).setHttpConfiguration( config );
     }
 
-    public void testDefaultPooledConnectionManager()
-        throws Exception
-    {
-        HttpWagon wagon = (HttpWagon) lookup( Wagon.class, "http" );
-        assertTrue( wagon.getConnectionManager() instanceof PoolingHttpClientConnectionManager );
-
-    }
-
     @Override
     protected boolean supportPreemptiveAuthenticationPut()
     {


[5/9] git commit: Use SSLContextBuilder provided by HttpClient to create custom SSL contexts

Posted by ol...@apache.org.
Use SSLContextBuilder provided by HttpClient to create custom SSL contexts


Project: http://git-wip-us.apache.org/repos/asf/maven-wagon/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-wagon/commit/008accb6
Tree: http://git-wip-us.apache.org/repos/asf/maven-wagon/tree/008accb6
Diff: http://git-wip-us.apache.org/repos/asf/maven-wagon/diff/008accb6

Branch: refs/heads/master
Commit: 008accb65f4c49d20c9ca2117ad9a71e4eb3d2a6
Parents: dc8f00e
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Tue Sep 24 14:55:23 2013 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Tue Sep 24 14:55:23 2013 +0200

----------------------------------------------------------------------
 .../providers/http/AbstractHttpClientWagon.java |  26 +++-
 .../providers/http/RelaxedTrustStrategy.java    |  85 ++++++++++++
 .../providers/http/RelaxedX509TrustManager.java | 132 -------------------
 3 files changed, 106 insertions(+), 137 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/008accb6/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
----------------------------------------------------------------------
diff --git 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
index 0b683ae..0fd7ada 100755
--- 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
@@ -28,6 +28,9 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.URLEncoder;
 import java.nio.ByteBuffer;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Locale;
@@ -37,6 +40,7 @@ import java.util.TimeZone;
 import java.util.concurrent.TimeUnit;
 
 import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
 
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
@@ -63,6 +67,8 @@ import org.apache.http.config.RegistryBuilder;
 import org.apache.http.conn.socket.ConnectionSocketFactory;
 import org.apache.http.conn.socket.PlainConnectionSocketFactory;
 import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.conn.ssl.SSLContextBuilder;
+import org.apache.http.conn.ssl.SSLInitializationException;
 import org.apache.http.entity.AbstractHttpEntity;
 import org.apache.http.impl.auth.BasicScheme;
 import org.apache.http.impl.client.BasicAuthCache;
@@ -281,11 +287,21 @@ public abstract class AbstractHttpClientWagon
         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 );
+            }
+            catch (Exception ex)
+            {
+                throw new SSLInitializationException(ex.getMessage(), ex);
+            }
         }
         else
         {

http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/008accb6/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/RelaxedTrustStrategy.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/RelaxedTrustStrategy.java b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/RelaxedTrustStrategy.java
new file mode 100644
index 0000000..c700218
--- /dev/null
+++ b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/RelaxedTrustStrategy.java
@@ -0,0 +1,85 @@
+package org.apache.maven.wagon.providers.http;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.http.conn.ssl.SSLInitializationException;
+import org.apache.http.conn.ssl.TrustStrategy;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+import javax.net.ssl.X509TrustManager;
+import java.io.IOException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateExpiredException;
+import java.security.cert.CertificateNotYetValidException;
+import java.security.cert.X509Certificate;
+
+/**
+ * Relaxed X509 certificate trust manager: can ignore invalid certificate date.
+ *
+ * @author Olivier Lamy
+ * @since 2.0
+ */
+public class RelaxedTrustStrategy
+    implements TrustStrategy
+{
+    private final boolean ignoreSSLValidityDates;
+
+    public RelaxedTrustStrategy(boolean ignoreSSLValidityDates)
+    {
+        this.ignoreSSLValidityDates = ignoreSSLValidityDates;
+    }
+
+    public boolean isTrusted(X509Certificate[] certificates, String authType)
+        throws CertificateException
+    {
+        if ( ( certificates != null ) && ( certificates.length == 1 ) )
+        {
+            try
+            {
+                certificates[0].checkValidity();
+            }
+            catch ( CertificateExpiredException e )
+            {
+                if ( !ignoreSSLValidityDates )
+                {
+                    throw e;
+                }
+            }
+            catch ( CertificateNotYetValidException e )
+            {
+                if ( !ignoreSSLValidityDates )
+                {
+                    throw e;
+                }
+            }
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/008accb6/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/RelaxedX509TrustManager.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/RelaxedX509TrustManager.java b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/RelaxedX509TrustManager.java
deleted file mode 100644
index 6d54059..0000000
--- a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/RelaxedX509TrustManager.java
+++ /dev/null
@@ -1,132 +0,0 @@
-package org.apache.maven.wagon.providers.http;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.http.conn.ssl.SSLInitializationException;
-
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.TrustManagerFactory;
-import javax.net.ssl.X509TrustManager;
-import java.io.IOException;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.cert.CertificateException;
-import java.security.cert.CertificateExpiredException;
-import java.security.cert.CertificateNotYetValidException;
-import java.security.cert.X509Certificate;
-
-/**
- * Relaxed X509 certificate trust manager: can ignore invalid certificate date.
- *
- * @author Olivier Lamy
- * @since 2.0
- */
-public class RelaxedX509TrustManager
-    implements X509TrustManager
-{
-    private final X509TrustManager standardTrustManager;
-    private final boolean ignoreSSLValidityDates;
-
-    public static SSLContext createRelaxedSSLContext( boolean ignoreSSLValidityDates )
-    {
-        try
-        {
-            SSLContext context = SSLContext.getInstance( "SSL" );
-            context.init( null, new TrustManager[]{
-                    new RelaxedX509TrustManager( null, ignoreSSLValidityDates ) }, null );
-            return context;
-        }
-        catch ( Exception e )
-        {
-            throw new SSLInitializationException(e.getMessage(), e);
-        }
-    }
-
-    /**
-     * Constructor for EasyX509TrustManager.
-     */
-    public RelaxedX509TrustManager( KeyStore keystore, boolean ignoreSSLValidityDates )
-        throws NoSuchAlgorithmException, KeyStoreException
-    {
-        super();
-        TrustManagerFactory factory = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() );
-        factory.init( keystore );
-        TrustManager[] trustmanagers = factory.getTrustManagers();
-        if ( trustmanagers.length == 0 )
-        {
-            throw new NoSuchAlgorithmException( "no trust manager found" );
-        }
-        this.standardTrustManager = (X509TrustManager) trustmanagers[0];
-        this.ignoreSSLValidityDates = ignoreSSLValidityDates;
-    }
-
-    /**
-     * @see javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[], String authType)
-     */
-    public void checkClientTrusted( X509Certificate[] certificates, String authType )
-        throws CertificateException
-    {
-        standardTrustManager.checkClientTrusted( certificates, authType );
-    }
-
-    /**
-     * @see javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[], String authType)
-     */
-    public void checkServerTrusted( X509Certificate[] certificates, String authType )
-        throws CertificateException
-    {
-
-        if ( ( certificates != null ) && ( certificates.length == 1 ) )
-        {
-            try
-            {
-                certificates[0].checkValidity();
-            }
-            catch ( CertificateExpiredException e )
-            {
-                if ( !ignoreSSLValidityDates )
-                {
-                    throw e;
-                }
-            }
-            catch ( CertificateNotYetValidException e )
-            {
-                if ( !ignoreSSLValidityDates )
-                {
-                    throw e;
-                }
-            }
-        }
-        else
-        {
-            standardTrustManager.checkServerTrusted( certificates, authType );
-        }
-    }
-
-    /**
-     * @see javax.net.ssl.X509TrustManager#getAcceptedIssuers()
-     */
-    public X509Certificate[] getAcceptedIssuers()
-    {
-        return this.standardTrustManager.getAcceptedIssuers();
-    }
-}


[8/9] git commit: Made HttpMethodConfiguration more pure bean like by moving utility methods into a separate class

Posted by ol...@apache.org.
Made HttpMethodConfiguration more pure bean like by moving utility methods into a separate class


Project: http://git-wip-us.apache.org/repos/asf/maven-wagon/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-wagon/commit/d4a6064b
Tree: http://git-wip-us.apache.org/repos/asf/maven-wagon/tree/d4a6064b
Diff: http://git-wip-us.apache.org/repos/asf/maven-wagon/diff/d4a6064b

Branch: refs/heads/master
Commit: d4a6064b1c81213a3add3dd4a06892317d77c46c
Parents: e198f01
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Wed Sep 25 09:57:15 2013 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Wed Sep 25 09:57:15 2013 +0200

----------------------------------------------------------------------
 .../providers/http/AbstractHttpClientWagon.java |   2 +-
 .../providers/http/ConfigurationUtils.java      | 231 +++++++++++++++++++
 .../wagon/providers/http/HttpConfiguration.java |   6 +-
 .../providers/http/HttpMethodConfiguration.java | 194 +---------------
 .../providers/http/HttpClientWagonTest.java     |   2 +-
 5 files changed, 237 insertions(+), 198 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/d4a6064b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
----------------------------------------------------------------------
diff --git 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
index 0a7e59d..fea72b4 100755
--- 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
@@ -702,7 +702,7 @@ public abstract class AbstractHttpClientWagon
 
         if ( config != null )
         {
-            config.applyConfig(requestConfigBuilder);
+            ConfigurationUtils.copyConfig(config, requestConfigBuilder );
 
             if ( config.isUsePreemptive() && authenticationInfo != null )
             {

http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/d4a6064b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/ConfigurationUtils.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/ConfigurationUtils.java b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/ConfigurationUtils.java
new file mode 100755
index 0000000..cfa1b13
--- /dev/null
+++ b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/ConfigurationUtils.java
@@ -0,0 +1,231 @@
+package org.apache.maven.wagon.providers.http;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.http.Header;
+import org.apache.http.HttpHost;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.message.BasicHeader;
+import org.apache.maven.wagon.Wagon;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+class ConfigurationUtils
+{
+
+    private static final String SO_TIMEOUT                  = "http.socket.timeout";
+    private static final String STALE_CONNECTION_CHECK      = "http.connection.stalecheck";
+    private static final String CONNECTION_TIMEOUT          = "http.connection.timeout";
+    private static final String USE_EXPECT_CONTINUE         = "http.protocol.expect-continue";
+    private static final String DEFAULT_PROXY               = "http.route.default-proxy";
+    private static final String LOCAL_ADDRESS               = "http.route.local-address";
+    private static final String PROXY_AUTH_PREF             = "http.auth.proxy-scheme-pref";
+    private static final String TARGET_AUTH_PREF            = "http.auth.target-scheme-pref";
+    private static final String HANDLE_AUTHENTICATION       = "http.protocol.handle-authentication";
+    private static final String ALLOW_CIRCULAR_REDIRECTS    = "http.protocol.allow-circular-redirects";
+    private static final String CONN_MANAGER_TIMEOUT        = "http.conn-manager.timeout";
+    private static final String COOKIE_POLICY               = "http.protocol.cookie-policy";
+    private static final String MAX_REDIRECTS               = "http.protocol.max-redirects";
+    private static final String HANDLE_REDIRECTS            = "http.protocol.handle-redirects";
+    private static final String REJECT_RELATIVE_REDIRECT    = "http.protocol.reject-relative-redirect";
+
+    private static final String COERCE_PATTERN = "%(\\w+),(.+)";
+
+    public static void copyConfig( HttpMethodConfiguration config, RequestConfig.Builder builder )
+    {
+        if ( config.getConnectionTimeout() > 0 )
+        {
+            builder.setConnectTimeout( config.getConnectionTimeout() );
+        }
+        if ( config.getReadTimeout() > 0 )
+        {
+            builder.setSocketTimeout( config.getReadTimeout() );
+        }
+        Properties params = config.getParams();
+        if ( params != null )
+        {
+
+            Pattern coercePattern = Pattern.compile( COERCE_PATTERN );
+            for ( Iterator<?> it = params.entrySet().iterator(); it.hasNext(); )
+            {
+                Map.Entry<String, String> entry = (Map.Entry) it.next();
+                String key = entry.getKey();
+                String value = entry.getValue();
+                Matcher matcher = coercePattern.matcher(value);
+                if ( matcher.matches() )
+                {
+                    value = matcher.group( 2 );
+                }
+
+                if ( key.equals( SO_TIMEOUT ) )
+                {
+                    builder.setSocketTimeout( Integer.parseInt( value ) );
+                }
+                else if ( key.equals( STALE_CONNECTION_CHECK ) )
+                {
+                    builder.setStaleConnectionCheckEnabled( Boolean.valueOf( value ) );
+                }
+                else if ( key.equals( CONNECTION_TIMEOUT ) )
+                {
+                    builder.setConnectTimeout( Integer.parseInt( value ) );
+                }
+                else if ( key.equals( USE_EXPECT_CONTINUE ) )
+                {
+                    builder.setExpectContinueEnabled( Boolean.valueOf( value ) );
+                }
+                else if ( key.equals( DEFAULT_PROXY ) )
+                {
+                    builder.setProxy( new HttpHost( value ));
+                }
+                else if ( key.equals( LOCAL_ADDRESS ) )
+                {
+                    try {
+                        builder.setLocalAddress( InetAddress.getByName( value ) );
+                    }
+                    catch (UnknownHostException ignore) {
+                    }
+                }
+                else if ( key.equals( PROXY_AUTH_PREF ) )
+                {
+                    builder.setProxyPreferredAuthSchemes( Arrays.asList( value.split( "," ) ) );
+                }
+                else if ( key.equals( TARGET_AUTH_PREF ) )
+                {
+                    builder.setTargetPreferredAuthSchemes( Arrays.asList( value.split( "," ) ) );
+                }
+                else if ( key.equals( HANDLE_AUTHENTICATION ) )
+                {
+                    builder.setAuthenticationEnabled( Boolean.valueOf( value ) );
+                }
+                else if ( key.equals( ALLOW_CIRCULAR_REDIRECTS ) )
+                {
+                    builder.setCircularRedirectsAllowed( Boolean.valueOf( value ) );
+                }
+                else if ( key.equals( CONN_MANAGER_TIMEOUT ) )
+                {
+                    builder.setConnectionRequestTimeout( Integer.parseInt( value ) );
+                }
+                else if ( key.equals( COOKIE_POLICY ) )
+                {
+                    builder.setCookieSpec( value );
+                }
+                else if ( key.equals( MAX_REDIRECTS ) )
+                {
+                    builder.setMaxRedirects( Integer.parseInt( value ) );
+                }
+                else if ( key.equals( HANDLE_REDIRECTS ) )
+                {
+                    builder.setRedirectsEnabled( Boolean.valueOf( value ) );
+                }
+                else if ( key.equals( REJECT_RELATIVE_REDIRECT ) )
+                {
+                    builder.setRelativeRedirectsAllowed( !Boolean.valueOf( value ) );
+                }
+            }
+        }
+    }
+
+    public static Header[] asRequestHeaders( HttpMethodConfiguration config )
+    {
+        Properties headers = config.getHeaders();
+        if ( headers == null )
+        {
+            return new Header[0];
+        }
+
+        Header[] result = new Header[headers.size()];
+
+        int index = 0;
+        for ( Iterator<?> it = headers.entrySet().iterator(); it.hasNext(); )
+        {
+            Map.Entry<String, String> entry = (Map.Entry) it.next();
+
+            String key = entry.getKey();
+            String value = entry.getValue();
+
+            Header header = new BasicHeader( key, value );
+            result[index++] = header;
+        }
+
+        return result;
+    }
+
+    public static HttpMethodConfiguration merge( HttpMethodConfiguration defaults, HttpMethodConfiguration base,
+                                            HttpMethodConfiguration local )
+    {
+        HttpMethodConfiguration result = merge( defaults, base );
+        return merge( result, local );
+    }
+
+    public static HttpMethodConfiguration merge( HttpMethodConfiguration base, HttpMethodConfiguration local )
+    {
+        if ( base == null && local == null )
+        {
+            return null;
+        }
+        else if ( base == null )
+        {
+            return local;
+        }
+        else if ( local == null )
+        {
+            return base;
+        }
+        else
+        {
+            HttpMethodConfiguration result = base.copy();
+
+            if ( local.getConnectionTimeout() != Wagon.DEFAULT_CONNECTION_TIMEOUT )
+            {
+                result.setConnectionTimeout( local.getConnectionTimeout() );
+            }
+
+            if ( local.getReadTimeout() != Wagon.DEFAULT_READ_TIMEOUT )
+            {
+                result.setReadTimeout( local.getReadTimeout() );
+            }
+
+            if ( local.getHeaders() != null )
+            {
+                result.getHeaders().putAll( local.getHeaders() );
+            }
+
+            if ( local.getParams() != null )
+            {
+                result.getParams().putAll( local.getParams() );
+            }
+
+            if ( local.getUseDefaultHeaders() != null )
+            {
+                result.setUseDefaultHeaders( local.isUseDefaultHeaders() );
+            }
+
+            return result;
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/d4a6064b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpConfiguration.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpConfiguration.java b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpConfiguration.java
index cacad63..94c0141 100644
--- a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpConfiguration.java
+++ b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpConfiguration.java
@@ -87,15 +87,15 @@ public class HttpConfiguration
     {
         if ( method instanceof HttpGet )
         {
-            return HttpMethodConfiguration.merge( all, get );
+            return ConfigurationUtils.merge( all, get );
         }
         else if ( method instanceof HttpPut )
         {
-            return HttpMethodConfiguration.merge( DEFAULT_PUT, all, put );
+            return ConfigurationUtils.merge( DEFAULT_PUT, all, put );
         }
         else if ( method instanceof HttpHead )
         {
-            return HttpMethodConfiguration.merge( all, head );
+            return ConfigurationUtils.merge( all, head );
         }
 
         return all;

http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/d4a6064b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpMethodConfiguration.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpMethodConfiguration.java b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpMethodConfiguration.java
index a1341eb..d8d26b4 100755
--- a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpMethodConfiguration.java
+++ b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpMethodConfiguration.java
@@ -19,25 +19,12 @@ package org.apache.maven.wagon.providers.http;
  * under the License.
  */
 
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
 import org.apache.http.Header;
-import org.apache.http.HttpHost;
-import org.apache.http.client.config.CookieSpecs;
-import org.apache.http.client.config.RequestConfig;
 import org.apache.http.message.BasicHeader;
-import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.HttpParams;
 import org.apache.maven.wagon.Wagon;
 
 public class HttpMethodConfiguration
@@ -128,131 +115,6 @@ public class HttpMethodConfiguration
         return this;
     }
 
-    private static final String SO_TIMEOUT                  = "http.socket.timeout";
-    private static final String STALE_CONNECTION_CHECK      = "http.connection.stalecheck";
-    private static final String CONNECTION_TIMEOUT          = "http.connection.timeout";
-    private static final String USE_EXPECT_CONTINUE         = "http.protocol.expect-continue";
-    private static final String DEFAULT_PROXY               = "http.route.default-proxy";
-    private static final String LOCAL_ADDRESS               = "http.route.local-address";
-    private static final String PROXY_AUTH_PREF             = "http.auth.proxy-scheme-pref";
-    private static final String TARGET_AUTH_PREF            = "http.auth.target-scheme-pref";
-    private static final String HANDLE_AUTHENTICATION       = "http.protocol.handle-authentication";
-    private static final String ALLOW_CIRCULAR_REDIRECTS    = "http.protocol.allow-circular-redirects";
-    private static final String CONN_MANAGER_TIMEOUT        = "http.conn-manager.timeout";
-    private static final String COOKIE_POLICY               = "http.protocol.cookie-policy";
-    private static final String MAX_REDIRECTS               = "http.protocol.max-redirects";
-    private static final String HANDLE_REDIRECTS            = "http.protocol.handle-redirects";
-    private static final String REJECT_RELATIVE_REDIRECT    = "http.protocol.reject-relative-redirect";
-
-    private static final String COERCE_PATTERN = "%(\\w+),(.+)";
-
-    public void applyConfig(RequestConfig.Builder builder)
-    {
-        if ( !hasParams() )
-        {
-            return;
-        }
-        if ( connectionTimeout > 0 )
-        {
-            builder.setConnectTimeout(connectionTimeout);
-        }
-        if ( readTimeout > 0 )
-        {
-            builder.setSocketTimeout(readTimeout);
-        }
-        if ( params != null )
-        {
-
-            Pattern coercePattern = Pattern.compile( COERCE_PATTERN );
-            for ( Iterator<?> it = params.entrySet().iterator(); it.hasNext(); )
-            {
-                Map.Entry<String, String> entry = (Map.Entry) it.next();
-                String key = entry.getKey();
-                String value = entry.getValue();
-                Matcher matcher = coercePattern.matcher(value);
-                if ( matcher.matches() )
-                {
-                    value = matcher.group( 2 );
-                }
-
-                if ( key.equals( SO_TIMEOUT ) )
-                {
-                    builder.setSocketTimeout( Integer.parseInt( value ) );
-                }
-                else if ( key.equals( STALE_CONNECTION_CHECK ) )
-                {
-                    builder.setStaleConnectionCheckEnabled( Boolean.valueOf( value ) );
-                }
-                else if ( key.equals( CONNECTION_TIMEOUT ) )
-                {
-                    builder.setConnectTimeout( Integer.parseInt( value ) );
-                }
-                else if ( key.equals( USE_EXPECT_CONTINUE ) )
-                {
-                    builder.setExpectContinueEnabled( Boolean.valueOf( value ) );
-                }
-                else if ( key.equals( DEFAULT_PROXY ) )
-                {
-                    builder.setProxy( new HttpHost( value ));
-                }
-                else if ( key.equals( LOCAL_ADDRESS ) )
-                {
-                    try {
-                        builder.setLocalAddress( InetAddress.getByName( value ) );
-                    }
-                    catch (UnknownHostException ignore) {
-                    }
-                }
-                else if ( key.equals( PROXY_AUTH_PREF ) )
-                {
-                    builder.setProxyPreferredAuthSchemes( Arrays.asList( value.split( "," ) ) );
-                }
-                else if ( key.equals( TARGET_AUTH_PREF ) )
-                {
-                    builder.setTargetPreferredAuthSchemes( Arrays.asList( value.split( "," ) ) );
-                }
-                else if ( key.equals( HANDLE_AUTHENTICATION ) )
-                {
-                    builder.setAuthenticationEnabled( Boolean.valueOf( value ) );
-                }
-                else if ( key.equals( ALLOW_CIRCULAR_REDIRECTS ) )
-                {
-                    builder.setCircularRedirectsAllowed( Boolean.valueOf( value ) );
-                }
-                else if ( key.equals( CONN_MANAGER_TIMEOUT ) )
-                {
-                    builder.setConnectionRequestTimeout( Integer.parseInt( value ) );
-                }
-                else if ( key.equals( COOKIE_POLICY ) )
-                {
-                    builder.setCookieSpec( value );
-                }
-                else if ( key.equals( MAX_REDIRECTS ) )
-                {
-                    builder.setMaxRedirects( Integer.parseInt( value ) );
-                }
-                else if ( key.equals( HANDLE_REDIRECTS ) )
-                {
-                    builder.setRedirectsEnabled( Boolean.valueOf( value ) );
-                }
-                else if ( key.equals( REJECT_RELATIVE_REDIRECT ) )
-                {
-                    builder.setRelativeRedirectsAllowed( !Boolean.valueOf( value ) );
-                }
-            }
-        }
-    }
-
-    private boolean hasParams()
-    {
-        if ( connectionTimeout < 1 && params == null && readTimeout < 1 )
-        {
-            return false;
-        }
-
-        return true;
-    }
-
     public boolean isUsePreemptive()
     {
         return usePreemptive;
@@ -288,7 +150,7 @@ public class HttpMethodConfiguration
         return result;
     }
 
-    private HttpMethodConfiguration copy()
+    HttpMethodConfiguration copy()
     {
         HttpMethodConfiguration copy = new HttpMethodConfiguration();
 
@@ -309,58 +171,4 @@ public class HttpMethodConfiguration
         return copy;
     }
 
-    public static HttpMethodConfiguration merge( HttpMethodConfiguration defaults, HttpMethodConfiguration base,
-                                                 HttpMethodConfiguration local )
-    {
-        HttpMethodConfiguration result = merge( defaults, base );
-        return merge( result, local );
-    }
-
-    public static HttpMethodConfiguration merge( HttpMethodConfiguration base, HttpMethodConfiguration local )
-    {
-        if ( base == null && local == null )
-        {
-            return null;
-        }
-        else if ( base == null )
-        {
-            return local;
-        }
-        else if ( local == null )
-        {
-            return base;
-        }
-        else
-        {
-            HttpMethodConfiguration result = base.copy();
-
-            if ( local.getConnectionTimeout() != Wagon.DEFAULT_CONNECTION_TIMEOUT )
-            {
-                result.setConnectionTimeout( local.getConnectionTimeout() );
-            }
-
-            if ( local.getReadTimeout() != Wagon.DEFAULT_READ_TIMEOUT )
-            {
-                result.setReadTimeout( local.getReadTimeout() );
-            }
-
-            if ( local.getHeaders() != null )
-            {
-                result.getHeaders().putAll( local.getHeaders() );
-            }
-
-            if ( local.getParams() != null )
-            {
-                result.getParams().putAll( local.getParams() );
-            }
-
-            if ( local.getUseDefaultHeaders() != null )
-            {
-                result.setUseDefaultHeaders( local.isUseDefaultHeaders() );
-            }
-
-            return result;
-        }
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/d4a6064b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java
index 01a130c..4634481 100755
--- a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java
+++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java
@@ -43,7 +43,7 @@ public class HttpClientWagonTest
 
         HttpHead method = new HttpHead();
         RequestConfig.Builder builder = RequestConfig.custom();
-        config.getMethodConfiguration(method).applyConfig( builder );
+        ConfigurationUtils.copyConfig( config.getMethodConfiguration( method ), builder );
         RequestConfig requestConfig = builder.build();
 
         assertEquals(2, requestConfig.getMaxRedirects());