Skip to content

Commit

Permalink
[MJAVADOC-687] Upgrade Jetty Version to last 9.4.x (#92)
Browse files Browse the repository at this point in the history
* [MJAVADOC-687] Upgrade Jetty Version to last 9.4.x

Signed-off-by: Olivier Lamy <olamy@apache.org>
  • Loading branch information
olamy committed Aug 6, 2021
1 parent 2bead1f commit f845fe4
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 89 deletions.
30 changes: 25 additions & 5 deletions pom.xml
Expand Up @@ -73,10 +73,12 @@ under the License.
<wagonVersion>2.4</wagonVersion>
<sonatypeAetherVersion>1.13.1</sonatypeAetherVersion>
<plexus-java.version>1.0.7</plexus-java.version>
<jetty.version>9.4.43.v20210629</jetty.version>
<!-- for ITs -->
<sitePluginVersion>3.3</sitePluginVersion>
<projectInfoReportsPluginVersion>2.7</projectInfoReportsPluginVersion>
<project.build.outputTimestamp>2021-05-18T17:44:35Z</project.build.outputTimestamp>
<slf4j.version>1.7.30</slf4j.version>
</properties>

<contributors>
Expand Down Expand Up @@ -333,15 +335,27 @@ under the License.
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>6.1.26</version>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-proxy</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>6.1.26</version>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -368,6 +382,11 @@ under the License.
<version>3.19.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -445,6 +464,7 @@ under the License.
<environmentVariables>
<JENKINS_MAVEN_AGENT_DISABLED>true</JENKINS_MAVEN_AGENT_DISABLED>
</environmentVariables>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
<plugin>
Expand Down
Expand Up @@ -63,6 +63,8 @@
import org.hamcrest.MatcherAssert;
import org.junit.AssumptionViolatedException;
import org.junit.Ignore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;

/**
Expand All @@ -86,6 +88,8 @@ public class JavadocReportTest

private File localRepo;

private static final Logger LOGGER = LoggerFactory.getLogger( JavadocReportTest.class );

/** {@inheritDoc} */
@Override
protected void setUp()
Expand Down Expand Up @@ -259,23 +263,31 @@ public void testDefaultConfiguration()
String url = Objects.requireNonNull( mojo.getDefaultJavadocApiLink() ).getUrl();
HttpURLConnection connection = (HttpURLConnection) new URL( url ).openConnection();
connection.setRequestMethod( "HEAD" );
if ( connection.getResponseCode() == HttpURLConnection.HTTP_OK )
try
{
try
{
assumeThat( connection.getURL().toString(), is( url ) );

// https://bugs.openjdk.java.net/browse/JDK-8216497
MatcherAssert.assertThat( url + " available, but " + appHtml + " is missing link to java.lang.Object",
new String( Files.readAllBytes(generatedFile), StandardCharsets.UTF_8 ),
anyOf( containsString( "/docs/api/java/lang/Object.html" ),
containsString( "/docs/api/java.base/java/lang/Object.html" ) ) );
}
catch ( AssumptionViolatedException e )
if ( connection.getResponseCode() == HttpURLConnection.HTTP_OK )
{
System.out.println( "Warning: ignoring defaultAPI check: " + e.getMessage() );
try
{
assumeThat( connection.getURL().toString(), is( url ) );

// https://bugs.openjdk.java.net/browse/JDK-8216497
MatcherAssert.assertThat( url + " available, but " + appHtml + " is missing link to java.lang.Object",
new String( Files.readAllBytes(generatedFile), StandardCharsets.UTF_8 ),
anyOf( containsString( "/docs/api/java/lang/Object.html" ),
containsString( "/docs/api/java.base/java/lang/Object.html" ) ) );
}
catch ( AssumptionViolatedException e )
{
LOGGER.warn( "ignoring defaultAPI check: {}", e.getMessage() );
}
}
}
catch (Exception e)
{
LOGGER.error("error connecting to javadoc URL: {}", url);
throw e;
}

assertThat( apidocs.resolve( "def/configuration/AppSample.html" )).exists();
assertThat( apidocs.resolve( "def/configuration/package-summary.html" )).exists();
Expand All @@ -285,7 +297,7 @@ public void testDefaultConfiguration()
// package-frame and allclasses-(no)frame not generated anymore since Java 11
if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "11" ) )
{
assertThat( apidocs.resolve( "def/configuration/package-frame.html" )).exists();;
assertThat( apidocs.resolve( "def/configuration/package-frame.html" )).exists();
assertThat( apidocs.resolve( "allclasses-frame.html" )).exists();
assertThat( apidocs.resolve( "allclasses-noframe.html" )).exists();
}
Expand Down Expand Up @@ -945,11 +957,6 @@ public void testJdk6()
public void testProxy()
throws Exception
{
// ignore test as annotation doesn't ignore anything..
if ( true )
{
return;
}
Settings settings = new Settings();
Proxy proxy = new Proxy();

Expand Down
43 changes: 22 additions & 21 deletions src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java
Expand Up @@ -37,6 +37,7 @@
import java.util.Set;
import java.util.regex.PatternSyntaxException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

Expand All @@ -46,10 +47,12 @@
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.AbstractHandler;
import org.mortbay.jetty.handler.MovedContextHandler;
import org.mortbay.util.ByteArrayISO8859Writer;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.MovedContextHandler;
import org.eclipse.jetty.util.ByteArrayISO8859Writer;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down Expand Up @@ -473,12 +476,11 @@ public void testGetRedirectUrl()
try
{
redirectServer = new Server( 0 );
redirectServer.addHandler( new AbstractHandler()
redirectServer.setHandler( new AbstractHandler()
{
@Override
public void handle( String target, HttpServletRequest request, HttpServletResponse response,
int dispatch )
throws IOException
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setStatus( HttpServletResponse.SC_OK );
ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer( 100 );
Expand All @@ -495,12 +497,12 @@ public void handle( String target, HttpServletRequest request, HttpServletRespon

server = new Server( 0 );
MovedContextHandler handler = new MovedContextHandler();
int redirectPort = redirectServer.getConnectors()[0].getLocalPort();
int redirectPort = ((ServerConnector)redirectServer.getConnectors()[0]).getLocalPort();
handler.setNewContextURL( "http://localhost:" + redirectPort );
server.addHandler( handler );
server.setHandler( handler );
server.start();

URL url = new URI( "http://localhost:" + server.getConnectors()[0].getLocalPort() ).toURL();
URL url = new URI( "http://localhost:" + ((ServerConnector)redirectServer.getConnectors()[0]).getLocalPort() ).toURL();
URL redirectUrl = JavadocUtil.getRedirectUrl( url, new Settings() );

assertTrue( redirectUrl.toString().startsWith( "http://localhost:" + redirectPort ) );
Expand All @@ -522,12 +524,11 @@ public void testGetRedirectUrlWithNoRedirects()
try
{
server = new Server( 0 );
server.addHandler( new AbstractHandler()
server.setHandler( new AbstractHandler()
{
@Override
public void handle( String target, HttpServletRequest request, HttpServletResponse response,
int dispatch )
throws IOException
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setStatus( HttpServletResponse.SC_OK );
ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer( 100 );
Expand All @@ -542,7 +543,7 @@ public void handle( String target, HttpServletRequest request, HttpServletRespon
} );
server.start();

URL url = new URI( "http://localhost:" + server.getConnectors()[0].getLocalPort() ).toURL();
URL url = new URI( "http://localhost:" + ((ServerConnector)server.getConnectors()[0]).getLocalPort() ).toURL();
URL redirectUrl = JavadocUtil.getRedirectUrl( url, new Settings() );

assertEquals( url.toURI(), redirectUrl.toURI() );
Expand All @@ -564,13 +565,13 @@ public void testGetRedirectUrlVerifyHeaders()
try
{
server = new Server( 0 );
server.addHandler( new AbstractHandler()
server.setHandler( new AbstractHandler()
{
@Override
public void handle( String target, HttpServletRequest request, HttpServletResponse response,
int dispatch )
throws IOException
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{

if ( request.getHeader( "Accept" ) == null )
{
response.setStatus( HttpServletResponse.SC_FORBIDDEN );
Expand All @@ -584,7 +585,7 @@ public void handle( String target, HttpServletRequest request, HttpServletRespon
} );
server.start();

URL url = new URI( "http://localhost:" + server.getConnectors()[0].getLocalPort() ).toURL();
URL url = new URI( "http://localhost:" + ((ServerConnector)server.getConnectors()[0]).getLocalPort() ).toURL();
JavadocUtil.getRedirectUrl( url, new Settings() );
}
finally
Expand Down
75 changes: 31 additions & 44 deletions src/test/java/org/apache/maven/plugins/javadoc/ProxyServer.java
Expand Up @@ -21,7 +21,8 @@

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Map;

import javax.servlet.ServletException;
Expand All @@ -30,13 +31,12 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.bio.SocketConnector;
import org.mortbay.jetty.security.B64Code;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;
import org.mortbay.proxy.AsyncProxyServlet;
import org.eclipse.jetty.proxy.AsyncProxyServlet;
import org.eclipse.jetty.proxy.ConnectHandler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;

/**
* A Proxy server.
Expand All @@ -48,6 +48,8 @@ class ProxyServer
{
private Server proxyServer;

private ServerConnector serverConnector;

/**
* @param proxyServlet the wanted auth proxy servlet
*/
Expand All @@ -63,31 +65,40 @@ public ProxyServer( AuthAsyncProxyServlet proxyServlet )
*/
public ProxyServer( String hostName, int port, AuthAsyncProxyServlet proxyServlet )
{
proxyServer = new Server();
proxyServer = new Server( );

serverConnector = new ServerConnector( proxyServer );
serverConnector.setHost( InetAddress.getLoopbackAddress().getHostName() );
serverConnector.setReuseAddress( true );
serverConnector.setPort( 0 );

proxyServer.addConnector( serverConnector );

proxyServer.addConnector( getDefaultConnector( hostName, port ) );
// Setup proxy handler to handle CONNECT methods
ConnectHandler proxy = new ConnectHandler();
proxyServer.setHandler(proxy);

Context context = new Context( proxyServer, "/", 0 );
// Setup proxy servlet
ServletContextHandler context = new ServletContextHandler(proxy, "/", true, false);
ServletHolder appServletHolder = new ServletHolder(proxyServlet);
context.addServlet(appServletHolder, "/*");

context.addServlet( new ServletHolder( proxyServlet ), "/" );
}

/**
* @return the host name
*/
public String getHostName()
{
Connector connector = proxyServer.getConnectors()[0];
return connector.getHost();
return serverConnector.getHost() == null ? InetAddress.getLoopbackAddress().getHostName() : serverConnector.getHost();
}

/**
* @return the host port
*/
public int getPort()
{
Connector connector = proxyServer.getConnectors()[0];
return ( connector.getLocalPort() <= 0 ? connector.getPort() : connector.getLocalPort() );
return serverConnector.getLocalPort();
}

/**
Expand Down Expand Up @@ -115,31 +126,6 @@ public void stop()
proxyServer = null;
}

private Connector getDefaultConnector( String hostName, int port )
{
Connector connector = new SocketConnector();
if ( hostName != null )
{
connector.setHost( hostName );
}
else
{
try
{
connector.setHost( InetAddress.getLocalHost().getCanonicalHostName() );
}
catch ( UnknownHostException e )
{
// nop
}
}
if ( port > 0 )
{
connector.setPort( port );
}

return connector;
}

/**
* A proxy servlet with authentication support.
Expand Down Expand Up @@ -180,7 +166,6 @@ public AuthAsyncProxyServlet( Map<String, String> authentications )
public AuthAsyncProxyServlet( Map<String, String> authentications, long sleepTime )
{
this();

this.authentications = authentications;
this.sleepTime = sleepTime;
}
Expand All @@ -198,8 +183,10 @@ public void service( ServletRequest req, ServletResponse res )
String proxyAuthorization = request.getHeader( "Proxy-Authorization" );
if ( proxyAuthorization != null && proxyAuthorization.startsWith( "Basic " ) )
{
String proxyAuth = proxyAuthorization.substring( 6 );
String authorization = B64Code.decode( proxyAuth );
String proxyAuth = proxyAuthorization.substring("Basic ".length());
String authorization = new String(Base64.getDecoder().decode(proxyAuth), StandardCharsets.UTF_8);


String[] authTokens = authorization.split( ":" );
String user = authTokens[0];
String password = authTokens[1];
Expand Down

0 comments on commit f845fe4

Please sign in to comment.