Merge branch 'master' of ssh://git.eclipse.org:29418/jetty/org.eclipse.jetty.project

This commit is contained in:
Thomas Becker 2012-08-28 13:58:05 +02:00
commit 3c952da6ed
9 changed files with 319 additions and 97 deletions

View File

@ -208,12 +208,12 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async
{
Connection switched=exchange.onSwitchProtocol(_endp);
if (switched!=null)
connection=switched;
{
// switched protocol!
_pipeline = null;
if (_pipeline!=null)
{
_destination.send(_pipeline);
}
_pipeline = null;
connection=switched;

View File

@ -139,17 +139,23 @@ public class WebappRegistrationCustomizerImpl implements WebappRegistrationCusto
public URL[] getJarsWithTlds(DeploymentManager deployer, BundleFileLocatorHelper locatorHelper) throws Exception
{
ArrayList<URL> urls = new ArrayList<URL>();
HashSet<Class<?>> classesToAddToTheTldBundles = new HashSet<Class<?>>();
// Look for the jstl bundle
// We assume the jstl's tlds are defined there.
// We assume that the jstl bundle is imported by this bundle
// So we can look for this class using this bundle's classloader:
try
{
Class<?> jstlClass = WebappRegistrationCustomizerImpl.class.getClassLoader().loadClass(DEFAULT_JSTL_BUNDLE_CLASS);
classesToAddToTheTldBundles.add(jstlClass);
ArrayList<URL> urls = new ArrayList<URL>();
}
catch (ClassNotFoundException e)
{
LOG.info("jstl not on classpath", e);
}
for (Class<?> cl : classesToAddToTheTldBundles)
{
Bundle tldBundle = FrameworkUtil.getBundle(cl);

View File

@ -37,7 +37,8 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/* ------------------------------------------------------------ */
/** SessionHandler.
/**
* SessionHandler.
*/
public class SessionHandler extends ScopedHandler
{
@ -47,9 +48,8 @@ public class SessionHandler extends ScopedHandler
private SessionManager _sessionManager;
/* ------------------------------------------------------------ */
/** Constructor.
* Construct a SessionHandler witha a HashSessionManager with a standard
* java.util.Random generator is created.
/**
* Constructor. Construct a SessionHandler witha a HashSessionManager with a standard java.util.Random generator is created.
*/
public SessionHandler()
{
@ -58,7 +58,8 @@ public class SessionHandler extends ScopedHandler
/* ------------------------------------------------------------ */
/**
* @param manager The session manager
* @param manager
* The session manager
*/
public SessionHandler(SessionManager manager)
{
@ -76,7 +77,8 @@ public class SessionHandler extends ScopedHandler
/* ------------------------------------------------------------ */
/**
* @param sessionManager The sessionManager to set.
* @param sessionManager
* The sessionManager to set.
*/
public void setSessionManager(SessionManager sessionManager)
{
@ -84,32 +86,30 @@ public class SessionHandler extends ScopedHandler
throw new IllegalStateException();
SessionManager old_session_manager = _sessionManager;
if (getServer()!=null)
getServer().getContainer().update(this, old_session_manager, sessionManager, "sessionManager",true);
if (getServer() != null)
getServer().getContainer().update(this,old_session_manager,sessionManager,"sessionManager",true);
if (sessionManager!=null)
if (sessionManager != null)
sessionManager.setSessionHandler(this);
_sessionManager = sessionManager;
if (old_session_manager!=null)
if (old_session_manager != null)
old_session_manager.setSessionHandler(null);
}
/* ------------------------------------------------------------ */
@Override
public void setServer(Server server)
{
Server old_server=getServer();
if (old_server!=null && old_server!=server)
old_server.getContainer().update(this, _sessionManager, null, "sessionManager",true);
Server old_server = getServer();
if (old_server != null && old_server != server)
old_server.getContainer().update(this,_sessionManager,null,"sessionManager",true);
super.setServer(server);
if (server!=null && server!=old_server)
server.getContainer().update(this, null,_sessionManager, "sessionManager",true);
if (server != null && server != old_server)
server.getContainer().update(this,null,_sessionManager,"sessionManager",true);
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.thread.AbstractLifeCycle#doStart()
@ -120,6 +120,7 @@ public class SessionHandler extends ScopedHandler
_sessionManager.start();
super.doStart();
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.thread.AbstractLifeCycle#doStop()
@ -132,18 +133,16 @@ public class SessionHandler extends ScopedHandler
super.doStop();
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.jetty.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
*/
@Override
public void doScope(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
public void doScope(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
SessionManager old_session_manager=null;
HttpSession old_session=null;
HttpSession access=null;
SessionManager old_session_manager = null;
HttpSession old_session = null;
HttpSession access = null;
try
{
old_session_manager = baseRequest.getSessionManager();
@ -158,54 +157,54 @@ public class SessionHandler extends ScopedHandler
}
// access any existing session
HttpSession session=null;
if (_sessionManager!=null)
HttpSession session = null;
if (_sessionManager != null)
{
session=baseRequest.getSession(false);
if (session!=null)
session = baseRequest.getSession(false);
if (session != null)
{
if(session!=old_session)
if (session != old_session)
{
access=session;
access = session;
HttpCookie cookie = _sessionManager.access(session,request.isSecure());
if (cookie!=null ) // Handle changed ID or max-age refresh
if (cookie != null) // Handle changed ID or max-age refresh
baseRequest.getResponse().addCookie(cookie);
}
}
else
{
session=baseRequest.recoverNewSession(_sessionManager);
if (session!=null)
session = baseRequest.recoverNewSession(_sessionManager);
if (session != null)
baseRequest.setSession(session);
}
}
if(LOG.isDebugEnabled())
if (LOG.isDebugEnabled())
{
LOG.debug("sessionManager="+_sessionManager);
LOG.debug("session="+session);
LOG.debug("sessionManager=" + _sessionManager);
LOG.debug("session=" + session);
}
// start manual inline of nextScope(target,baseRequest,request,response);
if (_nextScope!=null)
_nextScope.doScope(target,baseRequest,request, response);
else if (_outerScope!=null)
_outerScope.doHandle(target,baseRequest,request, response);
if (_nextScope != null)
_nextScope.doScope(target,baseRequest,request,response);
else if (_outerScope != null)
_outerScope.doHandle(target,baseRequest,request,response);
else
doHandle(target,baseRequest,request, response);
doHandle(target,baseRequest,request,response);
// end manual inline (pathentic attempt to reduce stack depth)
}
finally
{
if (access!=null)
if (access != null)
_sessionManager.complete(access);
HttpSession session = baseRequest.getSession(false);
if (session!=null && old_session==null && session!=access)
if (session != null && old_session == null && session != access)
_sessionManager.complete(session);
if (old_session_manager!=null && old_session_manager != _sessionManager)
if (old_session_manager != null && old_session_manager != _sessionManager)
{
baseRequest.setSessionManager(old_session_manager);
baseRequest.setSession(old_session);
@ -218,98 +217,109 @@ public class SessionHandler extends ScopedHandler
* @see org.eclipse.jetty.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
*/
@Override
public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
// start manual inline of nextHandle(target,baseRequest,request,response);
if (never())
nextHandle(target,baseRequest,request,response);
else if (_nextScope!=null && _nextScope==_handler)
_nextScope.doHandle(target,baseRequest,request, response);
else if (_handler!=null)
_handler.handle(target,baseRequest, request, response);
else if (_nextScope != null && _nextScope == _handler)
_nextScope.doHandle(target,baseRequest,request,response);
else if (_handler != null)
_handler.handle(target,baseRequest,request,response);
// end manual inline
}
/* ------------------------------------------------------------ */
/** Look for a requested session ID in cookies and URI parameters
/**
* Look for a requested session ID in cookies and URI parameters
*
* @param baseRequest
* @param request
*/
protected void checkRequestedSessionId(Request baseRequest, HttpServletRequest request)
{
String requested_session_id=request.getRequestedSessionId();
String requested_session_id = request.getRequestedSessionId();
SessionManager sessionManager = getSessionManager();
if (requested_session_id!=null && sessionManager!=null)
if (requested_session_id != null && sessionManager != null)
{
HttpSession session=sessionManager.getHttpSession(requested_session_id);
if (session!=null && sessionManager.isValid(session))
HttpSession session = sessionManager.getHttpSession(requested_session_id);
if (session != null && sessionManager.isValid(session))
baseRequest.setSession(session);
return;
}
else if (!DispatcherType.REQUEST.equals(baseRequest.getDispatcherType()))
return;
boolean requested_session_id_from_cookie=false;
HttpSession session=null;
boolean requested_session_id_from_cookie = false;
HttpSession session = null;
// Look for session id cookie
if (_sessionManager.isUsingCookies())
{
Cookie[] cookies=request.getCookies();
if (cookies!=null && cookies.length>0)
Cookie[] cookies = request.getCookies();
if (cookies != null && cookies.length > 0)
{
for (int i=0;i<cookies.length;i++)
for (int i = 0; i < cookies.length; i++)
{
if (sessionManager.getSessionCookie().equalsIgnoreCase(cookies[i].getName()))
{
requested_session_id=cookies[i].getValue();
requested_session_id = cookies[i].getValue();
requested_session_id_from_cookie = true;
if(LOG.isDebugEnabled())
LOG.debug("Got Session ID {} from cookie",requested_session_id);
session=sessionManager.getHttpSession(requested_session_id);
if (session!=null && sessionManager.isValid(session))
LOG.info("Got Session ID {} from cookie",requested_session_id);
if (requested_session_id != null)
{
session = sessionManager.getHttpSession(requested_session_id);
if (session != null && sessionManager.isValid(session))
{
break;
}
}
else
{
LOG.warn("null session id from cookie");
}
}
}
}
}
if (requested_session_id==null || session==null)
if (requested_session_id == null || session == null)
{
String uri = request.getRequestURI();
String prefix=sessionManager.getSessionIdPathParameterNamePrefix();
if (prefix!=null)
String prefix = sessionManager.getSessionIdPathParameterNamePrefix();
if (prefix != null)
{
int s = uri.indexOf(prefix);
if (s>=0)
if (s >= 0)
{
s+=prefix.length();
int i=s;
while (i<uri.length())
s += prefix.length();
int i = s;
while (i < uri.length())
{
char c=uri.charAt(i);
if (c==';'||c=='#'||c=='?'||c=='/')
char c = uri.charAt(i);
if (c == ';' || c == '#' || c == '?' || c == '/')
break;
i++;
}
requested_session_id = uri.substring(s,i);
requested_session_id_from_cookie = false;
session=sessionManager.getHttpSession(requested_session_id);
if(LOG.isDebugEnabled())
session = sessionManager.getHttpSession(requested_session_id);
if (LOG.isDebugEnabled())
LOG.debug("Got Session ID {} from URL",requested_session_id);
}
}
}
baseRequest.setRequestedSessionId(requested_session_id);
baseRequest.setRequestedSessionIdFromCookie(requested_session_id!=null && requested_session_id_from_cookie);
if (session!=null && sessionManager.isValid(session))
baseRequest.setRequestedSessionIdFromCookie(requested_session_id != null && requested_session_id_from_cookie);
if (session != null && sessionManager.isValid(session))
baseRequest.setSession(session);
}
@ -319,14 +329,14 @@ public class SessionHandler extends ScopedHandler
*/
public void addEventListener(EventListener listener)
{
if(_sessionManager!=null)
if (_sessionManager != null)
_sessionManager.addEventListener(listener);
}
/* ------------------------------------------------------------ */
public void clearEventListeners()
{
if(_sessionManager!=null)
if (_sessionManager != null)
_sessionManager.clearEventListeners();
}
}

View File

@ -111,7 +111,13 @@ public class TagLibConfiguration extends AbstractConfiguration
//Get the system classpath tlds and tell jasper about them, if jasper is on the classpath
try
{
Class<?> clazz = getClass().getClassLoader().loadClass("org.apache.jasper.compiler.TldLocationsCache");
ClassLoader loader = _context.getClassLoader();
if (loader == null || loader.getParent() == null)
loader = getClass().getClassLoader();
else
loader = loader.getParent();
Class<?> clazz = loader.loadClass("org.apache.jasper.compiler.TldLocationsCache");
assert clazz!=null;
Collection<Resource> tld_resources = (Collection<Resource>)_context.getAttribute(TLD_RESOURCES);

View File

@ -3,7 +3,7 @@
<parent>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-parent</artifactId>
<version>19</version>
<version>20</version>
</parent>
<artifactId>jetty-project</artifactId>
<version>7.6.6-SNAPSHOT</version>
@ -323,7 +323,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.5</version>
<version>2.7.1</version>
<configuration>
<targetJdk>1.5</targetJdk>
<rulesets>

View File

@ -0,0 +1,12 @@
package org.eclipse.jetty.server.session;
public class ImmortalSessionTest extends AbstractImmortalSessionTest
{
@Override
public AbstractTestServer createServer(int port, int max, int scavenge)
{
return new HashTestServer(port,max,scavenge);
}
}

View File

@ -0,0 +1,12 @@
package org.eclipse.jetty.server.session;
public class SessionCookieTest extends AbstractSessionCookieTest
{
@Override
public AbstractTestServer createServer(int port, int max, int scavenge)
{
return new HashTestServer(port, max, scavenge);
}
}

View File

@ -0,0 +1,12 @@
package org.eclipse.jetty.server.session;
public class SessionValueSharedSaving extends AbstractSessionValueSavingTest
{
@Override
public AbstractTestServer createServer(int port, int max, int scavenge)
{
return new HashTestServer(port,max,scavenge);
}
}

View File

@ -0,0 +1,164 @@
//
// ========================================================================
// Copyright (c) 1995-2012 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.server.session;
import java.io.IOException;
import java.util.Random;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import junit.framework.Assert;
import org.eclipse.jetty.client.Address;
import org.eclipse.jetty.client.ContentExchange;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.HttpDestination;
import org.eclipse.jetty.http.HttpCookie;
import org.eclipse.jetty.http.HttpMethods;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.util.log.Log;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* AbstractNewSessionTest
*/
public abstract class AbstractSessionCookieTest
{
public abstract AbstractTestServer createServer(int port, int max, int scavenge);
public void pause(int scavenge)
{
try
{
Thread.sleep(scavenge * 2500L);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
@Test
@Ignore("failing because an http cookie with null value is coming over as \"null\"")
public void testSessionCookie() throws Exception
{
String contextPath = "";
String servletMapping = "/server";
int scavengePeriod = 3;
AbstractTestServer server = createServer(0, 1, scavengePeriod);
ServletContextHandler context = server.addContext(contextPath);
context.addServlet(TestServlet.class, servletMapping);
server.start();
int port=server.getPort();
try
{
HttpClient client = new HttpClient();
client.setConnectorType(HttpClient.CONNECTOR_SOCKET);
client.start();
try
{
ContentExchange exchange = new ContentExchange(true);
exchange.setMethod(HttpMethods.GET);
exchange.setURL("http://localhost:" + port + contextPath + servletMapping + "?action=create");
client.send(exchange);
exchange.waitForDone();
assertEquals(HttpServletResponse.SC_OK,exchange.getResponseStatus());
String sessionCookie = exchange.getResponseFields().getStringField("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
//sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
// Let's wait for the scavenger to run, waiting 2.5 times the scavenger period
//pause(scavengePeriod);
exchange = new ContentExchange(true);
exchange.setMethod(HttpMethods.GET);
exchange.setURL("http://localhost:" + port + contextPath + servletMapping + "?action=check-cookie");
exchange.getRequestFields().add("Cookie", sessionCookie);
client.send(exchange);
exchange.waitForDone();
assertEquals(HttpServletResponse.SC_OK,exchange.getResponseStatus());
exchange = new ContentExchange(true);
exchange.setMethod(HttpMethods.GET);
exchange.setURL("http://localhost:" + port + contextPath + servletMapping + "?action=null-cookie");
//exchange.getRequestFields().add("Cookie", "null");
HttpDestination dest = client.getDestination(new Address("localhost",port),false);
dest.addCookie(new HttpCookie("Cookie",null));
client.send(exchange);
exchange.waitForDone();
assertEquals(HttpServletResponse.SC_OK,exchange.getResponseStatus());
}
finally
{
client.stop();
}
}
finally
{
server.stop();
}
}
public static class TestServlet extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String action = request.getParameter("action");
if ("create".equals(action))
{
HttpSession session = request.getSession(true);
assertTrue(session.isNew());
}
else if ("check-cookie".equals(action))
{
HttpSession session = request.getSession(false);
assertTrue(session != null);
//request.getSession(true);
}
else if ("null-cookie".equals(action))
{
HttpSession session = request.getSession(false);
assertEquals(1, request.getCookies().length);
Assert.assertFalse("null".equals(request.getCookies()[0].getValue()));
assertTrue(session == null);
}
else
{
assertTrue(false);
}
}
}
}