You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2013/02/09 08:25:27 UTC
[2/2] git commit: [WAGON-388] moved code dependant on HttpComponents
3.x from wagon-http-shared to wagon-webdav-jackrabbit
Updated Branches:
refs/heads/master 34e9c2a05 -> 24a54ebe7
[WAGON-388] moved code dependant on HttpComponents 3.x
from wagon-http-shared to wagon-webdav-jackrabbit
Project: http://git-wip-us.apache.org/repos/asf/maven-wagon/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-wagon/commit/24a54ebe
Tree: http://git-wip-us.apache.org/repos/asf/maven-wagon/tree/24a54ebe
Diff: http://git-wip-us.apache.org/repos/asf/maven-wagon/diff/24a54ebe
Branch: refs/heads/master
Commit: 24a54ebe78410c6a0bb508bed839809d5e34a753
Parents: 34e9c2a
Author: Hervé Boutemy <hb...@apache.org>
Authored: Sat Feb 9 08:25:22 2013 +0100
Committer: Hervé Boutemy <hb...@apache.org>
Committed: Sat Feb 9 08:25:22 2013 +0100
----------------------------------------------------------------------
wagon-providers/wagon-http-lightweight/pom.xml | 10 -
wagon-providers/wagon-http-shared/pom.xml | 30 +-
.../wagon/shared/http/AbstractHttpClientWagon.java | 783 ---------------
.../maven/wagon/shared/http/HttpConfiguration.java | 104 --
.../wagon/shared/http/HttpMethodConfiguration.java | 322 ------
.../shared/http/AbstractHttpClientWagonTest.java | 237 -----
.../providers/webdav/AbstractHttpClientWagon.java | 783 +++++++++++++++
.../wagon/providers/webdav/HttpConfiguration.java | 104 ++
.../providers/webdav/HttpMethodConfiguration.java | 322 ++++++
.../maven/wagon/providers/webdav/WebDavWagon.java | 1 -
.../webdav/AbstractHttpClientWagonTest.java | 240 +++++
11 files changed, 1450 insertions(+), 1486 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/24a54ebe/wagon-providers/wagon-http-lightweight/pom.xml
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http-lightweight/pom.xml b/wagon-providers/wagon-http-lightweight/pom.xml
index 734b792..9b7c691 100644
--- a/wagon-providers/wagon-http-lightweight/pom.xml
+++ b/wagon-providers/wagon-http-lightweight/pom.xml
@@ -38,16 +38,6 @@ under the License.
<groupId>${project.groupId}</groupId>
<artifactId>wagon-http-shared4</artifactId>
<version>${project.version}</version>
- <exclusions>
- <exclusion>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- </exclusion>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<!-- used fo the TCK -->
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/24a54ebe/wagon-providers/wagon-http-shared/pom.xml
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http-shared/pom.xml b/wagon-providers/wagon-http-shared/pom.xml
index a1fdb36..4a4b4ed 100644
--- a/wagon-providers/wagon-http-shared/pom.xml
+++ b/wagon-providers/wagon-http-shared/pom.xml
@@ -30,7 +30,7 @@ under the License.
<artifactId>wagon-http-shared</artifactId>
<name>Apache Maven Wagon :: Providers :: HTTP Shared Library</name>
<description>
- Shared Library for the wagon-webdav wagon provider based on httpclient-3.x.
+ Shared Library for wagon providers supporting HTTP.
</description>
<dependencies>
@@ -51,34 +51,6 @@ under the License.
</exclusions>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>3.1</version>
- <!--
- The version of commons-logging that comes transitively has class loader
- problems. So we exclude it here and add a newer version below.
- -->
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
- </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>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- </dependency>
- <dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/24a54ebe/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
deleted file mode 100644
index 62b5c12..0000000
--- a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
+++ /dev/null
@@ -1,783 +0,0 @@
-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.commons.httpclient.Credentials;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HostConfiguration;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpConnectionManager;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
-import org.apache.commons.httpclient.NTCredentials;
-import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.commons.httpclient.auth.AuthScope;
-import org.apache.commons.httpclient.cookie.CookiePolicy;
-import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.HeadMethod;
-import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.commons.httpclient.methods.RequestEntity;
-import org.apache.commons.httpclient.params.HttpMethodParams;
-import org.apache.commons.httpclient.util.DateParseException;
-import org.apache.commons.httpclient.util.DateUtil;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.StringUtils;
-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 java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URLEncoder;
-import java.nio.ByteBuffer;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Properties;
-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 RequestEntity
- {
- private final Resource resource;
-
- private final Wagon wagon;
-
- private File source;
-
- private ByteBuffer byteBuffer;
-
- private RequestEntityImplementation( final InputStream stream, final Resource resource, final Wagon wagon,
- final File source )
- throws TransferFailedException
- {
- if ( source != null )
- {
- this.source = source;
- }
- else
- {
- try
- {
- byte[] bytes = IOUtils.toByteArray( stream );
- this.byteBuffer = ByteBuffer.allocate( bytes.length );
- this.byteBuffer.put( bytes );
- }
- catch ( IOException e )
- {
- throw new TransferFailedException( e.getMessage(), e );
- }
- }
-
- this.resource = resource;
- this.wagon = wagon;
- }
-
- public long getContentLength()
- {
- return resource.getContentLength();
- }
-
- public String getContentType()
- {
- return null;
- }
-
- public boolean isRepeatable()
- {
- return true;
- }
-
- public void writeRequest( 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() );
-
- InputStream fin = null;
- try
- {
- fin = this.source != null
- ? new FileInputStream( source )
- : new ByteArrayInputStream( this.byteBuffer.array() );
- 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
- {
- IOUtils.closeQuietly( fin );
- }
-
- output.flush();
- }
- }
-
- protected static final int SC_NULL = -1;
-
- protected static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone( "GMT" );
-
- private HttpClient client;
-
- protected HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
-
- /**
- * @deprecated Use httpConfiguration instead.
- */
- private Properties httpHeaders;
-
- /**
- * @since 1.0-beta-6
- */
- private HttpConfiguration httpConfiguration;
-
- private HttpMethod getMethod;
-
- public void openConnectionInternal()
- {
- repository.setUrl( getURL( repository ) );
- client = new HttpClient( connectionManager );
-
- // WAGON-273: default the cookie-policy to browser compatible
- client.getParams().setCookiePolicy( CookiePolicy.BROWSER_COMPATIBILITY );
-
-
-
- String username = null;
- String password = null;
- String domain = null;
-
- if ( authenticationInfo != null )
- {
- username = authenticationInfo.getUserName();
-
- if ( StringUtils.contains( username, "\\" ) )
- {
- String[] domainAndUsername = username.split( "\\\\" );
- domain = domainAndUsername[0];
- username = domainAndUsername[1];
- }
-
- password = authenticationInfo.getPassword();
-
-
- }
-
- String host = getRepository().getHost();
-
- if ( StringUtils.isNotEmpty( username ) && StringUtils.isNotEmpty( password ) )
- {
- Credentials creds;
- if ( domain != null )
- {
- creds = new NTCredentials( username, password, host, domain );
- }
- else
- {
- creds = new UsernamePasswordCredentials( username, password );
- }
-
- int port = getRepository().getPort() > -1 ? getRepository().getPort() : AuthScope.ANY_PORT;
-
- AuthScope scope = new AuthScope( host, port );
- client.getState().setCredentials( scope, creds );
- }
-
- HostConfiguration hc = new HostConfiguration();
-
- 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 )
- {
- hc.setProxy( 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 scope = new AuthScope( proxyHost, port );
- client.getState().setProxyCredentials( scope, creds );
- }
- }
- }
-
- hc.setHost( host );
-
- //start a session with the webserver
- client.setHostConfiguration( hc );
- }
-
- public void closeConnection()
- {
- 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
- {
- StringBuilder url = new StringBuilder( getRepository().getUrl() );
- String[] parts = StringUtils.split( resource.getName(), "/" );
- for ( String part : parts )
- {
- // TODO: Fix encoding...
- if ( !url.toString().endsWith( "/" ) )
- {
- url.append( '/' );
- }
- url.append( URLEncoder.encode( part ) );
- }
- RequestEntityImplementation requestEntityImplementation =
- new RequestEntityImplementation( stream, resource, this, source );
- put( resource, source, requestEntityImplementation, url.toString() );
-
- }
-
- private void put( Resource resource, File source, RequestEntityImplementation requestEntityImplementation,
- String url )
- throws TransferFailedException, AuthorizationException, ResourceDoesNotExistException
- {
-
- // preemptive true for put
- client.getParams().setAuthenticationPreemptive( true );
-
- //Parent directories need to be created before posting
- try
- {
- mkdirs( PathUtils.dirname( resource.getName() ) );
- }
- catch ( IOException e )
- {
- fireTransferError( resource, e, TransferEvent.REQUEST_GET );
- }
-
- PutMethod putMethod = new PutMethod( url );
-
- firePutStarted( resource, source );
-
- try
- {
- putMethod.setRequestEntity( requestEntityImplementation );
-
- int statusCode;
- try
- {
- statusCode = execute( putMethod );
-
- }
- catch ( IOException e )
- {
- fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
-
- throw new TransferFailedException( e.getMessage(), e );
- }
-
- 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;
-
- // handle all redirect even if http specs says " the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user"
- case HttpStatus.SC_MOVED_PERMANENTLY: // 301
- case HttpStatus.SC_MOVED_TEMPORARILY: // 302
- case HttpStatus.SC_SEE_OTHER: // 303
- String relocatedUrl = calculateRelocatedUrl( putMethod );
- fireTransferDebug( "relocate to " + relocatedUrl );
- put( resource, source, requestEntityImplementation, relocatedUrl );
- return;
-
- 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.releaseConnection();
- }
- }
-
- protected String calculateRelocatedUrl( EntityEnclosingMethod method )
- {
- Header locationHeader = method.getResponseHeader( "Location" );
- String locationField = locationHeader.getValue();
- // is it a relative Location or a full ?
- return locationField.startsWith( "http" ) ? locationField : getURL( getRepository() ) + '/' + locationField;
- }
-
- protected void mkdirs( String dirname )
- throws IOException
- {
- // do nothing as default.
- }
-
- public boolean resourceExists( String resourceName )
- throws TransferFailedException, AuthorizationException
- {
- StringBuilder url = new StringBuilder( getRepository().getUrl() );
- if ( !url.toString().endsWith( "/" ) )
- {
- url.append( '/' );
- }
- url.append( resourceName );
- HeadMethod headMethod = new HeadMethod( url.toString() );
-
- int statusCode;
- try
- {
- statusCode = execute( headMethod );
- }
- catch ( IOException e )
- {
- throw new TransferFailedException( e.getMessage(), e );
- }
- try
- {
- 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.releaseConnection();
- }
- }
-
- protected int execute( HttpMethod httpMethod )
- throws IOException
- {
- int statusCode;
-
- setParameters( httpMethod );
- setHeaders( httpMethod );
-
- statusCode = client.executeMethod( httpMethod );
- return statusCode;
- }
-
- protected void setParameters( HttpMethod method )
- {
- HttpMethodConfiguration config =
- httpConfiguration == null ? null : httpConfiguration.getMethodConfiguration( method );
- if ( config != null )
- {
- HttpMethodParams params = config.asMethodParams( method.getParams() );
- if ( params != null )
- {
- method.setParams( params );
- }
- }
-
- if ( config == null || config.getConnectionTimeout() == HttpMethodConfiguration.DEFAULT_CONNECTION_TIMEOUT )
- {
- method.getParams().setSoTimeout( getTimeout() );
- }
- }
-
- protected void setHeaders( HttpMethod 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.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" );
- }
-
- if ( httpHeaders != null )
- {
- for ( Iterator i = httpHeaders.keySet().iterator(); i.hasNext(); )
- {
- String header = (String) i.next();
- method.addRequestHeader( header, httpHeaders.getProperty( header ) );
- }
- }
-
- Header[] headers = config == null ? null : config.asRequestHeaders();
- if ( headers != null )
- {
- for ( int i = 0; i < headers.length; i++ )
- {
- method.addRequestHeader( 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();
- }
-
- protected HttpClient getClient()
- {
- return client;
- }
-
- public void setConnectionManager( HttpConnectionManager connectionManager )
- {
- this.connectionManager = connectionManager;
- }
-
- public Properties getHttpHeaders()
- {
- return httpHeaders;
- }
-
- public void setHttpHeaders( Properties httpHeaders )
- {
- this.httpHeaders = httpHeaders;
- }
-
- 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();
-
- StringBuilder url = new StringBuilder( getRepository().getUrl() );
- if ( !url.toString().endsWith( "/" ) )
- {
- url.append( '/' );
- }
- url.append( resource.getName() );
-
- getMethod = new GetMethod( url.toString() );
-
- 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 Header( "If-Modified-Since", fmt.format( new Date( timestamp ) ) );
- fireTransferDebug( "sending ==> " + hdr + "(" + timestamp + ")" );
- getMethod.addRequestHeader( hdr );
- }
-
- int statusCode;
- try
- {
- statusCode = execute( getMethod );
- }
- catch ( IOException e )
- {
- fireTransferError( resource, e, TransferEvent.REQUEST_GET );
-
- throw new TransferFailedException( e.getMessage(), e );
- }
-
- 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 = getMethod.getResponseHeader( "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 = getMethod.getResponseHeader( "Last-Modified" );
-
- long lastModified = 0;
-
- if ( lastModifiedHeader != null )
- {
- try
- {
- lastModified = DateUtil.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 = getMethod.getResponseHeader( "Content-Encoding" );
- boolean isGZipped = contentEncoding != null && "gzip".equalsIgnoreCase( contentEncoding.getValue() );
-
- try
- {
- is = getMethod.getResponseBodyAsStream();
- 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.releaseConnection();
- }
- }
-
- @Override
- public void putFromStream( InputStream stream, String destination )
- throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
- {
- putFromStream( stream, destination, -1, -1 );
- }
-
- @Override
- protected void putFromStream( InputStream stream, Resource resource )
- throws TransferFailedException, AuthorizationException, ResourceDoesNotExistException
- {
- putFromStream( stream, resource.getName(), -1, -1 );
- }
-
- @Override
- public void fillOutputData( OutputData outputData )
- throws TransferFailedException
- {
- // no needed in this implementation but throw an Exception if used
- throw new IllegalStateException( "this wagon http client must not use fillOutputData" );
- }
-}
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/24a54ebe/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/HttpConfiguration.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/HttpConfiguration.java b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/HttpConfiguration.java
deleted file mode 100644
index 492e24a..0000000
--- a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/HttpConfiguration.java
+++ /dev/null
@@ -1,104 +0,0 @@
-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.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.HeadMethod;
-import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.commons.httpclient.params.HttpClientParams;
-
-public class HttpConfiguration
-{
-
- private static final HttpMethodConfiguration DEFAULT_PUT =
- new HttpMethodConfiguration().addParam( HttpClientParams.USE_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( HttpMethod method )
- {
- if ( method instanceof GetMethod )
- {
- return HttpMethodConfiguration.merge( all, get );
- }
- else if ( method instanceof PutMethod )
- {
- return HttpMethodConfiguration.merge( DEFAULT_PUT, all, put );
- }
- else if ( method instanceof HeadMethod )
- {
- return HttpMethodConfiguration.merge( all, head );
- }
-
- return all;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/24a54ebe/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/HttpMethodConfiguration.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/HttpMethodConfiguration.java b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/HttpMethodConfiguration.java
deleted file mode 100644
index 9bbc433..0000000
--- a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/HttpMethodConfiguration.java
+++ /dev/null
@@ -1,322 +0,0 @@
-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.commons.httpclient.Header;
-import org.apache.commons.httpclient.params.HttpMethodParams;
-
-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 HttpMethodParams asMethodParams( HttpMethodParams defaults )
- {
- if ( !hasParams() )
- {
- return null;
- }
-
- HttpMethodParams p = new HttpMethodParams();
- p.setDefaults( defaults );
-
- fillParams( p );
-
- return p;
- }
-
- private boolean hasParams()
- {
- if ( connectionTimeout < 1 && params == null )
- {
- return false;
- }
-
- return true;
- }
-
- private void fillParams( HttpMethodParams p )
- {
- if ( !hasParams() )
- {
- return;
- }
-
- if ( connectionTimeout > 0 )
- {
- p.setSoTimeout( 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 new Header[0];
- }
-
- 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 Header( 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;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/24a54ebe/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagonTest.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagonTest.java b/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagonTest.java
deleted file mode 100644
index cb2bef8..0000000
--- a/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagonTest.java
+++ /dev/null
@@ -1,237 +0,0 @@
-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.commons.httpclient.Credentials;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.NTCredentials;
-import org.apache.commons.httpclient.auth.AuthScope;
-import org.apache.commons.httpclient.methods.HeadMethod;
-import org.apache.commons.httpclient.params.HttpClientParams;
-import org.apache.commons.httpclient.params.HttpMethodParams;
-import org.apache.maven.wagon.ConnectionException;
-import org.apache.maven.wagon.OutputData;
-import org.apache.maven.wagon.TransferFailedException;
-import org.apache.maven.wagon.authentication.AuthenticationException;
-import org.apache.maven.wagon.authentication.AuthenticationInfo;
-import org.apache.maven.wagon.proxy.ProxyInfo;
-import org.apache.maven.wagon.repository.Repository;
-
-public class AbstractHttpClientWagonTest
- extends TestCase
-{
-
- public void testSetPreemptiveAuthParamViaConfig()
- {
- HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
- methodConfig.addParam( HttpClientParams.PREEMPTIVE_AUTHENTICATION, "%b,true" );
-
- HttpConfiguration config = new HttpConfiguration();
- config.setAll( methodConfig );
-
- TestWagon wagon = new TestWagon();
- wagon.setHttpConfiguration( config );
-
- HeadMethod method = new HeadMethod();
- wagon.setParameters( method );
-
- HttpMethodParams params = method.getParams();
- assertNotNull( params );
- assertTrue( params.isParameterTrue( HttpClientParams.PREEMPTIVE_AUTHENTICATION ) );
- }
-
- public void testSetMaxRedirectsParamViaConfig()
- {
- HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
- int maxRedirects = 2;
- methodConfig.addParam( HttpClientParams.MAX_REDIRECTS, "%i," + maxRedirects );
-
- HttpConfiguration config = new HttpConfiguration();
- config.setAll( methodConfig );
-
- TestWagon wagon = new TestWagon();
- wagon.setHttpConfiguration( config );
-
- HeadMethod method = new HeadMethod();
- wagon.setParameters( method );
-
- HttpMethodParams params = method.getParams();
- assertNotNull( params );
- assertEquals( maxRedirects, params.getIntParameter( HttpClientParams.MAX_REDIRECTS, -1 ) );
- }
-
- public void testDefaultHeadersUsedByDefault()
- {
- HttpConfiguration config = new HttpConfiguration();
- config.setAll( new HttpMethodConfiguration() );
-
- TestWagon wagon = new TestWagon();
- wagon.setHttpConfiguration( config );
-
- HeadMethod method = new HeadMethod();
- 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.getRequestHeader( "Cache-control" );
- assertNotNull( header );
- assertEquals( "no-cache", header.getValue() );
-
- header = method.getRequestHeader( "Cache-store" );
- assertNotNull( header );
- assertEquals( "no-store", header.getValue() );
-
- header = method.getRequestHeader( "Pragma" );
- assertNotNull( header );
- assertEquals( "no-cache", header.getValue() );
-
- header = method.getRequestHeader( "Expires" );
- assertNotNull( header );
- assertEquals( "0", header.getValue() );
-
- header = method.getRequestHeader( "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 );
-
- HeadMethod method = new HeadMethod();
- 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.getRequestHeader( "Cache-control" );
- assertNull( header );
-
- header = method.getRequestHeader( "Cache-store" );
- assertNull( header );
-
- header = method.getRequestHeader( "Pragma" );
- assertNull( header );
-
- header = method.getRequestHeader( "Expires" );
- assertNull( header );
-
- header = method.getRequestHeader( "Accept-Encoding" );
- assertNull( header );
- }
-
- public void testNTCredentialsWithUsernameNull()
- throws AuthenticationException, ConnectionException
- {
- TestWagon wagon = new TestWagon();
-
- Repository repository = new Repository( "mockRepoId", "mockRepoURL" );
- wagon.connect( repository );
-
- wagon.openConnection();
-
- assertNull( wagon.getAuthenticationInfo().getUserName() );
- assertNull( wagon.getAuthenticationInfo().getPassword() );
-
- assertFalse( wagon.getClient().getState().getCredentials( new AuthScope( null, 0 ) ) instanceof NTCredentials );
- }
-
- public void testNTCredentialsNoNTDomain()
- throws AuthenticationException, ConnectionException
- {
- TestWagon wagon = new TestWagon();
-
- AuthenticationInfo authenticationInfo = new AuthenticationInfo();
- String myUsernameNoNTDomain = "myUserNameNoNTDomain";
- authenticationInfo.setUserName( myUsernameNoNTDomain );
-
- String myPassword = "myPassword";
- authenticationInfo.setPassword( myPassword );
-
- Repository repository = new Repository( "mockRepoId", "mockRepoURL" );
-
- wagon.connect( repository, authenticationInfo, (ProxyInfo) null );
-
- wagon.openConnection();
-
- assertEquals( myUsernameNoNTDomain, wagon.getAuthenticationInfo().getUserName() );
- assertEquals( myPassword, wagon.getAuthenticationInfo().getPassword() );
-
- assertFalse( wagon.getClient().getState().getCredentials( new AuthScope( null, 0 ) ) instanceof NTCredentials );
- }
-
- public void testNTCredentialsWithNTDomain()
- throws AuthenticationException, ConnectionException
- {
- TestWagon wagon = new TestWagon();
-
- AuthenticationInfo authenticationInfo = new AuthenticationInfo();
- String myNTDomain = "myNTDomain";
- String myUsername = "myUsername";
- String myNTDomainAndUser = myNTDomain + "\\" + myUsername;
- authenticationInfo.setUserName( myNTDomainAndUser );
-
- String myPassword = "myPassword";
- authenticationInfo.setPassword( myPassword );
-
- Repository repository = new Repository( "mockRepoId", "mockRepoURL" );
-
- wagon.connect( repository, authenticationInfo, (ProxyInfo) null );
-
- wagon.openConnection();
-
- assertEquals( myNTDomainAndUser, wagon.getAuthenticationInfo().getUserName() );
- assertEquals( myPassword, wagon.getAuthenticationInfo().getPassword() );
-
- Credentials credentials = wagon.getClient().getState().getCredentials( new AuthScope( null, 0 ) );
- assertTrue( credentials instanceof NTCredentials );
-
- NTCredentials ntCredentials = (NTCredentials) credentials;
- assertEquals( myNTDomain, ntCredentials.getDomain() );
- assertEquals( myUsername, ntCredentials.getUserName() );
- assertEquals( myPassword, ntCredentials.getPassword() );
- }
-
- private static final class TestWagon
- extends AbstractHttpClientWagon
- {
- @Override
- public void fillOutputData( OutputData outputData )
- throws TransferFailedException
- {
-
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/24a54ebe/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/AbstractHttpClientWagon.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/AbstractHttpClientWagon.java b/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/AbstractHttpClientWagon.java
new file mode 100644
index 0000000..e2ed2f8
--- /dev/null
+++ b/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/AbstractHttpClientWagon.java
@@ -0,0 +1,783 @@
+package org.apache.maven.wagon.providers.webdav;
+
+/*
+ * 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.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpConnectionManager;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.NTCredentials;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.cookie.CookiePolicy;
+import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.HeadMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.commons.httpclient.util.DateParseException;
+import org.apache.commons.httpclient.util.DateUtil;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+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 java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URLEncoder;
+import java.nio.ByteBuffer;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Properties;
+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 RequestEntity
+ {
+ private final Resource resource;
+
+ private final Wagon wagon;
+
+ private File source;
+
+ private ByteBuffer byteBuffer;
+
+ private RequestEntityImplementation( final InputStream stream, final Resource resource, final Wagon wagon,
+ final File source )
+ throws TransferFailedException
+ {
+ if ( source != null )
+ {
+ this.source = source;
+ }
+ else
+ {
+ try
+ {
+ byte[] bytes = IOUtils.toByteArray( stream );
+ this.byteBuffer = ByteBuffer.allocate( bytes.length );
+ this.byteBuffer.put( bytes );
+ }
+ catch ( IOException e )
+ {
+ throw new TransferFailedException( e.getMessage(), e );
+ }
+ }
+
+ this.resource = resource;
+ this.wagon = wagon;
+ }
+
+ public long getContentLength()
+ {
+ return resource.getContentLength();
+ }
+
+ public String getContentType()
+ {
+ return null;
+ }
+
+ public boolean isRepeatable()
+ {
+ return true;
+ }
+
+ public void writeRequest( 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() );
+
+ InputStream fin = null;
+ try
+ {
+ fin = this.source != null
+ ? new FileInputStream( source )
+ : new ByteArrayInputStream( this.byteBuffer.array() );
+ 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
+ {
+ IOUtils.closeQuietly( fin );
+ }
+
+ output.flush();
+ }
+ }
+
+ protected static final int SC_NULL = -1;
+
+ protected static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone( "GMT" );
+
+ private HttpClient client;
+
+ protected HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
+
+ /**
+ * @deprecated Use httpConfiguration instead.
+ */
+ private Properties httpHeaders;
+
+ /**
+ * @since 1.0-beta-6
+ */
+ private HttpConfiguration httpConfiguration;
+
+ private HttpMethod getMethod;
+
+ public void openConnectionInternal()
+ {
+ repository.setUrl( getURL( repository ) );
+ client = new HttpClient( connectionManager );
+
+ // WAGON-273: default the cookie-policy to browser compatible
+ client.getParams().setCookiePolicy( CookiePolicy.BROWSER_COMPATIBILITY );
+
+
+
+ String username = null;
+ String password = null;
+ String domain = null;
+
+ if ( authenticationInfo != null )
+ {
+ username = authenticationInfo.getUserName();
+
+ if ( StringUtils.contains( username, "\\" ) )
+ {
+ String[] domainAndUsername = username.split( "\\\\" );
+ domain = domainAndUsername[0];
+ username = domainAndUsername[1];
+ }
+
+ password = authenticationInfo.getPassword();
+
+
+ }
+
+ String host = getRepository().getHost();
+
+ if ( StringUtils.isNotEmpty( username ) && StringUtils.isNotEmpty( password ) )
+ {
+ Credentials creds;
+ if ( domain != null )
+ {
+ creds = new NTCredentials( username, password, host, domain );
+ }
+ else
+ {
+ creds = new UsernamePasswordCredentials( username, password );
+ }
+
+ int port = getRepository().getPort() > -1 ? getRepository().getPort() : AuthScope.ANY_PORT;
+
+ AuthScope scope = new AuthScope( host, port );
+ client.getState().setCredentials( scope, creds );
+ }
+
+ HostConfiguration hc = new HostConfiguration();
+
+ 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 )
+ {
+ hc.setProxy( 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 scope = new AuthScope( proxyHost, port );
+ client.getState().setProxyCredentials( scope, creds );
+ }
+ }
+ }
+
+ hc.setHost( host );
+
+ //start a session with the webserver
+ client.setHostConfiguration( hc );
+ }
+
+ public void closeConnection()
+ {
+ 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
+ {
+ StringBuilder url = new StringBuilder( getRepository().getUrl() );
+ String[] parts = StringUtils.split( resource.getName(), "/" );
+ for ( String part : parts )
+ {
+ // TODO: Fix encoding...
+ if ( !url.toString().endsWith( "/" ) )
+ {
+ url.append( '/' );
+ }
+ url.append( URLEncoder.encode( part ) );
+ }
+ RequestEntityImplementation requestEntityImplementation =
+ new RequestEntityImplementation( stream, resource, this, source );
+ put( resource, source, requestEntityImplementation, url.toString() );
+
+ }
+
+ private void put( Resource resource, File source, RequestEntityImplementation requestEntityImplementation,
+ String url )
+ throws TransferFailedException, AuthorizationException, ResourceDoesNotExistException
+ {
+
+ // preemptive true for put
+ client.getParams().setAuthenticationPreemptive( true );
+
+ //Parent directories need to be created before posting
+ try
+ {
+ mkdirs( PathUtils.dirname( resource.getName() ) );
+ }
+ catch ( IOException e )
+ {
+ fireTransferError( resource, e, TransferEvent.REQUEST_GET );
+ }
+
+ PutMethod putMethod = new PutMethod( url );
+
+ firePutStarted( resource, source );
+
+ try
+ {
+ putMethod.setRequestEntity( requestEntityImplementation );
+
+ int statusCode;
+ try
+ {
+ statusCode = execute( putMethod );
+
+ }
+ catch ( IOException e )
+ {
+ fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
+
+ throw new TransferFailedException( e.getMessage(), e );
+ }
+
+ 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;
+
+ // handle all redirect even if http specs says " the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user"
+ case HttpStatus.SC_MOVED_PERMANENTLY: // 301
+ case HttpStatus.SC_MOVED_TEMPORARILY: // 302
+ case HttpStatus.SC_SEE_OTHER: // 303
+ String relocatedUrl = calculateRelocatedUrl( putMethod );
+ fireTransferDebug( "relocate to " + relocatedUrl );
+ put( resource, source, requestEntityImplementation, relocatedUrl );
+ return;
+
+ 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.releaseConnection();
+ }
+ }
+
+ protected String calculateRelocatedUrl( EntityEnclosingMethod method )
+ {
+ Header locationHeader = method.getResponseHeader( "Location" );
+ String locationField = locationHeader.getValue();
+ // is it a relative Location or a full ?
+ return locationField.startsWith( "http" ) ? locationField : getURL( getRepository() ) + '/' + locationField;
+ }
+
+ protected void mkdirs( String dirname )
+ throws IOException
+ {
+ // do nothing as default.
+ }
+
+ public boolean resourceExists( String resourceName )
+ throws TransferFailedException, AuthorizationException
+ {
+ StringBuilder url = new StringBuilder( getRepository().getUrl() );
+ if ( !url.toString().endsWith( "/" ) )
+ {
+ url.append( '/' );
+ }
+ url.append( resourceName );
+ HeadMethod headMethod = new HeadMethod( url.toString() );
+
+ int statusCode;
+ try
+ {
+ statusCode = execute( headMethod );
+ }
+ catch ( IOException e )
+ {
+ throw new TransferFailedException( e.getMessage(), e );
+ }
+ try
+ {
+ 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.releaseConnection();
+ }
+ }
+
+ protected int execute( HttpMethod httpMethod )
+ throws IOException
+ {
+ int statusCode;
+
+ setParameters( httpMethod );
+ setHeaders( httpMethod );
+
+ statusCode = client.executeMethod( httpMethod );
+ return statusCode;
+ }
+
+ protected void setParameters( HttpMethod method )
+ {
+ HttpMethodConfiguration config =
+ httpConfiguration == null ? null : httpConfiguration.getMethodConfiguration( method );
+ if ( config != null )
+ {
+ HttpMethodParams params = config.asMethodParams( method.getParams() );
+ if ( params != null )
+ {
+ method.setParams( params );
+ }
+ }
+
+ if ( config == null || config.getConnectionTimeout() == HttpMethodConfiguration.DEFAULT_CONNECTION_TIMEOUT )
+ {
+ method.getParams().setSoTimeout( getTimeout() );
+ }
+ }
+
+ protected void setHeaders( HttpMethod 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.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" );
+ }
+
+ if ( httpHeaders != null )
+ {
+ for ( Iterator i = httpHeaders.keySet().iterator(); i.hasNext(); )
+ {
+ String header = (String) i.next();
+ method.addRequestHeader( header, httpHeaders.getProperty( header ) );
+ }
+ }
+
+ Header[] headers = config == null ? null : config.asRequestHeaders();
+ if ( headers != null )
+ {
+ for ( int i = 0; i < headers.length; i++ )
+ {
+ method.addRequestHeader( 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();
+ }
+
+ protected HttpClient getClient()
+ {
+ return client;
+ }
+
+ public void setConnectionManager( HttpConnectionManager connectionManager )
+ {
+ this.connectionManager = connectionManager;
+ }
+
+ public Properties getHttpHeaders()
+ {
+ return httpHeaders;
+ }
+
+ public void setHttpHeaders( Properties httpHeaders )
+ {
+ this.httpHeaders = httpHeaders;
+ }
+
+ 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();
+
+ StringBuilder url = new StringBuilder( getRepository().getUrl() );
+ if ( !url.toString().endsWith( "/" ) )
+ {
+ url.append( '/' );
+ }
+ url.append( resource.getName() );
+
+ getMethod = new GetMethod( url.toString() );
+
+ 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 Header( "If-Modified-Since", fmt.format( new Date( timestamp ) ) );
+ fireTransferDebug( "sending ==> " + hdr + "(" + timestamp + ")" );
+ getMethod.addRequestHeader( hdr );
+ }
+
+ int statusCode;
+ try
+ {
+ statusCode = execute( getMethod );
+ }
+ catch ( IOException e )
+ {
+ fireTransferError( resource, e, TransferEvent.REQUEST_GET );
+
+ throw new TransferFailedException( e.getMessage(), e );
+ }
+
+ 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 = getMethod.getResponseHeader( "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 = getMethod.getResponseHeader( "Last-Modified" );
+
+ long lastModified = 0;
+
+ if ( lastModifiedHeader != null )
+ {
+ try
+ {
+ lastModified = DateUtil.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 = getMethod.getResponseHeader( "Content-Encoding" );
+ boolean isGZipped = contentEncoding != null && "gzip".equalsIgnoreCase( contentEncoding.getValue() );
+
+ try
+ {
+ is = getMethod.getResponseBodyAsStream();
+ 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.releaseConnection();
+ }
+ }
+
+ @Override
+ public void putFromStream( InputStream stream, String destination )
+ throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+ {
+ putFromStream( stream, destination, -1, -1 );
+ }
+
+ @Override
+ protected void putFromStream( InputStream stream, Resource resource )
+ throws TransferFailedException, AuthorizationException, ResourceDoesNotExistException
+ {
+ putFromStream( stream, resource.getName(), -1, -1 );
+ }
+
+ @Override
+ public void fillOutputData( OutputData outputData )
+ throws TransferFailedException
+ {
+ // no needed in this implementation but throw an Exception if used
+ throw new IllegalStateException( "this wagon http client must not use fillOutputData" );
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/24a54ebe/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/HttpConfiguration.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/HttpConfiguration.java b/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/HttpConfiguration.java
new file mode 100644
index 0000000..9c3e9e6
--- /dev/null
+++ b/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/HttpConfiguration.java
@@ -0,0 +1,104 @@
+package org.apache.maven.wagon.providers.webdav;
+
+/*
+ * 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.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.HeadMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.params.HttpClientParams;
+
+public class HttpConfiguration
+{
+
+ private static final HttpMethodConfiguration DEFAULT_PUT =
+ new HttpMethodConfiguration().addParam( HttpClientParams.USE_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( HttpMethod method )
+ {
+ if ( method instanceof GetMethod )
+ {
+ return HttpMethodConfiguration.merge( all, get );
+ }
+ else if ( method instanceof PutMethod )
+ {
+ return HttpMethodConfiguration.merge( DEFAULT_PUT, all, put );
+ }
+ else if ( method instanceof HeadMethod )
+ {
+ return HttpMethodConfiguration.merge( all, head );
+ }
+
+ return all;
+ }
+
+}