Merge remote-tracking branch 'origin/jetty-9.4.x'
This commit is contained in:
commit
44fa57b38a
|
@ -10,9 +10,11 @@
|
|||
<Call name="addBean">
|
||||
<Arg>
|
||||
<New id="sessionDataStoreFactory" class="org.eclipse.jetty.nosql.mongodb.MongoSessionDataStoreFactory">
|
||||
<Set name="dbName"><Property name="jetty.session.dbName" default="HttpSessions" /></Set>
|
||||
<Set name="collectionName"><Property name="jetty.session.collectionName" default="jettySessions" /></Set>
|
||||
<Set name="dbName"><Property name="jetty.session.mongo.dbName" default="HttpSessions" /></Set>
|
||||
<Set name="collectionName"><Property name="jetty.session.mongo.collectionName" default="jettySessions" /></Set>
|
||||
<Set name="gracePeriodSec"><Property name="jetty.session.gracePeriod.seconds" default="3600" /></Set>
|
||||
<Set name="host"><Property name="jetty.session.mongo.host" default="localhost"/></Set>
|
||||
<Set name="port"><Property name="jetty.session.mongo.port" default="27017"/></Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
|
|
@ -23,6 +23,9 @@ http://www.apache.org/licenses/LICENSE-2.0.html
|
|||
etc/sessions/mongo/session-store.xml
|
||||
|
||||
[ini-template]
|
||||
#jetty.session.dbName=HttpSessions
|
||||
#jetty.session.collectionName=jettySessions
|
||||
#jetty.session.mongo.dbName=HttpSessions
|
||||
#jetty.session.mongo.collectionName=jettySessions
|
||||
#jetty.session.mongo.host=localhost
|
||||
#jetty.session.mongo.port=27017
|
||||
#jetty.session.gracePeriod.seconds=3600
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.net.UnknownHostException;
|
|||
|
||||
import org.eclipse.jetty.server.session.AbstractSessionDataStoreFactory;
|
||||
import org.eclipse.jetty.server.session.SessionHandler;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.server.session.SessionDataStore;
|
||||
|
||||
|
||||
|
@ -38,6 +39,43 @@ public class MongoSessionDataStoreFactory extends AbstractSessionDataStoreFactor
|
|||
{
|
||||
String _dbName;
|
||||
String _collectionName;
|
||||
String _host;
|
||||
int _port = -1;
|
||||
|
||||
/**
|
||||
* @return the host
|
||||
*/
|
||||
public String getHost()
|
||||
{
|
||||
return _host;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param host the host to set
|
||||
*/
|
||||
public void setHost(String host)
|
||||
{
|
||||
_host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the port
|
||||
*/
|
||||
public int getPort()
|
||||
{
|
||||
return _port;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param port the port to set
|
||||
*/
|
||||
public void setPort(int port)
|
||||
{
|
||||
_port = port;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -83,7 +121,14 @@ public class MongoSessionDataStoreFactory extends AbstractSessionDataStoreFactor
|
|||
{
|
||||
MongoSessionDataStore store = new MongoSessionDataStore();
|
||||
store.setGracePeriodSec(getGracePeriodSec());
|
||||
store.setDBCollection(new Mongo().getDB(getDbName()).getCollection(getCollectionName()));
|
||||
Mongo mongo;
|
||||
if (!StringUtil.isBlank(getHost()) && getPort() != -1)
|
||||
mongo = new Mongo(getHost(), getPort());
|
||||
else if (!StringUtil.isBlank(getHost()))
|
||||
mongo = new Mongo(getHost());
|
||||
else
|
||||
mongo = new Mongo();
|
||||
store.setDBCollection(mongo.getDB(getDbName()).getCollection(getCollectionName()));
|
||||
return store;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import javax.servlet.ServletRequest;
|
|||
import javax.servlet.ServletResponse;
|
||||
|
||||
import org.eclipse.jetty.server.handler.ContextHandler.Context;
|
||||
import org.eclipse.jetty.util.URIUtil;
|
||||
import org.eclipse.jetty.util.thread.Scheduler;
|
||||
|
||||
public class AsyncContextEvent extends AsyncEvent implements Runnable
|
||||
|
@ -94,7 +95,7 @@ public class AsyncContextEvent extends AsyncEvent implements Runnable
|
|||
}
|
||||
|
||||
/**
|
||||
* @return The path in the context
|
||||
* @return The path in the context (encoded with possible query string)
|
||||
*/
|
||||
public String getPath()
|
||||
{
|
||||
|
@ -131,6 +132,9 @@ public class AsyncContextEvent extends AsyncEvent implements Runnable
|
|||
_dispatchContext=context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param path encoded URI
|
||||
*/
|
||||
public void setDispatchPath(String path)
|
||||
{
|
||||
_dispatchPath=path;
|
||||
|
|
|
@ -1219,6 +1219,8 @@ public class Request implements HttpServletRequest
|
|||
@Override
|
||||
public RequestDispatcher getRequestDispatcher(String path)
|
||||
{
|
||||
// path is encoded, potentially with query
|
||||
|
||||
path = URIUtil.compactPath(path);
|
||||
|
||||
if (path == null || _context == null)
|
||||
|
@ -1233,7 +1235,7 @@ public class Request implements HttpServletRequest
|
|||
relTo = relTo.substring(0,slash + 1);
|
||||
else
|
||||
relTo = "/";
|
||||
path = URIUtil.addPaths(relTo,path);
|
||||
path = URIUtil.addPaths(URIUtil.encodePath(relTo),path);
|
||||
}
|
||||
|
||||
return _context.getRequestDispatcher(path);
|
||||
|
@ -2176,7 +2178,7 @@ public class Request implements HttpServletRequest
|
|||
_async=new AsyncContextState(state);
|
||||
AsyncContextEvent event = new AsyncContextEvent(_context,_async,state,this,servletRequest,servletResponse);
|
||||
event.setDispatchContext(getServletContext());
|
||||
event.setDispatchPath(URIUtil.addPaths(getServletPath(),getPathInfo()));
|
||||
event.setDispatchPath(URIUtil.encodePath(URIUtil.addPaths(getServletPath(),getPathInfo())));
|
||||
state.startAsync(event);
|
||||
return _async;
|
||||
}
|
||||
|
|
|
@ -578,7 +578,7 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
// this is a dispatch with a path
|
||||
ServletContext context=event.getServletContext();
|
||||
String query=baseRequest.getQueryString();
|
||||
baseRequest.setURIPathQuery(URIUtil.encodePath(URIUtil.addPaths(context==null?null:context.getContextPath(), path)));
|
||||
baseRequest.setURIPathQuery(URIUtil.addPaths(context==null?null:URIUtil.encodePath(context.getContextPath()), path));
|
||||
HttpURI uri = baseRequest.getHttpURI();
|
||||
baseRequest.setPathInfo(uri.getDecodedPath());
|
||||
if (uri.getQuery()!=null)
|
||||
|
|
|
@ -2074,6 +2074,8 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
|||
@Override
|
||||
public RequestDispatcher getRequestDispatcher(String uriInContext)
|
||||
{
|
||||
// uriInContext is encoded, potentially with query
|
||||
|
||||
if (uriInContext == null)
|
||||
return null;
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
|||
import org.eclipse.jetty.server.handler.ResourceHandler;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.TypeUtil;
|
||||
import org.eclipse.jetty.util.URIUtil;
|
||||
import org.eclipse.jetty.util.UrlEncoded;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.After;
|
||||
|
@ -147,14 +148,23 @@ public class EncodedURITest
|
|||
{
|
||||
String response = _connector.getResponse("GET /context%20path/async%20servlet/path%20info HTTP/1.0\n\n");
|
||||
assertThat(response,startsWith("HTTP/1.1 200 "));
|
||||
assertThat(response,Matchers.containsString("requestURI=/context%20path/test servlet/path info"));
|
||||
assertThat(response,Matchers.containsString("contextPath=/context path"));
|
||||
assertThat(response,Matchers.containsString("servletPath=/test servlet"));
|
||||
assertThat(response,Matchers.containsString("pathInfo=/path info"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsyncServletTestServletEncoded() throws Exception
|
||||
{
|
||||
String response = _connector.getResponse("GET /context%20path/async%20servlet/path%20info?encode=true HTTP/1.0\n\n");
|
||||
assertThat(response,startsWith("HTTP/1.1 200 "));
|
||||
assertThat(response,Matchers.containsString("requestURI=/context%20path/test%20servlet/path%20info"));
|
||||
assertThat(response,Matchers.containsString("contextPath=/context path"));
|
||||
assertThat(response,Matchers.containsString("servletPath=/test servlet"));
|
||||
assertThat(response,Matchers.containsString("pathInfo=/path info"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static class TestServlet extends HttpServlet
|
||||
{
|
||||
|
@ -180,7 +190,7 @@ public class EncodedURITest
|
|||
:request.startAsync();
|
||||
|
||||
if (Boolean.parseBoolean(request.getParameter("encode")))
|
||||
async.dispatch("/test%20servlet"+URLEncoder.encode(request.getPathInfo(),"UTF-8"));
|
||||
async.dispatch("/test%20servlet"+URIUtil.encodePath(request.getPathInfo()));
|
||||
else
|
||||
async.dispatch("/test servlet/path info"+request.getPathInfo());
|
||||
return;
|
||||
|
|
|
@ -28,6 +28,12 @@ import java.util.concurrent.Callable;
|
|||
* <li>non-blocking, the invocation will certainly <strong>not</strong> block</li>
|
||||
* <li>either, the invocation <em>may</em> block</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>
|
||||
* Static methods and are provided that allow the current thread to be tagged
|
||||
* with a {@link ThreadLocal} to indicate if it has a blocking invocation type.
|
||||
* </p>
|
||||
*
|
||||
*/
|
||||
public interface Invocable
|
||||
{
|
||||
|
@ -45,11 +51,21 @@ public interface Invocable
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Test if the current thread has been tagged as non blocking
|
||||
* @return True if the task the current thread is running has
|
||||
* indicated that it will not block.
|
||||
*/
|
||||
public static boolean isNonBlockingInvocation()
|
||||
{
|
||||
return __nonBlocking.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke a task with the calling thread, tagged to indicate
|
||||
* that it will not block.
|
||||
* @param task The task to invoke.
|
||||
*/
|
||||
public static void invokeNonBlocking(Runnable task)
|
||||
{
|
||||
// a Choice exists, so we must indicate NonBlocking
|
||||
|
@ -65,6 +81,13 @@ public interface Invocable
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke a task with the calling thread.
|
||||
* If the task is an {@link Invocable} of {@link InvocationType#EITHER}
|
||||
* then it is invoked with {@link #invokeNonBlocking(Runnable)}, to
|
||||
* indicate the type of invocation that has been assumed.
|
||||
* @param task The task to invoke.
|
||||
*/
|
||||
public static void invokePreferNonBlocking(Runnable task)
|
||||
{
|
||||
switch (getInvocationType(task))
|
||||
|
@ -81,6 +104,15 @@ public interface Invocable
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke a task with the calling thread.
|
||||
* If the task is an {@link Invocable} of {@link InvocationType#EITHER}
|
||||
* and the preferredInvocationType is not {@link InvocationType#BLOCKING}
|
||||
* then it is invoked with {@link #invokeNonBlocking(Runnable)}.
|
||||
* @param task The task to invoke.
|
||||
* @param preferredInvocationType The invocation type to use if the task
|
||||
* does not indicate a preference.
|
||||
*/
|
||||
public static void invokePreferred(Runnable task, InvocationType preferredInvocationType)
|
||||
{
|
||||
switch (getInvocationType(task))
|
||||
|
@ -99,6 +131,17 @@ public interface Invocable
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* wrap a task with the to indicate invocation type.
|
||||
* If the task is an {@link Invocable} of {@link InvocationType#EITHER}
|
||||
* and the preferredInvocationType is not {@link InvocationType#BLOCKING}
|
||||
* then it is wrapped with an invocation of {@link #invokeNonBlocking(Runnable)}.
|
||||
* otherwise the task itself is returned.
|
||||
* @param task The task to invoke.
|
||||
* @param preferredInvocationType The invocation type to use if the task
|
||||
* does not indicate a preference.
|
||||
* @return A Runnable that invokes the task in the declared or preferred type.
|
||||
*/
|
||||
public static Runnable asPreferred(Runnable task, InvocationType preferredInvocationType)
|
||||
{
|
||||
switch (getInvocationType(task))
|
||||
|
@ -116,6 +159,12 @@ public interface Invocable
|
|||
return task;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the invocation type of an Object.
|
||||
* @param o The object to check the invocation type of.
|
||||
* @return If the object is a {@link Invocable}, it is coerced and the {@link #getInvocationType()}
|
||||
* used, otherwise {@link InvocationType#BLOCKING} is returned.
|
||||
*/
|
||||
public static InvocationType getInvocationType(Object o)
|
||||
{
|
||||
if (o instanceof Invocable)
|
||||
|
@ -123,6 +172,9 @@ public interface Invocable
|
|||
return InvocationType.BLOCKING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The InvocationType of this object
|
||||
*/
|
||||
default InvocationType getInvocationType()
|
||||
{
|
||||
return InvocationType.BLOCKING;
|
||||
|
|
Loading…
Reference in New Issue