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 2011/10/20 18:17:01 UTC

svn commit: r1186886 - /maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java

Author: olamy
Date: Thu Oct 20 16:17:01 2011
New Revision: 1186886

URL: http://svn.apache.org/viewvc?rev=1186886&view=rev
Log:
fix formatting I have broken in a previous commit: no functionnal change. sorry herve :P

Modified:
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java

Modified: maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java?rev=1186886&r1=1186885&r2=1186886&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java Thu Oct 20 16:17:01 2011
@@ -122,7 +122,7 @@ public abstract class AbstractHttpClient
                 try
                 {
                     this.source = File.createTempFile( "http-wagon.", ".tmp" );
-                    this.source.deleteOnExit( );
+                    this.source.deleteOnExit();
 
                     fos = new FileOutputStream( this.source );
                     IOUtil.copy( stream, fos );
@@ -142,22 +142,22 @@ public abstract class AbstractHttpClient
             this.wagon = wagon;
         }
 
-        public long getContentLength( )
+        public long getContentLength()
         {
-            return resource.getContentLength( );
+            return resource.getContentLength();
         }
 
-        public Header getContentType( )
+        public Header getContentType()
         {
             return null;
         }
 
-        public Header getContentEncoding( )
+        public Header getContentEncoding()
         {
             return null;
         }
 
-        public InputStream getContent( )
+        public InputStream getContent()
             throws IOException, IllegalStateException
         {
             FileInputStream fis = new FileInputStream( source );
@@ -165,12 +165,12 @@ public abstract class AbstractHttpClient
             return fis;
         }
 
-        public boolean isRepeatable( )
+        public boolean isRepeatable()
         {
             return true;
         }
 
-        public boolean isChunked( )
+        public boolean isChunked()
         {
             return false;
         }
@@ -182,7 +182,7 @@ public abstract class AbstractHttpClient
 
             TransferEvent transferEvent =
                 new TransferEvent( wagon, resource, TransferEvent.TRANSFER_PROGRESS, TransferEvent.REQUEST_PUT );
-            transferEvent.setTimestamp( System.currentTimeMillis( ) );
+            transferEvent.setTimestamp( System.currentTimeMillis() );
 
             FileInputStream fin = null;
             try
@@ -210,15 +210,15 @@ public abstract class AbstractHttpClient
                 IOUtil.close( fin );
             }
 
-            output.flush( );
+            output.flush();
         }
 
-        public boolean isStreaming( )
+        public boolean isStreaming()
         {
             return false;
         }
 
-        public void consumeContent( )
+        public void consumeContent()
             throws IOException
         {
         }
@@ -238,7 +238,7 @@ public abstract class AbstractHttpClient
     /**
      * @since 2.0
      */
