maven-wagon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1128840 [1/3] - in /maven/wagon/trunk: ./ wagon-providers/ wagon-providers/wagon-http-lightweight/ wagon-providers/wagon-http-shared4/ wagon-providers/wagon-http-shared4/src/ wagon-providers/wagon-http-shared4/src/main/ wagon-providers/wag...
Date Sun, 29 May 2011 08:25:29 GMT
Author: struberg
Date: Sun May 29 08:25:27 2011
New Revision: 1128840

URL: http://svn.apache.org/viewvc?rev=1128840&view=rev
Log:
WAGON-330 upgrade to httpclient-4.1.1

httpclient moved from commons to the httpcomponents TLP.
It is not compatible, so I had to add a completely new
http-shared4.
Since jackrabbit still needs the old httpclient-3.1 
we had to keep the old http-shared as well. 

Added:
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/   (with props)
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/pom.xml   (with props)
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java   (with props)
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/HtmlFileListParser.java   (with props)
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/HttpConfiguration.java   (with props)
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/HttpMethodConfiguration.java   (with props)
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/site/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/site/site.xml   (with props)
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/java/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/java/org/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/java/org/apache/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/java/org/apache/maven/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/java/org/apache/maven/wagon/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/java/org/apache/maven/wagon/shared/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/java/org/apache/maven/wagon/shared/http/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagonTest.java   (with props)
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/java/org/apache/maven/wagon/shared/http/HtmlFileListParserTest.java   (with props)
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/resources/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/resources/filelistings/
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/resources/filelistings/commons-lang.html   (with props)
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/resources/filelistings/ibiblio-wagon.html   (with props)
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/resources/filelistings/jetty-wagon.html   (with props)
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/resources/filelistings/mevenide.html   (with props)
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/resources/filelistings/mirror-wagon.html   (with props)
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/resources/filelistings/nekohtml.html   (with props)
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/resources/filelistings/net_sf.html   (with props)
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/resources/filelistings/org.apache.maven.html   (with props)
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/resources/filelistings/org.codehaus.html   (with props)
Modified:
    maven/wagon/trunk/pom.xml
    maven/wagon/trunk/wagon-providers/pom.xml
    maven/wagon/trunk/wagon-providers/wagon-http-lightweight/pom.xml
    maven/wagon/trunk/wagon-providers/wagon-http/pom.xml
    maven/wagon/trunk/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
    maven/wagon/trunk/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonTest.java
    maven/wagon/trunk/wagon-providers/wagon-webdav-jackrabbit/pom.xml
    maven/wagon/trunk/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java

Modified: maven/wagon/trunk/pom.xml
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/pom.xml?rev=1128840&r1=1128839&r2=1128840&view=diff
==============================================================================
--- maven/wagon/trunk/pom.xml (original)
+++ maven/wagon/trunk/pom.xml Sun May 29 08:25:27 2011
@@ -295,7 +295,6 @@ under the License.
         <artifactId>jetty</artifactId>
         <version>6.1.26</version>
       </dependency>
-
     </dependencies>
   </dependencyManagement>
 

Modified: maven/wagon/trunk/wagon-providers/pom.xml
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/pom.xml?rev=1128840&r1=1128839&r2=1128840&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/pom.xml (original)
+++ maven/wagon/trunk/wagon-providers/pom.xml Sun May 29 08:25:27 2011
@@ -37,6 +37,7 @@ under the License.
     <module>wagon-http-lightweight</module>
     <module>wagon-http</module>
     <module>wagon-http-shared</module>
+    <module>wagon-http-shared4</module>
     <module>wagon-scm</module>
     <module>wagon-ssh-external</module>
     <module>wagon-ssh-common</module>

Modified: maven/wagon/trunk/wagon-providers/wagon-http-lightweight/pom.xml
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-http-lightweight/pom.xml?rev=1128840&r1=1128839&r2=1128840&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-http-lightweight/pom.xml (original)
+++ maven/wagon/trunk/wagon-providers/wagon-http-lightweight/pom.xml Sun May 29 08:25:27 2011
@@ -36,7 +36,7 @@ under the License.
   <dependencies>
     <dependency>
       <groupId>${project.groupId}</groupId>
-      <artifactId>wagon-http-shared</artifactId>
+      <artifactId>wagon-http-shared4</artifactId>
       <version>${project.version}</version>
       <exclusions>
         <exclusion>

Propchange: maven/wagon/trunk/wagon-providers/wagon-http-shared4/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun May 29 08:25:27 2011
@@ -0,0 +1,7 @@
+target
+.settings
+.project
+.classpath
+*.iml
+*.ipr
+*.iws

