f50bd0
From a98d4de91d767519ed9f4680607d466ba170e45d Mon Sep 17 00:00:00 2001
f50bd0
From: Michal Srb <msrb@redhat.com>
f50bd0
Date: Wed, 27 Feb 2013 12:38:47 +0100
f50bd0
Subject: [PATCH] Port to jetty 9
f50bd0
f50bd0
---
f50bd0
 wagon-provider-test/pom.xml                        | 30 ++++++-
f50bd0
 .../apache/maven/wagon/http/HttpWagonTestCase.java | 97 +++++++++++-----------
f50bd0
 2 files changed, 78 insertions(+), 49 deletions(-)
f50bd0
f50bd0
diff --git a/wagon-provider-test/pom.xml b/wagon-provider-test/pom.xml
f50bd0
index 1bc9826..efa730d 100644
f50bd0
--- a/wagon-provider-test/pom.xml
f50bd0
+++ b/wagon-provider-test/pom.xml
f50bd0
@@ -51,8 +51,34 @@ under the License.
f50bd0
       <scope>compile</scope>
f50bd0
     </dependency>
f50bd0
     <dependency>
f50bd0
-      <groupId>org.mortbay.jetty</groupId>
f50bd0
-      <artifactId>jetty</artifactId>
f50bd0
+      <groupId>log4j</groupId>
f50bd0
+      <artifactId>log4j</artifactId>
f50bd0
+      <scope>compile</scope>
f50bd0
+    </dependency>
f50bd0
+    <dependency>
f50bd0
+      <groupId>org.eclipse.jetty</groupId>
f50bd0
+      <artifactId>jetty-server</artifactId>
f50bd0
+      <scope>compile</scope>
f50bd0
+    </dependency>
f50bd0
+    <dependency>
f50bd0
+      <groupId>org.eclipse.jetty</groupId>
f50bd0
+      <artifactId>jetty-util</artifactId>
f50bd0
+      <scope>compile</scope>
f50bd0
+    </dependency>
f50bd0
+    <dependency>
f50bd0
+      <groupId>org.eclipse.jetty</groupId>
f50bd0
+      <artifactId>jetty-client</artifactId>
f50bd0
+      <scope>compile</scope>
f50bd0
+    </dependency>
f50bd0
+    <dependency>
f50bd0
+      <groupId>org.eclipse.jetty</groupId>
f50bd0
+      <artifactId>jetty-security</artifactId>
f50bd0
+      <scope>compile</scope>
f50bd0
+    </dependency>
f50bd0
+    <dependency>
f50bd0
+      <groupId>org.eclipse.jetty</groupId>
f50bd0
+      <artifactId>jetty-servlet</artifactId>
f50bd0
+      <scope>compile</scope>
f50bd0
     </dependency>
f50bd0
 
f50bd0
   </dependencies>
f50bd0
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
f50bd0
index 4ee5475..96728d3 100644
f50bd0
--- a/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java
f50bd0
+++ b/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java
f50bd0
@@ -34,20 +34,25 @@
f50bd0
 import org.codehaus.plexus.util.IOUtil;
f50bd0
 import org.codehaus.plexus.util.StringOutputStream;
f50bd0
 import org.codehaus.plexus.util.StringUtils;
