Merged branch 'jetty-9.4.x' into 'master'.

This commit is contained in:
Simone Bordet 2016-12-14 11:53:48 +01:00
commit b6c4e5b7c9
25 changed files with 654 additions and 192 deletions

View File

@ -1,5 +1,16 @@
jetty-10.0.0-SNAPSHOT
jetty-9.4.0.v20161208 - 08 December 2016
+ 1112 How config async support in jsp tag?
+ 1124 Allow configuration of WebSocket mappings from Spring
+ 1139 Support configuration of properties during --add-to-start
+ 1146 jetty.server.HttpInput deadlock
+ 1148 Support HTTP/2 HEADERS trailer
+ 1151 NPE in ClasspathPattern.match()
+ 1153 Make SessionData easier to subclass
+ 123 AbstractSessionIdManager can't atomically check for uniqueness of new
session ID
jetty-9.4.0.RC3 - 05 December 2016
+ 1051 NCSARequestLog/RolloverFileOutputStream does not roll day after DST
ends
@ -405,7 +416,7 @@ jetty-9.3.12.v20160915 - 15 September 2016
+ 832 ServerWithJNDI example uses wrong webapp
+ 841 support reset in buffering interceptors
+ 844 Implement a Thread Limit Handler
+ 845 Improve blocking IO for data rate limiting.
+ 845 Improve blocking IO for data rate limiting
+ 851 MBeanContainer no longer unregisters MBeans when "stopped"
+ 854 If container.destroy() is called, calling container.start() again should
throw an IllegalStateException

View File

@ -240,7 +240,6 @@ public class HttpClient extends ContainerLifeCycle
@Override
protected void doStop() throws Exception
{
cookieStore.removeAll();
decoderFactories.clear();
handlers.clear();

View File

@ -23,12 +23,17 @@ import java.io.InterruptedIOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -451,4 +456,139 @@ public class StreamResetTest extends AbstractTest
Assert.assertThat(((ISession)client).updateSendWindow(0), Matchers.greaterThan(0));
}
}
@Test
public void testResetAfterAsyncRequestBlockingWriteStalledByFlowControl() throws Exception
{
int windowSize = FlowControlStrategy.DEFAULT_WINDOW_SIZE;
CountDownLatch writeLatch = new CountDownLatch(1);
start(new HttpServlet()
{
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
AsyncContext asyncContext = request.startAsync();
asyncContext.start(() ->
{
try
{
// Make sure we are in async wait before writing.
Thread.sleep(1000);
response.getOutputStream().write(new byte[10 * windowSize]);
asyncContext.complete();
}
catch (IOException x)
{
writeLatch.countDown();
}
catch (Throwable x)
{
x.printStackTrace();
}
});
}
});
Deque<Object> dataQueue = new ArrayDeque<>();
AtomicLong received = new AtomicLong();
CountDownLatch latch = new CountDownLatch(1);
Session client = newClient(new Session.Listener.Adapter());
MetaData.Request request = newRequest("GET", new HttpFields());
HeadersFrame frame = new HeadersFrame(request, null, true);
FuturePromise<Stream> promise = new FuturePromise<>();
client.newStream(frame, promise, new Stream.Listener.Adapter()
{
@Override
public void onData(Stream stream, DataFrame frame, Callback callback)
{
dataQueue.offer(frame);
dataQueue.offer(callback);
// Do not consume the data yet.
if (received.addAndGet(frame.getData().remaining()) == windowSize)
latch.countDown();
}
});
Stream stream = promise.get(5, TimeUnit.SECONDS);
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
// Reset and consume.
stream.reset(new ResetFrame(stream.getId(), ErrorCode.CANCEL_STREAM_ERROR.code), Callback.NOOP);
dataQueue.stream()
.filter(item -> item instanceof Callback)
.map(item -> (Callback)item)
.forEach(Callback::succeeded);
Assert.assertTrue(writeLatch.await(5, TimeUnit.SECONDS));
}
@Test
public void testResetAfterAsyncRequestAsyncWriteStalledByFlowControl() throws Exception
{
int windowSize = FlowControlStrategy.DEFAULT_WINDOW_SIZE;
CountDownLatch writeLatch = new CountDownLatch(1);
start(new HttpServlet()
{
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
AsyncContext asyncContext = request.startAsync();
ServletOutputStream output = response.getOutputStream();
output.setWriteListener(new WriteListener()
{
private boolean written;
@Override
public void onWritePossible() throws IOException
{
while (output.isReady())
{
if (written)
{
asyncContext.complete();
break;
}
else
{
output.write(new byte[10 * windowSize]);
written = true;
}
}
}
@Override
public void onError(Throwable t)
{
writeLatch.countDown();
}
});
}
});
Deque<Callback> dataQueue = new ArrayDeque<>();
AtomicLong received = new AtomicLong();
CountDownLatch latch = new CountDownLatch(1);
Session client = newClient(new Session.Listener.Adapter());
MetaData.Request request = newRequest("GET", new HttpFields());
HeadersFrame frame = new HeadersFrame(request, null, true);
FuturePromise<Stream> promise = new FuturePromise<>();
client.newStream(frame, promise, new Stream.Listener.Adapter()
{
@Override
public void onData(Stream stream, DataFrame frame, Callback callback)
{
dataQueue.offer(callback);
// Do not consume the data yet.
if (received.addAndGet(frame.getData().remaining()) == windowSize)
latch.countDown();
}
});
Stream stream = promise.get(5, TimeUnit.SECONDS);
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
// Reset and consume.
stream.reset(new ResetFrame(stream.getId(), ErrorCode.CANCEL_STREAM_ERROR.code), Callback.NOOP);
dataQueue.forEach(Callback::succeeded);
Assert.assertTrue(writeLatch.await(5, TimeUnit.SECONDS));
}
}