Added: maven/wagon/trunk/wagon-providers/wagon-http-shared4/pom.xml
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-http-shared4/pom.xml?rev=1128840&view=auto
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-http-shared4/pom.xml (added)
+++ maven/wagon/trunk/wagon-providers/wagon-http-shared4/pom.xml Sun May 29 08:25:27 2011
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.maven.wagon</groupId>
+    <artifactId>wagon-providers</artifactId>
+    <version>2.0-SNAPSHOT</version>
+    <relativePath>../pom.xml</relativePath>
+  </parent>
+
+  <artifactId>wagon-http-shared4</artifactId>
+  <name>Maven Wagon HTTP Shared Library 4</name>
+  <description>
+    Shared Library for the wagon-http, and wagon-http-lightweight wagon
+    providers based on httpclient-4.x.
+  </description>
+
+  <dependencies>
+    <dependency>
+      <groupId>nekohtml</groupId>
+      <artifactId>xercesMinimal</artifactId>
+      <version>1.9.6.2</version>
+    </dependency>
+    <dependency>
+      <groupId>nekohtml</groupId>
+      <artifactId>nekohtml</artifactId>
+      <version>1.9.6.2</version>
+      <exclusions>
+        <exclusion>
+          <groupId>xerces</groupId>
+          <artifactId>xercesImpl</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+      <version>4.1.1</version>
+    </dependency>
+    <!--
+      This dependency is here to upgrade to a version of commons-logging that is
+      newer than the one that comes transitively from commons-httpclient above.
+    -->
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <version>1.1.1</version>
+    </dependency>
+  </dependencies>
+</project>