f50bd0
-import org.mortbay.jetty.Handler;
f50bd0
-import org.mortbay.jetty.HttpConnection;
f50bd0
-import org.mortbay.jetty.Request;
f50bd0
-import org.mortbay.jetty.Response;
f50bd0
-import org.mortbay.jetty.Server;
f50bd0
-import org.mortbay.jetty.handler.AbstractHandler;
f50bd0
-import org.mortbay.jetty.handler.HandlerCollection;
f50bd0
-import org.mortbay.jetty.security.Constraint;
f50bd0
-import org.mortbay.jetty.security.ConstraintMapping;
f50bd0
-import org.mortbay.jetty.security.HashUserRealm;
f50bd0
-import org.mortbay.jetty.security.SecurityHandler;
f50bd0
-import org.mortbay.jetty.servlet.Context;
f50bd0
-import org.mortbay.jetty.servlet.DefaultServlet;
f50bd0
-import org.mortbay.jetty.servlet.ServletHolder;
f50bd0
+import org.eclipse.jetty.server.Handler;
f50bd0
+import org.eclipse.jetty.server.HttpConnection;
f50bd0
+import org.eclipse.jetty.server.HttpChannel;
f50bd0
+import org.eclipse.jetty.server.Request;
f50bd0
+import org.eclipse.jetty.server.Response;
f50bd0
+import org.eclipse.jetty.server.Server;
f50bd0
+import org.eclipse.jetty.server.NetworkConnector;
f50bd0
+import org.eclipse.jetty.server.UserIdentity;
f50bd0
+import org.eclipse.jetty.server.handler.AbstractHandler;
f50bd0
+import org.eclipse.jetty.server.handler.HandlerCollection;
f50bd0
+import org.eclipse.jetty.util.security.Constraint;
f50bd0
+import org.eclipse.jetty.util.security.Password;
f50bd0
+import org.eclipse.jetty.security.ConstraintMapping;
f50bd0
+import org.eclipse.jetty.security.HashLoginService;
f50bd0
+import org.eclipse.jetty.security.SecurityHandler;
f50bd0
+import org.eclipse.jetty.security.ConstraintSecurityHandler;
f50bd0
+import org.eclipse.jetty.servlet.ServletContextHandler;
f50bd0
+import org.eclipse.jetty.servlet.DefaultServlet;
f50bd0
+import org.eclipse.jetty.servlet.ServletHolder;
f50bd0
 
f50bd0
 import javax.servlet.ServletException;
f50bd0
 import javax.servlet.ServletInputStream;
f50bd0
@@ -95,7 +100,7 @@ protected void setupWagonTestingFixtures()
f50bd0
         server = new Server( 0 );
f50bd0
 
f50bd0
         PutHandler putHandler = new PutHandler( repositoryDirectory );
f50bd0
-        server.addHandler( putHandler );
f50bd0
+        server.setHandler( putHandler );
f50bd0
 
f50bd0
         createContext( server, repositoryDirectory );
f50bd0
 
f50bd0
@@ -113,14 +118,14 @@ protected final int getTestRepositoryPort()
f50bd0
         {
f50bd0
             return 0;
f50bd0
         }
f50bd0
-        return server.getConnectors()[0].getLocalPort();
f50bd0
+        return ((NetworkConnector) (server.getConnectors()[0])).getLocalPort();
f50bd0
     }
f50bd0
 
f50bd0
     protected void createContext( Server server, File repositoryDirectory )
f50bd0
         throws IOException
f50bd0
     {
f50bd0
-        Context root = new Context( server, "/", Context.SESSIONS );
f50bd0
-        root.setResourceBase( repositoryDirectory.getAbsolutePath() );
f50bd0
+        ServletContextHandler root = new ServletContextHandler( server, "/", ServletContextHandler.SESSIONS );
f50bd0
+        //root.setResourceBase( repositoryDirectory.getAbsolutePath() );
f50bd0
         ServletHolder servletHolder = new ServletHolder( new DefaultServlet() );
f50bd0
         root.addServlet( servletHolder, "/*" );
f50bd0
     }
f50bd0
@@ -160,7 +165,7 @@ public void testHttpHeaders()
f50bd0
         server.start();
f50bd0
 
f50bd0
         wagon.connect(
f50bd0
-            new Repository( "id", getProtocol() + "://localhost:" + server.getConnectors()[0].getLocalPort() ) );
f50bd0
+            new Repository( "id", getProtocol() + "://localhost:" + ((NetworkConnector) (server.getConnectors()[0])).getLocalPort() ) );
f50bd0
 
f50bd0
         wagon.getToStream( "resource", new StringOutputStream() );
f50bd0
 
f50bd0
@@ -192,7 +197,7 @@ public void testHttpHeadersWithCommonMethods()
f50bd0
         server.start();
f50bd0
 
f50bd0
         wagon.connect(
f50bd0
-            new Repository( "id", getProtocol() + "://localhost:" + server.getConnectors()[0].getLocalPort() ) );
f50bd0
+            new Repository( "id", getProtocol() + "://localhost:" + ((NetworkConnector) (server.getConnectors()[0])).getLocalPort() ) );
f50bd0
 