View File

@ -86,7 +86,7 @@ public class HTTP2Stream extends IdleTimeout implements IStream, Callback
@Override
public void headers(HeadersFrame frame, Callback callback)
{
if (!checkWrite(callback))
if (!startWrite(callback))
return;
session.frames(this, this, frame, Frame.EMPTY_ARRAY);
}
@ -100,7 +100,7 @@ public class HTTP2Stream extends IdleTimeout implements IStream, Callback
@Override
public void data(DataFrame frame, Callback callback)
{
if (!checkWrite(callback))
if (!startWrite(callback))
return;
session.data(this, this, frame);
}
@ -114,7 +114,7 @@ public class HTTP2Stream extends IdleTimeout implements IStream, Callback
session.frames(this, callback, frame, Frame.EMPTY_ARRAY);
}
private boolean checkWrite(Callback callback)
private boolean startWrite(Callback callback)
{
if (writing.compareAndSet(null, callback))
return true;
@ -381,17 +381,24 @@ public class HTTP2Stream extends IdleTimeout implements IStream, Callback
@Override
public void succeeded()
{
Callback callback = writing.getAndSet(null);
Callback callback = endWrite();
if (callback != null)
callback.succeeded();
}
@Override
public void failed(Throwable x)
{
Callback callback = writing.getAndSet(null);
Callback callback = endWrite();
if (callback != null)
callback.failed(x);
}
private Callback endWrite()
{
return writing.getAndSet(null);
}
private void notifyData(Stream stream, DataFrame frame, Callback callback)
{
final Listener listener = this.listener;

View File

@ -378,7 +378,7 @@ public class HpackContext
_offset = (_offset+1)%_entries.length;
_size--;
if (LOG.isDebugEnabled())
LOG.debug(String.format("HdrTbl[%x] evict %s",hashCode(),entry));
LOG.debug(String.format("HdrTbl[%x] evict %s",HpackContext.this.hashCode(),entry));
_dynamicTableSizeInBytes-=entry.getSize();
entry._slot=-1;
_fieldMap.remove(entry.getHttpField());
@ -388,7 +388,7 @@ public class HpackContext
}
if (LOG.isDebugEnabled())
LOG.debug(String.format("HdrTbl[%x] entries=%d, size=%d, max=%d",hashCode(),_dynamicTable.size(),_dynamicTableSizeInBytes,_maxDynamicTableSizeInBytes));
LOG.debug(String.format("HdrTbl[%x] entries=%d, size=%d, max=%d",HpackContext.this.hashCode(),_dynamicTable.size(),_dynamicTableSizeInBytes,_maxDynamicTableSizeInBytes));
}
}