-    protected ClientConnectionManager clientConnectionManager = new SingleClientConnManager( );
+    protected ClientConnectionManager clientConnectionManager = new SingleClientConnManager();
 
     /**
      * use http(s) connection pool mechanism.
@@ -284,7 +284,7 @@ public abstract class AbstractHttpClient
         else
         {
 
-            ThreadSafeClientConnManager threadSafeClientConnManager = new ThreadSafeClientConnManager( );
+            ThreadSafeClientConnManager threadSafeClientConnManager = new ThreadSafeClientConnManager();
             int maxPerRoute =
                 Integer.parseInt( System.getProperty( "maven.wagon.httpconnectionManager.maxPerRoute", "20" ) );
             threadSafeClientConnManager.setDefaultMaxPerRoute( maxPerRoute );
@@ -297,21 +297,21 @@ public abstract class AbstractHttpClient
                 try
                 {
                     SSLSocketFactory sslSocketFactory =
-                        new SSLSocketFactory( EasyX509TrustManager.createEasySSLContext( ), sslAllowAll
-                            ? new EasyHostNameVerifier( )
-                            : new BrowserCompatHostnameVerifier( ) );
+                        new SSLSocketFactory( EasyX509TrustManager.createEasySSLContext(), sslAllowAll
+                            ? new EasyHostNameVerifier()
+                            : new BrowserCompatHostnameVerifier() );
                     Scheme httpsScheme = new Scheme( "https", 443, sslSocketFactory );
 
-                    threadSafeClientConnManager.getSchemeRegistry( ).register( httpsScheme );
+                    threadSafeClientConnManager.getSchemeRegistry().register( httpsScheme );
                 }
                 catch ( IOException e )
                 {
-                    throw new RuntimeException( "failed to init SSLSocket Factory " + e.getMessage( ), e );
+                    throw new RuntimeException( "failed to init SSLSocket Factory " + e.getMessage(), e );
                 }
             }
             System.out.println( " wagon http use multi threaded http connection manager maxPerRoute "
-                                    + threadSafeClientConnManager.getDefaultMaxPerRoute( ) + ", max total "
-                                    + threadSafeClientConnManager.getMaxTotal( ) );
+                                    + threadSafeClientConnManager.getDefaultMaxPerRoute() + ", max total "
+                                    + threadSafeClientConnManager.getMaxTotal() );
 
             connectionManagerPooled = threadSafeClientConnManager;
         }
@@ -349,7 +349,7 @@ public abstract class AbstractHttpClient
         }
     }
 
-    public ClientConnectionManager getConnectionManager( )
+    public ClientConnectionManager getConnectionManager()
     {
         if ( !useClientManagerPooled )
         {
@@ -381,52 +381,51 @@ public abstract class AbstractHttpClient
 
     private HttpGet getMethod;
 
-    public void openConnectionInternal( )
+    public void openConnectionInternal()
     {
         repository.setUrl( getURL( repository ) );
-        client = new DefaultHttpClient( getConnectionManager( ) );
+        client = new DefaultHttpClient( getConnectionManager() );
 
         // WAGON-273: default the cookie-policy to browser compatible
-        client.getParams( ).setParameter( ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY );
+        client.getParams().setParameter( ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY );
 
         String username = null;
         String password = null;
 
         if ( authenticationInfo != null )
         {
-            username = authenticationInfo.getUserName( );
+            username = authenticationInfo.getUserName();
 
-            password = authenticationInfo.getPassword( );
+            password = authenticationInfo.getPassword();
         }
 
         if ( StringUtils.isNotEmpty( username ) && StringUtils.isNotEmpty( password ) )
         {
             Credentials creds = new UsernamePasswordCredentials( username, password );
 
-            String host = getRepository( ).getHost( );
-            int port = getRepository( ).getPort( ) > -1 ? getRepository( ).getPort( ) : AuthScope.ANY_PORT;
+            String host = getRepository().getHost();
+            int port = getRepository().getPort() > -1 ? getRepository().getPort() : AuthScope.ANY_PORT;
 
-            client.getCredentialsProvider( ).setCredentials( new AuthScope( host, port ), creds );
+            client.getCredentialsProvider().setCredentials( new AuthScope( host, port ), creds );
 
-            AuthCache authCache = new BasicAuthCache( );
-            BasicScheme basicAuth = new BasicScheme( );
-            HttpHost targetHost =
-                new HttpHost( repository.getHost( ), repository.getPort( ), repository.getProtocol( ) );
+            AuthCache authCache = new BasicAuthCache();
+            BasicScheme basicAuth = new BasicScheme();
+            HttpHost targetHost = new HttpHost( repository.getHost(), repository.getPort(), repository.getProtocol() );
             authCache.put( targetHost, basicAuth );
 
-            localContext = new BasicHttpContext( );
+            localContext = new BasicHttpContext();
             localContext.setAttribute( ClientContext.AUTH_CACHE, authCache );
         }
 
-        ProxyInfo proxyInfo = getProxyInfo( getRepository( ).getProtocol( ), getRepository( ).getHost( ) );
+        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( );
+            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 )
             {
                 HttpHost proxy = new HttpHost( proxyHost, proxyPort );
@@ -443,22 +442,22 @@ public abstract class AbstractHttpClient
                         creds = new UsernamePasswordCredentials( proxyUsername, proxyPassword );
                     }
 
-                    int port = proxyInfo.getPort( ) > -1 ? proxyInfo.getPort( ) : AuthScope.ANY_PORT;
+                    int port = proxyInfo.getPort() > -1 ? proxyInfo.getPort() : AuthScope.ANY_PORT;
 
                     AuthScope authScope = new AuthScope( proxyHost, port );
-                    client.getCredentialsProvider( ).setCredentials( authScope, creds );
+                    client.getCredentialsProvider().setCredentials( authScope, creds );
                 }
 
-                client.getParams( ).setParameter( ConnRoutePNames.DEFAULT_PROXY, proxy );
+                client.getParams().setParameter( ConnRoutePNames.DEFAULT_PROXY, proxy );
             }
         }
     }
 
-    public void closeConnection( )
+    public void closeConnection()
     {
         if ( !useClientManagerPooled )
         {
-            getConnectionManager( ).shutdown( );
+            getConnectionManager().shutdown();
         }
     }
 
@@ -469,9 +468,9 @@ public abstract class AbstractHttpClient
 
         firePutInitiated( resource, source );
 
-        resource.setContentLength( source.length( ) );
+        resource.setContentLength( source.length() );
 
-        resource.setLastModified( source.lastModified( ) );
+        resource.setLastModified( source.lastModified() );
 
         put( null, resource, source );
     }
@@ -499,13 +498,13 @@ public abstract class AbstractHttpClient
     private void put( Resource resource, File source, HttpEntity httpEntity )
         throws TransferFailedException, AuthorizationException, ResourceDoesNotExistException
     {
-        StringBuilder url = new StringBuilder( getRepository( ).getUrl( ) );
-        String[] parts = StringUtils.split( resource.getName( ), "/" );
+        StringBuilder url = new StringBuilder( getRepository().getUrl() );
+        String[] parts = StringUtils.split( resource.getName(), "/" );
         for ( String part : parts )
         {
             // TODO: Fix encoding...
             // url += "/" + URLEncoder.encode( parts[i], System.getProperty("file.encoding") );
-            if ( !url.toString( ).endsWith( "/" ) )
+            if ( !url.toString().endsWith( "/" ) )
             {
                 url.append( '/' );
             }
@@ -515,7 +514,7 @@ public abstract class AbstractHttpClient
         //Parent directories need to be created before posting
         try
         {
-            mkdirs( PathUtils.dirname( resource.getName( ) ) );
+            mkdirs( PathUtils.dirname( resource.getName() ) );
         }
         catch ( HttpException he )
         {
@@ -526,7 +525,7 @@ public abstract class AbstractHttpClient
             fireTransferError( resource, e, TransferEvent.REQUEST_GET );
         }
 
-        HttpPut putMethod = new HttpPut( url.toString( ) );
+        HttpPut putMethod = new HttpPut( url.toString() );
 
         firePutStarted( resource, source );
 
@@ -543,17 +542,17 @@ public abstract class AbstractHttpClient
             {
                 fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
 
-                throw new TransferFailedException( e.getMessage( ), e );
+                throw new TransferFailedException( e.getMessage(), e );
             }
             catch ( HttpException e )
             {
                 fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
 
-                throw new TransferFailedException( e.getMessage( ), e );
+                throw new TransferFailedException( e.getMessage(), e );
             }
 
-            int statusCode = response.getStatusLine( ).getStatusCode( );
-            String reasonPhrase = ", ReasonPhrase:" + response.getStatusLine( ).getReasonPhrase( ) + ".";
+            int statusCode = response.getStatusLine().getStatusCode();
+            String reasonPhrase = ", ReasonPhrase:" + response.getStatusLine().getReasonPhrase() + ".";
             fireTransferDebug( url + " - Status code: " + statusCode + reasonPhrase );
 
             // Check that we didn't run out of retries.
@@ -575,7 +574,7 @@ public abstract class AbstractHttpClient
                 }
 
                 case HttpStatus.SC_FORBIDDEN:
-                    fireSessionConnectionRefused( );
+                    fireSessionConnectionRefused();
                     throw new AuthorizationException( "Access denied to: " + url + reasonPhrase );
 
                 case HttpStatus.SC_NOT_FOUND:
@@ -595,7 +594,7 @@ public abstract class AbstractHttpClient
         }
         finally
         {
-            putMethod.abort( );
+            putMethod.abort();
         }
     }
 
@@ -608,7 +607,7 @@ public abstract class AbstractHttpClient
     public boolean resourceExists( String resourceName )
         throws TransferFailedException, AuthorizationException
     {
-        String repositoryUrl = getRepository( ).getUrl( );
+        String repositoryUrl = getRepository().getUrl();
         String url = repositoryUrl + ( repositoryUrl.endsWith( "/" ) ? "" : "/" ) + resourceName;
         HttpHead headMethod = new HttpHead( url );
         HttpResponse response = null;
@@ -619,17 +618,17 @@ public abstract class AbstractHttpClient
         }
         catch ( IOException e )
         {
-            throw new TransferFailedException( e.getMessage( ), e );
+            throw new TransferFailedException( e.getMessage(), e );
         }
         catch ( HttpException e )
         {
-            throw new TransferFailedException( e.getMessage( ), e );
+            throw new TransferFailedException( e.getMessage(), e );
         }
 
         try
         {
-            statusCode = response.getStatusLine( ).getStatusCode( );
-            String reasonPhrase = ", ReasonPhrase:" + response.getStatusLine( ).getReasonPhrase( ) + ".";
+            statusCode = response.getStatusLine().getStatusCode();
+            String reasonPhrase = ", ReasonPhrase:" + response.getStatusLine().getReasonPhrase() + ".";
             switch ( statusCode )
             {
                 case HttpStatus.SC_OK:
@@ -661,7 +660,7 @@ public abstract class AbstractHttpClient
         }
         finally
         {
-            headMethod.abort( );
+            headMethod.abort();
         }
     }
 
@@ -670,7 +669,7 @@ public abstract class AbstractHttpClient
     {
         setParameters( httpMethod );
         setHeaders( httpMethod );
-        client.getParams( ).setParameter( CoreProtocolPNames.USER_AGENT, getUserAgent( httpMethod ) );
+        client.getParams().setParameter( CoreProtocolPNames.USER_AGENT, getUserAgent( httpMethod ) );
 
         return client.execute( httpMethod, localContext );
     }
@@ -681,16 +680,16 @@ public abstract class AbstractHttpClient
             httpConfiguration == null ? null : httpConfiguration.getMethodConfiguration( method );
         if ( config != null )
         {
-            HttpParams params = config.asMethodParams( method.getParams( ) );
+            HttpParams params = config.asMethodParams( method.getParams() );
             if ( params != null )
             {
                 method.setParams( params );
             }
         }
 
-        if ( config == null || config.getReadTimeout( ) == HttpMethodConfiguration.DEFAULT_CONNECTION_TIMEOUT )
+        if ( config == null || config.getReadTimeout() == HttpMethodConfiguration.DEFAULT_CONNECTION_TIMEOUT )
         {
-            method.getParams( ).setParameter( CoreConnectionPNames.SO_TIMEOUT, getTimeout( ) );
+            method.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, getTimeout() );
         }
     }
 
@@ -698,7 +697,7 @@ public abstract class AbstractHttpClient
     {
         HttpMethodConfiguration config =
             httpConfiguration == null ? null : httpConfiguration.getMethodConfiguration( method );
-        if ( config == null || config.isUseDefaultHeaders( ) )
+        if ( config == null || config.isUseDefaultHeaders() )
         {
             // TODO: merge with the other headers and have some better defaults, unify with lightweight headers
             method.addHeader( "Cache-control", "no-cache" );
@@ -710,13 +709,13 @@ public abstract class AbstractHttpClient
 
         if ( httpHeaders != null )
         {
-            for ( Map.Entry<Object, Object> entry : httpHeaders.entrySet( ) )
+            for ( Map.Entry<Object, Object> entry : httpHeaders.entrySet() )
             {
-                method.addHeader( (String) entry.getKey( ), (String) entry.getValue( ) );
+                method.addHeader( (String) entry.getKey(), (String) entry.getValue() );
             }
         }
 
-        Header[] headers = config == null ? null : config.asRequestHeaders( );
+        Header[] headers = config == null ? null : config.asRequestHeaders();
         if ( headers != null )
         {
             for ( int i = 0; i < headers.length; i++ )
@@ -741,7 +740,7 @@ public abstract class AbstractHttpClient
 
         if ( config != null )
         {
-            return (String) config.getHeaders( ).get( "User-Agent" );
+            return (String) config.getHeaders().get( "User-Agent" );
         }
         return null;
     }
@@ -755,10 +754,10 @@ public abstract class AbstractHttpClient
      */
     protected String getURL( Repository repository )
     {
-        return repository.getUrl( );
+        return repository.getUrl();
     }
 