f50bd0
         wagon.getToStream( "resource", new StringOutputStream() );
f50bd0
 
f50bd0
@@ -211,7 +216,7 @@ protected void addConnectors( Server server )
f50bd0
 
f50bd0
     protected String getRepositoryUrl( Server server )
f50bd0
     {
f50bd0
-        int localPort = server.getConnectors()[0].getLocalPort();
f50bd0
+        int localPort = ((NetworkConnector) (server.getConnectors()[0])).getLocalPort();
f50bd0
         return getProtocol() + "://localhost:" + localPort;
f50bd0
     }
f50bd0
 
f50bd0
@@ -368,7 +373,7 @@ public void testGzipGet()
f50bd0
         Server server = new Server( getTestRepositoryPort() );
f50bd0
 
f50bd0
         String localRepositoryPath = FileTestUtils.getTestOutputDir().toString();
f50bd0
-        Context root = new Context( server, "/", Context.SESSIONS );
f50bd0
+        ServletContextHandler root = new ServletContextHandler( server, "/", ServletContextHandler.SESSIONS );
f50bd0
         root.setResourceBase( localRepositoryPath );
f50bd0
         ServletHolder servletHolder = new ServletHolder( new DefaultServlet() );
f50bd0
         servletHolder.setInitParameter( "gzip", "true" );
f50bd0
@@ -471,7 +476,7 @@ public void testRedirectGetToStream()
f50bd0
             protocol = "https";
f50bd0
         }
f50bd0
 
f50bd0
-        String redirectUrl = protocol + "://localhost:" + server.getConnectors()[0].getLocalPort();
f50bd0
+        String redirectUrl = protocol + "://localhost:" + ((NetworkConnector) (server.getConnectors()[0])).getLocalPort();
f50bd0
 
f50bd0
         RedirectHandler redirectHandler = new RedirectHandler( "Found", 303, redirectUrl, null );
f50bd0
 
f50bd0
@@ -537,7 +542,7 @@ public void testRedirectGet()
f50bd0
             protocol = "https";
f50bd0
         }
f50bd0
 
f50bd0
-        String redirectUrl = protocol + "://localhost:" + server.getConnectors()[0].getLocalPort();
f50bd0
+        String redirectUrl = protocol + "://localhost:" + ((NetworkConnector) (server.getConnectors()[0])).getLocalPort();
f50bd0
 
f50bd0
         RedirectHandler redirectHandler = new RedirectHandler( "Found", 303, redirectUrl, null );
f50bd0
 
f50bd0
@@ -605,7 +610,7 @@ public void testRedirectPutFromStreamWithFullUrl()
f50bd0
             protocol = "https";
f50bd0
         }
f50bd0
 
f50bd0
-        String redirectUrl = protocol + "://localhost:" + realServer.getConnectors()[0].getLocalPort();
f50bd0
+        String redirectUrl = protocol + "://localhost:" + ((NetworkConnector) (realServer.getConnectors()[0])).getLocalPort();
f50bd0
 
f50bd0
         RedirectHandler redirectHandler = new RedirectHandler( "Found", 303, redirectUrl, repositoryDirectory );
f50bd0
 
f50bd0
@@ -776,7 +781,7 @@ public void testRedirectPutFileWithFullUrl()
f50bd0
             protocol = "https";
f50bd0
         }
f50bd0
 
f50bd0
-        String redirectUrl = protocol + "://localhost:" + realServer.getConnectors()[0].getLocalPort();
f50bd0
+        String redirectUrl = protocol + "://localhost:" + ((NetworkConnector) (realServer.getConnectors()[0])).getLocalPort();
f50bd0
 
f50bd0
         RedirectHandler redirectHandler = new RedirectHandler( "Found", 303, redirectUrl, repositoryDirectory );
f50bd0
 
f50bd0
@@ -901,13 +906,13 @@ public void testRedirectPutFileRelativeUrl()
f50bd0
             this.repositoryDirectory = repositoryDirectory;
f50bd0
         }
f50bd0
 