View File

@ -296,6 +296,7 @@ public class HttpChannelOverHTTP2 extends HttpChannel
public void onFailure(Throwable failure)
{
getHttpTransport().onStreamFailure(failure);
if (onEarlyEOF())
handle();
else

View File

@ -197,6 +197,11 @@ public class HttpTransportOverHTTP2 implements HttpTransport
stream.data(frame, callback);
}
public void onStreamFailure(Throwable failure)
{
transportCallback.failed(failure);
}
public boolean onStreamTimeout(Throwable failure)
{
return transportCallback.onIdleTimeout(failure);
@ -264,9 +269,10 @@ public class HttpTransportOverHTTP2 implements HttpTransport
synchronized (this)
{
commit = this.commit;
if (state != State.TIMEOUT)
if (state == State.WRITING)
{
callback = this.callback;
this.callback = null;
this.state = State.IDLE;
}
}
@ -284,9 +290,10 @@ public class HttpTransportOverHTTP2 implements HttpTransport
synchronized (this)
{
commit = this.commit;
if (state != State.TIMEOUT)
if (state == State.WRITING)
{
callback = this.callback;
this.callback = null;
this.state = State.FAILED;
}
}
@ -317,6 +324,7 @@ public class HttpTransportOverHTTP2 implements HttpTransport
if (result)
{
callback = this.callback;
this.callback = null;
this.state = State.TIMEOUT;
}
}

View File

@ -36,6 +36,7 @@
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@ -65,14 +65,12 @@
<version>${url.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.tinybundles</groupId>
<artifactId>tinybundles</artifactId>
<version>2.1.1</version>
</dependency>
<!-- OSGi R4 frameworks -->
<!--
<dependency>
@ -153,7 +151,6 @@
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jta_1.1_spec</artifactId>

View File

@ -30,7 +30,6 @@
</instructions>
</configuration>
</plugin>
<!-- always include the sources to be able to prepare the eclipse-jetty-SDK feature
with a snapshot. -->
<plugin>

View File

@ -345,7 +345,8 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
{
if (_response.isCommitted())
{
LOG.warn("Error Dispatch already committed");
if (LOG.isDebugEnabled())
LOG.debug("Could not perform Error Dispatch because the response is already committed, aborting");
_transport.abort((Throwable)_request.getAttribute(ERROR_EXCEPTION));
}
else

View File

@ -106,8 +106,9 @@ public interface SessionIdManager extends LifeCycle
* @param oldId the old plain session id
* @param oldExtendedId the old fully qualified id
* @param request the request containing the session
* @return the new session id
*/
public void renewSessionId(String oldId, String oldExtendedId, HttpServletRequest request);
public String renewSessionId(String oldId, String oldExtendedId, HttpServletRequest request);
/* ------------------------------------------------------------ */
/**

View File

@ -483,7 +483,7 @@ public class DefaultSessionIdManager extends ContainerLifeCycle implements Sessi
* @see org.eclipse.jetty.server.SessionIdManager#renewSessionId(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest)
*/
@Override
public void renewSessionId (String oldClusterId, String oldNodeId, HttpServletRequest request)
public String renewSessionId (String oldClusterId, String oldNodeId, HttpServletRequest request)
{
//generate a new id
String newClusterId = newSessionId(request.hashCode());
@ -495,6 +495,8 @@ public class DefaultSessionIdManager extends ContainerLifeCycle implements Sessi
{
manager.renewSessionId(oldClusterId, oldNodeId, newClusterId, getExtendedId(newClusterId, request));
}
return newClusterId;
}

View File

@ -810,7 +810,13 @@ public class Session implements SessionHandler.SessionIf
extendedId = getExtendedId();
}
_handler._sessionIdManager.renewSessionId(id, extendedId, request);
String newId = _handler._sessionIdManager.renewSessionId(id, extendedId, request);
try (Lock lock = _lock.lockIfNotHeld())
{
checkValidForWrite();
_sessionData.setId(newId);
setExtendedId(_handler._sessionIdManager.getExtendedId(newId, request));
}
setIdChanged(true);
}

