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

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