f50bd0
-        public void handle( String s, HttpServletRequest req, HttpServletResponse resp, int i )
f50bd0
+        public void handle( String s, Request baseRequest, HttpServletRequest req, HttpServletResponse resp )
f50bd0
             throws IOException, ServletException
f50bd0
         {
f50bd0
             if ( req.getRequestURI().contains( "redirectRequest" ) )
f50bd0
             {
f50bd0
                 PutHandler putHandler = new PutHandler( this.repositoryDirectory );
f50bd0
-                putHandler.handle( s, req, resp, i );
f50bd0
+                putHandler.handle( s, baseRequest, req, resp );
f50bd0
                 handlerRequestResponses.add(
f50bd0
                     new HandlerRequestResponse( req.getMethod(), ( (Response) resp ).getStatus(),
f50bd0
                                                 req.getRequestURI() ) );
f50bd0
@@ -935,7 +940,7 @@ private void runTestProxiedRequest( ProxyInfo proxyInfo, TestHeaderHandler handl
f50bd0
 
f50bd0
         proxyServer.start();
f50bd0
 
f50bd0
-        proxyInfo.setPort( proxyServer.getConnectors()[0].getLocalPort() );
f50bd0
+        proxyInfo.setPort( ((NetworkConnector) (proxyServer.getConnectors()[0])).getLocalPort() );
f50bd0
 
f50bd0
         System.out.println(
f50bd0
             "start proxy on host/port " + proxyInfo.getHost() + "/" + proxyInfo.getPort() + " with non proxyHosts "
f50bd0
@@ -1062,7 +1067,7 @@ public void runTestSecuredGet( AuthenticationInfo authInfo )
f50bd0
 
f50bd0
             assertEquals( "top secret", IOUtil.toString( in ) );
f50bd0
 
f50bd0
-            TestSecurityHandler securityHandler = (TestSecurityHandler) ( (Context) server.getHandler() ).getHandler();
f50bd0
+            TestSecurityHandler securityHandler = (TestSecurityHandler) ( (ServletContextHandler) server.getHandler() ).getHandler();
f50bd0
             testPreemptiveAuthenticationGet( securityHandler, supportPreemptiveAuthenticationGet() );
f50bd0
 
f50bd0
         }
f50bd0
@@ -1113,7 +1118,7 @@ public void runTestSecuredGetToStream( AuthenticationInfo authInfo )
f50bd0
 
f50bd0
             assertEquals( "top secret", out.toString() );
f50bd0
 
f50bd0
-            TestSecurityHandler securityHandler = (TestSecurityHandler) ( (Context) server.getHandler() ).getHandler();
f50bd0
+            TestSecurityHandler securityHandler = (TestSecurityHandler) ( (ServletContextHandler) server.getHandler() ).getHandler();
f50bd0
             testPreemptiveAuthenticationGet( securityHandler, supportPreemptiveAuthenticationGet() );
f50bd0
         }
f50bd0
         finally
f50bd0
@@ -1203,9 +1208,9 @@ private Server createSecurityServer( String localRepositoryPath )
f50bd0
 
f50bd0
         SecurityHandler sh = createSecurityHandler();
f50bd0
 
f50bd0
-        Context root = new Context( Context.SESSIONS );
f50bd0
+        ServletContextHandler root = new ServletContextHandler( ServletContextHandler.SESSIONS );
f50bd0
         root.setContextPath( "/" );
f50bd0
-        root.addHandler( sh );
f50bd0
+        root.setHandler( sh );
f50bd0
         root.setResourceBase( localRepositoryPath );
f50bd0
         ServletHolder servletHolder = new ServletHolder( new DefaultServlet() );
f50bd0
         root.addServlet( servletHolder, "/*" );
f50bd0
@@ -1566,7 +1571,7 @@ public void setStatusToReturn( int status )
f50bd0
             this.status = status;
f50bd0
         }
f50bd0
 
f50bd0
-        public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
f50bd0
+        public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response )
f50bd0
             throws IOException, ServletException
f50bd0
         {
f50bd0
             if ( status != 0 )
f50bd0
@@ -1622,11 +1627,11 @@ public PutHandler( File repositoryDirectory )
f50bd0
             this.resourceBase = repositoryDirectory;
f50bd0
         }