View File

@ -148,9 +148,9 @@ public class SessionCookieTest
}
@Override
public void renewSessionId(String oldClusterId, String oldNodeId, HttpServletRequest request)
public String renewSessionId(String oldClusterId, String oldNodeId, HttpServletRequest request)
{
// TODO Auto-generated method stub
return "";
}
}

View File

@ -109,7 +109,7 @@ public class Main
}
private BaseHome baseHome;
private StartArgs startupArgs;
private StartArgs jsvcStartArgs;
public Main() throws IOException
{
@ -486,7 +486,7 @@ public class Main
catch (Throwable e)
{
e.printStackTrace();
usageExit(e,ERR_INVOKE_MAIN,startupArgs.isTestingModeEnabled());
usageExit(e,ERR_INVOKE_MAIN,args.isTestingModeEnabled());
}
}
@ -573,11 +573,11 @@ public class Main
}
catch (ConnectException e)
{
usageExit(e,ERR_NOT_STOPPED,startupArgs.isTestingModeEnabled());
usageExit(e,ERR_NOT_STOPPED,jsvcStartArgs.isTestingModeEnabled());
}
catch (Exception e)
{
usageExit(e,ERR_UNKNOWN,startupArgs.isTestingModeEnabled());
usageExit(e,ERR_UNKNOWN,jsvcStartArgs.isTestingModeEnabled());
}
}
@ -630,29 +630,35 @@ public class Main
{
try
{
startupArgs = processCommandLine(args);
jsvcStartArgs = processCommandLine(args);
}
catch (UsageException e)
{
StartLog.error(e.getMessage());
usageExit(e.getCause(),e.getExitCode(),startupArgs.isTestingModeEnabled());
usageExit(e.getCause(),e.getExitCode(),false);
}
catch (Throwable e)
{
usageExit(e,UsageException.ERR_UNKNOWN,startupArgs.isTestingModeEnabled());
usageExit(e,UsageException.ERR_UNKNOWN,false);
}
}
// ------------------------------------------------------------
// implement Apache commons daemon (jsvc) lifecycle methods (init, start, stop, destroy)
public void start() throws Exception
{
start(startupArgs);
start(jsvcStartArgs);
}
// ------------------------------------------------------------
// implement Apache commons daemon (jsvc) lifecycle methods (init, start, stop, destroy)
public void stop() throws Exception
{
doStop(startupArgs);
doStop(jsvcStartArgs);
}
// ------------------------------------------------------------
// implement Apache commons daemon (jsvc) lifecycle methods (init, start, stop, destroy)
public void destroy()
{
}

View File