Propchange: maven/wagon/trunk/wagon-providers/wagon-http-shared4/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=1128840&view=auto
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java (added)
+++ maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java Sun May 29 08:25:27 2011
@@ -0,0 +1,722 @@
+package org.apache.maven.wagon.shared.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.*;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.Credentials;
+import org.apache.http.auth.NTCredentials;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.methods.HttpGet;
+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.conn.ClientConnectionManager;
+import org.apache.http.conn.params.ConnRoutePNames;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.SingleClientConnManager;
+import org.apache.http.impl.cookie.DateParseException;
+import org.apache.http.impl.cookie.DateUtils;
+import org.apache.http.message.BasicHeader;
+import org.apache.http.params.CoreConnectionPNames;
+import org.apache.http.params.HttpParams;
+import org.apache.maven.wagon.InputData;
+import org.apache.maven.wagon.OutputData;
+import org.apache.maven.wagon.PathUtils;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.wagon.StreamWagon;
+import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.Wagon;
+import org.apache.maven.wagon.authorization.AuthorizationException;
+import org.apache.maven.wagon.events.TransferEvent;
+import org.apache.maven.wagon.proxy.ProxyInfo;
+import org.apache.maven.wagon.repository.Repository;
+import org.apache.maven.wagon.resource.Resource;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+import java.util.zip.GZIPInputStream;
+
+/**
+ * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+public abstract class AbstractHttpClientWagon
+    extends StreamWagon
+{
+    private final class RequestEntityImplementation
+        implements HttpEntity
+    {
+        private final Resource resource;
+
+        private final Wagon wagon;
+
+        private final File source;
+
+
+        private RequestEntityImplementation( final InputStream stream, final Resource resource, final Wagon wagon, final File source )
+            throws TransferFailedException
+        {
+            if ( source != null )
+            {
+                this.source = source;
+            }
+            else
+            {
+                FileOutputStream fos = null;
+                try
+                {
+                    this.source = File.createTempFile( "http-wagon.", ".tmp" );
+                    this.source.deleteOnExit();
+                    
+                    fos = new FileOutputStream( this.source );
+                    IOUtil.copy( stream, fos );
+                }
+                catch ( IOException e )
+                {
+                    fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
+                    throw new TransferFailedException( "Failed to buffer stream contents to temp file for upload.", e );
+                }
+                finally
+                {
+                    IOUtil.close( fos );
+                }
+            }
+            
+            this.resource = resource;
+            this.wagon = wagon;
+        }
+
+        public long getContentLength()
+        {
+            return resource.getContentLength();
+        }
+
+        public Header getContentType()
+        {
+            return null;
+        }
+
+        public Header getContentEncoding() {
+            return null;  //X TODO
+        }
+
+        public InputStream getContent() throws IOException, IllegalStateException {
+            FileInputStream fis = new FileInputStream( source );
+
+            return fis;
+        }
+
+        public boolean isRepeatable()
+        {
+            return true;
+        }
+
+        public boolean isChunked() {
+            return false;  //X TODO
+        }
+
+        public void writeTo( OutputStream output )
+            throws IOException
+        {
+            byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
+            
+            TransferEvent transferEvent =
+                new TransferEvent( wagon, resource, TransferEvent.TRANSFER_PROGRESS, TransferEvent.REQUEST_PUT );
+            transferEvent.setTimestamp( System.currentTimeMillis() );
+            
+            FileInputStream fin = null;
+            try
+            {
+                fin = new FileInputStream( source );
+                int remaining = Integer.MAX_VALUE;
+                while ( remaining > 0 )
+                {
+                    int n = fin.read( buffer, 0, Math.min( buffer.length, remaining ) );
+                
+                    if ( n == -1 )
+                    {
+                        break;
+                    }
+                
+                    fireTransferProgress( transferEvent, buffer, n );
+                
+                    output.write( buffer, 0, n );
+                
+                    remaining -= n;
+                }
+            }
+            finally
+            {
+                IOUtil.close( fin );
+            }
+            
+            output.flush();
+        }
+
+        public boolean isStreaming() {
+            return false;  //X TODO
+        }
+
+        public void consumeContent() throws IOException {
+            //X TODO
+        }
+    }
+
+    protected static final int SC_NULL = -1;
+
+    protected static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone( "GMT" );
+
+    private DefaultHttpClient client;
+
+    protected ClientConnectionManager connectionManager = new SingleClientConnManager();
+
+    /**
+     * @since 1.0-beta-6
+     */
+    private HttpConfiguration httpConfiguration;
+
+    private HttpGet getMethod;
+
+    public void openConnectionInternal()
+    {
+        repository.setUrl( getURL( repository ) );
+        client = new DefaultHttpClient( connectionManager );
+        String username = null;
+        String password = null;
+
+        if ( authenticationInfo != null )
+        {
+            username = authenticationInfo.getUserName();
+
+            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;
+
+            client.getCredentialsProvider().setCredentials( new AuthScope( host, port ), creds );
+        }
+
+        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 )
+            {
+                HttpHost proxy = new HttpHost(proxyHost, proxyPort);
+
+                if ( proxyUsername != null && proxyPassword != null )
+                {
+                    Credentials creds;
+                    if ( proxyNtlmHost != null || proxyNtlmDomain != null )
+                    {
+                        creds = new NTCredentials( proxyUsername, proxyPassword, proxyNtlmHost, proxyNtlmDomain );
+                    }
+                    else
+                    {
+                        creds = new UsernamePasswordCredentials( proxyUsername, proxyPassword );
+                    }
+
+                    int port = proxyInfo.getPort() > -1 ? proxyInfo.getPort() : AuthScope.ANY_PORT;
+                    
+                    AuthScope authScope = new AuthScope( proxyHost, port );
+                    client.getCredentialsProvider().setCredentials( authScope, creds );
+                }
+
+                client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
+            }
+        }
+
+        /*X original
+        hc.setHost( host );
+
+        //start a session with the webserver
+        client.setHostConfiguration( hc );
+        */
+    }
+
+    public void closeConnection()
+    {
+        connectionManager.shutdown();
+
+        /*X original
+        if ( connectionManager instanceof MultiThreadedHttpConnectionManager )
+        {
+            ( (MultiThreadedHttpConnectionManager) connectionManager ).shutdown();
+        }
+        */
+    }
+
+    public void put( File source, String resourceName )
+        throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+    {
+        Resource resource = new Resource( resourceName );
+        
+        firePutInitiated( resource, source );
+        
+        resource.setContentLength( source.length() );
+        
+        resource.setLastModified( source.lastModified() );
+
+        put( null, resource, source );
+    }
+    
+    public void putFromStream( final InputStream stream, String destination, long contentLength, long lastModified )
+        throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+    {
+        Resource resource = new Resource( destination );
+        
+        firePutInitiated( resource, null );
+        
+        resource.setContentLength( contentLength );
+        
+        resource.setLastModified( lastModified );
+
+        put( stream, resource, null );
+    }
+
+    private void put( final InputStream stream, Resource resource, File source )
+        throws TransferFailedException, AuthorizationException, ResourceDoesNotExistException
+    {
+        String url = getRepository().getUrl();
+        String[] parts = StringUtils.split( resource.getName(), "/" );
+        for ( int i = 0; i < parts.length; i++ )
+        {
+            // TODO: Fix encoding...
+            // url += "/" + URLEncoder.encode( parts[i], System.getProperty("file.encoding") );
+            url += "/" + URLEncoder.encode( parts[i] );
+        }
+
+        //Parent directories need to be created before posting
+        try
+        {
+            mkdirs( PathUtils.dirname( resource.getName() ) );
+        }
+        catch ( HttpException he )
+        {
+            fireTransferError( resource, he, TransferEvent.REQUEST_GET );
+        }
+        catch ( IOException e )
+        {
+            fireTransferError( resource, e, TransferEvent.REQUEST_GET );
+        }
+
+        HttpPut putMethod = new HttpPut( url );
+
+        firePutStarted( resource, source );
+                
+        try
+        {
+            putMethod.setEntity(new RequestEntityImplementation(stream, resource, this, source));
+
+            HttpResponse response;
+            try
+            {
+                response = execute( putMethod );
+            }
+            catch ( IOException e )
+            {
+                fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
+
+                throw new TransferFailedException( e.getMessage(), e );
+            }
+            catch (HttpException e) {
+                fireTransferError(resource, e, TransferEvent.REQUEST_PUT);
+
+                throw new TransferFailedException( e.getMessage(), e );
+            }
+
+            int statusCode = response.getStatusLine().getStatusCode();
+
+            fireTransferDebug( url + " - Status code: " + statusCode );
+
+            // Check that we didn't run out of retries.
+            switch ( statusCode )
+            {
+                // Success Codes
+                case HttpStatus.SC_OK: // 200
+                case HttpStatus.SC_CREATED: // 201
+                case HttpStatus.SC_ACCEPTED: // 202
+                case HttpStatus.SC_NO_CONTENT:  // 204
+                    break;
+
+                case SC_NULL:
+                {
+                    TransferFailedException e = new TransferFailedException( "Failed to transfer file: " + url );
+                    fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
+                    throw e;
+                }
+
+                case HttpStatus.SC_FORBIDDEN:
+                    fireSessionConnectionRefused();
+                    throw new AuthorizationException( "Access denied to: " + url );
+
+                case HttpStatus.SC_NOT_FOUND:
+                    throw new ResourceDoesNotExistException( "File: " + url + " does not exist" );
+
+                //add more entries here
+                default :
+                {
+                    TransferFailedException e =
+                            new TransferFailedException( "Failed to transfer file: " + url + ". Return code is: "
+                                + statusCode );
+                    fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
+                    throw e;
+                }
+            }
+
+            firePutCompleted( resource, source );
+        }
+        finally
+        {
+            putMethod.abort();
+        }
+    }
+    
+    protected void mkdirs( String dirname ) throws HttpException, IOException
+    {
+    }
+
+    public boolean resourceExists( String resourceName )
+        throws TransferFailedException, AuthorizationException
+    {
+        String url = getRepository().getUrl() + "/" + resourceName;
+        HttpHead headMethod = new HttpHead( url );
+        HttpResponse response = null;
+        int statusCode;
+        try
+        {
+            response = execute( headMethod );
+        }
+        catch ( IOException e )
+        {
+            throw new TransferFailedException( e.getMessage(), e );
+        }
+        catch (HttpException e) {
+            throw new TransferFailedException( e.getMessage(), e );
+        }
+
+        try
+        {
+            statusCode = response.getStatusLine().getStatusCode();
+            switch ( statusCode )
+            {
+                case HttpStatus.SC_OK:
+                    return true;
+
+                case HttpStatus.SC_NOT_MODIFIED:
+                    return true;
+
+                case SC_NULL:
+                    throw new TransferFailedException( "Failed to transfer file: " + url );
+
+                case HttpStatus.SC_FORBIDDEN:
+                    throw new AuthorizationException( "Access denied to: " + url );
+
+                case HttpStatus.SC_UNAUTHORIZED:
+                    throw new AuthorizationException( "Not authorized." );
+
+                case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
+                    throw new AuthorizationException( "Not authorized by proxy." );
+
+                case HttpStatus.SC_NOT_FOUND:
+                    return false;
+
+                    //add more entries here
+                default:
+                    throw new TransferFailedException( "Failed to transfer file: " + url + ". Return code is: "
+                        + statusCode );
+            }
+        }
+        finally
+        {
+            headMethod.abort();
+        }
+    }
+
+    protected HttpResponse execute( HttpUriRequest httpMethod ) throws HttpException, IOException
+    {
+        int statusCode = SC_NULL;
+        
+        setParameters( httpMethod );
+        setHeaders( httpMethod );
+        
+        return client.execute(httpMethod);
+    }
+
+    protected void setParameters( HttpUriRequest method )
+    {
+        HttpMethodConfiguration config = httpConfiguration == null ? null : httpConfiguration.getMethodConfiguration( method );
+        if ( config != null )
+        {
+            HttpParams params = config.asMethodParams( method.getParams() );
+            if ( params != null )
+            {
+                method.setParams( params );
+            }
+        }
+        
+        if ( config == null || config.getConnectionTimeout() == HttpMethodConfiguration.DEFAULT_CONNECTION_TIMEOUT )
+        {
+            method.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, getTimeout() );
+        }
+    }
+
+    protected void setHeaders( HttpUriRequest method )
+    {
+        HttpMethodConfiguration config = httpConfiguration == null ? null : httpConfiguration.getMethodConfiguration( method );
+        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");
+            method.addHeader("Cache-store", "no-store");
+            method.addHeader("Pragma", "no-cache");
+            method.addHeader("Expires", "0");
+            method.addHeader("Accept-Encoding", "gzip");
+        }
+        
+        Header[] headers = config == null ? null : config.asRequestHeaders();
+        if ( headers != null )
+        {
+            for ( int i = 0; i < headers.length; i++ )
+            {
+                method.addHeader(headers[i]);
+            }
+        }
+    }
+
+    /**
+     * getUrl
+     * Implementors can override this to remove unwanted parts of the url such as role-hints
+     * @param repository
+     * @return
+     */
+    protected String getURL( Repository repository )
+    {
+        return repository.getUrl();
+    }
+
+/*X original
+    protected HttpClient getClient()
+    {
+        return client;
+    }
+
+    public void setConnectionManager( HttpConnectionManager connectionManager )
+    {
+        this.connectionManager = connectionManager;
+    }
+*/
+
+    public HttpConfiguration getHttpConfiguration()
+    {
+        return httpConfiguration;
+    }
+
+    public void setHttpConfiguration( HttpConfiguration httpConfiguration )
+    {
+        this.httpConfiguration = httpConfiguration;
+    }
+
+    public void fillInputData( InputData inputData )
+        throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+    {
+        Resource resource = inputData.getResource();
+        
+        String url = getRepository().getUrl() + "/" + resource.getName();
+        getMethod = new HttpGet( url );
+        long timestamp = resource.getLastModified();
+        if ( timestamp > 0 )
+        {
+            SimpleDateFormat fmt = new SimpleDateFormat( "EEE, dd-MMM-yy HH:mm:ss zzz", Locale.US );
+            fmt.setTimeZone( GMT_TIME_ZONE );
+            Header hdr = new BasicHeader( "If-Modified-Since", fmt.format( new Date( timestamp ) ) );
+            fireTransferDebug( "sending ==> " + hdr + "(" + timestamp + ")" );
+            getMethod.addHeader(hdr);
+        }
+
+        HttpResponse response;
+        int statusCode;
+        try
+        {
+            response = execute( getMethod );
+        }
+        catch ( IOException e )
+        {
+            fireTransferError( resource, e, TransferEvent.REQUEST_GET );
+
+            throw new TransferFailedException( e.getMessage(), e );
+        }
+        catch (HttpException e) {
+            fireTransferError(resource, e, TransferEvent.REQUEST_GET);
+
+            throw new TransferFailedException( e.getMessage(), e );
+        }
+
+        statusCode = response.getStatusLine().getStatusCode();
+
+        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 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 );
+                fireTransferError( resource, e, TransferEvent.REQUEST_GET );
+                throw e;
+            }
+
+            case HttpStatus.SC_FORBIDDEN:
+                fireSessionConnectionRefused();
+                throw new AuthorizationException( "Access denied to: " + url );
+
+            case HttpStatus.SC_UNAUTHORIZED:
+                fireSessionConnectionRefused();
+                throw new AuthorizationException( "Not authorized." );
+
+            case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
+                fireSessionConnectionRefused();
+                throw new AuthorizationException( "Not authorized by proxy." );
+
+            case HttpStatus.SC_NOT_FOUND:
+                throw new ResourceDoesNotExistException( "File: " + url + " does not exist" );
+
+                // add more entries here
+            default:
+            {
+                cleanupGetTransfer( resource );
+                TransferFailedException e =
+                    new TransferFailedException( "Failed to transfer file: " + url + ". Return code is: "
+                        + statusCode );
+                fireTransferError( resource, e, TransferEvent.REQUEST_GET );
+                throw e;
+            }
+        }
+
+        InputStream is = null;
+
+        Header contentLengthHeader = response.getFirstHeader("Content-Length");
+
+        if ( contentLengthHeader != null )
+        {
+            try
+            {
+                long contentLength = Integer.valueOf( contentLengthHeader.getValue() ).intValue();
+
+                resource.setContentLength( contentLength );
+            }
+            catch ( NumberFormatException e )
+            {
+                fireTransferDebug( "error parsing content length header '" + contentLengthHeader.getValue() + "' "
+                    + e );
+            }
+        }
+
+        Header lastModifiedHeader = response.getFirstHeader("Last-Modified");
+
+        long lastModified = 0;
+
+        if ( lastModifiedHeader != null )
+        {
+            try
+            {
+                lastModified = DateUtils.parseDate( lastModifiedHeader.getValue() ).getTime();
+
+                resource.setLastModified( lastModified );
+            }
+            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
+        {
+            //X original is = getMethod.getResponseBodyAsStream();
+            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 );
+        }
+        
+        inputData.setInputStream( is );
+    }
+
+    protected void cleanupGetTransfer( Resource resource )
+    {
+        if ( getMethod != null )
+        {
+            getMethod.abort();
+        }
+    }
+
+    public void fillOutputData( OutputData outputData )
+        throws TransferFailedException
+    {
+        throw new IllegalStateException( "Should not be using the streaming wagon for HTTP PUT" );        
+    }
+}