-    public HttpConfiguration getHttpConfiguration( )
+    public HttpConfiguration getHttpConfiguration()
     {
         return httpConfiguration;
     }
@@ -771,12 +770,12 @@ public abstract class AbstractHttpClient
     public void fillInputData( InputData inputData )
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
     {
-        Resource resource = inputData.getResource( );
+        Resource resource = inputData.getResource();
 
-        String repositoryUrl = getRepository( ).getUrl( );
-        String url = repositoryUrl + ( repositoryUrl.endsWith( "/" ) ? "" : "/" ) + resource.getName( );
+        String repositoryUrl = getRepository().getUrl();
+        String url = repositoryUrl + ( repositoryUrl.endsWith( "/" ) ? "" : "/" ) + resource.getName();
         getMethod = new HttpGet( url );
-        long timestamp = resource.getLastModified( );
+        long timestamp = resource.getLastModified();
         if ( timestamp > 0 )
         {
             SimpleDateFormat fmt = new SimpleDateFormat( "EEE, dd-MMM-yy HH:mm:ss zzz", Locale.US );
@@ -796,18 +795,18 @@ public abstract class AbstractHttpClient
         {
             fireTransferError( resource, e, TransferEvent.REQUEST_GET );
 
-            throw new TransferFailedException( e.getMessage( ), e );
+            throw new TransferFailedException( e.getMessage(), e );
         }
         catch ( HttpException e )
         {
             fireTransferError( resource, e, TransferEvent.REQUEST_GET );
 
-            throw new TransferFailedException( e.getMessage( ), e );
+            throw new TransferFailedException( e.getMessage(), e );
         }
 
-        statusCode = response.getStatusLine( ).getStatusCode( );
+        statusCode = response.getStatusLine().getStatusCode();
 
-        String reasonPhrase = ", ReasonPhrase:" + response.getStatusLine( ).getReasonPhrase( ) + ".";
+        String reasonPhrase = ", ReasonPhrase:" + response.getStatusLine().getReasonPhrase() + ".";
 
         fireTransferDebug( url + " - Status code: " + statusCode + reasonPhrase );
 
@@ -831,15 +830,15 @@ public abstract class AbstractHttpClient
             }
 
             case HttpStatus.SC_FORBIDDEN:
-                fireSessionConnectionRefused( );
+                fireSessionConnectionRefused();
                 throw new AuthorizationException( "Access denied to: " + url + reasonPhrase );
 
             case HttpStatus.SC_UNAUTHORIZED:
-                fireSessionConnectionRefused( );
+                fireSessionConnectionRefused();
                 throw new AuthorizationException( "Not authorized" + reasonPhrase );
 
             case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
-                fireSessionConnectionRefused( );
+                fireSessionConnectionRefused();
                 throw new AuthorizationException( "Not authorized by proxy" + reasonPhrase );
 
             case HttpStatus.SC_NOT_FOUND:
@@ -864,14 +863,14 @@ public abstract class AbstractHttpClient
         {
             try
             {
-                long contentLength = Integer.valueOf( contentLengthHeader.getValue( ) ).intValue( );
+                long contentLength = Integer.valueOf( contentLengthHeader.getValue() ).intValue();
 
                 resource.setContentLength( contentLength );
             }
             catch ( NumberFormatException e )
             {
                 fireTransferDebug(
-                    "error parsing content length header '" + contentLengthHeader.getValue( ) + "' " + e );
+                    "error parsing content length header '" + contentLengthHeader.getValue() + "' " + e );
             }
         }
 