@ -43,6 +43,5 @@
<artifactId>jetty-test-helper</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,284 @@
//
// ========================================================================
// 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.server.session;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
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 javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionIdListener;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.webapp.WebAppContext;
import org.junit.Test;
/**
* NullCacheRenewSessionTest
*
* Test that changes the session id during a request
* on a SessionHandler that does not use session
* caching.
*/
public class NullCacheRenewSessionTest
{
/**
* MemorySessionDataStore
*
* Make a fake session data store that creates a new SessionData object
* every time load(id) is called.
*/
public static class MemorySessionDataStore extends AbstractSessionDataStore
{
public Map<String,SessionData> _map = new HashMap<>();
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating()
*/
@Override
public boolean isPassivating()
{
return false;
}
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String)
*/
@Override
public boolean exists(String id) throws Exception
{
return _map.containsKey(id);
}
/**
* @see org.eclipse.jetty.server.session.SessionDataMap#load(java.lang.String)
*/
@Override
public SessionData load(String id) throws Exception
{
SessionData sd = _map.get(id);
if (sd == null)
return null;
SessionData nsd = new SessionData(id,"","",System.currentTimeMillis(),System.currentTimeMillis(), System.currentTimeMillis(),0 );
nsd.copy(sd);
return nsd;
}
/**
* @see org.eclipse.jetty.server.session.SessionDataMap#delete(java.lang.String)
*/
@Override
public boolean delete(String id) throws Exception
{
return (_map.remove(id) != null);
}
/**
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long)
*/
@Override
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
{
_map.put(id, data);
}
/**
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doGetExpired(java.util.Set)
*/
@Override
public Set<String> doGetExpired(Set<String> candidates)
{
return Collections.emptySet();
}
}
public static class NullCacheServer extends AbstractTestServer
{
/**
* @param port
* @param maxInactivePeriod
* @param scavengePeriod
* @param evictionPolicy
* @throws Exception
*/
public NullCacheServer(int port, int maxInactivePeriod, int scavengePeriod, int evictionPolicy) throws Exception
{
super(port, maxInactivePeriod, scavengePeriod, evictionPolicy);
}
/**
* @see org.eclipse.jetty.server.session.AbstractTestServer#newSessionHandler()
*/
@Override
public SessionHandler newSessionHandler()
{
SessionHandler handler = new TestSessionHandler();
SessionCache ss = new NullSessionCache(handler);
handler.setSessionCache(ss);
ss.setSessionDataStore(new MemorySessionDataStore());
return handler;
}
}
@Test
/**
* @throws Exception
*/
public void testSessionRenewal() throws Exception
{
String contextPath = "";
String servletMapping = "/server";
int maxInactive = 1;
int scavengePeriod = 3;
AbstractTestServer server = new NullCacheServer (0, maxInactive, scavengePeriod, SessionCache.NEVER_EVICT);
WebAppContext context = server.addWebAppContext(".", contextPath);
context.setParentLoaderPriority(true);
context.addServlet(TestServlet.class, servletMapping);
TestHttpSessionIdListener testListener = new TestHttpSessionIdListener();
context.addEventListener(testListener);
HttpClient client = new HttpClient();
try
{
server.start();
int port=server.getPort();
client.start();
//make a request to create a session
ContentResponse response = client.GET("http://localhost:" + port + contextPath + servletMapping + "?action=create");
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
String sessionCookie = response.getHeaders().get("Set-Cookie");
assertTrue(sessionCookie != null);
assertFalse(testListener.isCalled());
//make a request to change the sessionid
Request request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=renew");
request.header("Cookie", sessionCookie);
ContentResponse renewResponse = request.send();
assertEquals(HttpServletResponse.SC_OK,renewResponse.getStatus());
String renewSessionCookie = renewResponse.getHeaders().get("Set-Cookie");
assertNotNull(renewSessionCookie);
assertNotSame(sessionCookie, renewSessionCookie);
assertTrue(testListener.isCalled());
}
finally
{
client.stop();
server.stop();
}
}
public static class TestHttpSessionIdListener implements HttpSessionIdListener
{
boolean called = false;
@Override
public void sessionIdChanged(HttpSessionEvent event, String oldSessionId)
{
assertNotNull(event.getSession());
assertNotSame(oldSessionId, event.getSession().getId());
called = true;
}
public boolean isCalled()
{
return called;
}
}
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 ("renew".equals(action))
{
HttpSession beforeSession = request.getSession(false);
assertTrue(beforeSession != null);
String beforeSessionId = beforeSession.getId();
((Session)beforeSession).renewId(request);
HttpSession afterSession = request.getSession(false);
assertTrue(afterSession != null);
String afterSessionId = afterSession.getId();
assertTrue(beforeSession==afterSession); //same object
assertFalse(beforeSessionId.equals(afterSessionId)); //different id
SessionHandler sessionManager = ((Session)afterSession).getSessionHandler();
DefaultSessionIdManager sessionIdManager = (DefaultSessionIdManager)sessionManager.getSessionIdManager();
assertTrue(sessionIdManager.isIdInUse(afterSessionId)); //new session id should be in use
assertFalse(sessionIdManager.isIdInUse(beforeSessionId));
HttpSession session = sessionManager.getSession(afterSessionId);
assertNotNull(session);
session = sessionManager.getSession(beforeSessionId);
assertNull(session);
if (((Session)afterSession).isIdChanged())
{
((org.eclipse.jetty.server.Response)response).addCookie(sessionManager.getSessionCookie(afterSession, request.getContextPath(), request.isSecure()));
}
}
}
}
}