You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2011/12/01 22:27:00 UTC
svn commit: r1209251 - in /maven/wagon/trunk:
wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java
wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/AbstractHttpClientWagon.java
Author: olamy
Date: Thu Dec 1 21:26:59 2011
New Revision: 1209251
URL: http://svn.apache.org/viewvc?rev=1209251&view=rev
Log:
[WAGON-361] avoid writing temporary file in putFromStream from wagon-http.
Modified:
maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java
maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/AbstractHttpClientWagon.java
Modified: maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java?rev=1209251&r1=1209250&r2=1209251&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java (original)
+++ maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java Thu Dec 1 21:26:59 2011
@@ -33,6 +33,7 @@ import org.apache.maven.wagon.resource.R
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringOutputStream;
+import org.codehaus.plexus.util.StringUtils;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.HttpConnection;
import org.mortbay.jetty.Request;
@@ -932,12 +933,13 @@ public abstract class HttpWagonTestCase
File tempFile = File.createTempFile( "wagon", "tmp" );
tempFile.deleteOnExit();
- FileUtils.fileWrite( tempFile.getAbsolutePath(), "put top secret" );
+ String content = "put top secret";
+ FileUtils.fileWrite( tempFile.getAbsolutePath(), content );
FileInputStream fileInputStream = new FileInputStream( tempFile );
try
{
- wagon.putFromStream( fileInputStream, "test-secured-put-resource" );
+ wagon.putFromStream( fileInputStream, "test-secured-put-resource", content.length(), -1 );
}
finally
{
@@ -946,7 +948,7 @@ public abstract class HttpWagonTestCase
}
- assertEquals( "put top secret", FileUtils.fileRead( sourceFile.getAbsolutePath() ) );
+ assertEquals( content, FileUtils.fileRead( sourceFile.getAbsolutePath() ) );
}
}
finally
@@ -959,6 +961,15 @@ public abstract class HttpWagonTestCase
{
testPreemptiveAuthentication( sh );
}
+
+ // ensure we didn't use chuncked transfer which doesn't work on ngnix
+ for ( DeployedResource deployedResource : putHandler.deployedResources )
+ {
+ if ( StringUtils.equalsIgnoreCase( "chuncked", deployedResource.transferEncoding ) )
+ {
+ fail( "deployedResource use chuncked: " + deployedResource );
+ }
+ }
}
@@ -1004,11 +1015,42 @@ public abstract class HttpWagonTestCase
}
}
+ static class DeployedResource
+ {
+ String httpMethod;
+
+ String requestUri;
+
+ String contentLength;
+
+ String transferEncoding;
+
+ public DeployedResource()
+ {
+ // no op
+ }
+
+ @Override
+ public String toString()
+ {
+ final StringBuilder sb = new StringBuilder();
+ sb.append( "DeployedResource" );
+ sb.append( "{httpMethod='" ).append( httpMethod ).append( '\'' );
+ sb.append( ", requestUri='" ).append( requestUri ).append( '\'' );
+ sb.append( ", contentLength='" ).append( contentLength ).append( '\'' );
+ sb.append( ", transferEncoding='" ).append( transferEncoding ).append( '\'' );
+ sb.append( '}' );
+ return sb.toString();
+ }
+ }
+
static class PutHandler
extends AbstractHandler
{
private final File resourceBase;
+ public List<DeployedResource> deployedResources = new ArrayList<DeployedResource>();
+
public int putCallNumber = 0;
public PutHandler( File repositoryDirectory )
@@ -1044,6 +1086,14 @@ public abstract class HttpWagonTestCase
}
System.out.println( "put file " + request.getPathInfo() );
putCallNumber++;
+ DeployedResource deployedResource = new DeployedResource();
+
+ deployedResource.httpMethod = request.getMethod();
+ deployedResource.requestUri = request.getRequestURI();
+ deployedResource.transferEncoding = request.getHeader( "Transfer-Encoding" );
+ deployedResource.contentLength = request.getHeader( "Content-Length" );
+ deployedResources.add( deployedResource );
+
response.setStatus( HttpServletResponse.SC_CREATED );
}
}
Modified: maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/AbstractHttpClientWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/AbstractHttpClientWagon.java?rev=1209251&r1=1209250&r2=1209251&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/AbstractHttpClientWagon.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/AbstractHttpClientWagon.java Thu Dec 1 21:26:59 2011
@@ -43,6 +43,7 @@ import org.apache.http.conn.scheme.Schem
import org.apache.http.conn.ssl.BrowserCompatHostnameVerifier;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.X509HostnameVerifier;
+import org.apache.http.entity.AbstractHttpEntity;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.DefaultHttpClient;
@@ -67,7 +68,6 @@ import org.apache.maven.wagon.events.Tra
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 javax.net.ssl.SSLException;
@@ -75,7 +75,6 @@ import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -100,13 +99,20 @@ public abstract class AbstractHttpClient
private BasicHttpContext localContext;
private final class RequestEntityImplementation
- implements HttpEntity
+ extends AbstractHttpEntity//implements HttpEntity
{
+
+ private final static int BUFFER_SIZE = 2048;
+
private final Resource resource;
private final Wagon wagon;
- private final File source;
+ private InputStream stream;
+
+ private File source;
+
+ private long length;
private RequestEntityImplementation( final InputStream stream, final Resource resource, final Wagon wagon,
final File source )
@@ -118,63 +124,79 @@ public abstract class AbstractHttpClient
}
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.stream = stream;
}
-
this.resource = resource;
+ this.length = resource == null ? -1 : resource.getContentLength();
this.wagon = wagon;
}
public long getContentLength()
{
- return resource.getContentLength();
+ return length;
}
- public Header getContentType()
- {
- return null;
- }
-
- public Header getContentEncoding()
- {
- return null;
- }
public InputStream getContent()
throws IOException, IllegalStateException
{
- FileInputStream fis = new FileInputStream( source );
-
- return fis;
+ return this.source != null ? new FileInputStream( this.source ) : this.stream;
}
public boolean isRepeatable()
{
- return true;
+ return false;
}
- public boolean isChunked()
+
+ public void writeTo( final OutputStream outstream )
+ throws IOException
{
- return false;
+ if ( outstream == null )
+ {
+ throw new IllegalArgumentException( "Output stream may not be null" );
+ }
+ TransferEvent transferEvent =
+ new TransferEvent( wagon, resource, TransferEvent.TRANSFER_PROGRESS, TransferEvent.REQUEST_PUT );
+ transferEvent.setTimestamp( System.currentTimeMillis() );
+ InputStream instream = this.source != null ? new FileInputStream( this.source ) : this.stream;
+ try
+ {
+ byte[] buffer = new byte[BUFFER_SIZE];
+ int l;
+ if ( this.length < 0 )
+ {
+ // until EOF
+ while ( ( l = instream.read( buffer ) ) != -1 )
+ {
+ fireTransferProgress( transferEvent, buffer, -1 );
+ outstream.write( buffer, 0, l );
+ }
+ }
+ else
+ {
+ // no need to consume more than length
+ long remaining = this.length;
+ while ( remaining > 0 )
+ {
+ l = instream.read( buffer, 0, (int) Math.min( BUFFER_SIZE, remaining ) );
+ if ( l == -1 )
+ {
+ break;
+ }
+ fireTransferProgress( transferEvent, buffer, (int) Math.min( BUFFER_SIZE, remaining ) );
+ outstream.write( buffer, 0, l );
+ remaining -= l;
+ }
+ }
+ }
+ finally
+ {
+ instream.close();
+ }
}
+ /*
public void writeTo( OutputStream output )
throws IOException
{
@@ -212,16 +234,14 @@ public abstract class AbstractHttpClient
output.flush();
}
+ */
public boolean isStreaming()
{
- return false;
+ return true;
}
- public void consumeContent()
- throws IOException
- {
- }
+
}
protected static final int SC_NULL = -1;
Re: svn commit: r1209251 - in /maven/wagon/trunk: wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java
wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/AbstractHttpClientWagon.java
Posted by Olivier Lamy <ol...@apache.org>.
good catch !
I will fix this typo
2011/12/2 Brett Porter <br...@apache.org>:
>
> On 02/12/2011, at 8:27 AM, olamy@apache.org wrote:
>
>> + // ensure we didn't use chuncked transfer which doesn't work on ngnix
>> + for ( DeployedResource deployedResource : putHandler.deployedResources )
>> + {
>> + if ( StringUtils.equalsIgnoreCase( "chuncked", deployedResource.transferEncoding ) )
>> + {
>> + fail( "deployedResource use chuncked: " + deployedResource );
>> + }
>> + }
>
> Is that spelling right?
>
> - Brett
>
>
> --
> Brett Porter
> brett@apache.org
> http://brettporter.wordpress.com/
> http://au.linkedin.com/in/brettporter
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
--
Olivier Lamy
Talend: http://coders.talend.com
http://twitter.com/olamy | http://linkedin.com/in/olamy
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: svn commit: r1209251 - in /maven/wagon/trunk: wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/AbstractHttpClientWagon.java
Posted by Brett Porter <br...@apache.org>.
On 02/12/2011, at 8:27 AM, olamy@apache.org wrote:
> + // ensure we didn't use chuncked transfer which doesn't work on ngnix
> + for ( DeployedResource deployedResource : putHandler.deployedResources )
> + {
> + if ( StringUtils.equalsIgnoreCase( "chuncked", deployedResource.transferEncoding ) )
> + {
> + fail( "deployedResource use chuncked: " + deployedResource );
> + }
> + }
Is that spelling right?
- Brett
--
Brett Porter
brett@apache.org
http://brettporter.wordpress.com/
http://au.linkedin.com/in/brettporter
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org