Blame SOURCES/0001-Port-to-jetty-9.patch

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