f50bd0
 
f50bd0
-        public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
f50bd0
+        public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response )
f50bd0
             throws IOException, ServletException
f50bd0
         {
f50bd0
             Request base_request =
f50bd0
-                request instanceof Request ? (Request) request : HttpConnection.getCurrentConnection().getRequest();
f50bd0
+                request instanceof Request ? (Request) request : HttpConnection.getCurrentConnection().getHttpChannel().getRequest();
f50bd0
 
f50bd0
             if ( base_request.isHandled() || !"PUT".equals( base_request.getMethod() ) )
f50bd0
             {
f50bd0
@@ -1671,7 +1676,7 @@ public void handle( String target, HttpServletRequest request, HttpServletRespon
f50bd0
 
f50bd0
         List<HandlerRequestResponse> handlerRequestResponses = new ArrayList<HandlerRequestResponse>();
f50bd0
 
f50bd0
-        public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
f50bd0
+        public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response )
f50bd0
             throws IOException, ServletException
f50bd0
         {
f50bd0
             System.out.println( " handle proxy request" );
f50bd0
@@ -1687,7 +1692,7 @@ public void handle( String target, HttpServletRequest request, HttpServletRespon
f50bd0
             }
f50bd0
             handlerRequestResponses.add(
f50bd0
                 new HandlerRequestResponse( request.getMethod(), 200, request.getRequestURI() ) );
f50bd0
-            super.handle( target, request, response, dispatch );
f50bd0
+            super.handle( target, baseRequest, request, response );
f50bd0
         }
f50bd0
     }
f50bd0
 
f50bd0
@@ -1702,7 +1707,7 @@ public TestHeaderHandler()
f50bd0
         {
f50bd0
         }
f50bd0
 
f50bd0
-        public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
f50bd0
+        public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response )
f50bd0
             throws IOException, ServletException
f50bd0
         {
f50bd0
             headers = new HashMap();
f50bd0
@@ -1737,31 +1742,29 @@ protected TestSecurityHandler createSecurityHandler()
f50bd0
         cm.setPathSpec( "/*" );
f50bd0
 
f50bd0
         TestSecurityHandler sh = new TestSecurityHandler();
f50bd0
-        HashUserRealm hashUserRealm = new HashUserRealm( "MyRealm" );
f50bd0
-        hashUserRealm.put( "user", "secret" );
f50bd0
-        hashUserRealm.addUserToRole( "user", "admin" );
f50bd0
-        sh.setUserRealm( hashUserRealm );
f50bd0
+        HashLoginService hashLoginService = new HashLoginService( "MyRealm" );
f50bd0
+        hashLoginService.putUser( "user", new Password( "secret" ),  new String[]{ "admin" } );
f50bd0
+        sh.setLoginService( hashLoginService );
f50bd0
         sh.setConstraintMappings( new ConstraintMapping[]{ cm } );
f50bd0
         return sh;
f50bd0
     }
f50bd0
 
f50bd0
     public static class TestSecurityHandler
f50bd0
-        extends SecurityHandler
f50bd0
+        extends ConstraintSecurityHandler
f50bd0
     {
f50bd0
 
f50bd0
         public List<HandlerRequestResponse> handlerRequestResponses = new ArrayList<HandlerRequestResponse>();
f50bd0
 
f50bd0
         @Override
f50bd0
-        public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
f50bd0
+        public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response )
f50bd0
             throws IOException, ServletException
f50bd0
         {
f50bd0
             String method = request.getMethod();
f50bd0
-            super.handle( target, request, response, dispatch );
f50bd0
+            super.handle( target, baseRequest, request, response );
f50bd0
 
f50bd0
             handlerRequestResponses.add(
f50bd0
                 new HandlerRequestResponse( method, ( (Response) response ).getStatus(), request.getRequestURI() ) );
f50bd0
         }
f50bd0
-
f50bd0
     }
f50bd0
 
f50bd0
     public static class HandlerRequestResponse
f50bd0
-- 
f50bd0
1.8.1.2
f50bd0