Merge branch 'jetty-9.3.x' of github.com:eclipse/jetty.project into jetty-9.3.x

This commit is contained in:
Joakim Erdfelt 2016-10-26 10:31:45 -07:00
commit 41cd3bd090
12 changed files with 291 additions and 51 deletions

View File

@ -69,11 +69,6 @@
<artifactId>jetty-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Schemas -->
<dependency>
@ -98,5 +93,25 @@
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
</dependency>
<!-- tests -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -29,8 +29,9 @@ import javax.servlet.ServletContext;
import org.apache.jasper.servlet.JasperInitializer;
import org.apache.jasper.servlet.TldPreScanned;
import org.apache.jasper.servlet.TldScanner;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.xml.sax.SAXException;
/**
@ -38,8 +39,7 @@ import org.xml.sax.SAXException;
*/
public class JettyJasperInitializer extends JasperInitializer
{
private static final Logger LOG = Log.getLogger(JettyJasperInitializer.class);
private static final Log LOG = LogFactory.getLog(JasperInitializer.class);
/**
* NullTldScanner
*
@ -111,6 +111,4 @@ public class JettyJasperInitializer extends JasperInitializer
if (LOG.isDebugEnabled()) LOG.debug("Defaulting to jasper tld scanning");
return super.newTldScanner(context, namespaceAware, validate, blockExternal);
}
}

View File

@ -19,6 +19,9 @@
package org.eclipse.jetty.jsp;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
@ -26,9 +29,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.jasper.servlet.JspServlet;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.resource.Resource;
/**
* JettyJspServlet
@ -76,7 +77,7 @@ public class JettyJspServlet extends JspServlet
pathInfo = request.getPathInfo();
}
String pathInContext = URIUtil.addPaths(servletPath,pathInfo);
String pathInContext = addPaths(servletPath,pathInfo);
String jspFile = getInitParameter("jspFile");
@ -84,7 +85,7 @@ public class JettyJspServlet extends JspServlet
//otherwise the default servlet might handle it
if (jspFile == null)
{
if (pathInContext.endsWith("/"))
if (pathInContext != null && pathInContext.endsWith("/"))
{
//dispatch via forward to the default servlet
getServletContext().getNamedDispatcher("default").forward(req, resp);
@ -93,9 +94,11 @@ public class JettyJspServlet extends JspServlet
else
{
//check if it resolves to a directory
Resource resource = ((ContextHandler.Context)getServletContext()).getContextHandler().getResource(pathInContext);
if (resource!=null && resource.isDirectory())
String realPath = getServletContext().getRealPath(pathInContext);
if (realPath != null)
{
Path asPath = Paths.get(realPath);
if (Files.exists(asPath) && Files.isDirectory(asPath))
{
//dispatch via forward to the default servlet
getServletContext().getNamedDispatcher("default").forward(req, resp);
@ -103,10 +106,25 @@ public class JettyJspServlet extends JspServlet
}
}
}
}
//fall through to the normal jsp servlet handling
super.service(req, resp);
}
/**
* @param servletPath the servletPath of the request
* @param pathInfo the pathInfo of the request
* @return servletPath with pathInfo appended
*/
private String addPaths(String servletPath, String pathInfo)
{
if (servletPath.length()==0)
return pathInfo;
if (pathInfo==null)
return servletPath;
return servletPath+pathInfo;
}
}

View File