Propchange: maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/HtmlFileListParser.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/HtmlFileListParser.java?rev=1128840&view=auto
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/HtmlFileListParser.java (added)
+++ maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/HtmlFileListParser.java Sun May 29 08:25:27 2011
@@ -0,0 +1,183 @@
+package org.apache.maven.wagon.shared.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 java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import org.apache.maven.wagon.TransferFailedException;
+import org.apache.xerces.xni.Augmentations;
+import org.apache.xerces.xni.QName;
+import org.apache.xerces.xni.XMLAttributes;
+import org.apache.xerces.xni.parser.XMLInputSource;
+import org.apache.xerces.xni.parser.XMLParserConfiguration;
+import org.codehaus.plexus.util.StringUtils;
+import org.cyberneko.html.HTMLConfiguration;
+import org.cyberneko.html.filters.DefaultFilter;
+
+/**
+ * Html File List Parser.
+ */
+public class HtmlFileListParser
+{
+    /**
+     * Fetches a raw HTML from a provided InputStream, parses it, and returns the file list.
+     * 
+     * @param stream the input stream.
+     * @return the file list.
+     * @throws TransferFailedException if there was a problem fetching the raw html.
+     */
+    public static List/* <String> */parseFileList( String baseurl, InputStream stream )
+        throws TransferFailedException
+    {
+        try
+        {
+            // Use URI object to get benefits of proper absolute and relative path resolution for free
+            URI baseURI = new URI( baseurl );
+
+            Parser handler = new Parser( baseURI );
+
+            XMLParserConfiguration parser = new HTMLConfiguration();
+            parser.setDocumentHandler( handler );
+            parser.setFeature( "http://cyberneko.org/html/features/augmentations", true );
+            parser.setProperty( "http://cyberneko.org/html/properties/names/elems", "upper" );
+            parser.setProperty( "http://cyberneko.org/html/properties/names/attrs", "upper" );
+            parser.parse( new XMLInputSource( null, baseurl, baseURI.toString(), stream, "UTF-8" ) );
+
+            return new ArrayList( handler.getLinks() );
+
+        }
+        catch ( URISyntaxException e )
+        {
+            throw new TransferFailedException( "Unable to parse as URI: " + baseurl );
+        }
+        catch ( IOException e )
+        {
+            throw new TransferFailedException( "I/O error: " + e.getMessage(), e );
+        }
+    }
+
+    private static class Parser
+        extends DefaultFilter
+    {
+        // Apache Fancy Index Sort Headers
+        private static final Pattern APACHE_INDEX_SKIP = Pattern.compile( "\\?[CDMNS]=.*" );
+
+        // URLs with excessive paths.
+        private static final Pattern URLS_WITH_PATHS = Pattern.compile( "/[^/]*/" );
+
+        // URLs that to a parent directory.
+        private static final Pattern URLS_TO_PARENT = Pattern.compile( "\\.\\./" );
+
+        // mailto urls
+        private static final Pattern MAILTO_URLS = Pattern.compile( "mailto:.*" );
+
+        private static final Pattern[] SKIPS =
+            new Pattern[] { APACHE_INDEX_SKIP, URLS_WITH_PATHS, URLS_TO_PARENT, MAILTO_URLS };
+        
+        private Set links = new HashSet();
+
+        private URI baseURI;
+
+        public Parser( URI baseURI )
+        {
+            this.baseURI = baseURI.normalize();
+        }
+
+        public Set getLinks()
+        {
+            return links;
+        }
+
+        public void startElement( QName element, XMLAttributes attrs, Augmentations augs )
+        {
+            if ( "A".equals( element.rawname ) )
+            {
+                String href = attrs.getValue( "HREF" );
+                if ( href != null )
+                {
+                    String link = cleanLink( baseURI, href );
+                    if ( isAcceptableLink( link ) )
+                    {
+                        links.add( link );
+                    }
+                }
+            }
+        }
+
+        private static String cleanLink( URI baseURI, String link )
+        {
+            if ( StringUtils.isEmpty( link ) )
+            {
+                return "";
+            }
+
+            String ret = link;
+
+            try
+            {
+                URI linkuri = new URI( ret );
+                URI relativeURI = baseURI.relativize( linkuri ).normalize();
+                ret = relativeURI.toASCIIString();
+                if ( ret.startsWith( baseURI.getPath() ) )
+                {
+                    ret = ret.substring( baseURI.getPath().length() );
+                }
+
+                ret = URLDecoder.decode( ret, "UTF-8" );
+            }
+            catch ( URISyntaxException e )
+            {
+            }
+            catch ( UnsupportedEncodingException e )
+            {
+            }
+
+            return ret;
+        }
+
+        private static boolean isAcceptableLink( String link )
+        {
+            if ( StringUtils.isEmpty( link ) )
+            {
+                return false;
+            }
+
+            for ( int i = 0; i < SKIPS.length; i++ )
+            {
+                if ( SKIPS[i].matcher( link ).find() )
+                {
+                    return false;
+                }
+            }
+
+            return true;
+        }
+    }
+}

