You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by og...@apache.org on 2009/04/28 01:12:32 UTC
svn commit: r769199 [15/19] - in /maven/mercury/trunk:
mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/
mercury-ant-tasks/src/test/java/org/apache/maven/mercury/ant/tasks/
mercury-core/src/main/java/org/apache/maven/mercury/artifact/...
Modified: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyDeployerTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyDeployerTest.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyDeployerTest.java (original)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyDeployerTest.java Mon Apr 27 23:12:25 2009
@@ -28,55 +28,62 @@
import org.apache.maven.mercury.spi.http.server.AuthenticatingPutServer;
import org.apache.maven.mercury.transport.api.Credentials;
-public class ProxyJettyDeployerTest extends JettyDeployerTest
+public class ProxyJettyDeployerTest
+ extends JettyDeployerTest
{
-
AuthenticatingProxyServer _proxyServer;
+
String _proxyPort;
-
- public ProxyJettyDeployerTest() throws Exception
+ public ProxyJettyDeployerTest()
+ throws Exception
{
super();
}
- protected void setUp() throws Exception
- {
+
+ protected void setUp()
+ throws Exception
+ {
setUpFiles();
- //Set up a proxy server (which requires authentication)
+ // Set up a proxy server (which requires authentication)
_proxyServer = new AuthenticatingProxyServer();
_proxyServer.start();
- _proxyPort = String.valueOf(_proxyServer.getPort());
-
+ _proxyPort = String.valueOf( _proxyServer.getPort() );
+
_deployer = new DefaultDeployer();
-
- //set up a target server (which requires authentication)
+
+ // set up a target server (which requires authentication)
_putServer = new AuthenticatingPutServer();
_putServer.start();
- _port = String.valueOf(_putServer.getPort());
+ _port = String.valueOf( _putServer.getPort() );
setUpServerType();
}
-
-
- protected void setUpServerType () throws Exception
+ protected void setUpServerType()
+ throws Exception
{
- HashSet<org.apache.maven.mercury.transport.api.Server> remoteServerTypes = new HashSet<org.apache.maven.mercury.transport.api.Server>();
- remoteServerType = new org.apache.maven.mercury.transport.api.Server( "test",
- new URL(_HOST_FRAGMENT+_port),
- false,
- false,
- new Credentials(((AuthenticatingPutServer)_putServer).getUsername(), ((AuthenticatingPutServer)_putServer).getPassword()),
- new URL(_HOST_FRAGMENT+_proxyPort),
- new Credentials(_proxyServer.getUsername(), _proxyServer.getPassword()));
- factories = new HashSet<StreamVerifierFactory>();
- remoteServerTypes.add(remoteServerType);
- _deployer.setServers(remoteServerTypes);
+ HashSet<org.apache.maven.mercury.transport.api.Server> remoteServerTypes =
+ new HashSet<org.apache.maven.mercury.transport.api.Server>();
+ remoteServerType =
+ new org.apache.maven.mercury.transport.api.Server(
+ "test",
+ new URL( _HOST_FRAGMENT + _port ),
+ false,
+ false,
+ new Credentials(
+ ( (AuthenticatingPutServer) _putServer ).getUsername(),
+ ( (AuthenticatingPutServer) _putServer ).getPassword() ),
+ new URL( _HOST_FRAGMENT + _proxyPort ),
+ new Credentials( _proxyServer.getUsername(),
+ _proxyServer.getPassword() ) );
+ factories = new HashSet<StreamVerifierFactory>();
+ remoteServerTypes.add( remoteServerType );
+ _deployer.setServers( remoteServerTypes );
}
-
-
- protected void tearDown() throws Exception
+ protected void tearDown()
+ throws Exception
{
_proxyServer.stop();
super.tearDown();
Modified: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyRetrieverTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyRetrieverTest.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyRetrieverTest.java (original)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyRetrieverTest.java Mon Apr 27 23:12:25 2009
@@ -28,41 +28,43 @@
import org.apache.maven.mercury.transport.api.Credentials;
import org.apache.maven.mercury.transport.api.Server;
-public class ProxyJettyRetrieverTest extends JettyRetrieverTest
+public class ProxyJettyRetrieverTest
+ extends JettyRetrieverTest
{
AuthenticatingProxyServer _proxyServer;
+
String _proxyPort;
-
- public void setUp ()
- throws Exception
- {
- //Set up a proxy server (which requires authentication)
+
+ public void setUp()
+ throws Exception
+ {
+ // Set up a proxy server (which requires authentication)
_proxyServer = new AuthenticatingProxyServer();
_proxyServer.start();
- _proxyPort = String.valueOf(_proxyServer.getPort());
-
- //Set up the real target server (which requires authentication)
+ _proxyPort = String.valueOf( _proxyServer.getPort() );
+
+ // Set up the real target server (which requires authentication)
server = new AuthenticatingTestServer();
server.start();
- _port=String.valueOf(server.getPort());
+ _port = String.valueOf( server.getPort() );
HashSet<Server> remoteServerTypes = new HashSet<Server>();
- remoteServerType = new Server( "test", new URL(__HOST_FRAGMENT+_port),
- false,
- false,
- new Credentials(((AuthenticatingTestServer)server).getUsername(), ((AuthenticatingTestServer)server).getPassword()),
- new URL(__HOST_FRAGMENT+_proxyPort),
- new Credentials(_proxyServer.getUsername(), _proxyServer.getPassword()));
+ remoteServerType =
+ new Server( "test", new URL( __HOST_FRAGMENT + _port ), false, false,
+ new Credentials( ( (AuthenticatingTestServer) server ).getUsername(),
+ ( (AuthenticatingTestServer) server ).getPassword() ),
+ new URL( __HOST_FRAGMENT + _proxyPort ), new Credentials( _proxyServer.getUsername(),
+ _proxyServer.getPassword() ) );
factories = new HashSet<StreamVerifierFactory>();
- remoteServerTypes.add(remoteServerType);
+ remoteServerTypes.add( remoteServerType );
retriever = new DefaultRetriever();
- retriever.setServers(remoteServerTypes);
+ retriever.setServers( remoteServerTypes );
}
-
- protected void tearDown() throws Exception
+ protected void tearDown()
+ throws Exception
{
_proxyServer.stop();
super.tearDown();
Modified: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/SecureJettyDeployerTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/SecureJettyDeployerTest.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/SecureJettyDeployerTest.java (original)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/SecureJettyDeployerTest.java Mon Apr 27 23:12:25 2009
@@ -22,25 +22,27 @@
import org.apache.maven.mercury.spi.http.client.deploy.DefaultDeployer;
import org.apache.maven.mercury.spi.http.server.SecurePutServer;
-public class SecureJettyDeployerTest extends JettyDeployerTest
+public class SecureJettyDeployerTest
+ extends JettyDeployerTest
{
- public SecureJettyDeployerTest() throws Exception
+ public SecureJettyDeployerTest()
+ throws Exception
{
super();
}
-
- protected void setUp() throws Exception
- {
+
+ protected void setUp()
+ throws Exception
+ {
_HOST_FRAGMENT = "https://localhost:";
-
+
setUpFiles();
_deployer = new DefaultDeployer();
_putServer = new SecurePutServer();
_putServer.start();
- _port = String.valueOf(_putServer.getPort());
+ _port = String.valueOf( _putServer.getPort() );
setUpServerType();
- //super.setUp();
+ // super.setUp();
}
-
}
Modified: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingProxyServer.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingProxyServer.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingProxyServer.java (original)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingProxyServer.java Mon Apr 27 23:12:25 2009
@@ -35,48 +35,50 @@
import org.mortbay.servlet.ProxyServlet;
import org.mortbay.util.StringUtil;
-public class AuthenticatingProxyServer extends Server
+public class AuthenticatingProxyServer
+ extends Server
{
public static final String __username = "foo";
+
public static final String __password = "banana";
+
public static final String __role = "fooproxy";
- protected Context _context;
-
-
-
-
- public static class AuthProxyServlet extends ProxyServlet
+
+ protected Context _context;
+
+ public static class AuthProxyServlet
+ extends ProxyServlet
{
- public void service(ServletRequest request, ServletResponse response)
- throws ServletException, IOException
+ public void service( ServletRequest request, ServletResponse response )
+ throws ServletException, IOException
{
- String proxyAuth = ((HttpServletRequest)request).getHeader("Proxy-Authorization");
- if (proxyAuth!=null)
+ String proxyAuth = ( (HttpServletRequest) request ).getHeader( "Proxy-Authorization" );
+ if ( proxyAuth != null )
{
- String authType = proxyAuth.substring(0,6);
-
- if (authType.equalsIgnoreCase("basic "))
- proxyAuth = proxyAuth.substring(6);
-
- proxyAuth = B64Code.decode(proxyAuth,StringUtil.__ISO_8859_1);
- int sep = proxyAuth.indexOf(":");
- String username = proxyAuth.substring(0,sep);
- String password = proxyAuth.substring(sep+1);
-
- if (__username.equalsIgnoreCase(username) && __password.equalsIgnoreCase(password))
- super.service(request, response);
+ String authType = proxyAuth.substring( 0, 6 );
+
+ if ( authType.equalsIgnoreCase( "basic " ) )
+ proxyAuth = proxyAuth.substring( 6 );
+
+ proxyAuth = B64Code.decode( proxyAuth, StringUtil.__ISO_8859_1 );
+ int sep = proxyAuth.indexOf( ":" );
+ String username = proxyAuth.substring( 0, sep );
+ String password = proxyAuth.substring( sep + 1 );
+
+ if ( __username.equalsIgnoreCase( username ) && __password.equalsIgnoreCase( password ) )
+ super.service( request, response );
else
- ((HttpServletResponse)response).setStatus(HttpServletResponse.SC_FORBIDDEN);
+ ( (HttpServletResponse) response ).setStatus( HttpServletResponse.SC_FORBIDDEN );
}
else
{
- ((HttpServletResponse)response).setStatus(HttpServletResponse.SC_FORBIDDEN);
+ ( (HttpServletResponse) response ).setStatus( HttpServletResponse.SC_FORBIDDEN );
}
- }
+ }
}
-
+
public AuthenticatingProxyServer()
- throws Exception
+ throws Exception
{
super( 0 );
@@ -87,23 +89,23 @@
handlers.addHandler( new DefaultHandler() );
_context.addServlet( AuthProxyServlet.class, "/" );
-
+
HashUserRealm realm = new HashUserRealm();
- realm.put (__username, __password);
- realm.addUserToRole(__username, __role);
- realm.setName("proxyrealm");
+ realm.put( __username, __password );
+ realm.addUserToRole( __username, __role );
+ realm.setName( "proxyrealm" );
}
-
+
public int getPort()
{
return getConnectors()[0].getLocalPort();
}
-
+
public String getUsername()
{
return __username;
}
-
+
public String getPassword()
{
return __password;
Modified: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingPutServer.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingPutServer.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingPutServer.java (original)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingPutServer.java Mon Apr 27 23:12:25 2009
@@ -24,49 +24,52 @@
import org.mortbay.jetty.security.HashUserRealm;
import org.mortbay.jetty.security.SecurityHandler;
-public class AuthenticatingPutServer extends SimplePutServer
+public class AuthenticatingPutServer
+ extends SimplePutServer
{
private String _username = "foo";
+
private String _password = "bar";
+
private String _role = "foomeister";
-
+
public AuthenticatingPutServer()
- throws Exception
+ throws Exception
{
super();
-
+
HashUserRealm realm = new HashUserRealm();
- realm.put (_username, _password);
- realm.addUserToRole(_username, _role);
- realm.setName("foorealm");
-
+ realm.put( _username, _password );
+ realm.addUserToRole( _username, _role );
+ realm.setName( "foorealm" );
+
SecurityHandler securityHandler = new SecurityHandler();
- securityHandler.setAuthenticator(new BasicAuthenticator());
- securityHandler.setUserRealm(realm);
+ securityHandler.setAuthenticator( new BasicAuthenticator() );
+ securityHandler.setUserRealm( realm );
Constraint constraint = new Constraint();
- constraint.setAuthenticate(true);
- constraint.setRoles(new String[]{_role});
+ constraint.setAuthenticate( true );
+ constraint.setRoles( new String[] { _role } );
ConstraintMapping cm = new ConstraintMapping();
- cm.setConstraint(constraint);
- cm.setPathSpec("/*");
- securityHandler.setConstraintMappings(new ConstraintMapping[]{cm});
- context.addHandler(securityHandler);
+ cm.setConstraint( constraint );
+ cm.setPathSpec( "/*" );
+ securityHandler.setConstraintMappings( new ConstraintMapping[] { cm } );
+ context.addHandler( securityHandler );
}
-
- public static void main(String[] args)
- throws Exception
+
+ public static void main( String[] args )
+ throws Exception
{
AuthenticatingPutServer server = new AuthenticatingPutServer();
server.start();
server.join();
}
-
+
public String getUsername()
{
return _username;
}
-
- public String getPassword ()
+
+ public String getPassword()
{
return _password;
}
Modified: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingTestServer.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingTestServer.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingTestServer.java (original)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingTestServer.java Mon Apr 27 23:12:25 2009
@@ -27,58 +27,60 @@
import org.mortbay.jetty.security.SecurityHandler;
public class AuthenticatingTestServer
-extends SimpleTestServer
+ extends SimpleTestServer
{
private static final String __username = "foo";
+
private static final String __password = "bar";
+
private static final String __role = "foomeister";
-
+
public void secure()
{
- HashUserRealm realm = new HashUserRealm();
- realm.put (__username, __password);
- realm.addUserToRole(__username, __role);
- realm.setName("foorealm");
-
- SecurityHandler securityHandler = new SecurityHandler();
- securityHandler.setAuthenticator(new BasicAuthenticator());
- securityHandler.setUserRealm(realm);
- Constraint constraint = new Constraint();
- constraint.setAuthenticate(true);
- constraint.setRoles(new String[]{__role});
- ConstraintMapping cm = new ConstraintMapping();
- cm.setConstraint(constraint);
- cm.setPathSpec("/*");
- securityHandler.setConstraintMappings(new ConstraintMapping[]{cm});
- context.addHandler(securityHandler);
+ HashUserRealm realm = new HashUserRealm();
+ realm.put( __username, __password );
+ realm.addUserToRole( __username, __role );
+ realm.setName( "foorealm" );
+
+ SecurityHandler securityHandler = new SecurityHandler();
+ securityHandler.setAuthenticator( new BasicAuthenticator() );
+ securityHandler.setUserRealm( realm );
+ Constraint constraint = new Constraint();
+ constraint.setAuthenticate( true );
+ constraint.setRoles( new String[] { __role } );
+ ConstraintMapping cm = new ConstraintMapping();
+ cm.setConstraint( constraint );
+ cm.setPathSpec( "/*" );
+ securityHandler.setConstraintMappings( new ConstraintMapping[] { cm } );
+ context.addHandler( securityHandler );
}
-
+
public AuthenticatingTestServer( int port, File localBase, String remotePathFragment, boolean secured )
- throws Exception
+ throws Exception
{
- super( port, localBase, remotePathFragment );
- if( secured )
- secure();
+ super( port, localBase, remotePathFragment );
+ if ( secured )
+ secure();
}
-
+
public AuthenticatingTestServer( int port, File localBase, String remotePathFragment )
- throws Exception
+ throws Exception
{
- this( port, localBase, remotePathFragment, true );
+ this( port, localBase, remotePathFragment, true );
}
public AuthenticatingTestServer()
- throws Exception
+ throws Exception
{
- super();
- secure();
+ super();
+ secure();
}
public String getUsername()
{
return __username;
}
-
+
public String getPassword()
{
return __password;
Modified: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/BatchFilter.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/BatchFilter.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/BatchFilter.java (original)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/BatchFilter.java Mon Apr 27 23:12:25 2009
@@ -46,41 +46,44 @@
/**
* BatchFilter
* <p/>
- * Base class for handling atomic uploads of batches of files.
- * Subclasses should implement their own means of making the
- * uploads atomic. The methods putFile, commitFiles, discardFiles
- * can be overridden/implemented in order to facilitate this.
- * For example, the DefaultBatchFilter subclass copies all files
- * to a staging area before moving them to their final locations
- * upon receipt of a Jetty-Batch-Commit message.
+ * Base class for handling atomic uploads of batches of files. Subclasses should implement their own means of making the
+ * uploads atomic. The methods putFile, commitFiles, discardFiles can be overridden/implemented in order to facilitate
+ * this. For example, the DefaultBatchFilter subclass copies all files to a staging area before moving them to their
+ * final locations upon receipt of a Jetty-Batch-Commit message.
* <p/>
* TODO consider having a scavenger thread to remove failed or incomplete uploads?
- *
+ *
* @see org.sonatype.mercury.server.jetty.DefaultBatchFilter
*/
-public abstract class BatchFilter extends PutFilter
+public abstract class BatchFilter
+ extends PutFilter
{
protected ConcurrentMap<String, Batch> _batches = new ConcurrentHashMap<String, Batch>();
+
protected String _batchIdHeader = "Jetty-Batch-Id";
+
protected String _batchSupportedHeader = "Jetty-Batch-Supported";
+
protected String _batchCommitHeader = "Jetty-Batch-Commit";
+
protected String _batchDiscardHeader = "Jetty-Batch-Discard";
/**
* Batch
* <p/>
- * Retains the status of a mercury. If a mercury succeeds it is removed
- * from the list. If it fails, then it is retained in the list
- * but marked as failed. If a mercury is not completed, then the
- * timestamp can be used by a timer thread to clean up.
+ * Retains the status of a mercury. If a mercury succeeds it is removed from the list. If it fails, then it is
+ * retained in the list but marked as failed. If a mercury is not completed, then the timestamp can be used by a
+ * timer thread to clean up.
*/
protected class Batch
{
protected String _batchId;
+
protected long _timestamp;
+
protected boolean _ok;
- protected List<String> _files;
+ protected List<String> _files;
public Batch( String batchId, long timestamp )
{
@@ -126,10 +129,9 @@
}
/**
- * Implement this method to finish the upload of the files by making them
- * available for download. When this method returns, all files forming part of
- * the mercury should be available.
- *
+ * Implement this method to finish the upload of the files by making them available for download. When this method
+ * returns, all files forming part of the mercury should be available.
+ *
* @param request
* @param response
* @param batchId
@@ -140,9 +142,9 @@
throws Exception;
/**
- * Implement this method to abort the upload of a mercury of files. When this method returns,
- * none of the files forming part of the upload should be available for download.
- *
+ * Implement this method to abort the upload of a mercury of files. When this method returns, none of the files
+ * forming part of the upload should be available for download.
+ *
* @param request
* @param response
* @param batchId
@@ -152,10 +154,9 @@
public abstract boolean discardFiles( HttpServletRequest request, HttpServletResponse response, Batch batch )
throws Exception;
-
/**
* Initialize the filter. Read all configurable parameters.
- *
+ *
* @see org.sonatype.servlet.PutFilter#init(javax.servlet.FilterConfig)
*/
public void init( FilterConfig config )
@@ -163,7 +164,7 @@
{
super.init( config );
- //allow name of headers to be exchanged to be configured
+ // allow name of headers to be exchanged to be configured
String s = config.getInitParameter( "batchIdHeader" );
if ( s != null )
{
@@ -186,11 +187,11 @@
}
}
-
/**
* Run the filter.
- *
- * @see org.sonatype.servlet.PutFilter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
+ *
+ * @see org.sonatype.servlet.PutFilter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse,
+ * javax.servlet.FilterChain)
*/
public void doFilter( ServletRequest req, ServletResponse res, FilterChain chain )
throws IOException, ServletException
@@ -198,36 +199,31 @@
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
- //if GET fall through to filter chain
+ // if GET fall through to filter chain
if ( request.getMethod().equals( HttpMethods.GET ) )
{
chain.doFilter( req, res );
return;
}
-
String batchId = request.getHeader( _batchIdHeader );
String commitId = request.getHeader( _batchCommitHeader );
String discardId = request.getHeader( _batchDiscardHeader );
- //System.err.println("method="+request.getMethod()+" batchid="+batchId+" commitId="+commitId+" discardId="+discardId);
+ // System.err.println("method="+request.getMethod()+" batchid="+batchId+" commitId="+commitId+" discardId="+discardId);
- //we can't do atomic batches, handle as a normal PUT
+ // we can't do atomic batches, handle as a normal PUT
if ( batchId == null && commitId == null && discardId == null )
{
super.doFilter( req, res, chain );
return;
}
- /* TODO Is it worth handling this situation? This would mean that a directory was sent as the url
- * along with a batchId. The cost is that the pathContext would be calculated twice in this case.
-
- if (pathInContext.endsWith("/"))
- {
- super.doFilter(req,res,chain);
- return;
- }
- */
+ /*
+ * TODO Is it worth handling this situation? This would mean that a directory was sent as the url along with a
+ * batchId. The cost is that the pathContext would be calculated twice in this case. if
+ * (pathInContext.endsWith("/")) { super.doFilter(req,res,chain); return; }
+ */
if ( batchId != null )
{
@@ -247,21 +243,19 @@
return;
}
- //otherwise - shouldn't get here
+ // otherwise - shouldn't get here
chain.doFilter( req, res );
}
/**
* Handle a PUT request.
* <p/>
- * The batchId is saved to a list of currently active batchIds so that
- * all files forming part of the mercury can be committed or discarded as a
- * whole later on.
+ * The batchId is saved to a list of currently active batchIds so that all files forming part of the mercury can be
+ * committed or discarded as a whole later on.
* <p/>
- * If a file already exists, then status 200 is returned; if the file
- * did not previously exist, then status 201 is returned, otherwise
- * a 403 is returned.
- *
+ * If a file already exists, then status 200 is returned; if the file did not previously exist, then status 201 is
+ * returned, otherwise a 403 is returned.
+ *
* @param request
* @param response
* @param batchId
@@ -294,7 +288,8 @@
{
contextPath += "/";
}
- String commitBatchUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + contextPath;
+ String commitBatchUrl =
+ request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + contextPath;
response.setHeader( _batchSupportedHeader, commitBatchUrl );
response.setStatus( exists ? HttpServletResponse.SC_OK : HttpServletResponse.SC_CREATED );
response.flushBuffer();
@@ -308,7 +303,7 @@
/**
* Client side wants us to discard all files in mercury.
- *
+ *
* @param request
* @param response
* @param batchId
@@ -336,10 +331,9 @@
}
}
-
/**
* Client side wants us to move files into final position.
- *
+ *
* @param request
* @param response
* @param batchId
@@ -371,9 +365,8 @@
/**
* Default behaviour is to put the file directly to it's final location.
* <p/>
- * Subclasses can choose to override this method and put the file
- * into a staging area first.
- *
+ * Subclasses can choose to override this method and put the file into a staging area first.
+ *
* @param request
* @param response
* @param pathInContext
@@ -381,10 +374,7 @@
* @throws Exception
* @see org.sonatype.mercury.server.jetty.DefaultBatchFilter
*/
- public void putFile( HttpServletRequest request,
- HttpServletResponse response,
- String pathInContext,
- String batchId )
+ public void putFile( HttpServletRequest request, HttpServletResponse response, String pathInContext, String batchId )
throws Exception
{
String finalResource = URIUtil.addPaths( _baseURI, pathInContext );
@@ -408,7 +398,7 @@
/**
* Remember a mercury, or update the count of files in the mercury.
- *
+ *
* @param batchId
*/
protected Batch addBatch( String batchId, String file )
@@ -424,12 +414,11 @@
return status;
}
-
/**
* Update the status of the mercury.
- *
+ *
* @param batchId
- * @param ok if true, the mercury job is removed from the list; otherwise it is marked as failed
+ * @param ok if true, the mercury job is removed from the list; otherwise it is marked as failed
*/
protected void updateBatch( String batchId, boolean ok )
{
@@ -446,7 +435,7 @@
}
else
{
- status.failed(); //mark as failed
+ status.failed(); // mark as failed
}
}
}
Modified: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/BatchFilterTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/BatchFilterTest.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/BatchFilterTest.java (original)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/BatchFilterTest.java Mon Apr 27 23:12:25 2009
@@ -32,207 +32,211 @@
import org.mortbay.jetty.testing.ServletTester;
import org.mortbay.util.IO;
-public class BatchFilterTest extends TestCase
+public class BatchFilterTest
+ extends TestCase
{
File _baseDir;
+
File _stagingDir;
-
+
ServletTester tester;
-
- public void setUp () throws Exception
+ public void setUp()
+ throws Exception
{
- _baseDir = File.createTempFile("testBatchFilter",null);
+ _baseDir = File.createTempFile( "testBatchFilter", null );
_baseDir.delete();
_baseDir.mkdir();
_baseDir.deleteOnExit();
- assertTrue(_baseDir.isDirectory());
-
- _stagingDir = new File(System.getProperty("java.io.tmpdir"));
+ assertTrue( _baseDir.isDirectory() );
+
+ _stagingDir = new File( System.getProperty( "java.io.tmpdir" ) );
super.setUp();
- tester=new ServletTester();
- tester.setContextPath("/context");
- tester.setResourceBase(_baseDir.getCanonicalPath());
- tester.addServlet( DefaultServlet.class, "/");
- FilterHolder holder = tester.addFilter( StagingBatchFilter.class,"/*",0);
- holder.setInitParameter("stagingDirURI", _stagingDir.toURI().toString());
+ tester = new ServletTester();
+ tester.setContextPath( "/context" );
+ tester.setResourceBase( _baseDir.getCanonicalPath() );
+ tester.addServlet( DefaultServlet.class, "/" );
+ FilterHolder holder = tester.addFilter( StagingBatchFilter.class, "/*", 0 );
+ holder.setInitParameter( "stagingDirURI", _stagingDir.toURI().toString() );
tester.start();
- System.err.println("Set up tester, basedir="+tester.getResourceBase()+" exists?"+_baseDir.exists());
- System.err.println("Set up tester, stagingdir="+_stagingDir.toURI().toString());
+ System.err.println( "Set up tester, basedir=" + tester.getResourceBase() + " exists?" + _baseDir.exists() );
+ System.err.println( "Set up tester, stagingdir=" + _stagingDir.toURI().toString() );
}
-
- protected void tearDown() throws Exception
+
+ protected void tearDown()
+ throws Exception
{
super.tearDown();
tester.stop();
- destroy(_baseDir);
+ destroy( _baseDir );
}
-
- public void destroy (File f)
+
+ public void destroy( File f )
{
- if (f == null)
+ if ( f == null )
return;
- if (f.isDirectory())
+ if ( f.isDirectory() )
{
File[] files = f.listFiles();
- for (int i=0;files!=null && i<files.length; i++)
+ for ( int i = 0; files != null && i < files.length; i++ )
{
- destroy (files[i]);
- }
+ destroy( files[i] );
+ }
}
- f.delete();
+ f.delete();
f.deleteOnExit();
}
- public void testHandlePutWithoutBatching() throws Exception
+ public void testHandlePutWithoutBatching()
+ throws Exception
{
// generated and parsed test
HttpTester request = new HttpTester();
HttpTester response = new HttpTester();
-
- request.setMethod("PUT");
- request.setVersion("HTTP/1.1");
- request.setHeader("Host","tester");
- request.setURI("/context/file.txt");
- request.setHeader("Content-Type","text/plain");
- String data0="Now is the time for all good men to come to the aid of the party";
- request.setContent(data0);
- response.parse(tester.getResponses(request.generate()));
- assertTrue(response.getMethod()==null);
- assertEquals(HttpServletResponse.SC_CREATED,response.getStatus());
-
- File file=new File(_baseDir,"file.txt");
- assertTrue(file.exists());
- assertEquals(data0,IO.toString(new FileInputStream(file)));
+
+ request.setMethod( "PUT" );
+ request.setVersion( "HTTP/1.1" );
+ request.setHeader( "Host", "tester" );
+ request.setURI( "/context/file.txt" );
+ request.setHeader( "Content-Type", "text/plain" );
+ String data0 = "Now is the time for all good men to come to the aid of the party";
+ request.setContent( data0 );
+ response.parse( tester.getResponses( request.generate() ) );
+ assertTrue( response.getMethod() == null );
+ assertEquals( HttpServletResponse.SC_CREATED, response.getStatus() );
+
+ File file = new File( _baseDir, "file.txt" );
+ assertTrue( file.exists() );
+ assertEquals( data0, IO.toString( new FileInputStream( file ) ) );
}
-
- public void testBatchingCommit() throws Exception
+
+ public void testBatchingCommit()
+ throws Exception
{
// generated and parsed test
HttpTester request = new HttpTester();
HttpTester response = new HttpTester();
-
- request.setMethod("PUT");
- request.setVersion("HTTP/1.1");
- request.setHeader("Host","tester");
- request.setURI("/context/file1.txt");
- request.setHeader("Content-Type","text/plain");
- request.setHeader("Jetty-Batch-Id", "999999");
- String data1="How Now BROWN COW!!!!";
- request.setContent(data1);
- response.parse(tester.getResponses(request.generate()));
- assertTrue(response.getMethod()==null);
- assertEquals(HttpServletResponse.SC_CREATED,response.getStatus());
-
- File batchDir = new File (_stagingDir, "999999");
- File stagedFile = new File (batchDir, "file1.txt");
- System.err.println("Checking existence of "+stagedFile.getCanonicalPath());
- assertTrue(stagedFile.exists());
- FileInputStream fis = new FileInputStream(stagedFile);
- assertEquals(data1,IO.toString(fis));
+
+ request.setMethod( "PUT" );
+ request.setVersion( "HTTP/1.1" );
+ request.setHeader( "Host", "tester" );
+ request.setURI( "/context/file1.txt" );
+ request.setHeader( "Content-Type", "text/plain" );
+ request.setHeader( "Jetty-Batch-Id", "999999" );
+ String data1 = "How Now BROWN COW!!!!";
+ request.setContent( data1 );
+ response.parse( tester.getResponses( request.generate() ) );
+ assertTrue( response.getMethod() == null );
+ assertEquals( HttpServletResponse.SC_CREATED, response.getStatus() );
+
+ File batchDir = new File( _stagingDir, "999999" );
+ File stagedFile = new File( batchDir, "file1.txt" );
+ System.err.println( "Checking existence of " + stagedFile.getCanonicalPath() );
+ assertTrue( stagedFile.exists() );
+ FileInputStream fis = new FileInputStream( stagedFile );
+ assertEquals( data1, IO.toString( fis ) );
fis.close();
- request.setMethod("PUT");
- request.setURI("/context/file2.txt");
- request.setHeader("Content-Type","text/plain");
- String data2="Blah blah blah Blah blah";
- request.setHeader("Jetty-Batch-Id", "999999");
- request.setContent(data2);
- response.parse(tester.getResponses(request.generate()));
- assertEquals(HttpServletResponse.SC_CREATED,response.getStatus());
-
- batchDir = new File (_stagingDir, "999999");
- stagedFile = new File (batchDir, "file2.txt");
- assertTrue(stagedFile.exists());
- fis = new FileInputStream(stagedFile);
- assertEquals(data2,IO.toString(fis));
+ request.setMethod( "PUT" );
+ request.setURI( "/context/file2.txt" );
+ request.setHeader( "Content-Type", "text/plain" );
+ String data2 = "Blah blah blah Blah blah";
+ request.setHeader( "Jetty-Batch-Id", "999999" );
+ request.setContent( data2 );
+ response.parse( tester.getResponses( request.generate() ) );
+ assertEquals( HttpServletResponse.SC_CREATED, response.getStatus() );
+
+ batchDir = new File( _stagingDir, "999999" );
+ stagedFile = new File( batchDir, "file2.txt" );
+ assertTrue( stagedFile.exists() );
+ fis = new FileInputStream( stagedFile );
+ assertEquals( data2, IO.toString( fis ) );
fis.close();
// test POST commit
request = new HttpTester();
- request.setMethod("POST");
- request.setVersion("HTTP/1.1");
- request.setHeader("Content-Type","text/plain");
- request.setHeader("Host","tester");
- request.setHeader("Jetty-Batch-Commit", "999999");
- request.setURI("/context/");
- response.parse(tester.getResponses(request.generate()));
- assertTrue(response.getMethod()==null);
- assertEquals(HttpServletResponse.SC_OK,response.getStatus());
-
- File finalFile1 = new File(_baseDir, "file1.txt");
- assertTrue(finalFile1.exists());
- File finalFile2 = new File(_baseDir, "file2.txt");
- assertTrue(finalFile2.exists());
- }
-
-
- public void testBatchingDiscard ()
- throws Exception
+ request.setMethod( "POST" );
+ request.setVersion( "HTTP/1.1" );
+ request.setHeader( "Content-Type", "text/plain" );
+ request.setHeader( "Host", "tester" );
+ request.setHeader( "Jetty-Batch-Commit", "999999" );
+ request.setURI( "/context/" );
+ response.parse( tester.getResponses( request.generate() ) );
+ assertTrue( response.getMethod() == null );
+ assertEquals( HttpServletResponse.SC_OK, response.getStatus() );
+
+ File finalFile1 = new File( _baseDir, "file1.txt" );
+ assertTrue( finalFile1.exists() );
+ File finalFile2 = new File( _baseDir, "file2.txt" );
+ assertTrue( finalFile2.exists() );
+ }
+
+ public void testBatchingDiscard()
+ throws Exception
{
// generated and parsed test
HttpTester request = new HttpTester();
HttpTester response = new HttpTester();
-
- request.setMethod("PUT");
- request.setVersion("HTTP/1.1");
- request.setHeader("Host","tester");
- request.setURI("/context/org/foo/file1.txt");
- request.setHeader("Content-Type","text/plain");
- request.setHeader("Jetty-Batch-Id", "999999");
- String data1="How Now BROWN COW!!!!";
- request.setContent(data1);
- response.parse(tester.getResponses(request.generate()));
- assertTrue(response.getMethod()==null);
- assertEquals(HttpServletResponse.SC_CREATED,response.getStatus());
-
- File batchDir = new File (_stagingDir, "999999");
- File stagedFile = new File(batchDir, "org");
- stagedFile = new File(stagedFile, "foo");
- stagedFile = new File (stagedFile, "file1.txt");
- System.err.println("Checking existence of "+stagedFile.getCanonicalPath());
- FileInputStream fis = new FileInputStream(stagedFile);
- assertTrue(stagedFile.exists());
- assertEquals(data1,IO.toString(fis));
+
+ request.setMethod( "PUT" );
+ request.setVersion( "HTTP/1.1" );
+ request.setHeader( "Host", "tester" );
+ request.setURI( "/context/org/foo/file1.txt" );
+ request.setHeader( "Content-Type", "text/plain" );
+ request.setHeader( "Jetty-Batch-Id", "999999" );
+ String data1 = "How Now BROWN COW!!!!";
+ request.setContent( data1 );
+ response.parse( tester.getResponses( request.generate() ) );
+ assertTrue( response.getMethod() == null );
+ assertEquals( HttpServletResponse.SC_CREATED, response.getStatus() );
+
+ File batchDir = new File( _stagingDir, "999999" );
+ File stagedFile = new File( batchDir, "org" );
+ stagedFile = new File( stagedFile, "foo" );
+ stagedFile = new File( stagedFile, "file1.txt" );
+ System.err.println( "Checking existence of " + stagedFile.getCanonicalPath() );
+ FileInputStream fis = new FileInputStream( stagedFile );
+ assertTrue( stagedFile.exists() );
+ assertEquals( data1, IO.toString( fis ) );
fis.close();
-
- request.setMethod("PUT");
- request.setVersion("HTTP/1.1");
- request.setHeader("Host","tester");
- request.setURI("/context/file2.txt");
- request.setHeader("Content-Type","text/plain");
- String data2="Blah blah blah Blah blah";
- request.setHeader("Jetty-Batch-Id", "999999");
- request.setContent(data2);
- response.parse(tester.getResponses(request.generate()));
- assertEquals(HttpServletResponse.SC_CREATED,response.getStatus());
-
- batchDir = new File (_stagingDir, "999999");
- stagedFile = new File (batchDir, "file2.txt");
- assertTrue(stagedFile.exists());
- fis = new FileInputStream(stagedFile);
- assertEquals(data2,IO.toString(fis));
+
+ request.setMethod( "PUT" );
+ request.setVersion( "HTTP/1.1" );
+ request.setHeader( "Host", "tester" );
+ request.setURI( "/context/file2.txt" );
+ request.setHeader( "Content-Type", "text/plain" );
+ String data2 = "Blah blah blah Blah blah";
+ request.setHeader( "Jetty-Batch-Id", "999999" );
+ request.setContent( data2 );
+ response.parse( tester.getResponses( request.generate() ) );
+ assertEquals( HttpServletResponse.SC_CREATED, response.getStatus() );
+
+ batchDir = new File( _stagingDir, "999999" );
+ stagedFile = new File( batchDir, "file2.txt" );
+ assertTrue( stagedFile.exists() );
+ fis = new FileInputStream( stagedFile );
+ assertEquals( data2, IO.toString( fis ) );
fis.close();
-
+
// test POST discard
request = new HttpTester();
- request.setMethod("POST");
- request.setVersion("HTTP/1.1");
- request.setHeader("Content-Type","text/plain");
- request.setHeader("Host","tester");
- request.setHeader("Jetty-Batch-Discard", "999999");
- request.setURI("/context/");
- response.parse(tester.getResponses(request.generate()));
- assertTrue(response.getMethod()==null);
- assertEquals(HttpServletResponse.SC_OK,response.getStatus());
-
- File finalFile1 = new File(_baseDir, "org");
- finalFile1 = new File(finalFile1, "foo");
- finalFile1 = new File(finalFile1, "file1.txt");
- assertFalse(finalFile1.exists());
- File finalFile2 = new File(_baseDir, "file2.txt");
- assertFalse(finalFile2.exists());
+ request.setMethod( "POST" );
+ request.setVersion( "HTTP/1.1" );
+ request.setHeader( "Content-Type", "text/plain" );
+ request.setHeader( "Host", "tester" );
+ request.setHeader( "Jetty-Batch-Discard", "999999" );
+ request.setURI( "/context/" );
+ response.parse( tester.getResponses( request.generate() ) );
+ assertTrue( response.getMethod() == null );
+ assertEquals( HttpServletResponse.SC_OK, response.getStatus() );
+
+ File finalFile1 = new File( _baseDir, "org" );
+ finalFile1 = new File( finalFile1, "foo" );
+ finalFile1 = new File( finalFile1, "file1.txt" );
+ assertFalse( finalFile1.exists() );
+ File finalFile2 = new File( _baseDir, "file2.txt" );
+ assertFalse( finalFile2.exists() );
}
-
+
}
Modified: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/HttpTestServer.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/HttpTestServer.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/HttpTestServer.java (original)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/HttpTestServer.java Mon Apr 27 23:12:25 2009
@@ -32,19 +32,19 @@
super( 0 );
System.out.println( base );
-
+
if ( !base.exists() )
{
throw new IllegalArgumentException( "Specified base directory does not exist: " + base.getCanonicalPath() );
}
-
+
HandlerCollection handlers = new HandlerCollection();
setHandler( handlers );
Context context = new Context( handlers, remotePathFragment );
handlers.addHandler( new DefaultHandler() );
- context.addServlet( DefaultServlet.class, "/" );
+ context.addServlet( DefaultServlet.class, "/" );
context.setResourceBase( base.getCanonicalPath() );
}
Modified: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/SecurePutServer.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/SecurePutServer.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/SecurePutServer.java (original)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/SecurePutServer.java Mon Apr 27 23:12:25 2009
@@ -30,55 +30,59 @@
import org.mortbay.jetty.servlet.FilterHolder;
import org.mortbay.servlet.PutFilter;
-public class SecurePutServer extends SimplePutServer
+public class SecurePutServer
+ extends SimplePutServer
{
private File _base;
-
- public SecurePutServer() throws Exception
- {
+
+ public SecurePutServer()
+ throws Exception
+ {
SslSocketConnector connector = new SslSocketConnector();
- String keystore = System.getProperty("user.dir") + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator
- + "secureServer" + File.separator + "keystore";
+ String keystore =
+ System.getProperty( "user.dir" ) + File.separator + "src" + File.separator + "test" + File.separator
+ + "resources" + File.separator + "secureServer" + File.separator + "keystore";
- connector.setPort(0);
- connector.setKeystore(keystore);
- connector.setPassword("storepwd");
- connector.setKeyPassword("keypwd");
+ connector.setPort( 0 );
+ connector.setKeystore( keystore );
+ connector.setPassword( "storepwd" );
+ connector.setKeyPassword( "keypwd" );
+
+ setConnectors( new Connector[] { connector } );
- setConnectors(new Connector[] { connector });
-
HandlerCollection handlers = new HandlerCollection();
- setHandler(handlers);
-
- Context context = new Context(handlers,"/maven2/repo");
- handlers.addHandler(new DefaultHandler());
+ setHandler( handlers );
+
+ Context context = new Context( handlers, "/maven2/repo" );
+ handlers.addHandler( new DefaultHandler() );
- _base = File.createTempFile("securePutServer",null);
+ _base = File.createTempFile( "securePutServer", null );
_base.delete();
_base.mkdir();
_base.deleteOnExit();
- FilterHolder holder = context.addFilter(PutFilter.class, "/*", 0);
- holder.setInitParameter("delAllowed","true");
- context.addServlet(DefaultServlet.class,"/");
- context.setResourceBase(_base.getCanonicalPath());
+ FilterHolder holder = context.addFilter( PutFilter.class, "/*", 0 );
+ holder.setInitParameter( "delAllowed", "true" );
+ context.addServlet( DefaultServlet.class, "/" );
+ context.setResourceBase( _base.getCanonicalPath() );
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
* @see org.apache.maven.mercury.spi.http.server.PutServer#getPutDir()
*/
- public File getPutDir ()
+ public File getPutDir()
{
return _base;
}
-
- public void destroy ()
+
+ public void destroy()
{
super.destroy();
- destroy(_base);
+ destroy( _base );
}
-
- public static void main(String[] args)
- throws Exception
+
+ public static void main( String[] args )
+ throws Exception
{
SecurePutServer server = new SecurePutServer();
server.start();
Modified: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/SimplePutServer.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/SimplePutServer.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/SimplePutServer.java (original)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/SimplePutServer.java Mon Apr 27 23:12:25 2009
@@ -29,86 +29,87 @@
import org.mortbay.jetty.servlet.FilterHolder;
import org.mortbay.servlet.PutFilter;
-public class SimplePutServer extends Server
+public class SimplePutServer
+ extends Server
{
protected File _base;
+
protected Context context;
-
-
+
public SimplePutServer()
- throws Exception
+ throws Exception
{
- this("/maven2/repo", null );
+ this( "/maven2/repo", null );
}
-
+
/**
* @param string
* @param targetDirectory
*/
public SimplePutServer( String contextPath, File targetDirectory )
- throws Exception
+ throws Exception
{
- super(0);
+ super( 0 );
+
+ HandlerCollection handlers = new HandlerCollection();
+ setHandler( handlers );
+
+ context = new Context( handlers, contextPath );
+ handlers.addHandler( new DefaultHandler() );
+
+ if ( targetDirectory == null )
+ {
+ _base = File.createTempFile( "simplePutServer", null );
+ _base.delete();
+ _base.mkdir();
+ _base.deleteOnExit();
+ }
+ else
+ {
+ _base = targetDirectory;
+ }
- HandlerCollection handlers = new HandlerCollection();
- setHandler(handlers);
+ if ( _base == null || !_base.exists() || !_base.isDirectory() )
+ throw new Exception( "File not appropriate for base directory: " + _base );
- context = new Context( handlers, contextPath );
- handlers.addHandler(new DefaultHandler());
-
- if( targetDirectory == null )
- {
- _base = File.createTempFile("simplePutServer",null);
- _base.delete();
- _base.mkdir();
- _base.deleteOnExit();
- }
- else
- {
- _base = targetDirectory;
- }
-
- if( _base == null || !_base.exists() || !_base.isDirectory() )
- throw new Exception("File not appropriate for base directory: "+_base);
-
- FilterHolder holder = context.addFilter(PutFilter.class, "/*", 0);
- holder.setInitParameter("delAllowed","true");
- context.addServlet(DefaultServlet.class,"/");
- context.setResourceBase(_base.getCanonicalPath());
+ FilterHolder holder = context.addFilter( PutFilter.class, "/*", 0 );
+ holder.setInitParameter( "delAllowed", "true" );
+ context.addServlet( DefaultServlet.class, "/" );
+ context.setResourceBase( _base.getCanonicalPath() );
}
- public void destroy ()
+ public void destroy()
{
super.destroy();
- destroy(_base);
+ destroy( _base );
}
-
- public void destroy (File f)
+
+ public void destroy( File f )
{
- if (f == null)
+ if ( f == null )
return;
- if (f.isDirectory())
+ if ( f.isDirectory() )
{
File[] files = f.listFiles();
- for (int i=0;files!=null && i<files.length; i++)
+ for ( int i = 0; files != null && i < files.length; i++ )
{
- destroy (files[i]);
- }
+ destroy( files[i] );
+ }
}
- f.delete();
+ f.delete();
}
-
-
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
* @see org.apache.maven.mercury.spi.http.server.PutServer#getPutDir()
*/
- public File getPutDir ()
+ public File getPutDir()
{
return _base;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* @see org.apache.maven.mercury.spi.http.server.PutServer#getPort()
*/
public int getPort()
@@ -116,8 +117,8 @@
return getConnectors()[0].getLocalPort();
}
- public static void main(String[] args)
- throws Exception
+ public static void main( String[] args )
+ throws Exception
{
SimplePutServer server = new SimplePutServer();
server.start();
Modified: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/SimpleTestServer.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/SimpleTestServer.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/SimpleTestServer.java (original)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/SimpleTestServer.java Mon Apr 27 23:12:25 2009
@@ -32,33 +32,35 @@
public class SimpleTestServer
extends Server
{
-
- final static String LOCAL_PATH = "/testRepo/";
- final static String REMOTE_SEG = "/maven2/repo";
-
- File base;
- Context context;
-
+
+ final static String LOCAL_PATH = "/testRepo/";
+
+ final static String REMOTE_SEG = "/maven2/repo";
+
+ File base;
+
+ Context context;
+
public SimpleTestServer( int port )
- throws Exception
+ throws Exception
{
- this( port, LOCAL_PATH, REMOTE_SEG );
+ this( port, LOCAL_PATH, REMOTE_SEG );
}
-
+
public SimpleTestServer()
- throws Exception
+ throws Exception
{
- this( 0, LOCAL_PATH, REMOTE_SEG );
+ this( 0, LOCAL_PATH, REMOTE_SEG );
}
public SimpleTestServer( String localPathFragment, String remotePathFragment )
- throws Exception
+ throws Exception
{
- this( 0, localPathFragment, remotePathFragment );
+ this( 0, localPathFragment, remotePathFragment );
}
-
+
public SimpleTestServer( int port, String localPathFragment, String remotePathFragment )
- throws Exception
+ throws Exception
{
super( port );
@@ -91,13 +93,13 @@
}
public SimpleTestServer( File localBase, String remotePathFragment )
- throws Exception
+ throws Exception
{
- this( 0, localBase, remotePathFragment );
+ this( 0, localBase, remotePathFragment );
}
public SimpleTestServer( int port, File localBase, String remotePathFragment )
- throws Exception
+ throws Exception
{
super( port );
@@ -115,28 +117,27 @@
{
return getConnectors()[0].getLocalPort();
}
-
+
public void destroy()
{
super.destroy();
- destroy(base);
+ destroy( base );
}
-
- public void destroy (File f)
+
+ public void destroy( File f )
{
- if (f == null)
+ if ( f == null )
return;
- if (f.isDirectory())
+ if ( f.isDirectory() )
{
File[] files = f.listFiles();
- for (int i=0;files!=null && i<files.length; i++)
+ for ( int i = 0; files != null && i < files.length; i++ )
{
- destroy (files[i]);
- }
+ destroy( files[i] );
+ }
}
- f.delete();
+ f.delete();
}
-
public static void main( String[] args )
throws Exception
Modified: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/StagingBatchFilter.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/StagingBatchFilter.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/StagingBatchFilter.java (original)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/StagingBatchFilter.java Mon Apr 27 23:12:25 2009
@@ -33,22 +33,19 @@
import org.mortbay.util.IO;
import org.mortbay.util.URIUtil;
-
/**
* DefaultBatchFilter
* <p/>
- * Handles the atomic upload (using PUT messages) of a batch of files. "Atomic" means
- * that either all file uploads succeed or none do. This transactionality can only be
- * guaranteed when using the mercury client, as a "commit/discard" message
- * is sent from the client side to indicate how to terminate the mercury operation. If
- * a commit is received, then all files that form part of the batch - indicated by a
- * batch id in the PUT headers - are moved from a staging location to the final
- * location. If a discard is received, then all files forming part of the mercury will
- * be deleted. If the client side is not the jetty batcher, then the server side
- * cannot know when the batch has ended, and therefore will immediately copy files
- * to their final locations during the PUT.
+ * Handles the atomic upload (using PUT messages) of a batch of files. "Atomic" means that either all file uploads
+ * succeed or none do. This transactionality can only be guaranteed when using the mercury client, as a "commit/discard"
+ * message is sent from the client side to indicate how to terminate the mercury operation. If a commit is received,
+ * then all files that form part of the batch - indicated by a batch id in the PUT headers - are moved from a staging
+ * location to the final location. If a discard is received, then all files forming part of the mercury will be deleted.
+ * If the client side is not the jetty batcher, then the server side cannot know when the batch has ended, and therefore
+ * will immediately copy files to their final locations during the PUT.
*/
-public class StagingBatchFilter extends BatchFilter
+public class StagingBatchFilter
+ extends BatchFilter
{
private String _stagingDirURI;
@@ -57,7 +54,7 @@
{
super.init( config );
- //allow tmp dir location to be configured
+ // allow tmp dir location to be configured
String t = config.getInitParameter( "stagingDirURI" );
if ( t != null )
{
@@ -65,7 +62,7 @@
}
else
{
- //fall back to WEB-INF/lib
+ // fall back to WEB-INF/lib
File f = new File( _context.getRealPath( "/" ) );
File w = new File( f, "WEB-INF" );
File l = new File( w, "lib" );
@@ -73,21 +70,17 @@
}
}
-
/**
- * Put the file to a staging area before doing move to final location
- * on a commit.
- *
- * @see BatchFilter#putFile(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String)
+ * Put the file to a staging area before doing move to final location on a commit.
+ *
+ * @see BatchFilter#putFile(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
+ * java.lang.String, java.lang.String)
*/
- public void putFile( HttpServletRequest request,
- HttpServletResponse response,
- String pathInContext,
- String batchId )
+ public void putFile( HttpServletRequest request, HttpServletResponse response, String pathInContext, String batchId )
throws Exception
{
- String stagedResource = URIUtil.addPaths( _stagingDirURI,
- batchId ); //put the file into staging dir under the batchid
+ String stagedResource = URIUtil.addPaths( _stagingDirURI, batchId ); // put the file into staging dir under the
+ // batchid
stagedResource = URIUtil.addPaths( stagedResource, pathInContext );
File stagedFile = null;
@@ -127,18 +120,18 @@
}
}
-
/**
* Do the move of all files in mercury to a final location
- *
- * @see BatchFilter#commitFiles(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String)
+ *
+ * @see BatchFilter#commitFiles(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
+ * java.lang.String)
*/
public boolean commitFiles( HttpServletRequest request, HttpServletResponse response, Batch batch )
throws Exception
{
if ( batch == null )
{
- return true; //nothing to do
+ return true; // nothing to do
}
boolean ok = true;
@@ -152,30 +145,30 @@
if ( !files[i].renameTo( dest ) )
{
ok = false;
- _context.log("Unable to rename file "+files[i].getAbsolutePath()+" to "+dest.getAbsolutePath());
+ _context.log( "Unable to rename file " + files[i].getAbsolutePath() + " to " + dest.getAbsolutePath() );
}
}
if ( ok )
{
ok = batchDir.delete();
- if (!ok)
- _context.log("Unable to delete batch dir "+batchDir.getAbsolutePath());
+ if ( !ok )
+ _context.log( "Unable to delete batch dir " + batchDir.getAbsolutePath() );
}
return ok;
}
-
/**
* Delete all files in the mercury from the staging area.
- *
- * @see BatchFilter#discardFiles(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String)
+ *
+ * @see BatchFilter#discardFiles(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
+ * java.lang.String)
*/
public boolean discardFiles( HttpServletRequest request, HttpServletResponse response, Batch batch )
throws Exception
{
if ( batch == null )
{
- return true; //nothing to do
+ return true; // nothing to do
}
String stagedResource = URIUtil.addPaths( _stagingDirURI, batch.getBatchId() );
@@ -188,10 +181,9 @@
return ok;
}
-
/**
* Recursively descend file hierarchy and delete all files.
- *
+ *
* @param f
* @return
*/
@@ -204,8 +196,8 @@
if ( f.isFile() )
{
boolean ok = f.delete();
- if (!ok)
- _context.log("Unable to delete file "+f.getAbsolutePath());
+ if ( !ok )
+ _context.log( "Unable to delete file " + f.getAbsolutePath() );
return ok;
}
else if ( f.isDirectory() )
@@ -223,7 +215,7 @@
if ( !f.delete() )
{
ok = false;
- _context.log("Unable to delete dir "+f.getAbsolutePath());
+ _context.log( "Unable to delete dir " + f.getAbsolutePath() );
}
return ok;