@ -0,0 +1,123 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.jsp;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspFactory;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.servlet.ServletTester;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.apache.jasper.runtime.JspFactoryImpl;
import org.apache.tomcat.InstanceManager;
import org.apache.tomcat.SimpleInstanceManager;
import org.eclipse.jetty.servlet.ServletContextHandler;
public class TestJettyJspServlet
{
File _dir;
ServletTester _tester;
public static class DfltServlet extends HttpServlet
{
public DfltServlet()
{
super();
}
/**
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
resp.setContentType("html/text");
resp.getOutputStream().println("This.Is.The.Default.");
}
}
@Before
public void setUp () throws Exception
{
JspFactory.setDefaultFactory(new JspFactoryImpl());
_dir = MavenTestingUtils.getTestResourceDir("base");
_tester = new ServletTester("/context");
_tester.getContext().setClassLoader(new URLClassLoader(new URL[0], Thread.currentThread().getContextClassLoader()));
ServletHolder jspHolder = _tester.getContext().addServlet(JettyJspServlet.class, "/*");
jspHolder.setInitParameter("scratchdir", MavenTestingUtils.getTargetTestingDir().getAbsolutePath());
_tester.getContext().setResourceBase(_dir.getAbsolutePath());
_tester.getContext().setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
ServletHolder dfltHolder = new ServletHolder();
dfltHolder.setName("default");
dfltHolder.setHeldClass( DfltServlet.class);
_tester.getContext().addServlet(dfltHolder, "/");
_tester.start();
}
@After
public void tearDown() throws Exception
{
if (_tester != null)
_tester.stop();
}
@Test
public void testWithJsp() throws Exception
{
//test that an ordinary jsp is served by jsp servlet
String request = "" +
"GET /context/foo.jsp HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"Connection: close\r\n" +
"\r\n";
String response = _tester.getResponses(request);
assertTrue(!response.contains("This.Is.The.Default."));
}
@Test
public void testWithDirectory() throws Exception
{
//test that a dir is served by the default servlet
String request = "" +
"GET /context/dir HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"Connection: close\r\n" +
"\r\n";
String response = _tester.getResponses(request);
assertTrue(response.contains("This.Is.The.Default."));
}
}

View File

@ -0,0 +1,23 @@
<html><head>
<%@ page import="java.util.Enumeration" %>
</head><body>
<h1>JSP Dump</h1>
<table border="1">
<tr><th>Request URI:</th><td><%= request.getRequestURI() %></td></tr>
<tr><th>ServletPath:</th><td><%= request.getServletPath() %></td></tr>
<tr><th>PathInfo:</th><td><%= request.getPathInfo() %></td></tr>
<%
Enumeration e =request.getParameterNames();
while(e.hasMoreElements())
{
String name = (String)e.nextElement();
%>
<tr>
<th>getParameter("<%= name %>")</th>
<td><%= request.getParameter(name) %></td></tr>
<% } %>
</table>
</body></html>

View File

@ -0,0 +1,8 @@
[name]
alpn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/alpn/alpn-boot/8.1.9.v20160720/alpn-boot-8.1.9.v20160720.jar|lib/alpn/alpn-boot-8.1.9.v20160720.jar
[exec]
-Xbootclasspath/p:lib/alpn/alpn-boot-8.1.9.v20160720.jar

View File

@ -0,0 +1,8 @@
[name]
alpn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/alpn/alpn-boot/8.1.10.v20161026/alpn-boot-8.1.10.v20161026.jar|lib/alpn/alpn-boot-8.1.10.v20161026.jar
[exec]
-Xbootclasspath/p:lib/alpn/alpn-boot-8.1.10.v20161026.jar

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.http;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;
@ -51,30 +52,56 @@ public class PreEncodedHttpField extends HttpField
{
try
{
encoders.add(iter.next());
HttpFieldPreEncoder encoder = iter.next();
if (index(encoder.getHttpVersion())>=0)
encoders.add(encoder);
}
catch(Error|RuntimeException e)
{
LOG.debug(e);
}
}
// TODO avoid needing this catch all
if (encoders.size()==0)
encoders.add(new Http1FieldPreEncoder());
LOG.debug("HttpField encoders loaded: {}",encoders);
__encoders = encoders.toArray(new HttpFieldPreEncoder[encoders.size()]);
int size=encoders.size();
__encoders = new HttpFieldPreEncoder[size==0?1:size];
for (HttpFieldPreEncoder e:encoders)
{
int i = index(e.getHttpVersion());
if (__encoders[i]==null)
__encoders[i] = e;
else
LOG.warn("multiple PreEncoders for "+e.getHttpVersion());
}
private final byte[][] _encodedField=new byte[2][];
// Always support HTTP1
if (__encoders[0]==null)
__encoders[0] = new Http1FieldPreEncoder();
}
private static int index(HttpVersion version)
{
switch (version)
{
case HTTP_1_0:
case HTTP_1_1:
return 0;
case HTTP_2:
return 1;
default:
return -1;
}
}
private final byte[][] _encodedField=new byte[__encoders.length][];
public PreEncodedHttpField(HttpHeader header,String name,String value)
{
super(header,name, value);
for (HttpFieldPreEncoder e:__encoders)
{
_encodedField[e.getHttpVersion()==HttpVersion.HTTP_2?1:0]=e.getEncodedField(header,header.asString(),value);
}
for (int i=0;i<__encoders.length;i++)
_encodedField[i]=__encoders[i].getEncodedField(header,header.asString(),value);
}
public PreEncodedHttpField(HttpHeader header,String value)
@ -89,6 +116,6 @@ public class PreEncodedHttpField extends HttpField
public void putTo(ByteBuffer bufferInFillMode, HttpVersion version)
{
bufferInFillMode.put(_encodedField[version==HttpVersion.HTTP_2?1:0]);
bufferInFillMode.put(_encodedField[index(version)]);
}
}

View File

@ -0,0 +1,8 @@
[name]
alpn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/alpn/alpn-boot/8.1.9.v20160720/alpn-boot-8.1.9.v20160720.jar|lib/alpn/alpn-boot-8.1.9.v20160720.jar
[exec]
-Xbootclasspath/p:lib/alpn/alpn-boot-8.1.9.v20160720.jar

View File

@ -0,0 +1,8 @@
[name]
alpn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/alpn/alpn-boot/8.1.10.v20161026/alpn-boot-8.1.10.v20161026.jar|lib/alpn/alpn-boot-8.1.10.v20161026.jar
[exec]
-Xbootclasspath/p:lib/alpn/alpn-boot-8.1.10.v20161026.jar

36
pom.xml
View File

@ -1162,24 +1162,28 @@
</properties>
</profile>
<profile>
<id>jdk9</id>
<id>8u111</id>
<activation>
<jdk>1.9</jdk>
<property>
<name>java.version</name>
<value>1.8.0_111</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.9</source>
<target>1.9</target>
<testSource>1.9</testSource>
<testTarget>1.9</testTarget>
<compilerArgument>-Xlint:all</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<alpn.version>8.1.9.v20160720</alpn.version>
</properties>
</profile>
<profile>
<id>8u112</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_112</value>
</property>
</activation>
<properties>
<alpn.version>8.1.10.v20161026</alpn.version>
</properties>
</profile>
</profiles>
</project>