Propchange: maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/HtmlFileListParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/HttpConfiguration.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/HttpConfiguration.java?rev=1128840&view=auto
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/HttpConfiguration.java (added)
+++ maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/HttpConfiguration.java Sun May 29 08:25:27 2011
@@ -0,0 +1,104 @@
+package org.apache.maven.wagon.shared.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.client.methods.HttpGet;
+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.protocol.HTTP;
+
+public class HttpConfiguration
+{
+    
+    private static final HttpMethodConfiguration DEFAULT_PUT =
+        new HttpMethodConfiguration().addParam( HTTP.EXPECT_CONTINUE, "%b,true" );
+    
+    private HttpMethodConfiguration all;
+    
+    private HttpMethodConfiguration get;
+    
+    private HttpMethodConfiguration put;
+    
+    private HttpMethodConfiguration head;
+
+    public HttpMethodConfiguration getAll()
+    {
+        return all;
+    }
+
+    public HttpConfiguration setAll( HttpMethodConfiguration all )
+    {
+        this.all = all;
+        return this;
+    }
+
+    public HttpMethodConfiguration getGet()
+    {
+        return get;
+    }
+    
+    public HttpConfiguration setGet( HttpMethodConfiguration get )
+    {
+        this.get = get;
+        return this;
+    }
+
+    public HttpMethodConfiguration getPut()
+    {
+        return put;
+    }
+
+    public HttpConfiguration setPut( HttpMethodConfiguration put )
+    {
+        this.put = put;
+        return this;
+    }
+
+    public HttpMethodConfiguration getHead()
+    {
+        return head;
+    }
+
+    public HttpConfiguration setHead( HttpMethodConfiguration head )
+    {
+        this.head = head;
+        return this;
+    }
+    
+    public HttpMethodConfiguration getMethodConfiguration( HttpUriRequest method )
+    {
+        if ( method instanceof HttpGet )
+        {
+            return HttpMethodConfiguration.merge( all, get );
+        }
+        else if ( method instanceof HttpPut)
+        {
+            return HttpMethodConfiguration.merge( DEFAULT_PUT, all, put );
+        }
+        else if ( method instanceof HttpHead)
+        {
+            return HttpMethodConfiguration.merge( all, head );
+        }
+        
+        return all;
+    }
+
+}

