From a98d4de91d767519ed9f4680607d466ba170e45d Mon Sep 17 00:00:00 2001 From: Michal Srb 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 1bc9826..efa730d 100644 --- a/wagon-provider-test/pom.xml +++ b/wagon-provider-test/pom.xml @@ -51,8 +51,34 @@ under the License. compile - org.mortbay.jetty - jetty + log4j + log4j + compile + + + org.eclipse.jetty + jetty-server + compile + + + org.eclipse.jetty + jetty-util + compile + + + org.eclipse.jetty + jetty-client + compile + + + org.eclipse.jetty + jetty-security + compile + + + org.eclipse.jetty + jetty-servlet + compile 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 4ee5475..96728d3 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.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringOutputStream; 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; @@ -95,7 +100,7 @@ protected void setupWagonTestingFixtures() server = new Server( 0 ); PutHandler putHandler = new PutHandler( repositoryDirectory ); - server.addHandler( putHandler ); + server.setHandler( putHandler ); createContext( server, repositoryDirectory ); @@ -113,14 +118,14 @@ protected final int getTestRepositoryPort() { 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, "/*" ); } @@ -160,7 +165,7 @@ public void testHttpHeaders() 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 StringOutputStream() ); @@ -192,7 +197,7 @@ public void testHttpHeadersWithCommonMethods() 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 StringOutputStream() ); @@ -211,7 +216,7 @@ protected void addConnectors( Server server ) protected String getRepositoryUrl( Server server ) { - int localPort = server.getConnectors()[0].getLocalPort(); + int localPort = ((NetworkConnector) (server.getConnectors()[0])).getLocalPort(); return getProtocol() + "://localhost:" + localPort; } @@ -368,7 +373,7 @@ public void testGzipGet() 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" ); @@ -471,7 +476,7 @@ public void testRedirectGetToStream() protocol = "https"; } - String redirectUrl = protocol + "://localhost:" + server.getConnectors()[0].getLocalPort(); + String redirectUrl = protocol + "://localhost:" + ((NetworkConnector) (server.getConnectors()[0])).getLocalPort(); RedirectHandler redirectHandler = new RedirectHandler( "Found", 303, redirectUrl, null ); @@ -537,7 +542,7 @@ public void testRedirectGet() protocol = "https"; } - String redirectUrl = protocol + "://localhost:" + server.getConnectors()[0].getLocalPort(); + String redirectUrl = protocol + "://localhost:" + ((NetworkConnector) (server.getConnectors()[0])).getLocalPort(); RedirectHandler redirectHandler = new RedirectHandler( "Found", 303, redirectUrl, null ); @@ -605,7 +610,7 @@ public void testRedirectPutFromStreamWithFullUrl() protocol = "https"; } - String redirectUrl = protocol + "://localhost:" + realServer.getConnectors()[0].getLocalPort(); + String redirectUrl = protocol + "://localhost:" + ((NetworkConnector) (realServer.getConnectors()[0])).getLocalPort(); RedirectHandler redirectHandler = new RedirectHandler( "Found", 303, redirectUrl, repositoryDirectory ); @@ -776,7 +781,7 @@ public void testRedirectPutFileWithFullUrl() protocol = "https"; } - String redirectUrl = protocol + "://localhost:" + realServer.getConnectors()[0].getLocalPort(); + String redirectUrl = protocol + "://localhost:" + ((NetworkConnector) (realServer.getConnectors()[0])).getLocalPort(); RedirectHandler redirectHandler = new RedirectHandler( "Found", 303, redirectUrl, repositoryDirectory ); @@ -901,13 +906,13 @@ public void testRedirectPutFileRelativeUrl() 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() ) ); @@ -935,7 +940,7 @@ private void runTestProxiedRequest( ProxyInfo proxyInfo, TestHeaderHandler handl 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 " @@ -1062,7 +1067,7 @@ public void runTestSecuredGet( AuthenticationInfo authInfo ) assertEquals( "top secret", IOUtil.toString( in ) ); - TestSecurityHandler securityHandler = (TestSecurityHandler) ( (Context) server.getHandler() ).getHandler(); + TestSecurityHandler securityHandler = (TestSecurityHandler) ( (ServletContextHandler) server.getHandler() ).getHandler(); testPreemptiveAuthenticationGet( securityHandler, supportPreemptiveAuthenticationGet() ); } @@ -1113,7 +1118,7 @@ public void runTestSecuredGetToStream( AuthenticationInfo authInfo ) assertEquals( "top secret", out.toString() ); - TestSecurityHandler securityHandler = (TestSecurityHandler) ( (Context) server.getHandler() ).getHandler(); + TestSecurityHandler securityHandler = (TestSecurityHandler) ( (ServletContextHandler) server.getHandler() ).getHandler(); testPreemptiveAuthenticationGet( securityHandler, supportPreemptiveAuthenticationGet() ); } finally @@ -1203,9 +1208,9 @@ private Server createSecurityServer( String localRepositoryPath ) 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, "/*" ); @@ -1566,7 +1571,7 @@ public void setStatusToReturn( int status ) 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 ) @@ -1622,11 +1627,11 @@ public PutHandler( File repositoryDirectory ) 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 base_request = - request instanceof Request ? (Request) request : HttpConnection.getCurrentConnection().getRequest(); + request instanceof Request ? (Request) request : HttpConnection.getCurrentConnection().getHttpChannel().getRequest(); if ( base_request.isHandled() || !"PUT".equals( base_request.getMethod() ) ) { @@ -1671,7 +1676,7 @@ public void handle( String target, HttpServletRequest request, HttpServletRespon List handlerRequestResponses = new ArrayList(); - 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" ); @@ -1687,7 +1692,7 @@ public void handle( String target, HttpServletRequest request, HttpServletRespon } handlerRequestResponses.add( new HandlerRequestResponse( request.getMethod(), 200, request.getRequestURI() ) ); - super.handle( target, request, response, dispatch ); + super.handle( target, baseRequest, request, response ); } } @@ -1702,7 +1707,7 @@ public TestHeaderHandler() { } - 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(); @@ -1737,31 +1742,29 @@ protected TestSecurityHandler createSecurityHandler() 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; } public static class TestSecurityHandler - extends SecurityHandler + extends ConstraintSecurityHandler { public List handlerRequestResponses = new ArrayList(); @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() ) ); } - } public static class HandlerRequestResponse -- 1.8.1.2