From 5cb833d14c6752642812122c249b71bd3b1fb99d Mon Sep 17 00:00:00 2001
From: Michal Srb <msrb@redhat.com>
Date: Wed, 27 Feb 2013 12:38:47 +0100
Subject: [PATCH] Port to jetty 9
---
wagon-provider-test/pom.xml | 30 ++++++-
.../apache/maven/wagon/http/HttpWagonTestCase.java | 97 +++++++++++-----------
2 files changed, 78 insertions(+), 49 deletions(-)
diff --git a/wagon-provider-test/pom.xml b/wagon-provider-test/pom.xml
index cf9a53d..439a476 100644
--- a/wagon-provider-test/pom.xml
+++ b/wagon-provider-test/pom.xml
@@ -51,8 +51,34 @@ under the License.
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>jetty</artifactId>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-client</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-security</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlet</artifactId>
+ <scope>compile</scope>
</dependency>
</dependencies>
diff --git a/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java b/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java
index acdab16..78ecbc5 100644
--- a/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java
+++ b/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java
@@ -34,20 +34,25 @@ import org.apache.maven.wagon.resource.Resource;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
-import org.mortbay.jetty.Handler;
-import org.mortbay.jetty.HttpConnection;
-import org.mortbay.jetty.Request;
-import org.mortbay.jetty.Response;
-import org.mortbay.jetty.Server;
-import org.mortbay.jetty.handler.AbstractHandler;
-import org.mortbay.jetty.handler.HandlerCollection;
-import org.mortbay.jetty.security.Constraint;
-import org.mortbay.jetty.security.ConstraintMapping;
-import org.mortbay.jetty.security.HashUserRealm;
-import org.mortbay.jetty.security.SecurityHandler;
-import org.mortbay.jetty.servlet.Context;
-import org.mortbay.jetty.servlet.DefaultServlet;
-import org.mortbay.jetty.servlet.ServletHolder;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.HttpConnection;
+import org.eclipse.jetty.server.HttpChannel;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Response;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.NetworkConnector;
+import org.eclipse.jetty.server.UserIdentity;
+import org.eclipse.jetty.server.handler.AbstractHandler;
+import org.eclipse.jetty.server.handler.HandlerCollection;
+import org.eclipse.jetty.util.security.Constraint;
+import org.eclipse.jetty.util.security.Password;
+import org.eclipse.jetty.security.ConstraintMapping;
+import org.eclipse.jetty.security.HashLoginService;
+import org.eclipse.jetty.security.SecurityHandler;
+import org.eclipse.jetty.security.ConstraintSecurityHandler;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.DefaultServlet;
+import org.eclipse.jetty.servlet.ServletHolder;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
@@ -99,7 +104,7 @@ public abstract class HttpWagonTestCase
server = new Server( 0 );
PutHandler putHandler = new PutHandler( repositoryDirectory );
- server.addHandler( putHandler );
+ server.setHandler( putHandler );
createContext( server, repositoryDirectory );
@@ -117,14 +122,14 @@ public abstract class HttpWagonTestCase
{
return 0;
}
- return server.getConnectors()[0].getLocalPort();
+ return ((NetworkConnector) (server.getConnectors()[0])).getLocalPort();
}
protected void createContext( Server server, File repositoryDirectory )
throws IOException
{
- Context root = new Context( server, "/", Context.SESSIONS );
- root.setResourceBase( repositoryDirectory.getAbsolutePath() );
+ ServletContextHandler root = new ServletContextHandler( server, "/", ServletContextHandler.SESSIONS );
+ //root.setResourceBase( repositoryDirectory.getAbsolutePath() );
ServletHolder servletHolder = new ServletHolder( new DefaultServlet() );
root.addServlet( servletHolder, "/*" );
}
@@ -164,7 +169,7 @@ public abstract class HttpWagonTestCase
server.start();
wagon.connect(
- new Repository( "id", getProtocol() + "://localhost:" + server.getConnectors()[0].getLocalPort() ) );
+ new Repository( "id", getProtocol() + "://localhost:" + ((NetworkConnector) (server.getConnectors()[0])).getLocalPort() ) );
wagon.getToStream( "resource", new ByteArrayOutputStream() );
@@ -196,7 +201,7 @@ public abstract class HttpWagonTestCase
server.start();
wagon.connect(
- new Repository( "id", getProtocol() + "://localhost:" + server.getConnectors()[0].getLocalPort() ) );
+ new Repository( "id", getProtocol() + "://localhost:" + ((NetworkConnector) (server.getConnectors()[0])).getLocalPort() ) );
wagon.getToStream( "resource", new ByteArrayOutputStream() );
@@ -265,7 +270,7 @@ public abstract class HttpWagonTestCase
protected String getRepositoryUrl( Server server )
{
- int localPort = server.getConnectors()[0].getLocalPort();
+ int localPort = ((NetworkConnector) (server.getConnectors()[0])).getLocalPort();
return getProtocol() + "://localhost:" + localPort;
}
@@ -543,7 +548,7 @@ public abstract class HttpWagonTestCase
Server server = new Server( getTestRepositoryPort() );
String localRepositoryPath = FileTestUtils.getTestOutputDir().toString();
- Context root = new Context( server, "/", Context.SESSIONS );
+ ServletContextHandler root = new ServletContextHandler( server, "/", ServletContextHandler.SESSIONS );
root.setResourceBase( localRepositoryPath );
ServletHolder servletHolder = new ServletHolder( new DefaultServlet() );
servletHolder.setInitParameter( "gzip", "true" );
@@ -679,7 +684,7 @@ public abstract class HttpWagonTestCase
protocol = "https";
}
- String redirectUrl = protocol + "://localhost:" + server.getConnectors()[0].getLocalPort();
+ String redirectUrl = protocol + "://localhost:" + ((NetworkConnector) (server.getConnectors()[0])).getLocalPort();
RedirectHandler redirectHandler =
new RedirectHandler( "Found", HttpServletResponse.SC_SEE_OTHER, redirectUrl, null );
@@ -744,7 +749,7 @@ public abstract class HttpWagonTestCase
protocol = "https";
}
- String redirectUrl = protocol + "://localhost:" + server.getConnectors()[0].getLocalPort();
+ String redirectUrl = protocol + "://localhost:" + ((NetworkConnector) (server.getConnectors()[0])).getLocalPort();
RedirectHandler redirectHandler =
new RedirectHandler( "Found", HttpServletResponse.SC_SEE_OTHER, redirectUrl, null );
@@ -811,7 +816,7 @@ public abstract class HttpWagonTestCase
protocol = "https";
}
- String redirectUrl = protocol + "://localhost:" + realServer.getConnectors()[0].getLocalPort();
+ String redirectUrl = protocol + "://localhost:" + ((NetworkConnector) (realServer.getConnectors()[0])).getLocalPort();
RedirectHandler redirectHandler =
new RedirectHandler( "Found", HttpServletResponse.SC_SEE_OTHER, redirectUrl, repositoryDirectory );
@@ -991,7 +996,7 @@ public abstract class HttpWagonTestCase
protocol = "https";
}
- String redirectUrl = protocol + "://localhost:" + realServer.getConnectors()[0].getLocalPort();
+ String redirectUrl = protocol + "://localhost:" + ((NetworkConnector) (realServer.getConnectors()[0])).getLocalPort();
RedirectHandler redirectHandler =
new RedirectHandler( "Found", HttpServletResponse.SC_SEE_OTHER, redirectUrl, repositoryDirectory );
@@ -1122,13 +1127,13 @@ public abstract class HttpWagonTestCase
this.repositoryDirectory = repositoryDirectory;
}
- public void handle( String s, HttpServletRequest req, HttpServletResponse resp, int i )
+ public void handle( String s, Request baseRequest, HttpServletRequest req, HttpServletResponse resp )
throws IOException, ServletException
{
if ( req.getRequestURI().contains( "redirectRequest" ) )
{
PutHandler putHandler = new PutHandler( this.repositoryDirectory );
- putHandler.handle( s, req, resp, i );
+ putHandler.handle( s, baseRequest, req, resp );
handlerRequestResponses.add(
new HandlerRequestResponse( req.getMethod(), ( (Response) resp ).getStatus(),
req.getRequestURI() ) );
@@ -1158,7 +1163,7 @@ public abstract class HttpWagonTestCase
proxyServer.start();
- proxyInfo.setPort( proxyServer.getConnectors()[0].getLocalPort() );
+ proxyInfo.setPort( ((NetworkConnector) (proxyServer.getConnectors()[0])).getLocalPort() );
System.out.println(
"start proxy on host/port " + proxyInfo.getHost() + "/" + proxyInfo.getPort() + " with non proxyHosts "
@@ -1342,7 +1347,7 @@ public abstract class HttpWagonTestCase
assertEquals( "top secret", IOUtil.toString( in ) );
- TestSecurityHandler securityHandler = (TestSecurityHandler) ( (Context) server.getHandler() ).getHandler();
+ TestSecurityHandler securityHandler = (TestSecurityHandler) ( (ServletContextHandler) server.getHandler() ).getHandler();
testPreemptiveAuthenticationGet( securityHandler, supportPreemptiveAuthenticationGet() );
}
@@ -1393,7 +1398,7 @@ public abstract class HttpWagonTestCase
assertEquals( "top secret", out.toString( "US-ASCII" ) );
- TestSecurityHandler securityHandler = (TestSecurityHandler) ( (Context) server.getHandler() ).getHandler();
+ TestSecurityHandler securityHandler = (TestSecurityHandler) ( (ServletContextHandler) server.getHandler() ).getHandler();
testPreemptiveAuthenticationGet( securityHandler, supportPreemptiveAuthenticationGet() );
}
finally
@@ -1483,9 +1488,9 @@ public abstract class HttpWagonTestCase
SecurityHandler sh = createSecurityHandler();
- Context root = new Context( Context.SESSIONS );
+ ServletContextHandler root = new ServletContextHandler( ServletContextHandler.SESSIONS );
root.setContextPath( "/" );
- root.addHandler( sh );
+ root.setHandler( sh );
root.setResourceBase( localRepositoryPath );
ServletHolder servletHolder = new ServletHolder( new DefaultServlet() );
root.addServlet( servletHolder, "/*" );
@@ -1908,7 +1913,7 @@ public abstract class HttpWagonTestCase
this.status = status;
}
- public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
+ public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response )
throws IOException, ServletException
{
if ( status != 0 )
@@ -1968,11 +1973,11 @@ public abstract class HttpWagonTestCase
this.resourceBase = repositoryDirectory;
}
- public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
+ public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response )
throws IOException, ServletException
{
Request baseRequest =
- request instanceof Request ? (Request) request : HttpConnection.getCurrentConnection().getRequest();
+ request instanceof Request ? (Request) request : HttpConnection.getCurrentConnection().getHttpChannel().getRequest();
if ( baseRequest.isHandled() || !"PUT".equals( baseRequest.getMethod() ) )
{
@@ -2017,7 +2022,7 @@ public abstract class HttpWagonTestCase
List<HandlerRequestResponse> handlerRequestResponses = new ArrayList<HandlerRequestResponse>();
- public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
+ public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response )
throws IOException, ServletException
{
System.out.println( " handle proxy request" );
@@ -2035,7 +2040,7 @@ public abstract class HttpWagonTestCase
}
handlerRequestResponses.add(
new HandlerRequestResponse( request.getMethod(), HttpServletResponse.SC_OK, request.getRequestURI() ) );
- super.handle( target, request, response, dispatch );
+ super.handle( target, baseRequest, request, response );
}
}
@@ -2054,7 +2059,7 @@ public abstract class HttpWagonTestCase
{
}
- public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
+ public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response )
throws IOException, ServletException
{
headers = new HashMap<String, String>();
@@ -2102,10 +2107,9 @@ public abstract class HttpWagonTestCase
cm.setPathSpec( "/*" );
TestSecurityHandler sh = new TestSecurityHandler();
- HashUserRealm hashUserRealm = new HashUserRealm( "MyRealm" );
- hashUserRealm.put( "user", "secret" );
- hashUserRealm.addUserToRole( "user", "admin" );
- sh.setUserRealm( hashUserRealm );
+ HashLoginService hashLoginService = new HashLoginService( "MyRealm" );
+ hashLoginService.putUser( "user", new Password( "secret" ), new String[]{ "admin" } );
+ sh.setLoginService( hashLoginService );
sh.setConstraintMappings( new ConstraintMapping[]{ cm } );
return sh;
}
@@ -2115,22 +2119,21 @@ public abstract class HttpWagonTestCase
*/
@SuppressWarnings( "checkstyle:visibilitymodifier" )
public static class TestSecurityHandler
- extends SecurityHandler
+ extends ConstraintSecurityHandler
{
public List<HandlerRequestResponse> handlerRequestResponses = new ArrayList<HandlerRequestResponse>();
@Override
- public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
+ public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response )
throws IOException, ServletException
{
String method = request.getMethod();
- super.handle( target, request, response, dispatch );
+ super.handle( target, baseRequest, request, response );
handlerRequestResponses.add(
new HandlerRequestResponse( method, ( (Response) response ).getStatus(), request.getRequestURI() ) );
}
-
}
/**
--
2.1.0