Propchange: maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/HttpConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/HttpMethodConfiguration.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/HttpMethodConfiguration.java?rev=1128840&view=auto
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/HttpMethodConfiguration.java (added)
+++ maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/HttpMethodConfiguration.java Sun May 29 08:25:27 2011
@@ -0,0 +1,324 @@
+package org.apache.maven.wagon.shared.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.message.BasicHeader;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.CoreConnectionPNames;
+import org.apache.http.params.DefaultedHttpParams;
+import org.apache.http.params.HttpParams;
+
+import java.util.ArrayList;
+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;
+
+public class HttpMethodConfiguration
+{
+    
+    public static final int DEFAULT_CONNECTION_TIMEOUT = 60000;
+
+    private static final String COERCE_PATTERN = "%(\\w+),(.+)";
+    
+    private Boolean useDefaultHeaders;
+    
+    private Properties headers = new Properties();
+    
+    private Properties params = new Properties();
+    
+    private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
+
+    public boolean isUseDefaultHeaders()
+    {
+        return useDefaultHeaders == null ? true : useDefaultHeaders.booleanValue();
+    }
+
+    public HttpMethodConfiguration setUseDefaultHeaders( boolean useDefaultHeaders )
+    {
+        this.useDefaultHeaders = Boolean.valueOf( useDefaultHeaders );
+        return this;
+    }
+    
+    public Boolean getUseDefaultHeaders()
+    {
+        return useDefaultHeaders;
+    }
+    
+    public HttpMethodConfiguration addHeader( String header, String value )
+    {
+        headers.setProperty( header, value );
+        return this;
+    }
+
+    public Properties getHeaders()
+    {
+        return headers;
+    }
+
+    public HttpMethodConfiguration setHeaders( Properties headers )
+    {
+        this.headers = headers;
+        return this;
+    }
+    
+    public HttpMethodConfiguration addParam( String param, String value )
+    {
+        params.setProperty( param, value );
+        return this;
+    }
+
+    public Properties getParams()
+    {
+        return params;
+    }
+
+    public HttpMethodConfiguration setParams( Properties params )
+    {
+        this.params = params;
+        return this;
+    }
+
+    public int getConnectionTimeout()
+    {
+        return connectionTimeout;
+    }
+
+    public HttpMethodConfiguration setConnectionTimeout( int connectionTimeout )
+    {
+        this.connectionTimeout = connectionTimeout;
+        return this;
+    }
+
+    public HttpParams asMethodParams( HttpParams defaults )
+    {
+        if ( !hasParams() )
+        {
+            return null;
+        }
+        
+        DefaultedHttpParams p = new DefaultedHttpParams( new BasicHttpParams(), defaults);
+
+        fillParams( p );
+        
+        return p;
+    }
+
+    private boolean hasParams()
+    {
+        if ( connectionTimeout < 1 && params == null )
+        {
+            return false;
+        }
+        
+        return true;
+    }
+
+    private void fillParams( HttpParams p )
+    {
+        if ( !hasParams() )
+        {
+            return;
+        }
+        
+        if ( connectionTimeout > 0 )
+        {
+            p.setParameter( CoreConnectionPNames.SO_TIMEOUT, connectionTimeout );
+        }
+        
+        if ( params != null )
+        {
+            Pattern coercePattern = Pattern.compile( COERCE_PATTERN );
+            
+            for ( Iterator it = params.entrySet().iterator(); it.hasNext(); )
+            {
+                Map.Entry entry = (Map.Entry) it.next();
+                
+                String key = (String) entry.getKey();
+                String value = (String) 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 collection = new ArrayList();
+                            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 map = new LinkedHashMap();
+                            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 )
+        {
+            return null;
+        }
+        
+        Header[] result = new Header[headers.size()];
+        
+        int index = 0;
+        for ( Iterator it = headers.entrySet().iterator(); it.hasNext(); )
+        {
+            Map.Entry entry = (Map.Entry) it.next();
+            
+            String key = (String) entry.getKey();
+            String value = (String) entry.getValue();
+            
+            Header header = new BasicHeader( key, value );
+            result[index++] = header;
+        }
+        
+        return result;
+    }
+    
+    private HttpMethodConfiguration copy()
+    {
+        HttpMethodConfiguration copy = new HttpMethodConfiguration();
+        
+        copy.setConnectionTimeout( getConnectionTimeout() );
+        if ( getHeaders() != null )
+        {
+            copy.setHeaders( getHeaders() );
+        }
+        
+        if ( getParams() != null )
+        {
+            copy.setParams( getParams() );
+        }
+
+        copy.setUseDefaultHeaders( isUseDefaultHeaders() );
+        
+        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() != DEFAULT_CONNECTION_TIMEOUT )
+            {
+                result.setConnectionTimeout( local.getConnectionTimeout() );
+            }
+            
+            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;
+        }
+    }
+    
+}

