Merge remote-tracking branch 'origin/jetty-8'

Conflicts:
	jetty-webapp/src/main/java/org/eclipse/jetty/webapp/StandardDescriptorProcessor.java
This commit is contained in:
Jan Bartel 2013-02-26 12:50:30 +11:00
commit 42475b1564
3 changed files with 154 additions and 16 deletions

View File

@ -0,0 +1,141 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.servlet;
import java.io.IOException;
import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.eclipse.jetty.server.Dispatcher;
import org.eclipse.jetty.server.HttpConnection;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.resource.Resource;
/* ------------------------------------------------------------ */
/** Servlet handling JSP Property Group mappings
* <p>
* This servlet is mapped to by any URL pattern for a JSP property group.
* Resources handled by this servlet that are not directories will be passed
* directly to the JSP servlet. Resources that are directories will be
* passed directly to the default servlet.
*/
public class JspPropertyGroupServlet extends GenericServlet
{
private static final long serialVersionUID = 3681783214726776945L;
public final static String NAME = "__org.eclipse.jetty.servlet.JspPropertyGroupServlet__";
private final ServletHandler _servletHandler;
private final ContextHandler _contextHandler;
private ServletHolder _dftServlet;
private ServletHolder _jspServlet;
private boolean _starJspMapped;
public JspPropertyGroupServlet(ContextHandler context, ServletHandler servletHandler)
{
_contextHandler=context;
_servletHandler=servletHandler;
}
@Override
public void init() throws ServletException
{
String jsp_name = "jsp";
ServletMapping servlet_mapping =_servletHandler.getServletMapping("*.jsp");
if (servlet_mapping!=null)
{
_starJspMapped=true;
//now find the jsp servlet, ignoring the mapping that is for ourself
ServletMapping[] mappings = _servletHandler.getServletMappings();
for (ServletMapping m:mappings)
{
String[] paths = m.getPathSpecs();
if (paths!=null)
{
for (String path:paths)
{
if ("*.jsp".equals(path) && !NAME.equals(m.getServletName()))
servlet_mapping = m;
}
}
}
jsp_name=servlet_mapping.getServletName();
}
_jspServlet=_servletHandler.getServlet(jsp_name);
String dft_name="default";
ServletMapping default_mapping=_servletHandler.getServletMapping("/");
if (default_mapping!=null)
dft_name=default_mapping.getServletName();
_dftServlet=_servletHandler.getServlet(dft_name);
}
@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
{
Request request=(req instanceof Request)?(Request)req:HttpConnection.getCurrentConnection().getHttpChannel().getRequest();
String servletPath=null;
String pathInfo=null;
if (request.getAttribute(Dispatcher.INCLUDE_REQUEST_URI)!=null)
{
servletPath=(String)request.getAttribute(Dispatcher.INCLUDE_SERVLET_PATH);
pathInfo=(String)request.getAttribute(Dispatcher.INCLUDE_PATH_INFO);
if (servletPath==null)
{
servletPath=request.getServletPath();
pathInfo=request.getPathInfo();
}
}
else
{
servletPath = request.getServletPath();
pathInfo = request.getPathInfo();
}
String pathInContext=URIUtil.addPaths(servletPath,pathInfo);
if (pathInContext.endsWith("/"))
{
_dftServlet.getServlet().service(req,res);
}
else if (_starJspMapped && pathInContext.toLowerCase().endsWith(".jsp"))
{
_jspServlet.getServlet().service(req,res);
}
else
{
Resource resource = _contextHandler.getResource(pathInContext);
if (resource!=null && resource.isDirectory())
_dftServlet.getServlet().service(req,res);
else
_jspServlet.getServlet().service(req,res);
}
}
}

View File

@ -41,6 +41,9 @@ import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.FilterMapping;
import org.eclipse.jetty.servlet.Holder;
import org.eclipse.jetty.servlet.JspPropertyGroupServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletContextHandler.JspConfig;
import org.eclipse.jetty.servlet.ServletContextHandler.JspPropertyGroup;
import org.eclipse.jetty.servlet.ServletContextHandler.TagLib;
@ -1336,23 +1339,20 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
if (paths.size() > 0)
{
String jspName = "jsp";
Map.Entry entry = context.getServletHandler().getHolderEntry("test.jsp");
if (entry != null)
ServletHandler handler = context.getServletHandler();
ServletHolder jsp_pg_servlet = handler.getServlet(JspPropertyGroupServlet.NAME);
if (jsp_pg_servlet==null)
{
ServletHolder holder = (ServletHolder) entry.getValue();
jspName = holder.getName();
jsp_pg_servlet=new ServletHolder(JspPropertyGroupServlet.NAME,new JspPropertyGroupServlet(context,handler));
handler.addServlet(jsp_pg_servlet);
}
if (jspName != null)
{
ServletMapping mapping = new ServletMapping();
mapping.setServletName(jspName);
mapping.setServletName(JspPropertyGroupServlet.NAME);
mapping.setPathSpecs(paths.toArray(new String[paths.size()]));
context.getServletHandler().addServletMapping(mapping);
}
}
}
/**
* @param context

View File

@ -93,10 +93,7 @@ public class WebSocketMinVersionTest
}
catch(IllegalStateException e) {
String respHeader = e.getMessage();
Assert.assertThat("Response Header", respHeader, allOf(
containsString("HTTP/1.1 400 Unsupported"),
containsString("minVersion [8]"),
containsString("[13, 8]")));
Assert.assertThat("Response Header", respHeader, containsString("HTTP/1.1 400 Unsupported websocket version specification"));
}
finally
{