@@ -883,7 +882,7 @@ public abstract class AbstractHttpClient
         {
             try
             {
-                lastModified = DateUtils.parseDate( lastModifiedHeader.getValue( ) ).getTime( );
+                lastModified = DateUtils.parseDate( lastModifiedHeader.getValue() ).getTime();
 
                 resource.setLastModified( lastModified );
             }
@@ -892,15 +891,15 @@ public abstract class AbstractHttpClient
                 fireTransferDebug( "Unable to parse last modified header" );
             }
 
-            fireTransferDebug( "last-modified = " + lastModifiedHeader.getValue( ) + " (" + lastModified + ")" );
+            fireTransferDebug( "last-modified = " + lastModifiedHeader.getValue() + " (" + lastModified + ")" );
         }
 
         Header contentEncoding = response.getFirstHeader( "Content-Encoding" );
-        boolean isGZipped = contentEncoding == null ? false : "gzip".equalsIgnoreCase( contentEncoding.getValue( ) );
+        boolean isGZipped = contentEncoding == null ? false : "gzip".equalsIgnoreCase( contentEncoding.getValue() );
 
         try
         {
-            is = response.getEntity( ).getContent( );
+            is = response.getEntity().getContent();
 
             if ( isGZipped )
             {
@@ -912,7 +911,7 @@ public abstract class AbstractHttpClient
             fireTransferError( resource, e, TransferEvent.REQUEST_GET );
 
             String msg =
-                "Error occurred while retrieving from remote repository:" + getRepository( ) + ": " + e.getMessage( );
+                "Error occurred while retrieving from remote repository:" + getRepository() + ": " + e.getMessage();
 
             throw new TransferFailedException( msg, e );
         }
@@ -924,7 +923,7 @@ public abstract class AbstractHttpClient
     {
         if ( getMethod != null )
         {
-            getMethod.abort( );
+            getMethod.abort();
         }
     }
 
@@ -940,10 +939,10 @@ public abstract class AbstractHttpClient
     protected void putFromStream( InputStream stream, Resource resource )
         throws TransferFailedException, AuthorizationException, ResourceDoesNotExistException
     {
-        putFromStream( stream, resource.getName( ), -1, -1 );
+        putFromStream( stream, resource.getName(), -1, -1 );
     }
 
-    public Properties getHttpHeaders( )
+    public Properties getHttpHeaders()
     {
         return httpHeaders;
     }