Propchange: maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/HttpMethodConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/site/site.xml
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/site/site.xml?rev=1128840&view=auto
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/site/site.xml (added)
+++ maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/site/site.xml Sun May 29 08:25:27 2011
@@ -0,0 +1,6 @@
+<project>
+  <body>
+    <menu ref="parent"/>
+    <menu ref="reports"/>
+  </body>
+</project>
\ No newline at end of file

Propchange: maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/site/site.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagonTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagonTest.java?rev=1128840&view=auto
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagonTest.java (added)
+++ maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagonTest.java Sun May 29 08:25:27 2011
@@ -0,0 +1,150 @@
+package org.apache.maven.wagon.shared.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 junit.framework.TestCase;
+import org.apache.http.Header;
+import org.apache.http.client.methods.HttpHead;
+import org.apache.http.client.params.ClientPNames;
+import org.apache.http.params.HttpParams;
+
+public class AbstractHttpClientWagonTest
+    extends TestCase
+{
+
+    public void testSetPreemptiveAuthParamViaConfig()
+    {
+        HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
+        //X TODO methodConfig.addParam( HttpClientParams.PREEMPTIVE_AUTHENTICATION, "%b,true" );
+
+        HttpConfiguration config = new HttpConfiguration();
+        config.setAll( methodConfig );
+
+        TestWagon wagon = new TestWagon();
+        wagon.setHttpConfiguration( config );
+
+        HttpHead method = new HttpHead();
+        wagon.setParameters( method );
+
+        HttpParams params = method.getParams();
+        assertNotNull( params );
+        //X TODO assertTrue( params.isParameterTrue( HttpClientParams.PREEMPTIVE_AUTHENTICATION ) );
+    }
+
+    public void testSetMaxRedirectsParamViaConfig()
+    {
+        HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
+        int maxRedirects = 2;
+        methodConfig.addParam( ClientPNames.MAX_REDIRECTS, "%i," + maxRedirects );
+
+        HttpConfiguration config = new HttpConfiguration();
+        config.setAll( methodConfig );
+
+        TestWagon wagon = new TestWagon();
+        wagon.setHttpConfiguration( config );
+
+        HttpHead method = new HttpHead();
+        wagon.setParameters( method );
+
+        HttpParams params = method.getParams();
+        assertNotNull( params );
+        assertEquals( maxRedirects, params.getIntParameter( ClientPNames.MAX_REDIRECTS, -1 ) );
+    }
+
+    public void testDefaultHeadersUsedByDefault()
+    {
+        HttpConfiguration config = new HttpConfiguration();
+        config.setAll( new HttpMethodConfiguration() );
+
+        TestWagon wagon = new TestWagon();
+        wagon.setHttpConfiguration( config );
+
+        HttpHead method = new HttpHead();
+        wagon.setHeaders( method );
+
+        // these are the default headers.
+        // method.addRequestHeader( "Cache-control", "no-cache" );
+        // method.addRequestHeader( "Cache-store", "no-store" );
+        // method.addRequestHeader( "Pragma", "no-cache" );
+        // method.addRequestHeader( "Expires", "0" );
+        // method.addRequestHeader( "Accept-Encoding", "gzip" );
+
+        Header header = method.getFirstHeader( "Cache-control" );
+        assertNotNull( header );
+        assertEquals( "no-cache", header.getValue() );
+
+        header = method.getFirstHeader( "Cache-store" );
+        assertNotNull( header );
+        assertEquals( "no-store", header.getValue() );
+
+        header = method.getFirstHeader( "Pragma" );
+        assertNotNull( header );
+        assertEquals( "no-cache", header.getValue() );
+
+        header = method.getFirstHeader( "Expires" );
+        assertNotNull( header );
+        assertEquals( "0", header.getValue() );
+
+        header = method.getFirstHeader( "Accept-Encoding" );
+        assertNotNull( header );
+        assertEquals( "gzip", header.getValue() );
+    }
+
+    public void testTurnOffDefaultHeaders()
+    {
+        HttpConfiguration config = new HttpConfiguration();
+        config.setAll( new HttpMethodConfiguration().setUseDefaultHeaders( false ) );
+
+        TestWagon wagon = new TestWagon();
+        wagon.setHttpConfiguration( config );
+
+        HttpHead method = new HttpHead();
+        wagon.setHeaders( method );
+
+        // these are the default headers.
+        // method.addRequestHeader( "Cache-control", "no-cache" );
+        // method.addRequestHeader( "Cache-store", "no-store" );
+        // method.addRequestHeader( "Pragma", "no-cache" );
+        // method.addRequestHeader( "Expires", "0" );
+        // method.addRequestHeader( "Accept-Encoding", "gzip" );
+
+        Header header = method.getFirstHeader( "Cache-control" );
+        assertNull( header );
+
+        header = method.getFirstHeader( "Cache-store" );
+        assertNull( header );
+
+        header = method.getFirstHeader( "Pragma" );
+        assertNull( header );
+
+        header = method.getFirstHeader( "Expires" );
+        assertNull( header );
+
+        header = method.getFirstHeader( "Accept-Encoding" );
+        assertNull( header );
+    }
+
+    private static final class TestWagon
+        extends AbstractHttpClientWagon
+    {
+    }
+
+}

Propchange: maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/test/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagonTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-commits-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-commits-help@maven.apache.org


Mime
View raw message