Merge branch 'master' into jetty-9.4.x-Feature
This commit is contained in:
commit
36b5687329
|
@ -26,6 +26,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||
|
||||
import org.eclipse.jetty.client.api.Authentication;
|
||||
import org.eclipse.jetty.client.api.AuthenticationStore;
|
||||
import org.eclipse.jetty.client.util.AbstractAuthentication;
|
||||
|
||||
public class HttpAuthenticationStore implements AuthenticationStore
|
||||
{
|
||||
|
@ -85,7 +86,7 @@ public class HttpAuthenticationStore implements AuthenticationStore
|
|||
// TODO: I should match the longest URI
|
||||
for (Map.Entry<URI, Authentication.Result> entry : results.entrySet())
|
||||
{
|
||||
if (uri.toString().startsWith(entry.getKey().toString()))
|
||||
if (AbstractAuthentication.matchesURI(entry.getKey(), uri))
|
||||
return entry.getValue();
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -1035,7 +1035,7 @@ public class HttpClient extends ContainerLifeCycle
|
|||
return host;
|
||||
}
|
||||
|
||||
protected int normalizePort(String scheme, int port)
|
||||
public static int normalizePort(String scheme, int port)
|
||||
{
|
||||
if (port > 0)
|
||||
return port;
|
||||
|
@ -1053,7 +1053,7 @@ public class HttpClient extends ContainerLifeCycle
|
|||
return port == 80;
|
||||
}
|
||||
|
||||
public boolean isSchemeSecure(String scheme)
|
||||
static boolean isSchemeSecure(String scheme)
|
||||
{
|
||||
return HttpScheme.HTTPS.is(scheme) || HttpScheme.WSS.is(scheme);
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ public abstract class HttpDestination extends ContainerLifeCycle implements Dest
|
|||
|
||||
public boolean isSecure()
|
||||
{
|
||||
return client.isSchemeSecure(getScheme());
|
||||
return HttpClient.isSchemeSecure(getScheme());
|
||||
}
|
||||
|
||||
public HttpClient getHttpClient()
|
||||
|
|
|
@ -88,7 +88,7 @@ public class HttpRequest implements Request
|
|||
this.conversation = conversation;
|
||||
scheme = uri.getScheme();
|
||||
host = client.normalizeHost(uri.getHost());
|
||||
port = client.normalizePort(scheme, uri.getPort());
|
||||
port = HttpClient.normalizePort(scheme, uri.getPort());
|
||||
path = uri.getRawPath();
|
||||
query = uri.getRawQuery();
|
||||
extractParams(query);
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// 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.client.util;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.api.Authentication;
|
||||
|
||||
public abstract class AbstractAuthentication implements Authentication
|
||||
{
|
||||
private final URI uri;
|
||||
private final String realm;
|
||||
|
||||
public AbstractAuthentication(URI uri, String realm)
|
||||
{
|
||||
this.uri = uri;
|
||||
this.realm = realm;
|
||||
}
|
||||
|
||||
public abstract String getType();
|
||||
|
||||
public URI getURI()
|
||||
{
|
||||
return uri;
|
||||
}
|
||||
|
||||
public String getRealm()
|
||||
{
|
||||
return realm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(String type, URI uri, String realm)
|
||||
{
|
||||
if (!getType().equalsIgnoreCase(type))
|
||||
return false;
|
||||
|
||||
if (!this.realm.equals(realm))
|
||||
return false;
|
||||
|
||||
return matchesURI(this.uri, uri);
|
||||
}
|
||||
|
||||
public static boolean matchesURI(URI uri1, URI uri2)
|
||||
{
|
||||
String scheme = uri1.getScheme();
|
||||
if (uri1.getScheme().equalsIgnoreCase(scheme))
|
||||
{
|
||||
if (uri1.getHost().equalsIgnoreCase(uri2.getHost()))
|
||||
{
|
||||
// Handle default HTTP ports.
|
||||
int thisPort = HttpClient.normalizePort(scheme, uri1.getPort());
|
||||
int thatPort = HttpClient.normalizePort(scheme, uri2.getPort());
|
||||
if (thisPort == thatPort)
|
||||
{
|
||||
// Use decoded URI paths.
|
||||
return uri2.getPath().startsWith(uri1.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -22,7 +22,6 @@ import java.net.URI;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.api.Authentication;
|
||||
import org.eclipse.jetty.client.api.AuthenticationStore;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
|
@ -37,10 +36,8 @@ import org.eclipse.jetty.util.B64Code;
|
|||
* {@link AuthenticationStore} retrieved from the {@link HttpClient}
|
||||
* via {@link HttpClient#getAuthenticationStore()}.
|
||||
*/
|
||||
public class BasicAuthentication implements Authentication
|
||||
public class BasicAuthentication extends AbstractAuthentication
|
||||
{
|
||||
private final URI uri;
|
||||
private final String realm;
|
||||
private final String user;
|
||||
private final String password;
|
||||
|
||||
|
@ -52,48 +49,39 @@ public class BasicAuthentication implements Authentication
|
|||
*/
|
||||
public BasicAuthentication(URI uri, String realm, String user, String password)
|
||||
{
|
||||
this.uri = uri;
|
||||
this.realm = realm;
|
||||
super(uri, realm);
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(String type, URI uri, String realm)
|
||||
public String getType()
|
||||
{
|
||||
if (!"basic".equalsIgnoreCase(type))
|
||||
return false;
|
||||
|
||||
if (!uri.toString().startsWith(this.uri.toString()))
|
||||
return false;
|
||||
|
||||
return this.realm.equals(realm);
|
||||
return "Basic";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result authenticate(Request request, ContentResponse response, HeaderInfo headerInfo, Attributes context)
|
||||
{
|
||||
String value = "Basic " + B64Code.encode(user + ":" + password, StandardCharsets.ISO_8859_1);
|
||||
return new BasicResult(headerInfo.getHeader(), uri, value);
|
||||
return new BasicResult(headerInfo.getHeader(), value);
|
||||
}
|
||||
|
||||
private static class BasicResult implements Result
|
||||
private class BasicResult implements Result
|
||||
{
|
||||
private final HttpHeader header;
|
||||
private final URI uri;
|
||||
private final String value;
|
||||
|
||||
public BasicResult(HttpHeader header, URI uri, String value)
|
||||
public BasicResult(HttpHeader header, String value)
|
||||
{
|
||||
this.header = header;
|
||||
this.uri = uri;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getURI()
|
||||
{
|
||||
return uri;
|
||||
return BasicAuthentication.this.getURI();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -105,7 +93,7 @@ public class BasicAuthentication implements Authentication
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("Basic authentication result for %s", uri);
|
||||
return String.format("Basic authentication result for %s", getURI());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
@ -34,7 +33,6 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.api.Authentication;
|
||||
import org.eclipse.jetty.client.api.AuthenticationStore;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
|
@ -50,12 +48,10 @@ import org.eclipse.jetty.util.TypeUtil;
|
|||
* {@link AuthenticationStore} retrieved from the {@link HttpClient}
|
||||
* via {@link HttpClient#getAuthenticationStore()}.
|
||||
*/
|
||||
public class DigestAuthentication implements Authentication
|
||||
public class DigestAuthentication extends AbstractAuthentication
|
||||
{
|
||||
private static final Pattern PARAM_PATTERN = Pattern.compile("([^=]+)=(.*)");
|
||||
|
||||
private final URI uri;
|
||||
private final String realm;
|
||||
private final String user;
|
||||
private final String password;
|
||||
|
||||
|
@ -67,22 +63,15 @@ public class DigestAuthentication implements Authentication
|
|||
*/
|
||||
public DigestAuthentication(URI uri, String realm, String user, String password)
|
||||
{
|
||||
this.uri = uri;
|
||||
this.realm = realm;
|
||||
super(uri, realm);
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(String type, URI uri, String realm)
|
||||
public String getType()
|
||||
{
|
||||
if (!"digest".equalsIgnoreCase(type))
|
||||
return false;
|
||||
|
||||
if (!uri.toString().startsWith(this.uri.toString()))
|
||||
return false;
|
||||
|
||||
return this.realm.equals(realm);
|
||||
return "Digest";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -110,7 +99,7 @@ public class DigestAuthentication implements Authentication
|
|||
clientQOP = "auth-int";
|
||||
}
|
||||
|
||||
return new DigestResult(headerInfo.getHeader(), uri, response.getContent(), realm, user, password, algorithm, nonce, clientQOP, opaque);
|
||||
return new DigestResult(headerInfo.getHeader(), response.getContent(), getRealm(), user, password, algorithm, nonce, clientQOP, opaque);
|
||||
}
|
||||
|
||||
private Map<String, String> parseParameters(String wwwAuthenticate)
|
||||
|
@ -181,7 +170,6 @@ public class DigestAuthentication implements Authentication
|
|||
{
|
||||
private final AtomicInteger nonceCount = new AtomicInteger();
|
||||
private final HttpHeader header;
|
||||
private final URI uri;
|
||||
private final byte[] content;
|
||||
private final String realm;
|
||||
private final String user;
|
||||
|
@ -191,10 +179,9 @@ public class DigestAuthentication implements Authentication
|
|||
private final String qop;
|
||||
private final String opaque;
|
||||
|
||||
public DigestResult(HttpHeader header, URI uri, byte[] content, String realm, String user, String password, String algorithm, String nonce, String qop, String opaque)
|
||||
public DigestResult(HttpHeader header, byte[] content, String realm, String user, String password, String algorithm, String nonce, String qop, String opaque)
|
||||
{
|
||||
this.header = header;
|
||||
this.uri = uri;
|
||||
this.content = content;
|
||||
this.realm = realm;
|
||||
this.user = user;
|
||||
|
@ -208,7 +195,7 @@ public class DigestAuthentication implements Authentication
|
|||
@Override
|
||||
public URI getURI()
|
||||
{
|
||||
return uri;
|
||||
return DigestAuthentication.this.getURI();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -125,7 +125,7 @@ public class HostnameVerificationTest
|
|||
if (cause instanceof SSLHandshakeException)
|
||||
Assert.assertThat(cause.getCause().getCause(), Matchers.instanceOf(CertificateException.class));
|
||||
else
|
||||
Assert.assertThat(cause.getCause(), Matchers.instanceOf(ClosedChannelException.class));
|
||||
Assert.assertThat(cause, Matchers.instanceOf(ClosedChannelException.class));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// 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.client;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.client.api.Authentication;
|
||||
import org.eclipse.jetty.client.api.AuthenticationStore;
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
import org.eclipse.jetty.client.util.BasicAuthentication;
|
||||
import org.eclipse.jetty.client.util.DigestAuthentication;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HttpAuthenticationStoreTest
|
||||
{
|
||||
@Test
|
||||
public void testFindAuthenticationWithDefaultHTTPPort() throws Exception
|
||||
{
|
||||
AuthenticationStore store = new HttpAuthenticationStore();
|
||||
|
||||
URI uri1 = URI.create("http://host:80");
|
||||
URI uri2 = URI.create("http://host");
|
||||
String realm = "realm";
|
||||
store.addAuthentication(new BasicAuthentication(uri1, realm, "user", "password"));
|
||||
|
||||
Authentication result = store.findAuthentication("Basic", uri2, realm);
|
||||
Assert.assertNotNull(result);
|
||||
|
||||
store.clearAuthentications();
|
||||
|
||||
// Flip the URIs.
|
||||
uri1 = URI.create("https://server/");
|
||||
uri2 = URI.create("https://server:443/path");
|
||||
store.addAuthentication(new DigestAuthentication(uri1, realm, "user", "password"));
|
||||
result = store.findAuthentication("Digest", uri2, realm);
|
||||
Assert.assertNotNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAuthenticationResultWithDefaultHTTPPort() throws Exception
|
||||
{
|
||||
AuthenticationStore store = new HttpAuthenticationStore();
|
||||
|
||||
store.addAuthenticationResult(new Authentication.Result()
|
||||
{
|
||||
@Override
|
||||
public URI getURI()
|
||||
{
|
||||
return URI.create("http://host:80");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Request request)
|
||||
{
|
||||
}
|
||||
});
|
||||
|
||||
URI uri2 = URI.create("http://host");
|
||||
Authentication.Result result = store.findAuthenticationResult(uri2);
|
||||
Assert.assertNotNull(result);
|
||||
|
||||
store.clearAuthenticationResults();
|
||||
|
||||
// Flip the URIs.
|
||||
store.addAuthenticationResult(new Authentication.Result()
|
||||
{
|
||||
@Override
|
||||
public URI getURI()
|
||||
{
|
||||
return URI.create("https://server/");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Request request)
|
||||
{
|
||||
}
|
||||
});
|
||||
|
||||
uri2 = URI.create("https://server:443/path");
|
||||
result = store.findAuthenticationResult(uri2);
|
||||
Assert.assertNotNull(result);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,183 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// 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.client;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.http.HttpScheme;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HttpClientTLSTest
|
||||
{
|
||||
private Server server;
|
||||
private ServerConnector connector;
|
||||
private HttpClient client;
|
||||
|
||||
private void startServer(SslContextFactory sslContextFactory, Handler handler) throws Exception
|
||||
{
|
||||
QueuedThreadPool serverThreads = new QueuedThreadPool();
|
||||
serverThreads.setName("server");
|
||||
server = new Server(serverThreads);
|
||||
|
||||
connector = new ServerConnector(server, sslContextFactory);
|
||||
server.addConnector(connector);
|
||||
|
||||
server.setHandler(handler);
|
||||
server.start();
|
||||
}
|
||||
|
||||
private void startClient(SslContextFactory sslContextFactory) throws Exception
|
||||
{
|
||||
QueuedThreadPool clientThreads = new QueuedThreadPool();
|
||||
clientThreads.setName("client");
|
||||
client = new HttpClient(sslContextFactory);
|
||||
client.setExecutor(clientThreads);
|
||||
client.start();
|
||||
}
|
||||
|
||||
private SslContextFactory createSslContextFactory()
|
||||
{
|
||||
SslContextFactory sslContextFactory = new SslContextFactory();
|
||||
sslContextFactory.setEndpointIdentificationAlgorithm("");
|
||||
sslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
|
||||
sslContextFactory.setKeyStorePassword("storepwd");
|
||||
sslContextFactory.setTrustStorePath("src/test/resources/truststore.jks");
|
||||
sslContextFactory.setTrustStorePassword("storepwd");
|
||||
return sslContextFactory;
|
||||
}
|
||||
|
||||
@After
|
||||
public void dispose() throws Exception
|
||||
{
|
||||
if (client != null)
|
||||
client.stop();
|
||||
if (server != null)
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoCommonTLSProtocol() throws Exception
|
||||
{
|
||||
SslContextFactory serverTLSFactory = createSslContextFactory();
|
||||
serverTLSFactory.setIncludeProtocols("TLSv1.2");
|
||||
startServer(serverTLSFactory, new EmptyServerHandler());
|
||||
|
||||
SslContextFactory clientTLSFactory = createSslContextFactory();
|
||||
clientTLSFactory.setIncludeProtocols("TLSv1.1");
|
||||
startClient(clientTLSFactory);
|
||||
|
||||
try
|
||||
{
|
||||
client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(HttpScheme.HTTPS.asString())
|
||||
.timeout(5, TimeUnit.SECONDS)
|
||||
.send();
|
||||
Assert.fail();
|
||||
}
|
||||
catch (ExecutionException x)
|
||||
{
|
||||
// Expected.
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoCommonTLSCiphers() throws Exception
|
||||
{
|
||||
SslContextFactory serverTLSFactory = createSslContextFactory();
|
||||
serverTLSFactory.setIncludeCipherSuites("TLS_RSA_WITH_AES_128_CBC_SHA");
|
||||
startServer(serverTLSFactory, new EmptyServerHandler());
|
||||
|
||||
SslContextFactory clientTLSFactory = createSslContextFactory();
|
||||
clientTLSFactory.setExcludeCipherSuites(".*_SHA$");
|
||||
startClient(clientTLSFactory);
|
||||
|
||||
try
|
||||
{
|
||||
client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(HttpScheme.HTTPS.asString())
|
||||
.timeout(5, TimeUnit.SECONDS)
|
||||
.send();
|
||||
Assert.fail();
|
||||
}
|
||||
catch (ExecutionException x)
|
||||
{
|
||||
// Expected.
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMismatchBetweenTLSProtocolAndTLSCiphersOnServer() throws Exception
|
||||
{
|
||||
SslContextFactory serverTLSFactory = createSslContextFactory();
|
||||
// TLS 1.1 protocol, but only TLS 1.2 ciphers.
|
||||
serverTLSFactory.setIncludeProtocols("TLSv1.1");
|
||||
serverTLSFactory.setIncludeCipherSuites("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256");
|
||||
startServer(serverTLSFactory, new EmptyServerHandler());
|
||||
|
||||
SslContextFactory clientTLSFactory = createSslContextFactory();
|
||||
startClient(clientTLSFactory);
|
||||
|
||||
try
|
||||
{
|
||||
client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(HttpScheme.HTTPS.asString())
|
||||
.timeout(5, TimeUnit.SECONDS)
|
||||
.send();
|
||||
Assert.fail();
|
||||
}
|
||||
catch (ExecutionException x)
|
||||
{
|
||||
// Expected.
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMismatchBetweenTLSProtocolAndTLSCiphersOnClient() throws Exception
|
||||
{
|
||||
SslContextFactory serverTLSFactory = createSslContextFactory();
|
||||
startServer(serverTLSFactory, new EmptyServerHandler());
|
||||
|
||||
SslContextFactory clientTLSFactory = createSslContextFactory();
|
||||
// TLS 1.1 protocol, but only TLS 1.2 ciphers.
|
||||
clientTLSFactory.setIncludeProtocols("TLSv1.1");
|
||||
clientTLSFactory.setIncludeCipherSuites("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256");
|
||||
startClient(clientTLSFactory);
|
||||
|
||||
try
|
||||
{
|
||||
client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(HttpScheme.HTTPS.asString())
|
||||
.timeout(5, TimeUnit.SECONDS)
|
||||
.send();
|
||||
Assert.fail();
|
||||
}
|
||||
catch (ExecutionException x)
|
||||
{
|
||||
// Expected.
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.client.ssl;
|
||||
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
|
@ -1862,8 +1860,11 @@ public class SslBytesServerTest extends SslBytesTest
|
|||
// Instead of passing the Client Hello, we simulate plain text was passed in
|
||||
proxy.flushToServer(0, "GET / HTTP/1.1\r\n".getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
// We expect that the server closes the connection immediately
|
||||
// We expect that the server sends an alert message and closes.
|
||||
TLSRecord record = proxy.readFromServer();
|
||||
Assert.assertNotNull(record);
|
||||
Assert.assertEquals(TLSRecord.Type.ALERT, record.getType());
|
||||
record = proxy.readFromServer();
|
||||
Assert.assertNull(String.valueOf(record), record);
|
||||
|
||||
// Check that we did not spin
|
||||
|
@ -1982,6 +1983,6 @@ public class SslBytesServerTest extends SslBytesTest
|
|||
Assert.assertEquals(record.getType(),Type.ALERT);
|
||||
record = proxy.readFromServer();
|
||||
}
|
||||
Assert.assertThat(record,nullValue());
|
||||
Assert.assertThat(record, Matchers.nullValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import java.net.Socket;
|
|||
import java.net.SocketTimeoutException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
|
@ -49,16 +48,16 @@ public abstract class SslBytesTest
|
|||
|
||||
public static class TLSRecord
|
||||
{
|
||||
private final SslBytesServerTest.TLSRecord.Type type;
|
||||
private final Type type;
|
||||
private final byte[] bytes;
|
||||
|
||||
public TLSRecord(SslBytesServerTest.TLSRecord.Type type, byte[] bytes)
|
||||
public TLSRecord(Type type, byte[] bytes)
|
||||
{
|
||||
this.type = type;
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public SslBytesServerTest.TLSRecord.Type getType()
|
||||
public Type getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
@ -80,15 +79,15 @@ public abstract class SslBytesTest
|
|||
|
||||
private int code;
|
||||
|
||||
private Type(int code)
|
||||
Type(int code)
|
||||
{
|
||||
this.code = code;
|
||||
SslBytesServerTest.TLSRecord.Type.Mapper.codes.put(this.code, this);
|
||||
Mapper.codes.put(this.code, this);
|
||||
}
|
||||
|
||||
public static SslBytesServerTest.TLSRecord.Type from(int code)
|
||||
public static Type from(int code)
|
||||
{
|
||||
SslBytesServerTest.TLSRecord.Type result = SslBytesServerTest.TLSRecord.Type.Mapper.codes.get(code);
|
||||
Type result = Mapper.codes.get(code);
|
||||
if (result == null)
|
||||
throw new IllegalArgumentException("Invalid TLSRecord.Type " + code);
|
||||
return result;
|
||||
|
@ -96,7 +95,7 @@ public abstract class SslBytesTest
|
|||
|
||||
private static class Mapper
|
||||
{
|
||||
private static final Map<Integer, SslBytesServerTest.TLSRecord.Type> codes = new HashMap<>();
|
||||
private static final Map<Integer, Type> codes = new HashMap<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -218,7 +217,7 @@ public abstract class SslBytesTest
|
|||
}
|
||||
}
|
||||
|
||||
private TLSRecord read(SslBytesServerTest.TLSRecord.Type type, InputStream input, byte[] bytes, int offset, int length) throws IOException
|
||||
private TLSRecord read(TLSRecord.Type type, InputStream input, byte[] bytes, int offset, int length) throws IOException
|
||||
{
|
||||
while (length > 0)
|
||||
{
|
||||
|
@ -291,13 +290,11 @@ public abstract class SslBytesTest
|
|||
}
|
||||
}
|
||||
|
||||
public SslBytesServerTest.SimpleProxy.AutomaticFlow startAutomaticFlow() throws InterruptedException
|
||||
public SslBytesTest.SimpleProxy.AutomaticFlow startAutomaticFlow() throws InterruptedException
|
||||
{
|
||||
final CountDownLatch startLatch = new CountDownLatch(2);
|
||||
final CountDownLatch stopLatch = new CountDownLatch(2);
|
||||
Future<Object> clientToServer = threadPool.submit(new Callable<Object>()
|
||||
{
|
||||
public Object call() throws Exception
|
||||
Future<Object> clientToServer = threadPool.submit(() ->
|
||||
{
|
||||
startLatch.countDown();
|
||||
logger.debug("Automatic flow C --> S started");
|
||||
|
@ -317,11 +314,8 @@ public abstract class SslBytesTest
|
|||
stopLatch.countDown();
|
||||
logger.debug("Automatic flow C --> S finished");
|
||||
}
|
||||
}
|
||||
});
|
||||
Future<Object> serverToClient = threadPool.submit(new Callable<Object>()
|
||||
{
|
||||
public Object call() throws Exception
|
||||
Future<Object> serverToClient = threadPool.submit(() ->
|
||||
{
|
||||
startLatch.countDown();
|
||||
logger.debug("Automatic flow C <-- S started");
|
||||
|
@ -341,7 +335,6 @@ public abstract class SslBytesTest
|
|||
stopLatch.countDown();
|
||||
logger.debug("Automatic flow C <-- S finished");
|
||||
}
|
||||
}
|
||||
});
|
||||
Assert.assertTrue(startLatch.await(5, TimeUnit.SECONDS));
|
||||
return new SslBytesServerTest.SimpleProxy.AutomaticFlow(stopLatch, clientToServer, serverToClient);
|
||||
|
|
|
@ -185,11 +185,9 @@ public class MultiPartContentProviderTest extends AbstractHttpClientServerTest
|
|||
.content(multiPart)
|
||||
.send(result ->
|
||||
{
|
||||
if (result.isSucceeded())
|
||||
{
|
||||
Assert.assertTrue(String.valueOf(result.getFailure()), result.isSucceeded());
|
||||
Assert.assertEquals(200, result.getResponse().getStatus());
|
||||
responseLatch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
// Wait until the request has been sent.
|
||||
|
@ -408,11 +406,9 @@ public class MultiPartContentProviderTest extends AbstractHttpClientServerTest
|
|||
.content(multiPart)
|
||||
.send(result ->
|
||||
{
|
||||
if (result.isSucceeded())
|
||||
{
|
||||
Assert.assertTrue(String.valueOf(result.getFailure()), result.isSucceeded());
|
||||
Assert.assertEquals(200, result.getResponse().getStatus());
|
||||
responseLatch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
// Wait until the request has been sent.
|
||||
|
|
|
@ -19,20 +19,6 @@
|
|||
|
||||
package org.eclipse.jetty.gcloud.session;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.eclipse.jetty.server.session.AbstractSessionDataStore;
|
||||
import org.eclipse.jetty.server.session.SessionContext;
|
||||
import org.eclipse.jetty.server.session.SessionData;
|
||||
import org.eclipse.jetty.util.ClassLoadingObjectInputStream;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
import com.google.gcloud.datastore.Blob;
|
||||
import com.google.gcloud.datastore.Datastore;
|
||||
import com.google.gcloud.datastore.DatastoreFactory;
|
||||
|
@ -49,6 +35,21 @@ import com.google.gcloud.datastore.StructuredQuery.Projection;
|
|||
import com.google.gcloud.datastore.StructuredQuery.ProjectionEntityQueryBuilder;
|
||||
import com.google.gcloud.datastore.StructuredQuery.PropertyFilter;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.eclipse.jetty.server.session.AbstractSessionDataStore;
|
||||
import org.eclipse.jetty.server.session.SessionContext;
|
||||
import org.eclipse.jetty.server.session.SessionData;
|
||||
import org.eclipse.jetty.util.ClassLoadingObjectInputStream;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
/**
|
||||
* GCloudSessionDataStore
|
||||
*
|
||||
|
@ -83,11 +84,6 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStart()
|
||||
*/
|
||||
|
@ -186,17 +182,19 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(java.util.Set)
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set, int)
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getExpired(Set<String> candidates)
|
||||
public Set<String> doGetExpired(Set<String> candidates, int expiryTimeoutSec)
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
Set<String> expired = new HashSet<String>();
|
||||
|
||||
try
|
||||
{
|
||||
//get up to maxResult number of sessions that have expired
|
||||
ProjectionEntityQueryBuilder pbuilder = Query.projectionEntityQueryBuilder();
|
||||
pbuilder.addProjection(Projection.property(ID));
|
||||
pbuilder.addProjection(Projection.property(ID), Projection.property(LASTNODE), Projection.property(EXPIRY));
|
||||
pbuilder.filter(CompositeFilter.and(PropertyFilter.gt(EXPIRY, 0), PropertyFilter.le(EXPIRY, now)));
|
||||
pbuilder.limit(_maxResults);
|
||||
pbuilder.kind(KIND);
|
||||
|
@ -207,8 +205,33 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
|||
{
|
||||
ProjectionEntity pe = presults.next();
|
||||
String id = pe.getString(ID);
|
||||
String lastNode = pe.getString(LASTNODE);
|
||||
long expiry = pe.getLong(EXPIRY);
|
||||
|
||||
if (StringUtil.isBlank(lastNode))
|
||||
expired.add(id); //nobody managing it
|
||||
else
|
||||
{
|
||||
if (_context.getWorkerName().equals(lastNode))
|
||||
expired.add(id); //we're managing it, we can expire it
|
||||
else
|
||||
{
|
||||
if (_lastExpiryCheckTime <= 0)
|
||||
{
|
||||
//our first check, just look for sessions that we managed by another node that
|
||||
//expired at least 3 graceperiods ago
|
||||
if (expiry < (now - (1000L * (3 * _gracePeriodSec))))
|
||||
expired.add(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
//another node was last managing it, only expire it if it expired a graceperiod ago
|
||||
if (expiry < (now - (1000L * _gracePeriodSec)))
|
||||
expired.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//reconcile against ids that the SessionStore thinks are expired
|
||||
Set<String> tmp = new HashSet<String>(candidates);
|
||||
|
@ -239,6 +262,12 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
|||
}
|
||||
|
||||
return expired;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.warn(e);
|
||||
return expired; //return what we got
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -267,8 +296,9 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
|||
* </ol>
|
||||
*
|
||||
*
|
||||
* @param session
|
||||
* @return
|
||||
* @param id the id
|
||||
* @param context the session context
|
||||
* @return the key
|
||||
*/
|
||||
private Key makeKey (String id, SessionContext context)
|
||||
{
|
||||
|
@ -279,9 +309,9 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
|||
|
||||
/**
|
||||
* Generate a gcloud datastore Entity from SessionData
|
||||
* @param session
|
||||
* @param key
|
||||
* @return
|
||||
* @param session the session data
|
||||
* @param key the key
|
||||
* @return the entity
|
||||
* @throws Exception
|
||||
*/
|
||||
private Entity entityFromSession (SessionData session, Key key) throws Exception
|
||||
|
@ -297,6 +327,8 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
|||
oos.writeObject(session.getAllAttributes());
|
||||
oos.flush();
|
||||
|
||||
try
|
||||
{
|
||||
//turn a session into an entity
|
||||
entity = Entity.builder(key)
|
||||
.set(ID, session.getId())
|
||||
|
@ -310,6 +342,12 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
|||
.set(EXPIRY, session.getExpiry())
|
||||
.set(MAXINACTIVE, session.getMaxInactiveMs())
|
||||
.set(ATTRIBUTES, Blob.copyFrom(baos.toByteArray())).build();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
|
|
@ -18,11 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.gcloud.session;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.eclipse.jetty.server.session.AbstractSessionStore;
|
||||
import org.eclipse.jetty.server.session.MemorySessionStore;
|
||||
import org.eclipse.jetty.server.session.SessionManager;
|
||||
|
@ -49,9 +44,7 @@ public class GCloudSessionManager extends SessionManager
|
|||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
*//**
|
||||
/* *
|
||||
* Session
|
||||
*
|
||||
* Representation of a session in local memory.
|
||||
|
@ -75,7 +68,8 @@ public class GCloudSessionManager extends SessionManager
|
|||
|
||||
|
||||
|
||||
*//**
|
||||
*/
|
||||
/* *
|
||||
* Called on entry to the session.
|
||||
*
|
||||
* @see org.eclipse.jetty.server.session.AbstractSession#access(long)
|
||||
|
@ -295,7 +289,7 @@ public class GCloudSessionManager extends SessionManager
|
|||
/**
|
||||
* Start the session manager.
|
||||
*
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionManager#doStart()
|
||||
* @see org.eclipse.jetty.server.session.SessionManager#doStart()
|
||||
*/
|
||||
@Override
|
||||
public void doStart() throws Exception
|
||||
|
@ -308,7 +302,7 @@ public class GCloudSessionManager extends SessionManager
|
|||
/**
|
||||
* Stop the session manager.
|
||||
*
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionManager#doStop()
|
||||
* @see org.eclipse.jetty.server.session.SessionManager#doStop()
|
||||
*/
|
||||
@Override
|
||||
public void doStop() throws Exception
|
||||
|
|
|
@ -73,7 +73,7 @@ public interface HttpContent
|
|||
* @param maxBuffer The maximum buffer to allocated for this request. For cached content, a larger buffer may have
|
||||
* previously been allocated and returned by the {@link HttpContent#getDirectBuffer()} or {@link HttpContent#getIndirectBuffer()} calls.
|
||||
* @return A {@link HttpContent}
|
||||
* @throws IOException
|
||||
* @throws IOException if unable to get content
|
||||
*/
|
||||
HttpContent getContent(String path,int maxBuffer) throws IOException;
|
||||
}
|
||||
|
|
|
@ -1174,7 +1174,7 @@ public class HttpParser
|
|||
{
|
||||
_value=null;
|
||||
_string.setLength(0);
|
||||
_valueString=_compliance.ordinal()<=HttpCompliance.RFC2616.ordinal()?"":null;
|
||||
_valueString="";
|
||||
_length=-1;
|
||||
|
||||
setState(State.HEADER);
|
||||
|
|
|
@ -177,9 +177,10 @@ public class HttpURI
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Parse according to https://tools.ietf.org/html/rfc7230#section-5.3
|
||||
* @param method
|
||||
* @param uri
|
||||
/**
|
||||
* Parse according to https://tools.ietf.org/html/rfc7230#section-5.3
|
||||
* @param method the request method
|
||||
* @param uri the request uri
|
||||
*/
|
||||
public void parseRequestTarget(String method,String uri)
|
||||
{
|
||||
|
|
|
@ -62,7 +62,6 @@ public enum PathSpecGroup
|
|||
MIDDLE_GLOB,
|
||||
/**
|
||||
* For path specs that have a hardcoded prefix and a trailing wildcard glob.
|
||||
* <p>
|
||||
*
|
||||
* <pre>
|
||||
* "/downloads/*" - servlet spec
|
||||
|
|
|
@ -13,6 +13,7 @@ bin=application/octet-stream
|
|||
bmp=image/bmp
|
||||
cab=application/x-cabinet
|
||||
cdf=application/x-netcdf
|
||||
chm=application/vnd.ms-htmlhelp
|
||||
class=application/java-vm
|
||||
cpio=application/x-cpio
|
||||
cpt=application/mac-compactpro
|
||||
|
|
|
@ -334,9 +334,8 @@ public class HttpParserTest
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test2616NoValue() throws Exception
|
||||
public void testNoValue() throws Exception
|
||||
{
|
||||
ByteBuffer buffer= BufferUtil.toBuffer(
|
||||
"GET / HTTP/1.0\015\012" +
|
||||
|
@ -366,37 +365,6 @@ public class HttpParserTest
|
|||
assertEquals(3, _headers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test7230NoValue() throws Exception
|
||||
{
|
||||
ByteBuffer buffer= BufferUtil.toBuffer(
|
||||
"GET / HTTP/1.0\015\012" +
|
||||
"Host: localhost\015\012" +
|
||||
"Name0: \015\012"+
|
||||
"Name1: \015\012"+
|
||||
"Connection: close\015\012" +
|
||||
"\015\012");
|
||||
|
||||
HttpParser.RequestHandler handler = new Handler();
|
||||
HttpParser parser= new HttpParser(handler);
|
||||
parseAll(parser,buffer);
|
||||
|
||||
assertTrue(_headerCompleted);
|
||||
assertTrue(_messageCompleted);
|
||||
assertEquals("GET", _methodOrVersion);
|
||||
assertEquals("/", _uriOrStatus);
|
||||
assertEquals("HTTP/1.0", _versionOrReason);
|
||||
assertEquals("Host", _hdr[0]);
|
||||
assertEquals("localhost", _val[0]);
|
||||
assertEquals("Name0", _hdr[1]);
|
||||
assertEquals(null, _val[1]);
|
||||
assertEquals("Name1", _hdr[2]);
|
||||
assertEquals(null, _val[2]);
|
||||
assertEquals("Connection", _hdr[3]);
|
||||
assertEquals("close", _val[3]);
|
||||
assertEquals(3, _headers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeaderParseDirect() throws Exception
|
||||
{
|
||||
|
|
|
@ -19,22 +19,24 @@
|
|||
|
||||
package org.eclipse.jetty.http;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.util.URIUtil;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameter;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assume.assumeNoException;
|
||||
import static org.junit.Assume.assumeNotNull;
|
||||
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class HttpURIParseTest
|
||||
|
@ -69,6 +71,7 @@ public class HttpURIParseTest
|
|||
{"/path/info;param#fragment",null,null,null,"/path/info;param","param",null,"fragment"},
|
||||
{"/path/info;param?query",null,null,null,"/path/info;param","param","query",null},
|
||||
{"/path/info;param?query#fragment",null,null,null,"/path/info;param","param","query","fragment"},
|
||||
// FIXME: {"/path/info;a=b/foo;c=d",null,null,null,"/data/info;a=b/foo;c=d","foo=bar1",null,null},
|
||||
|
||||
// Protocol Less (aka scheme-less) URIs
|
||||
{"//host/path/info",null,"host",null,"/path/info",null,null,null},
|
||||
|
@ -151,14 +154,14 @@ public class HttpURIParseTest
|
|||
// Interpreted as relative path of "*" (no host/port/scheme/query/fragment)
|
||||
{"*",null,null,null,"*",null, null,null},
|
||||
|
||||
// Path detection Tests (seen from JSP/JSTL and <c:url> use
|
||||
// Path detection Tests (seen from JSP/JSTL and <c:url> use)
|
||||
{"http://host:8080/path/info?q1=v1&q2=v2","http","host","8080","/path/info",null,"q1=v1&q2=v2",null},
|
||||
{"/path/info?q1=v1&q2=v2",null,null,null,"/path/info",null,"q1=v1&q2=v2",null},
|
||||
{"/info?q1=v1&q2=v2",null,null,null,"/info",null,"q1=v1&q2=v2",null},
|
||||
{"info?q1=v1&q2=v2",null,null,null,"info",null,"q1=v1&q2=v2",null},
|
||||
{"info;q1=v1?q2=v2",null,null,null,"info;q1=v1","q1=v1","q2=v2",null},
|
||||
|
||||
// Path-less, query only (seen from JSP/JSTL and <c:url> use
|
||||
// Path-less, query only (seen from JSP/JSTL and <c:url> use)
|
||||
{"?q1=v1&q2=v2",null,null,null,"",null,"q1=v1&q2=v2",null}
|
||||
};
|
||||
|
||||
|
|
|
@ -91,12 +91,17 @@ public class ALPNNegotiationTest extends AbstractALPNTest
|
|||
Assert.assertTrue(read > 0);
|
||||
// Cannot decrypt, as the SSLEngine has been already closed
|
||||
|
||||
// Now if we read more, we should either read the TLS Close Alert, or directly -1
|
||||
// Now if we read more, we should read a TLS Alert.
|
||||
encrypted.clear();
|
||||
read = channel.read(encrypted);
|
||||
// Sending a TLS Close Alert during handshake results in an exception when
|
||||
// unwrapping that the server react to by closing the connection abruptly.
|
||||
Assert.assertTrue(read < 0);
|
||||
if (read > 0)
|
||||
{
|
||||
encrypted.flip();
|
||||
// TLS Alert message type == 21.
|
||||
Assert.assertEquals(21, encrypted.get() & 0xFF);
|
||||
encrypted.clear();
|
||||
Assert.assertEquals(-1, channel.read(encrypted));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -138,6 +138,11 @@ public class HttpClientTransportOverHTTP2 extends ContainerLifeCycle implements
|
|||
return new HttpConnectionOverHTTP2(destination, session);
|
||||
}
|
||||
|
||||
protected void onClose(HttpConnectionOverHTTP2 connection, GoAwayFrame frame)
|
||||
{
|
||||
connection.close();
|
||||
}
|
||||
|
||||
private class SessionListenerPromise extends Session.Listener.Adapter implements Promise<Session>
|
||||
{
|
||||
private final HttpDestinationOverHTTP2 destination;
|
||||
|
@ -182,7 +187,7 @@ public class HttpClientTransportOverHTTP2 extends ContainerLifeCycle implements
|
|||
@Override
|
||||
public void onClose(Session session, GoAwayFrame frame)
|
||||
{
|
||||
connection.close();
|
||||
HttpClientTransportOverHTTP2.this.onClose(connection, frame);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -194,7 +199,9 @@ public class HttpClientTransportOverHTTP2 extends ContainerLifeCycle implements
|
|||
@Override
|
||||
public void onFailure(Session session, Throwable failure)
|
||||
{
|
||||
connection.close(failure);
|
||||
HttpConnectionOverHTTP2 c = connection;
|
||||
if (c != null)
|
||||
c.close(failure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
|
|||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#load(org.eclipse.jetty.server.session.SessionKey)
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#load(String)
|
||||
*/
|
||||
@Override
|
||||
public SessionData load(String id) throws Exception
|
||||
|
@ -120,7 +120,7 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#delete(org.eclipse.jetty.server.session.SessionKey)
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#delete(String)
|
||||
*/
|
||||
@Override
|
||||
public boolean delete(String id) throws Exception
|
||||
|
@ -131,10 +131,10 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(java.util.Set)
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set, int)
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getExpired(Set<String> candidates)
|
||||
public Set<String> doGetExpired(Set<String> candidates, int expiryTimeoutSec)
|
||||
{
|
||||
if (candidates == null || candidates.isEmpty())
|
||||
return candidates;
|
||||
|
@ -143,6 +143,9 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
|
|||
|
||||
Set<String> expired = new HashSet<String>();
|
||||
|
||||
//TODO if there is NOT an idle timeout set, need to check other sessions that
|
||||
//might have expired
|
||||
|
||||
for (String candidate:candidates)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
|
@ -151,11 +154,42 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
|
|||
{
|
||||
SessionData sd = load(candidate);
|
||||
|
||||
if (sd == null || sd.isExpiredAt(now))
|
||||
//if the session no longer exists
|
||||
if (sd == null)
|
||||
{
|
||||
expired.add(candidate);
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Is null {} is expired {}", (sd==null), (sd !=null));
|
||||
LOG.debug("Session {} does not exist in infinispan", candidate);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_context.getWorkerName().equals(sd.getLastNode()))
|
||||
{
|
||||
//we are its manager, add it to the expired set if it is expired now
|
||||
if ((sd.getExpiry() > 0 ) && sd.getExpiry() <= now)
|
||||
{
|
||||
expired.add(candidate);
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Session {} managed by {} is expired", candidate, _context.getWorkerName());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//if we are not the session's manager, only expire it iff:
|
||||
// this is our first expiryCheck and the session expired a long time ago
|
||||
//or
|
||||
//the session expired at least one graceperiod ago
|
||||
if (_lastExpiryCheckTime <=0)
|
||||
{
|
||||
if ((sd.getExpiry() > 0 ) && sd.getExpiry() < (now - (1000L * (3 * _gracePeriodSec))))
|
||||
expired.add(candidate);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((sd.getExpiry() > 0 ) && sd.getExpiry() < (now - (1000L * _gracePeriodSec)))
|
||||
expired.add(candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -168,7 +202,7 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(org.eclipse.jetty.server.session.SessionKey, org.eclipse.jetty.server.session.SessionData, long)
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(String, SessionData, long)
|
||||
*/
|
||||
@Override
|
||||
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
|
||||
|
@ -193,6 +227,11 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public static String getCacheKey (String id, SessionContext context)
|
||||
{
|
||||
return context.getCanonicalContextPath()+"_"+context.getVhost()+"_"+id;
|
||||
|
@ -224,11 +263,17 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* @param sec the infinispan-specific idle timeout in sec or 0 if not set
|
||||
*/
|
||||
public void setInfinispanIdleTimeoutSec (int sec)
|
||||
{
|
||||
_infinispanIdleTimeoutSec = sec;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int getInfinispanIdleTimeoutSec ()
|
||||
{
|
||||
return _infinispanIdleTimeoutSec;
|
||||
|
|
|
@ -21,17 +21,9 @@ package org.eclipse.jetty.session.infinispan;
|
|||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.session.AbstractSessionIdManager;
|
||||
import org.eclipse.jetty.server.session.Session;
|
||||
import org.eclipse.jetty.server.session.SessionHandler;
|
||||
import org.eclipse.jetty.server.session.SessionManager;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.infinispan.commons.api.BasicCache;
|
||||
|
@ -270,7 +262,7 @@ public class InfinispanSessionIdManager extends AbstractSessionIdManager
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.SessionIdManager#useId(java.lang.String)
|
||||
* @see org.eclipse.jetty.server.SessionIdManager#useId(Session)
|
||||
*/
|
||||
@Override
|
||||
public void useId(Session session)
|
||||
|
|
|
@ -51,7 +51,7 @@ public class InfinispanSessionManager extends SessionManager
|
|||
/**
|
||||
* Start the session manager.
|
||||
*
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionManager#doStart()
|
||||
* @see org.eclipse.jetty.server.session.SessionManager#doStart()
|
||||
*/
|
||||
@Override
|
||||
public void doStart() throws Exception
|
||||
|
@ -69,7 +69,7 @@ public class InfinispanSessionManager extends SessionManager
|
|||
/**
|
||||
* Stop the session manager.
|
||||
*
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionManager#doStop()
|
||||
* @see org.eclipse.jetty.server.session.SessionManager#doStop()
|
||||
*/
|
||||
@Override
|
||||
public void doStop() throws Exception
|
||||
|
|
|
@ -316,6 +316,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
|||
LOG.warn("Exception while notifying connection " + connection, x);
|
||||
else
|
||||
LOG.debug("Exception while notifying connection " + connection, x);
|
||||
throw x;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -678,12 +678,12 @@ public class SslConnection extends AbstractConnection
|
|||
{
|
||||
// Some internal error in SSLEngine
|
||||
LOG.debug(e);
|
||||
getEndPoint().close();
|
||||
close();
|
||||
throw new EofException(e);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
getEndPoint().close();
|
||||
close();
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
|
|
|
@ -40,15 +40,6 @@ public abstract class NoSqlSessionDataStore extends AbstractSessionDataStore
|
|||
private Set<String> _dirtyAttributes = new HashSet<String>();
|
||||
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @param cpath
|
||||
* @param vhost
|
||||
* @param created
|
||||
* @param accessed
|
||||
* @param lastAccessed
|
||||
* @param maxInactiveMs
|
||||
*/
|
||||
public NoSqlSessionData(String id, String cpath, String vhost, long created, long accessed, long lastAccessed, long maxInactiveMs)
|
||||
{
|
||||
super(id, cpath, vhost, created, accessed, lastAccessed, maxInactiveMs);
|
||||
|
|
|
@ -19,6 +19,12 @@
|
|||
|
||||
package org.eclipse.jetty.nosql.mongodb;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBCollection;
|
||||
import com.mongodb.DBCursor;
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.WriteConcern;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -36,13 +42,6 @@ import org.eclipse.jetty.util.ClassLoadingObjectInputStream;
|
|||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBCollection;
|
||||
import com.mongodb.DBCursor;
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.WriteConcern;
|
||||
import com.mongodb.WriteResult;
|
||||
|
||||
/**
|
||||
* MongoSessionDataStore
|
||||
*
|
||||
|
@ -153,43 +152,21 @@ public class MongoSessionDataStore extends NoSqlSessionDataStore
|
|||
private DBCollection _dbSessions;
|
||||
|
||||
|
||||
private long _gracePeriodMs = 1000L * 60 * 60; //default grace period is 1hr
|
||||
|
||||
public void setDBCollection (DBCollection collection)
|
||||
{
|
||||
_dbSessions = collection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public DBCollection getDBCollection ()
|
||||
{
|
||||
return _dbSessions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int getGracePeriodSec ()
|
||||
{
|
||||
return (int)(_gracePeriodMs == 0L? 0 : _gracePeriodMs/1000L);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param sec
|
||||
*/
|
||||
public void setGracePeriodSec (int sec)
|
||||
{
|
||||
if (sec < 0)
|
||||
_gracePeriodMs = 0;
|
||||
else
|
||||
_gracePeriodMs = sec * 1000L;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#load(org.eclipse.jetty.server.session.SessionKey)
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#load(String)
|
||||
*/
|
||||
@Override
|
||||
public SessionData load(String id) throws Exception
|
||||
|
@ -281,7 +258,7 @@ public class MongoSessionDataStore extends NoSqlSessionDataStore
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#delete(org.eclipse.jetty.server.session.SessionKey)
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#delete(String)
|
||||
*/
|
||||
@Override
|
||||
public boolean delete(String id) throws Exception
|
||||
|
@ -339,15 +316,17 @@ public class MongoSessionDataStore extends NoSqlSessionDataStore
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(java.util.Set)
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set, int)
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getExpired(Set<String> candidates)
|
||||
public Set<String> doGetExpired(Set<String> candidates, int expiryTimeoutSec)
|
||||
{
|
||||
long upperBound = System.currentTimeMillis();
|
||||
long now = System.currentTimeMillis();
|
||||
long upperBound = now;
|
||||
Set<String> expiredSessions = new HashSet<>();
|
||||
|
||||
//firstly ask mongo to verify if these candidate ids have expired
|
||||
//firstly ask mongo to verify if these candidate ids have expired - all of
|
||||
//these candidates will be for our node
|
||||
BasicDBObject query = new BasicDBObject();
|
||||
query.put(__ID,new BasicDBObject("$in", candidates));
|
||||
query.put(__EXPIRY, new BasicDBObject("$gt", 0));
|
||||
|
@ -369,9 +348,13 @@ public class MongoSessionDataStore extends NoSqlSessionDataStore
|
|||
if (verifiedExpiredSessions != null) verifiedExpiredSessions.close();
|
||||
}
|
||||
|
||||
//now ask mongo to find sessions last managed by other nodes that expired a while ago
|
||||
//if this is our first expiry check, make sure that we only grab really old sessions
|
||||
if (_lastExpiryCheckTime <= 0)
|
||||
upperBound = (now - (3*(1000L * _gracePeriodSec)));
|
||||
else
|
||||
upperBound = _lastExpiryCheckTime - (1000L * _gracePeriodSec);
|
||||
|
||||
//now ask mongo to find sessions that expired a while ago
|
||||
upperBound = upperBound - (3 * _gracePeriodMs);
|
||||
query.clear();
|
||||
query.put(__EXPIRY, new BasicDBObject("$gt", 0));
|
||||
query.put(__EXPIRY, new BasicDBObject("$lt", upperBound));
|
||||
|
@ -397,7 +380,7 @@ public class MongoSessionDataStore extends NoSqlSessionDataStore
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(org.eclipse.jetty.server.session.SessionKey, org.eclipse.jetty.server.session.SessionData, long)
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(String, SessionData, long)
|
||||
*/
|
||||
@Override
|
||||
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
|
||||
|
|
|
@ -18,21 +18,20 @@
|
|||
|
||||
package org.eclipse.jetty.nosql.mongodb;
|
||||
|
||||
import com.mongodb.DBCollection;
|
||||
import com.mongodb.MongoException;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.eclipse.jetty.server.SessionIdManager;
|
||||
import org.eclipse.jetty.server.session.AbstractSessionStore;
|
||||
import org.eclipse.jetty.server.session.MemorySessionStore;
|
||||
import org.eclipse.jetty.server.session.SessionDataStore;
|
||||
import org.eclipse.jetty.server.session.SessionManager;
|
||||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
import com.mongodb.DBCollection;
|
||||
import com.mongodb.MongoException;
|
||||
|
||||
|
||||
/**
|
||||
* MongoSessionManager
|
||||
|
@ -116,9 +115,6 @@ public class MongoSessionManager extends SessionManager
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionManager#setSessionIdManager(org.eclipse.jetty.server.SessionIdManager)
|
||||
*/
|
||||
@Override
|
||||
public void setSessionIdManager(SessionIdManager metaManager)
|
||||
{
|
||||
|
|
|
@ -222,6 +222,9 @@ public abstract class AbstractNCSARequestLog extends AbstractLifeCycle implement
|
|||
}
|
||||
|
||||
/**
|
||||
* @param request request object
|
||||
* @param b StringBuilder to write to
|
||||
* @throws IOException if unable to append extended log
|
||||
* @deprecated override {@link #logExtended(StringBuilder, Request, Response)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
|
|
|
@ -179,7 +179,7 @@ public interface PushBuilder
|
|||
* Set the URI path to be used for the push. The path may start
|
||||
* with "/" in which case it is treated as an absolute path,
|
||||
* otherwise it is relative to the context path of the associated
|
||||
* request. There is no path default and {@link #path(String)} must
|
||||
* request. There is no path default and <code>path(String)</code> must
|
||||
* be called before every call to {@link #push()}. If a query
|
||||
* string is present in the argument {@code path}, its contents must
|
||||
* be merged with the contents previously passed to {@link
|
||||
|
|
|
@ -2036,7 +2036,7 @@ public class Request implements HttpServletRequest
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return True if this is the first call of {@link #takeNewContext()} since the last
|
||||
* @return True if this is the first call of <code>takeNewContext()</code> since the last
|
||||
* {@link #setContext(org.eclipse.jetty.server.handler.ContextHandler.Context)} call.
|
||||
*/
|
||||
public boolean takeNewContext()
|
||||
|
|
|
@ -56,6 +56,8 @@ public class SecureRequestCustomizer implements HttpConfiguration.Customizer
|
|||
*/
|
||||
public static final String CACHED_INFO_ATTR = CachedInfo.class.getName();
|
||||
|
||||
private String sslSessionAttribute = "org.eclipse.jetty.servlet.request.ssl_session";
|
||||
|
||||
private boolean _sniHostCheck;
|
||||
private long _stsMaxAge=-1;
|
||||
private boolean _stsIncludeSubDomains;
|
||||
|
@ -270,6 +272,7 @@ public class SecureRequestCustomizer implements HttpConfiguration.Customizer
|
|||
request.setAttribute("javax.servlet.request.cipher_suite",cipherSuite);
|
||||
request.setAttribute("javax.servlet.request.key_size",keySize);
|
||||
request.setAttribute("javax.servlet.request.ssl_session_id", idStr);
|
||||
request.setAttribute(getSslSessionAttribute(), sslSession);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -277,6 +280,16 @@ public class SecureRequestCustomizer implements HttpConfiguration.Customizer
|
|||
}
|
||||
}
|
||||
|
||||
public void setSslSessionAttribute(String attribute)
|
||||
{
|
||||
this.sslSessionAttribute = attribute;
|
||||
}
|
||||
|
||||
public String getSslSessionAttribute()
|
||||
{
|
||||
return sslSessionAttribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
|
|
@ -32,15 +32,9 @@ import org.eclipse.jetty.server.session.SessionHandler;
|
|||
import org.eclipse.jetty.server.session.SessionStore;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/**
|
||||
* Session Manager.
|
||||
* The API required to manage sessions for a servlet context.
|
||||
*
|
||||
*/
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
*/
|
||||
public interface SessionManager extends LifeCycle
|
||||
{
|
||||
|
@ -313,7 +307,7 @@ public interface SessionManager extends LifeCycle
|
|||
|
||||
/**
|
||||
* Get the session store for this manager
|
||||
* @return
|
||||
* @return the session store
|
||||
*/
|
||||
public SessionStore getSessionStore();
|
||||
|
||||
|
|
|
@ -27,10 +27,12 @@ import java.net.InetSocketAddress;
|
|||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Properties;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.eclipse.jetty.util.component.Destroyable;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
|
@ -39,19 +41,20 @@ import org.eclipse.jetty.util.thread.ShutdownThread;
|
|||
/**
|
||||
* Shutdown/Stop Monitor thread.
|
||||
* <p>
|
||||
* This thread listens on the host/port specified by the STOP.HOST/STOP.PORT system parameter (defaults to 127.0.0.1/-1 for not listening) for
|
||||
* request authenticated with the key given by the STOP.KEY system parameter (defaults to "eclipse") for admin requests.
|
||||
* This thread listens on the host/port specified by the STOP.HOST/STOP.PORT
|
||||
* system parameter (defaults to 127.0.0.1/-1 for not listening) for request
|
||||
* authenticated with the key given by the STOP.KEY system parameter
|
||||
* (defaults to "eclipse") for admin requests.
|
||||
* <p>
|
||||
* If the stop port is set to zero, then a random port is assigned and the port number is printed to stdout.
|
||||
* If the stop port is set to zero, then a random port is assigned and the
|
||||
* port number is printed to stdout.
|
||||
* <p>
|
||||
* Commands "stop" and "status" are currently supported.
|
||||
*/
|
||||
public class ShutdownMonitor
|
||||
{
|
||||
private final Set<LifeCycle> _lifeCycles = new CopyOnWriteArraySet<LifeCycle>();
|
||||
|
||||
// Implementation of safe lazy init, using Initialization on Demand Holder technique.
|
||||
static class Holder
|
||||
private static class Holder
|
||||
{
|
||||
static ShutdownMonitor instance = new ShutdownMonitor();
|
||||
}
|
||||
|
@ -61,149 +64,326 @@ public class ShutdownMonitor
|
|||
return Holder.instance;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static synchronized void register(LifeCycle... lifeCycles)
|
||||
public static void register(LifeCycle... lifeCycles)
|
||||
{
|
||||
getInstance()._lifeCycles.addAll(Arrays.asList(lifeCycles));
|
||||
getInstance().addLifeCycles(lifeCycles);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static synchronized void deregister(LifeCycle lifeCycle)
|
||||
public static void deregister(LifeCycle lifeCycle)
|
||||
{
|
||||
getInstance()._lifeCycles.remove(lifeCycle);
|
||||
getInstance().removeLifeCycle(lifeCycle);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static synchronized boolean isRegistered(LifeCycle lifeCycle)
|
||||
public static boolean isRegistered(LifeCycle lifeCycle)
|
||||
{
|
||||
return getInstance()._lifeCycles.contains(lifeCycle);
|
||||
return getInstance().containsLifeCycle(lifeCycle);
|
||||
}
|
||||
|
||||
private final Set<LifeCycle> _lifeCycles = new LinkedHashSet<>();
|
||||
private boolean debug;
|
||||
private final String host;
|
||||
private int port;
|
||||
private String key;
|
||||
private boolean exitVm;
|
||||
private boolean alive;
|
||||
|
||||
/**
|
||||
* Creates a ShutdownMonitor using configuration from the System properties.
|
||||
* <p>
|
||||
* <code>STOP.PORT</code> = the port to listen on (empty, null, or values less than 0 disable the stop ability)<br>
|
||||
* <code>STOP.KEY</code> = the magic key/passphrase to allow the stop (defaults to "eclipse")<br>
|
||||
* <p>
|
||||
* Note: server socket will only listen on localhost, and a successful stop will issue a System.exit() call.
|
||||
*/
|
||||
private ShutdownMonitor()
|
||||
{
|
||||
this.debug = System.getProperty("DEBUG") != null;
|
||||
this.host = System.getProperty("STOP.HOST", "127.0.0.1");
|
||||
this.port = Integer.parseInt(System.getProperty("STOP.PORT", "-1"));
|
||||
this.key = System.getProperty("STOP.KEY", null);
|
||||
this.exitVm = true;
|
||||
}
|
||||
|
||||
private void addLifeCycles(LifeCycle... lifeCycles)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
_lifeCycles.addAll(Arrays.asList(lifeCycles));
|
||||
}
|
||||
}
|
||||
|
||||
private void removeLifeCycle(LifeCycle lifeCycle)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
_lifeCycles.remove(lifeCycle);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean containsLifeCycle(LifeCycle lifeCycle)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
return _lifeCycles.contains(lifeCycle);
|
||||
}
|
||||
}
|
||||
|
||||
private void debug(String format, Object... args)
|
||||
{
|
||||
if (debug)
|
||||
System.err.printf("[ShutdownMonitor] " + format + "%n", args);
|
||||
}
|
||||
|
||||
private void debug(Throwable t)
|
||||
{
|
||||
if (debug)
|
||||
t.printStackTrace(System.err);
|
||||
}
|
||||
|
||||
public String getKey()
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
public int getPort()
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
return port;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isExitVm()
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
return exitVm;
|
||||
}
|
||||
}
|
||||
|
||||
public void setDebug(boolean flag)
|
||||
{
|
||||
this.debug = flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param exitVm true to exit the VM on shutdown
|
||||
*/
|
||||
public void setExitVm(boolean exitVm)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
if (alive)
|
||||
throw new IllegalStateException("ShutdownMonitor already started");
|
||||
this.exitVm = exitVm;
|
||||
}
|
||||
}
|
||||
|
||||
public void setKey(String key)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
if (alive)
|
||||
throw new IllegalStateException("ShutdownMonitor already started");
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
|
||||
public void setPort(int port)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
if (alive)
|
||||
throw new IllegalStateException("ShutdownMonitor already started");
|
||||
this.port = port;
|
||||
}
|
||||
}
|
||||
|
||||
protected void start() throws Exception
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
if (alive)
|
||||
{
|
||||
debug("Already started");
|
||||
return; // cannot start it again
|
||||
}
|
||||
ServerSocket serverSocket = listen();
|
||||
if (serverSocket != null)
|
||||
{
|
||||
alive = true;
|
||||
Thread thread = new Thread(new ShutdownMonitorRunnable(serverSocket));
|
||||
thread.setDaemon(true);
|
||||
thread.setName("ShutdownMonitor");
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void stop()
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
alive = false;
|
||||
notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
// For test purposes only.
|
||||
void await() throws InterruptedException
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
while (alive)
|
||||
{
|
||||
wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isAlive()
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
return alive;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private ServerSocket listen()
|
||||
{
|
||||
int port = getPort();
|
||||
if (port < 0)
|
||||
{
|
||||
debug("Not enabled (port < 0): %d", port);
|
||||
return null;
|
||||
}
|
||||
|
||||
String key = getKey();
|
||||
try
|
||||
{
|
||||
ServerSocket serverSocket = new ServerSocket();
|
||||
serverSocket.setReuseAddress(true);
|
||||
serverSocket.bind(new InetSocketAddress(InetAddress.getByName(host), port));
|
||||
if (port == 0)
|
||||
{
|
||||
port = serverSocket.getLocalPort();
|
||||
System.out.printf("STOP.PORT=%d%n", port);
|
||||
setPort(port);
|
||||
}
|
||||
|
||||
if (key == null)
|
||||
{
|
||||
key = Long.toString((long)(Long.MAX_VALUE * Math.random() + this.hashCode() + System.currentTimeMillis()), 36);
|
||||
System.out.printf("STOP.KEY=%s%n", key);
|
||||
setKey(key);
|
||||
}
|
||||
|
||||
return serverSocket;
|
||||
}
|
||||
catch (Throwable x)
|
||||
{
|
||||
debug(x);
|
||||
System.err.println("Error binding ShutdownMonitor to port " + port + ": " + x.toString());
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// establish the port and key that are in use
|
||||
debug("STOP.PORT=%d", port);
|
||||
debug("STOP.KEY=%s", key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s[port=%d,alive=%b]", this.getClass().getName(), getPort(), isAlive());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* ShutdownMonitorRunnable
|
||||
*
|
||||
* Thread for listening to STOP.PORT for command to stop Jetty.
|
||||
* If ShowndownMonitor.exitVm is true, then Sytem.exit will also be
|
||||
* If ShutdownMonitor.exitVm is true, then System.exit will also be
|
||||
* called after the stop.
|
||||
*
|
||||
*/
|
||||
private class ShutdownMonitorRunnable implements Runnable
|
||||
{
|
||||
public ShutdownMonitorRunnable()
|
||||
private final ServerSocket serverSocket;
|
||||
|
||||
private ShutdownMonitorRunnable(ServerSocket serverSocket)
|
||||
{
|
||||
startListenSocket();
|
||||
this.serverSocket = serverSocket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (serverSocket == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (serverSocket != null)
|
||||
{
|
||||
Socket socket = null;
|
||||
debug("Started");
|
||||
try
|
||||
{
|
||||
socket = serverSocket.accept();
|
||||
|
||||
LineNumberReader lin = new LineNumberReader(new InputStreamReader(socket.getInputStream()));
|
||||
String receivedKey = lin.readLine();
|
||||
String key = getKey();
|
||||
while (true)
|
||||
{
|
||||
try (Socket socket = serverSocket.accept())
|
||||
{
|
||||
LineNumberReader reader = new LineNumberReader(new InputStreamReader(socket.getInputStream()));
|
||||
String receivedKey = reader.readLine();
|
||||
if (!key.equals(receivedKey))
|
||||
{
|
||||
System.err.println("Ignoring command with incorrect key");
|
||||
debug("Ignoring command with incorrect key: %s", receivedKey);
|
||||
continue;
|
||||
}
|
||||
|
||||
OutputStream out = socket.getOutputStream();
|
||||
|
||||
String cmd = lin.readLine();
|
||||
String cmd = reader.readLine();
|
||||
debug("command=%s", cmd);
|
||||
OutputStream out = socket.getOutputStream();
|
||||
boolean exitVm = isExitVm();
|
||||
|
||||
if ("stop".equalsIgnoreCase(cmd)) //historic, for backward compatibility
|
||||
{
|
||||
//Stop the lifecycles, only if they are registered with the ShutdownThread, only destroying if vm is exiting
|
||||
debug("Issuing stop...");
|
||||
|
||||
for (LifeCycle l:_lifeCycles)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (l.isStarted() && ShutdownThread.isRegistered(l))
|
||||
{
|
||||
l.stop();
|
||||
}
|
||||
|
||||
if ((l instanceof Destroyable) && exitVm)
|
||||
((Destroyable)l).destroy();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
debug(e);
|
||||
}
|
||||
}
|
||||
|
||||
//Stop accepting any more commands
|
||||
stopInput(socket);
|
||||
debug("Performing stop command");
|
||||
stopLifeCycles(ShutdownThread::isRegistered, exitVm);
|
||||
|
||||
// Reply to client
|
||||
debug("Informing client that we are stopped.");
|
||||
debug("Informing client that we are stopped");
|
||||
informClient(out, "Stopped\r\n");
|
||||
|
||||
//Stop the output and close the monitor socket
|
||||
stopOutput(socket);
|
||||
if (!exitVm)
|
||||
break;
|
||||
|
||||
if (exitVm)
|
||||
{
|
||||
// Kill JVM
|
||||
debug("Killing JVM");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
else if ("forcestop".equalsIgnoreCase(cmd))
|
||||
{
|
||||
debug("Issuing force stop...");
|
||||
|
||||
//Ensure that objects are stopped, destroyed only if vm is forcibly exiting
|
||||
stopLifeCycles(exitVm);
|
||||
|
||||
//Stop accepting any more commands
|
||||
stopInput(socket);
|
||||
debug("Performing forced stop command");
|
||||
stopLifeCycles(l -> true, exitVm);
|
||||
|
||||
// Reply to client
|
||||
debug("Informing client that we are stopped.");
|
||||
debug("Informing client that we are stopped");
|
||||
informClient(out, "Stopped\r\n");
|
||||
|
||||
//Stop the output and close the monitor socket
|
||||
stopOutput(socket);
|
||||
if (!exitVm)
|
||||
break;
|
||||
|
||||
//Honour any pre-setup config to stop the jvm when this command is given
|
||||
if (exitVm)
|
||||
{
|
||||
// Kill JVM
|
||||
debug("Killing JVM");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
else if ("stopexit".equalsIgnoreCase(cmd))
|
||||
{
|
||||
debug("Issuing stop and exit...");
|
||||
//Make sure that objects registered with the shutdown thread will be stopped
|
||||
stopLifeCycles(true);
|
||||
|
||||
//Stop accepting any more input
|
||||
stopInput(socket);
|
||||
debug("Performing stop and exit commands");
|
||||
stopLifeCycles(ShutdownThread::isRegistered, true);
|
||||
|
||||
// Reply to client
|
||||
debug("Informing client that we are stopped.");
|
||||
debug("Informing client that we are stopped");
|
||||
informClient(out, "Stopped\r\n");
|
||||
|
||||
//Stop the output and close the monitor socket
|
||||
stopOutput(socket);
|
||||
|
||||
debug("Killing JVM");
|
||||
System.exit(0);
|
||||
}
|
||||
|
@ -218,312 +398,52 @@ public class ShutdownMonitor
|
|||
informClient(out, "OK\r\n");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Throwable x)
|
||||
{
|
||||
debug(e);
|
||||
System.err.println(e.toString());
|
||||
debug(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable x)
|
||||
{
|
||||
debug(x);
|
||||
}
|
||||
finally
|
||||
{
|
||||
close(socket);
|
||||
socket = null;
|
||||
}
|
||||
stop();
|
||||
debug("Stopped");
|
||||
}
|
||||
}
|
||||
|
||||
public void stopInput (Socket socket)
|
||||
{
|
||||
//Stop accepting any more input
|
||||
close(serverSocket);
|
||||
serverSocket = null;
|
||||
//Shutdown input from client
|
||||
shutdownInput(socket);
|
||||
}
|
||||
|
||||
public void stopOutput (Socket socket) throws IOException
|
||||
{
|
||||
socket.shutdownOutput();
|
||||
close(socket);
|
||||
socket = null;
|
||||
debug("Shutting down monitor");
|
||||
serverSocket = null;
|
||||
}
|
||||
|
||||
public void informClient (OutputStream out, String message) throws IOException
|
||||
private void informClient(OutputStream out, String message) throws IOException
|
||||
{
|
||||
out.write(message.getBytes(StandardCharsets.UTF_8));
|
||||
out.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the registered lifecycles, optionally
|
||||
* calling destroy on them.
|
||||
*
|
||||
* @param destroy true if {@link Destroyable}'s should also be destroyed.
|
||||
*/
|
||||
public void stopLifeCycles (boolean destroy)
|
||||
private void stopLifeCycles(Predicate<LifeCycle> predicate, boolean destroy)
|
||||
{
|
||||
for (LifeCycle l:_lifeCycles)
|
||||
List<LifeCycle> lifeCycles = new ArrayList<>();
|
||||
synchronized (this)
|
||||
{
|
||||
lifeCycles.addAll(_lifeCycles);
|
||||
}
|
||||
|
||||
for (LifeCycle l : lifeCycles)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (l.isStarted())
|
||||
{
|
||||
if (l.isStarted() && predicate.test(l))
|
||||
l.stop();
|
||||
}
|
||||
|
||||
if ((l instanceof Destroyable) && destroy)
|
||||
((Destroyable)l).destroy();
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Throwable x)
|
||||
{
|
||||
debug(e);
|
||||
debug(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void startListenSocket()
|
||||
{
|
||||
if (port < 0)
|
||||
{
|
||||
if (DEBUG)
|
||||
System.err.println("ShutdownMonitor not in use (port < 0): " + port);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
serverSocket = new ServerSocket();
|
||||
serverSocket.setReuseAddress(true);
|
||||
serverSocket.bind(new InetSocketAddress(InetAddress.getByName(host), port), 1);
|
||||
if (port == 0)
|
||||
{
|
||||
// server assigned port in use
|
||||
port = serverSocket.getLocalPort();
|
||||
System.out.printf("STOP.PORT=%d%n",port);
|
||||
}
|
||||
|
||||
if (key == null)
|
||||
{
|
||||
// create random key
|
||||
key = Long.toString((long)(Long.MAX_VALUE * Math.random() + this.hashCode() + System.currentTimeMillis()),36);
|
||||
System.out.printf("STOP.KEY=%s%n",key);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
debug(e);
|
||||
System.err.println("Error binding monitor port " + port + ": " + e.toString());
|
||||
serverSocket = null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// establish the port and key that are in use
|
||||
debug("STOP.PORT=%d",port);
|
||||
debug("STOP.KEY=%s",key);
|
||||
debug("%s",serverSocket);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean DEBUG;
|
||||
private String host;
|
||||
private int port;
|
||||
private String key;
|
||||
private boolean exitVm;
|
||||
private ServerSocket serverSocket;
|
||||
private Thread thread;
|
||||
|
||||
/**
|
||||
* Create a ShutdownMonitor using configuration from the System properties.
|
||||
* <p>
|
||||
* <code>STOP.PORT</code> = the port to listen on (empty, null, or values less than 0 disable the stop ability)<br>
|
||||
* <code>STOP.KEY</code> = the magic key/passphrase to allow the stop (defaults to "eclipse")<br>
|
||||
* <p>
|
||||
* Note: server socket will only listen on localhost, and a successful stop will issue a System.exit() call.
|
||||
*/
|
||||
private ShutdownMonitor()
|
||||
{
|
||||
this.DEBUG = System.getProperty("DEBUG") != null;
|
||||
|
||||
// Use values passed thru via /jetty-start/
|
||||
this.host = System.getProperty("STOP.HOST","127.0.0.1");
|
||||
this.port = Integer.parseInt(System.getProperty("STOP.PORT","-1"));
|
||||
this.key = System.getProperty("STOP.KEY",null);
|
||||
this.exitVm = true;
|
||||
}
|
||||
|
||||
private void close(ServerSocket server)
|
||||
{
|
||||
if (server == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
server.close();
|
||||
}
|
||||
catch (IOException ignore)
|
||||
{
|
||||
debug(ignore);
|
||||
}
|
||||
}
|
||||
|
||||
private void close(Socket socket)
|
||||
{
|
||||
if (socket == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
socket.close();
|
||||
}
|
||||
catch (IOException ignore)
|
||||
{
|
||||
debug(ignore);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void shutdownInput(Socket socket)
|
||||
{
|
||||
if (socket == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
socket.shutdownInput();
|
||||
}
|
||||
catch (IOException ignore)
|
||||
{
|
||||
debug(ignore);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void debug(String format, Object... args)
|
||||
{
|
||||
if (DEBUG)
|
||||
{
|
||||
System.err.printf("[ShutdownMonitor] " + format + "%n",args);
|
||||
}
|
||||
}
|
||||
|
||||
private void debug(Throwable t)
|
||||
{
|
||||
if (DEBUG)
|
||||
{
|
||||
t.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
public String getKey()
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
||||
public int getPort()
|
||||
{
|
||||
return port;
|
||||
}
|
||||
|
||||
public ServerSocket getServerSocket()
|
||||
{
|
||||
return serverSocket;
|
||||
}
|
||||
|
||||
public boolean isExitVm()
|
||||
{
|
||||
return exitVm;
|
||||
}
|
||||
|
||||
|
||||
public void setDebug(boolean flag)
|
||||
{
|
||||
this.DEBUG = flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param exitVm true to exit the VM on shutdown
|
||||
*/
|
||||
public void setExitVm(boolean exitVm)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
if (thread != null && thread.isAlive())
|
||||
{
|
||||
throw new IllegalStateException("ShutdownMonitorThread already started");
|
||||
}
|
||||
this.exitVm = exitVm;
|
||||
}
|
||||
}
|
||||
|
||||
public void setKey(String key)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
if (thread != null && thread.isAlive())
|
||||
{
|
||||
throw new IllegalStateException("ShutdownMonitorThread already started");
|
||||
}
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
|
||||
public void setPort(int port)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
if (thread != null && thread.isAlive())
|
||||
{
|
||||
throw new IllegalStateException("ShutdownMonitorThread already started");
|
||||
}
|
||||
this.port = port;
|
||||
}
|
||||
}
|
||||
|
||||
protected void start() throws Exception
|
||||
{
|
||||
Thread t = null;
|
||||
|
||||
synchronized (this)
|
||||
{
|
||||
if (thread != null && thread.isAlive())
|
||||
{
|
||||
if (DEBUG)
|
||||
System.err.printf("ShutdownMonitorThread already started");
|
||||
return; // cannot start it again
|
||||
}
|
||||
|
||||
thread = new Thread(new ShutdownMonitorRunnable());
|
||||
thread.setDaemon(true);
|
||||
thread.setName("ShutdownMonitor");
|
||||
t = thread;
|
||||
}
|
||||
|
||||
if (t != null)
|
||||
t.start();
|
||||
}
|
||||
|
||||
|
||||
protected boolean isAlive ()
|
||||
{
|
||||
boolean result = false;
|
||||
synchronized (this)
|
||||
{
|
||||
result = (thread != null && thread.isAlive());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s[port=%d]",this.getClass().getName(),port);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -757,7 +757,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
|||
|
||||
try
|
||||
{
|
||||
// Set the classloader
|
||||
// Set the classloader, context and enter scope
|
||||
if (_classLoader != null)
|
||||
{
|
||||
current_thread = Thread.currentThread();
|
||||
|
|
|
@ -49,7 +49,7 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
/* ------------------------------------------------------------ */
|
||||
/** Handler for Error pages
|
||||
* An ErrorHandler is registered with {@link ContextHandler#setErrorHandler(ErrorHandler)} or
|
||||
* {@link Server#setErrorHandler(ErrorHandler).
|
||||
* {@link Server#setErrorHandler(ErrorHandler)}.
|
||||
* It is called by the HttpResponse.sendError method to write a error page via {@link #handle(String, Request, HttpServletRequest, HttpServletResponse)}
|
||||
* or via {@link #badMessageError(int, String, HttpFields)} for bad requests for which a dispatch cannot be done.
|
||||
*
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.server.handler.gzip;
|
||||
|
||||
import static org.eclipse.jetty.http.GzipHttpContent.ETAG_GZIP_QUOTE;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
@ -47,7 +45,6 @@ import org.eclipse.jetty.util.URIUtil;
|
|||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* A Handler that can dynamically GZIP compress responses. Unlike
|
||||
* previous and 3rd party GzipFilters, this mechanism works with asynchronously
|
||||
|
@ -71,7 +68,7 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
private boolean _syncFlush = false;
|
||||
|
||||
// non-static, as other GzipHandler instances may have different configurations
|
||||
private final ThreadLocal<Deflater> _deflater = new ThreadLocal<Deflater>();
|
||||
private final ThreadLocal<Deflater> _deflater = new ThreadLocal<>();
|
||||
|
||||
private final IncludeExclude<String> _agentPatterns=new IncludeExclude<>(RegexSet.class);
|
||||
private final IncludeExclude<String> _methods = new IncludeExclude<>();
|
||||
|
@ -398,6 +395,11 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
return _minGzipSize;
|
||||
}
|
||||
|
||||
protected HttpField getVaryField()
|
||||
{
|
||||
return _vary;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.handler.HandlerWrapper#handle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
|
@ -474,20 +476,21 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
String etag = baseRequest.getHttpFields().get(HttpHeader.IF_NONE_MATCH);
|
||||
if (etag!=null)
|
||||
{
|
||||
int i=etag.indexOf(ETAG_GZIP_QUOTE);
|
||||
int i=etag.indexOf(GzipHttpContent.ETAG_GZIP_QUOTE);
|
||||
if (i>0)
|
||||
{
|
||||
while (i>=0)
|
||||
{
|
||||
etag=etag.substring(0,i)+etag.substring(i+GzipHttpContent.ETAG_GZIP.length());
|
||||
i=etag.indexOf(ETAG_GZIP_QUOTE,i);
|
||||
i=etag.indexOf(GzipHttpContent.ETAG_GZIP_QUOTE,i);
|
||||
}
|
||||
baseRequest.getHttpFields().put(new HttpField(HttpHeader.IF_NONE_MATCH,etag));
|
||||
}
|
||||
}
|
||||
|
||||
// install interceptor and handle
|
||||
out.setInterceptor(new GzipHttpOutputInterceptor(this,_vary,baseRequest.getHttpChannel(),out.getInterceptor(),_syncFlush));
|
||||
out.setInterceptor(new GzipHttpOutputInterceptor(this,getVaryField(),baseRequest.getHttpChannel(),out.getInterceptor(),isSyncFlush()));
|
||||
|
||||
if (_handler!=null)
|
||||
_handler.handle(target,baseRequest, request, response);
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.eclipse.jetty.http.MimeTypes;
|
|||
import org.eclipse.jetty.http.PreEncodedHttpField;
|
||||
import org.eclipse.jetty.server.HttpChannel;
|
||||
import org.eclipse.jetty.server.HttpOutput;
|
||||
import org.eclipse.jetty.server.Response;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.util.IteratingNestedCallback;
|
||||
|
@ -150,7 +151,8 @@ public class GzipHttpOutputInterceptor implements HttpOutput.Interceptor
|
|||
protected void commit(ByteBuffer content, boolean complete, Callback callback)
|
||||
{
|
||||
// Are we excluding because of status?
|
||||
int sc = _channel.getResponse().getStatus();
|
||||
Response response = _channel.getResponse();
|
||||
int sc = response.getStatus();
|
||||
if (sc>0 && (sc<200 || sc==204 || sc==205 || sc>=300))
|
||||
{
|
||||
LOG.debug("{} exclude by status {}",this,sc);
|
||||
|
@ -160,7 +162,7 @@ public class GzipHttpOutputInterceptor implements HttpOutput.Interceptor
|
|||
}
|
||||
|
||||
// Are we excluding because of mime-type?
|
||||
String ct = _channel.getResponse().getContentType();
|
||||
String ct = response.getContentType();
|
||||
if (ct!=null)
|
||||
{
|
||||
ct=MimeTypes.getContentTypeWithoutCharset(ct);
|
||||
|
@ -174,7 +176,7 @@ public class GzipHttpOutputInterceptor implements HttpOutput.Interceptor
|
|||
}
|
||||
|
||||
// Has the Content-Encoding header already been set?
|
||||
String ce=_channel.getResponse().getHeader("Content-Encoding");
|
||||
String ce=response.getHeader("Content-Encoding");
|
||||
if (ce != null)
|
||||
{
|
||||
LOG.debug("{} exclude by content-encoding {}",this,ce);
|
||||
|
@ -187,10 +189,11 @@ public class GzipHttpOutputInterceptor implements HttpOutput.Interceptor
|
|||
if (_state.compareAndSet(GZState.MIGHT_COMPRESS,GZState.COMMITTING))
|
||||
{
|
||||
// We are varying the response due to accept encoding header.
|
||||
HttpFields fields = _channel.getResponse().getHttpFields();
|
||||
HttpFields fields = response.getHttpFields();
|
||||
if (_vary != null)
|
||||
fields.add(_vary);
|
||||
|
||||
long content_length = _channel.getResponse().getContentLength();
|
||||
long content_length = response.getContentLength();
|
||||
if (content_length<0 && complete)
|
||||
content_length=content.remaining();
|
||||
|
||||
|
@ -210,7 +213,7 @@ public class GzipHttpOutputInterceptor implements HttpOutput.Interceptor
|
|||
BufferUtil.fill(_buffer,GZIP_HEADER,0,GZIP_HEADER.length);
|
||||
|
||||
// Adjust headers
|
||||
_channel.getResponse().setContentLength(-1);
|
||||
response.setContentLength(-1);
|
||||
String etag=fields.get(HttpHeader.ETAG);
|
||||
if (etag!=null)
|
||||
{
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
package org.eclipse.jetty.server.session;
|
||||
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||
|
||||
/**
|
||||
|
@ -30,6 +32,8 @@ import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
|||
public abstract class AbstractSessionDataStore extends AbstractLifeCycle implements SessionDataStore
|
||||
{
|
||||
protected SessionContext _context; //context associated with this session data store
|
||||
protected int _gracePeriodSec = 60 * 60; //default of 1hr
|
||||
protected long _lastExpiryCheckTime = 0; //last time in ms that getExpired was called
|
||||
|
||||
|
||||
/**
|
||||
|
@ -38,11 +42,20 @@ public abstract class AbstractSessionDataStore extends AbstractLifeCycle impleme
|
|||
* @param id identity of session to store
|
||||
* @param data info of the session
|
||||
* @param lastSaveTime time of previous save or 0 if never saved
|
||||
* @throws Exception
|
||||
* @throws Exception if unable to store data
|
||||
*/
|
||||
public abstract void doStore(String id, SessionData data, long lastSaveTime) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Implemented by subclasses to resolve which sessions this node
|
||||
* should attempt to expire.
|
||||
*
|
||||
* @param candidates the ids of sessions the SessionStore thinks has expired
|
||||
* @param scavengePeriodSec the period in sec of the scavenge cycle checks
|
||||
* @return the reconciled set of session ids that this node should attempt to expire
|
||||
*/
|
||||
public abstract Set<String> doGetExpired (Set<String> candidates, int scavengePeriodSec);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -81,6 +94,25 @@ public abstract class AbstractSessionDataStore extends AbstractLifeCycle impleme
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(java.util.Set, int)
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getExpired(Set<String> candidates, int scavengePeriodSec)
|
||||
{
|
||||
try
|
||||
{
|
||||
return doGetExpired (candidates, scavengePeriodSec);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lastExpiryCheckTime = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#newSessionData(java.lang.String, long, long, long, long)
|
||||
*/
|
||||
|
@ -90,18 +122,12 @@ public abstract class AbstractSessionDataStore extends AbstractLifeCycle impleme
|
|||
return new SessionData(id, _context.getCanonicalContextPath(), _context.getVhost(), created, accessed, lastAccessed, maxInactiveMs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalStateException
|
||||
*/
|
||||
protected void checkStarted () throws IllegalStateException
|
||||
{
|
||||
if (isStarted())
|
||||
throw new IllegalStateException("Already started");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
|
@ -111,6 +137,13 @@ public abstract class AbstractSessionDataStore extends AbstractLifeCycle impleme
|
|||
super.doStart();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getGracePeriodSec()
|
||||
{
|
||||
return _gracePeriodSec;
|
||||
}
|
||||
|
||||
public void setGracePeriodSec(int sec)
|
||||
{
|
||||
_gracePeriodSec = sec;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ public abstract class AbstractSessionIdManager extends AbstractLifeCycle impleme
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param period inspector of sessions
|
||||
* @param inspector inspector of sessions
|
||||
*/
|
||||
public void setSessionInspector (PeriodicSessionInspector inspector)
|
||||
{
|
||||
|
@ -219,7 +219,7 @@ public abstract class AbstractSessionIdManager extends AbstractLifeCycle impleme
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param seedTerm
|
||||
* @param seedTerm the seed for RNG
|
||||
* @return a new unique session id
|
||||
*/
|
||||
public String newSessionId(long seedTerm)
|
||||
|
@ -399,9 +399,6 @@ public abstract class AbstractSessionIdManager extends AbstractLifeCycle impleme
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param id
|
||||
*/
|
||||
public void invalidateAll (String id)
|
||||
{
|
||||
//take the id out of the list of known sessionids for this node
|
||||
|
|
|
@ -21,15 +21,15 @@ package org.eclipse.jetty.server.session;
|
|||
|
||||
/**
|
||||
* AbstractInspector
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractSessionInspector implements SessionInspector
|
||||
{
|
||||
/**
|
||||
* <0 means never inspect
|
||||
* 0 means always inspect
|
||||
* >0 means inspect at that interval
|
||||
* <ul>
|
||||
* <li><0 means never inspect</li>
|
||||
* <li>0 means always inspect</li>
|
||||
* <li>>0 means inspect at that interval</li>
|
||||
* </ul>
|
||||
*/
|
||||
protected int _timeoutSec = -1;
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.eclipse.jetty.server.session;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -56,7 +55,7 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements
|
|||
|
||||
/**
|
||||
* Create a new Session object from session data
|
||||
* @param data
|
||||
* @param data the session data
|
||||
* @return a new Session object
|
||||
*/
|
||||
public abstract Session newSession (SessionData data);
|
||||
|
@ -84,9 +83,9 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements
|
|||
|
||||
/**
|
||||
* Replace the mapping from id to oldValue with newValue
|
||||
* @param id
|
||||
* @param oldValue
|
||||
* @param newValue
|
||||
* @param id the id
|
||||
* @param oldValue the old value
|
||||
* @param newValue the new value
|
||||
* @return true if replacement was done
|
||||
*/
|
||||
public abstract boolean doReplace (String id, Session oldValue, Session newValue);
|
||||
|
@ -95,7 +94,7 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements
|
|||
|
||||
/**
|
||||
* Check to see if the session exists in the store
|
||||
* @param id
|
||||
* @param id the id
|
||||
* @return true if the Session object exists in the session store
|
||||
*/
|
||||
public abstract boolean doExists (String id);
|
||||
|
@ -104,7 +103,7 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements
|
|||
|
||||
/**
|
||||
* Remove the session with this identity from the store
|
||||
* @param id
|
||||
* @param id the id
|
||||
* @return true if removed false otherwise
|
||||
*/
|
||||
public abstract Session doDelete (String id);
|
||||
|
@ -113,14 +112,12 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements
|
|||
|
||||
/**
|
||||
* PlaceHolder
|
||||
*
|
||||
*
|
||||
*/
|
||||
protected class PlaceHolderSession extends Session
|
||||
{
|
||||
|
||||
/**
|
||||
* @param data
|
||||
* @param data the session data
|
||||
*/
|
||||
public PlaceHolderSession(SessionData data)
|
||||
{
|
||||
|
@ -139,7 +136,7 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements
|
|||
|
||||
|
||||
/**
|
||||
* @param manager
|
||||
* @param manager the SessionManager
|
||||
*/
|
||||
public void setSessionManager (SessionManager manager)
|
||||
{
|
||||
|
@ -216,7 +213,7 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements
|
|||
}
|
||||
|
||||
/**
|
||||
* @param sessionDataStore
|
||||
* @param sessionDataStore the session datastore
|
||||
*/
|
||||
public void setSessionDataStore(SessionDataStore sessionDataStore)
|
||||
{
|
||||
|
@ -402,7 +399,7 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements
|
|||
/**
|
||||
* Load the info for the session from the session data store
|
||||
*
|
||||
* @param id
|
||||
* @param id the id
|
||||
* @return a Session object filled with data or null if the session doesn't exist
|
||||
* @throws Exception
|
||||
*/
|
||||
|
@ -555,7 +552,7 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements
|
|||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.SessionStore#checkExpiry(java.util.Set)
|
||||
* @see org.eclipse.jetty.server.session.SessionStore#checkExpiration(Set)
|
||||
*/
|
||||
@Override
|
||||
public Set<String> checkExpiration(Set<String> candidates)
|
||||
|
@ -565,7 +562,7 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements
|
|||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("SessionStore checking expiration on {}", candidates);
|
||||
return _sessionDataStore.getExpired(candidates);
|
||||
return _sessionDataStore.getExpired(candidates, _expiryTimeoutSec);
|
||||
}
|
||||
|
||||
|
||||
|
@ -695,24 +692,17 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param passivateOnComplete
|
||||
*/
|
||||
public void setPassivateOnComplete (boolean passivateOnComplete)
|
||||
{
|
||||
_passivateOnComplete = passivateOnComplete;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isPassivateOnComplete ()
|
||||
{
|
||||
return _passivateOnComplete;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.SessionStore#newSession(javax.servlet.http.HttpServletRequest, java.lang.String, long, long)
|
||||
*/
|
||||
|
|
|
@ -116,10 +116,10 @@ public class CachingSessionDataStore extends AbstractSessionDataStore
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(java.util.Set)
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set, int)
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getExpired(Set<String> candidates)
|
||||
public Set<String> doGetExpired(Set<String> candidates, int expiryTimeoutSec)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
|
|
|
@ -42,8 +42,8 @@ public class ExpiryInspector extends AbstractSessionInspector
|
|||
|
||||
|
||||
/**
|
||||
* @param sessionStore
|
||||
* @param idManager
|
||||
* @param sessionStore the session store
|
||||
* @param idManager the session id manager
|
||||
*/
|
||||
public ExpiryInspector (AbstractSessionStore sessionStore, SessionIdManager idManager)
|
||||
{
|
||||
|
@ -52,7 +52,7 @@ public class ExpiryInspector extends AbstractSessionInspector
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.SessionInspector#inspect(org.eclipse.jetty.server.session.SessionStore, org.eclipse.jetty.server.session.Session)
|
||||
* @see org.eclipse.jetty.server.session.SessionInspector#inspect(Session)
|
||||
*/
|
||||
@Override
|
||||
public void inspect(Session s)
|
||||
|
|
|
@ -111,10 +111,10 @@ public class FileSessionDataStore extends AbstractSessionDataStore
|
|||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(java.util.Set)
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set, int)
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getExpired(Set<String> candidates)
|
||||
public Set<String> doGetExpired(Set<String> candidates, int expiryTimeoutSec)
|
||||
{
|
||||
//we don't want to open up each file and check, so just leave it up to the SessionStore
|
||||
//TODO as the session manager is likely to be a lazy loader, if a session is never requested, its
|
||||
|
@ -258,7 +258,7 @@ public class FileSessionDataStore extends AbstractSessionDataStore
|
|||
|
||||
/**
|
||||
* @param id identity of session
|
||||
* @return
|
||||
* @return the filename of the session data store
|
||||
*/
|
||||
private String getFileName (String id)
|
||||
{
|
||||
|
@ -268,7 +268,7 @@ public class FileSessionDataStore extends AbstractSessionDataStore
|
|||
|
||||
/**
|
||||
* @param is inputstream containing session data
|
||||
* @return
|
||||
* @return the session data
|
||||
* @throws Exception
|
||||
*/
|
||||
private SessionData load (InputStream is)
|
||||
|
|
|
@ -54,7 +54,7 @@ public class FileSessionManager extends SessionManager
|
|||
|
||||
/**
|
||||
* Get the SessionDataStore to configure it
|
||||
* @return
|
||||
* @return the session datastore
|
||||
*/
|
||||
public FileSessionDataStore getSessionDataStore()
|
||||
{
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.eclipse.jetty.util.ConcurrentHashSet;
|
|||
public class HashSessionIdManager extends AbstractSessionIdManager
|
||||
{
|
||||
/**
|
||||
* @param server
|
||||
* @param server the server
|
||||
*/
|
||||
public HashSessionIdManager(Server server)
|
||||
{
|
||||
|
|
|
@ -39,7 +39,7 @@ public class IdleInspector extends AbstractSessionInspector
|
|||
protected AbstractSessionStore _sessionStore;
|
||||
|
||||
/**
|
||||
* @param sessionStore
|
||||
* @param sessionStore the session store
|
||||
*/
|
||||
public IdleInspector (AbstractSessionStore sessionStore)
|
||||
{
|
||||
|
|
|
@ -58,7 +58,6 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
|
|||
|
||||
private int _attempts = -1; // <= 0 means unlimited attempts to load a session
|
||||
private boolean _deleteUnloadables = false; //true means if attempts exhausted delete the session
|
||||
private long _gracePeriodMs = 1000L * 60 * 60; //default grace period is 1hr
|
||||
|
||||
/**
|
||||
* SessionTableSchema
|
||||
|
@ -285,7 +284,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
|
|||
}
|
||||
|
||||
|
||||
public PreparedStatement getMyExpiredSessionsStatement (Connection connection, String canonicalContextPath, String vhost, long expiry)
|
||||
public PreparedStatement getExpiredSessionsStatement (Connection connection, String canonicalContextPath, String vhost, long expiry)
|
||||
throws SQLException
|
||||
{
|
||||
if (_dbAdaptor == null)
|
||||
|
@ -318,6 +317,42 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
|
|||
}
|
||||
|
||||
|
||||
public PreparedStatement getMyExpiredSessionsStatement (Connection connection, SessionContext sessionContext, long expiry)
|
||||
throws SQLException
|
||||
{
|
||||
if (_dbAdaptor == null)
|
||||
throw new IllegalStateException("No DB adaptor");
|
||||
|
||||
if (sessionContext.getCanonicalContextPath() == null || "".equals(sessionContext.getCanonicalContextPath()))
|
||||
{
|
||||
if (_dbAdaptor.isEmptyStringNull())
|
||||
{
|
||||
PreparedStatement statement = connection.prepareStatement("select "+getIdColumn()+", "+getExpiryTimeColumn()+
|
||||
" from "+getTableName()+" where "+
|
||||
getLastNodeColumn() + " = ? and "+
|
||||
getContextPathColumn()+" is null and "+
|
||||
getVirtualHostColumn()+" = ? and "+getExpiryTimeColumn()+" >0 and "+getExpiryTimeColumn()+" <= ?");
|
||||
statement.setString(1, sessionContext.getWorkerName());
|
||||
statement.setString(2, sessionContext.getVhost());
|
||||
statement.setLong(3, expiry);
|
||||
return statement;
|
||||
}
|
||||
}
|
||||
|
||||
PreparedStatement statement = connection.prepareStatement("select "+getIdColumn()+", "+getExpiryTimeColumn()+
|
||||
" from "+getTableName()+" where "+
|
||||
getLastNodeColumn()+" = ? and "+
|
||||
getContextPathColumn()+" = ? and "+
|
||||
getVirtualHostColumn()+" = ? and "+
|
||||
getExpiryTimeColumn()+" >0 and "+getExpiryTimeColumn()+" <= ?");
|
||||
|
||||
statement.setString(1, sessionContext.getWorkerName());
|
||||
statement.setString(2, sessionContext.getCanonicalContextPath());
|
||||
statement.setString(3, sessionContext.getVhost());
|
||||
statement.setLong(4, expiry);
|
||||
return statement;
|
||||
}
|
||||
|
||||
|
||||
public PreparedStatement getAllAncientExpiredSessionsStatement (Connection connection)
|
||||
throws SQLException
|
||||
|
@ -483,10 +518,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
|
|||
|
||||
/**
|
||||
* Set up the tables in the database
|
||||
* @throws SQLException
|
||||
*/
|
||||
/**
|
||||
* @throws SQLException
|
||||
* @throws SQLException if unable to prepare tables
|
||||
*/
|
||||
public void prepareTables()
|
||||
throws SQLException
|
||||
|
@ -747,7 +779,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
|
|||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, boolean)
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(String, SessionData, long)
|
||||
*/
|
||||
@Override
|
||||
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
|
||||
|
@ -804,6 +836,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void doUpdate (String id, SessionData data)
|
||||
throws Exception
|
||||
{
|
||||
|
@ -851,30 +884,29 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
|
|||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(java.util.Set)
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set, int)
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getExpired(Set<String> candidates)
|
||||
public Set<String> doGetExpired(Set<String> candidates, int scavengeIntervalSec)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Getting expired sessions "+System.currentTimeMillis());
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
|
||||
Set<String> expiredSessionKeys = new HashSet<>();
|
||||
try (Connection connection = _dbAdaptor.getConnection())
|
||||
{
|
||||
connection.setAutoCommit(true);
|
||||
|
||||
/*
|
||||
* 1. Select sessions for our context that have expired
|
||||
* 1. Select sessions managed by this node for our context that have expired
|
||||
*/
|
||||
long upperBound = now;
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug ("{}- Pass 1: Searching for sessions for context {} expired before {}", _context.getWorkerName(), _context.getCanonicalContextPath(), upperBound);
|
||||
LOG.debug ("{}- Pass 1: Searching for sessions for context {} managed by me {} and expired before {}", _context.getCanonicalContextPath(), _context.getWorkerName(), upperBound);
|
||||
|
||||
try (PreparedStatement statement = _sessionTableSchema.getMyExpiredSessionsStatement(connection, _context.getCanonicalContextPath(), _context.getVhost(), upperBound))
|
||||
try (PreparedStatement statement = _sessionTableSchema.getExpiredSessionsStatement(connection, _context.getCanonicalContextPath(), _context.getVhost(), upperBound))
|
||||
{
|
||||
try (ResultSet result = statement.executeQuery())
|
||||
{
|
||||
|
@ -889,13 +921,17 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
|
|||
}
|
||||
|
||||
/*
|
||||
* 2. Select sessions for any node or context that have expired a long time ago (ie at least 3 grace periods ago)
|
||||
* 2. Select sessions for any node or context that have expired
|
||||
* at least 1 graceperiod since the last expiry check. If we haven't done previous expiry checks, then check
|
||||
* those that have expired at least 3 graceperiod ago.
|
||||
*/
|
||||
try (PreparedStatement selectExpiredSessions = _sessionTableSchema.getAllAncientExpiredSessionsStatement(connection))
|
||||
{
|
||||
upperBound = now - (3 * _gracePeriodMs);
|
||||
if (upperBound > 0)
|
||||
{
|
||||
if (_lastExpiryCheckTime <= 0)
|
||||
upperBound = (now - (3*(1000L * _gracePeriodSec)));
|
||||
else
|
||||
upperBound = _lastExpiryCheckTime - (1000L * _gracePeriodSec);
|
||||
|
||||
if (LOG.isDebugEnabled()) LOG.debug("{}- Pass 2: Searching for sessions expired before {}",_context.getWorkerName(), upperBound);
|
||||
|
||||
selectExpiredSessions.setLong(1, upperBound);
|
||||
|
@ -911,7 +947,6 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Set<String> notExpiredInDB = new HashSet<>();
|
||||
|
@ -958,20 +993,8 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
|
|||
LOG.warn(e);
|
||||
return expiredSessionKeys; //return whatever we got
|
||||
}
|
||||
|
||||
}
|
||||
public int getGracePeriodSec ()
|
||||
{
|
||||
return (int)(_gracePeriodMs == 0L? 0 : _gracePeriodMs/1000L);
|
||||
}
|
||||
|
||||
public void setGracePeriodSec (int sec)
|
||||
{
|
||||
if (sec < 0)
|
||||
_gracePeriodMs = 0;
|
||||
else
|
||||
_gracePeriodMs = sec * 1000L;
|
||||
}
|
||||
|
||||
public void setDatabaseAdaptor (DatabaseAdaptor dbAdaptor)
|
||||
{
|
||||
|
@ -1010,6 +1033,9 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
|
|||
_deleteUnloadables = delete;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if we should delete data for sessions that we cant reconstitute
|
||||
*/
|
||||
public boolean isDeleteUnloadableSessions ()
|
||||
{
|
||||
return _deleteUnloadables;
|
||||
|
@ -1027,6 +1053,10 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* @param id the id
|
||||
* @return number of attempts to load the given id
|
||||
*/
|
||||
public int getLoadAttempts (String id)
|
||||
{
|
||||
AtomicInteger i = _unloadables.get(id);
|
||||
|
@ -1035,20 +1065,23 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
|
|||
return i.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return how many sessions we've failed to load
|
||||
*/
|
||||
public Set<String> getUnloadableSessions ()
|
||||
{
|
||||
return new HashSet<String>(_unloadables.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void clearUnloadableSessions()
|
||||
{
|
||||
_unloadables.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating()
|
||||
*/
|
||||
|
|
|
@ -55,7 +55,7 @@ public class JDBCSessionManager extends SessionManager
|
|||
|
||||
/**
|
||||
* Get the db adaptor to configure jdbc settings
|
||||
* @return
|
||||
* @return the database adaptor
|
||||
*/
|
||||
public DatabaseAdaptor getDatabaseAdaptor()
|
||||
{
|
||||
|
@ -64,7 +64,7 @@ public class JDBCSessionManager extends SessionManager
|
|||
|
||||
/**
|
||||
* Get the SessionDataStore to configure it
|
||||
* @return
|
||||
* @return the session data store
|
||||
*/
|
||||
public JDBCSessionDataStore getSessionDataStore ()
|
||||
{
|
||||
|
|
|
@ -69,10 +69,10 @@ public class NullSessionDataStore extends AbstractSessionDataStore
|
|||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(java.util.Set)
|
||||
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set, int)
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getExpired(Set<String> candidates)
|
||||
public Set<String> doGetExpired(Set<String> candidates, int expiryTimeoutSec)
|
||||
{
|
||||
return candidates; //whatever is suggested we accept
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.server.SessionIdManager;
|
||||
|
@ -77,7 +76,7 @@ public class PeriodicSessionInspector extends AbstractLifeCycle
|
|||
|
||||
/**
|
||||
* SessionIdManager associated with this scavenger
|
||||
* @param sessionIdManager
|
||||
* @param sessionIdManager the session id manager
|
||||
*/
|
||||
public void setSessionIdManager (SessionIdManager sessionIdManager)
|
||||
{
|
||||
|
@ -137,7 +136,7 @@ public class PeriodicSessionInspector extends AbstractLifeCycle
|
|||
|
||||
/**
|
||||
* Set the period between scavenge cycles
|
||||
* @param sec
|
||||
* @param sec the interval (in seconds)
|
||||
*/
|
||||
public void setIntervalSec (long sec)
|
||||
{
|
||||
|
@ -176,7 +175,7 @@ public class PeriodicSessionInspector extends AbstractLifeCycle
|
|||
/**
|
||||
* Get the period between inspection cycles.
|
||||
*
|
||||
* @return
|
||||
* @return the interval (in seconds)
|
||||
*/
|
||||
public long getIntervalSec ()
|
||||
{
|
||||
|
|
|
@ -90,8 +90,8 @@ public class Session implements SessionManager.SessionIf
|
|||
/**
|
||||
* Create a new session
|
||||
*
|
||||
* @param request
|
||||
* @param data
|
||||
* @param request the request the session should be based on
|
||||
* @param data the session data
|
||||
*/
|
||||
public Session (HttpServletRequest request, SessionData data)
|
||||
{
|
||||
|
@ -104,7 +104,7 @@ public class Session implements SessionManager.SessionIf
|
|||
|
||||
/**
|
||||
* Re-create an existing session
|
||||
* @param data
|
||||
* @param data the session data
|
||||
*/
|
||||
public Session (SessionData data)
|
||||
{
|
||||
|
@ -116,7 +116,7 @@ public class Session implements SessionManager.SessionIf
|
|||
* Should call this method with a lock held if you want to
|
||||
* make decision on what to do with the session
|
||||
*
|
||||
* @return
|
||||
* @return the number of active requests for this session
|
||||
*/
|
||||
public long getRequests()
|
||||
{
|
||||
|
@ -206,18 +206,12 @@ public class Session implements SessionManager.SessionIf
|
|||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param nodename
|
||||
*/
|
||||
public void setLastNode (String nodename)
|
||||
{
|
||||
_sessionData.setLastNode(nodename);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getLastNode ()
|
||||
{
|
||||
return _sessionData.getLastNode();
|
||||
|
@ -479,9 +473,6 @@ public class Session implements SessionManager.SessionIf
|
|||
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
/**
|
||||
* @throws IllegalStateException
|
||||
*/
|
||||
protected void checkLocked ()
|
||||
throws IllegalStateException
|
||||
{
|
||||
|
@ -640,9 +631,6 @@ public class Session implements SessionManager.SessionIf
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param request
|
||||
*/
|
||||
public void renewId(HttpServletRequest request)
|
||||
{
|
||||
if (_manager == null)
|
||||
|
@ -740,21 +728,15 @@ public class Session implements SessionManager.SessionIf
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
/** Grab the lock on the session
|
||||
* @return
|
||||
* @return the lock
|
||||
*/
|
||||
public Lock lock ()
|
||||
{
|
||||
return _lock.lock();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
protected void doInvalidate() throws IllegalStateException
|
||||
{
|
||||
|
@ -863,21 +845,12 @@ public class Session implements SessionManager.SessionIf
|
|||
_passivationState = PassivationState.ACTIVE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isActive ()
|
||||
{
|
||||
checkLocked();
|
||||
return _passivationState == PassivationState.ACTIVE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isPassivated ()
|
||||
{
|
||||
checkLocked();
|
||||
|
|
|
@ -78,7 +78,7 @@ public class SessionContext
|
|||
/**
|
||||
* Run a runnable in the context (with context classloader set) if
|
||||
* there is one, otherwise just run it.
|
||||
* @param r
|
||||
* @param r the runnable
|
||||
*/
|
||||
public void run (Runnable r)
|
||||
{
|
||||
|
@ -120,8 +120,8 @@ public class SessionContext
|
|||
/**
|
||||
* Make an acceptable name from a context path.
|
||||
*
|
||||
* @param path
|
||||
* @return
|
||||
* @param path the path to normalize/fix
|
||||
* @return the clean/acceptable form of the path
|
||||
*/
|
||||
private String canonicalize (String path)
|
||||
{
|
||||
|
|
|
@ -62,16 +62,6 @@ public class SessionData implements Serializable
|
|||
protected boolean _dirty;
|
||||
protected long _lastSaved; //time in msec since last save
|
||||
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @param cpath
|
||||
* @param vhost
|
||||
* @param created
|
||||
* @param accessed
|
||||
* @param lastAccessed
|
||||
* @param maxInactiveMs
|
||||
*/
|
||||
public SessionData (String id, String cpath, String vhost, long created, long accessed, long lastAccessed, long maxInactiveMs)
|
||||
{
|
||||
_id = id;
|
||||
|
@ -123,10 +113,6 @@ public class SessionData implements Serializable
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param lastSaved
|
||||
*/
|
||||
public void setLastSaved(long lastSaved)
|
||||
{
|
||||
_lastSaved = lastSaved;
|
||||
|
@ -141,16 +127,13 @@ public class SessionData implements Serializable
|
|||
return _dirty;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dirty
|
||||
*/
|
||||
public void setDirty(boolean dirty)
|
||||
{
|
||||
_dirty = dirty;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param name the name of the attribute
|
||||
* @return the value of the attribute named
|
||||
*/
|
||||
public Object getAttribute (String name)
|
||||
|
@ -166,11 +149,6 @@ public class SessionData implements Serializable
|
|||
return _attributes.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Object setAttribute (String name, Object value)
|
||||
{
|
||||
Object old = (value==null?_attributes.remove(name):_attributes.put(name,value));
|
||||
|
@ -181,20 +159,11 @@ public class SessionData implements Serializable
|
|||
return old;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public void setDirty (String name)
|
||||
{
|
||||
setDirty (true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param attributes
|
||||
*/
|
||||
public void putAllAttributes (Map<String,Object> attributes)
|
||||
{
|
||||
_attributes.putAll(attributes);
|
||||
|
@ -224,9 +193,6 @@ public class SessionData implements Serializable
|
|||
return _id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
*/
|
||||
public void setId(String id)
|
||||
{
|
||||
_id = id;
|
||||
|
@ -240,9 +206,6 @@ public class SessionData implements Serializable
|
|||
return _contextPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param contextPath
|
||||
*/
|
||||
public void setContextPath(String contextPath)
|
||||
{
|
||||
_contextPath = contextPath;
|
||||
|
@ -256,9 +219,6 @@ public class SessionData implements Serializable
|
|||
return _vhost;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param vhost
|
||||
*/
|
||||
public void setVhost(String vhost)
|
||||
{
|
||||
_vhost = vhost;
|
||||
|
@ -272,9 +232,6 @@ public class SessionData implements Serializable
|
|||
return _lastNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lastNode
|
||||
*/
|
||||
public void setLastNode(String lastNode)
|
||||
{
|
||||
_lastNode = lastNode;
|
||||
|
@ -288,25 +245,16 @@ public class SessionData implements Serializable
|
|||
return _expiry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param expiry
|
||||
*/
|
||||
public void setExpiry(long expiry)
|
||||
{
|
||||
_expiry = expiry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public long getCreated()
|
||||
{
|
||||
return _created;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param created
|
||||
*/
|
||||
public void setCreated(long created)
|
||||
{
|
||||
_created = created;
|
||||
|
@ -320,9 +268,6 @@ public class SessionData implements Serializable
|
|||
return _cookieSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cookieSet
|
||||
*/
|
||||
public void setCookieSet(long cookieSet)
|
||||
{
|
||||
_cookieSet = cookieSet;
|
||||
|
@ -336,9 +281,6 @@ public class SessionData implements Serializable
|
|||
return _accessed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param accessed
|
||||
*/
|
||||
public void setAccessed(long accessed)
|
||||
{
|
||||
_accessed = accessed;
|
||||
|
@ -352,35 +294,21 @@ public class SessionData implements Serializable
|
|||
return _lastAccessed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lastAccessed
|
||||
*/
|
||||
public void setLastAccessed(long lastAccessed)
|
||||
{
|
||||
_lastAccessed = lastAccessed;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public long getMaxInactiveMs()
|
||||
{
|
||||
return _maxInactiveMs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maxInactive
|
||||
*/
|
||||
public void setMaxInactiveMs(long maxInactive)
|
||||
{
|
||||
_maxInactiveMs = maxInactive;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param out
|
||||
* @throws IOException
|
||||
*/
|
||||
private void writeObject(java.io.ObjectOutputStream out) throws IOException
|
||||
{
|
||||
out.writeUTF(_id); //session id
|
||||
|
@ -398,11 +326,6 @@ public class SessionData implements Serializable
|
|||
out.writeObject(_attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param in
|
||||
* @throws IOException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException
|
||||
{
|
||||
_id = in.readUTF();
|
||||
|
@ -419,11 +342,6 @@ public class SessionData implements Serializable
|
|||
_attributes = (ConcurrentHashMap<String,Object>)in.readObject();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param time
|
||||
* @return
|
||||
*/
|
||||
public boolean isExpiredAt (long time)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
|
@ -433,4 +351,23 @@ public class SessionData implements Serializable
|
|||
|
||||
return (getExpiry() < time);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("id="+_id);
|
||||
builder.append(", contextpath="+_contextPath);
|
||||
builder.append(", vhost="+_vhost);
|
||||
builder.append(", accessed="+_accessed);
|
||||
builder.append(", lastaccessed="+_lastAccessed);
|
||||
builder.append(", created="+_created);
|
||||
builder.append(", cookieset="+_cookieSet);
|
||||
builder.append(", lastnode="+_lastNode);
|
||||
builder.append(", expiry="+_expiry);
|
||||
builder.append(", maxinactive="+_maxInactiveMs);
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,18 +46,18 @@ public interface SessionDataStore extends LifeCycle
|
|||
* Read in session data from storage
|
||||
* @param id identity of session to load
|
||||
* @return the SessionData matching the id
|
||||
* @throws Exception
|
||||
* @throws Exception if unable to load session data
|
||||
*/
|
||||
public SessionData load (String id) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new SessionData
|
||||
* @param id
|
||||
* @param created
|
||||
* @param accessed
|
||||
* @param lastAccessed
|
||||
* @param maxInactiveMs
|
||||
* @param id the id
|
||||
* @param created the timestamp when created
|
||||
* @param accessed the timestamp when accessed
|
||||
* @param lastAccessed the timestamp when last accessed
|
||||
* @param maxInactiveMs the max inactive time in milliseconds
|
||||
* @return a new SessionData object
|
||||
*/
|
||||
public SessionData newSessionData (String id, long created, long accessed, long lastAccessed, long maxInactiveMs);
|
||||
|
@ -69,7 +69,7 @@ public interface SessionDataStore extends LifeCycle
|
|||
* Write out session data to storage
|
||||
* @param id identity of session to store
|
||||
* @param data info of session to store
|
||||
* @throws Exception
|
||||
* @throws Exception if unable to write session data
|
||||
*/
|
||||
public void store (String id, SessionData data) throws Exception;
|
||||
|
||||
|
@ -79,7 +79,7 @@ public interface SessionDataStore extends LifeCycle
|
|||
* Delete session data from storage
|
||||
* @param id identity of session to delete
|
||||
* @return true if the session was deleted from the permanent store
|
||||
* @throws Exception
|
||||
* @throws Exception if unable to delete session data
|
||||
*/
|
||||
public boolean delete (String id) throws Exception;
|
||||
|
||||
|
@ -93,9 +93,10 @@ public interface SessionDataStore extends LifeCycle
|
|||
* @param candidates if provided, these are keys of sessions that
|
||||
* the SessionStore thinks has expired and should be verified by the
|
||||
* SessionDataStore
|
||||
* @param scavengePeriodSec the time to attempt scavenge (in seconds)
|
||||
* @return set of session ids
|
||||
*/
|
||||
public Set<String> getExpired (Set<String> candidates);
|
||||
public Set<String> getExpired (Set<String> candidates, int scavengePeriodSec);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import static java.lang.Math.round;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
|
@ -53,7 +51,8 @@ import org.eclipse.jetty.util.log.Log;
|
|||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.statistic.CounterStatistic;
|
||||
import org.eclipse.jetty.util.statistic.SampleStatistic;
|
||||
import org.eclipse.jetty.util.thread.Locker.Lock;
|
||||
|
||||
import static java.lang.Math.round;
|
||||
|
||||
|
||||
|
||||
|
@ -766,7 +765,7 @@ public class SessionManager extends ContainerLifeCycle implements org.eclipse.je
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return
|
||||
* @return the session store
|
||||
*/
|
||||
public SessionStore getSessionStore ()
|
||||
{
|
||||
|
@ -1006,7 +1005,7 @@ public class SessionManager extends ContainerLifeCycle implements org.eclipse.je
|
|||
* Called either when a session has expired, or the app has
|
||||
* invalidated it.
|
||||
*
|
||||
* @param id
|
||||
* @param id the id to invalidate
|
||||
*/
|
||||
public void invalidate (String id)
|
||||
{
|
||||
|
@ -1032,9 +1031,6 @@ public class SessionManager extends ContainerLifeCycle implements org.eclipse.je
|
|||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public void inspect ()
|
||||
{
|
||||
//don't attempt to scavenge if we are shutting down
|
||||
|
|
|
@ -55,10 +55,6 @@ public class StalePeriodStrategy implements StalenessStrategy
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public long getStaleSec ()
|
||||
{
|
||||
return (_staleMs<=0?0L:_staleMs/1000L);
|
||||
|
@ -67,7 +63,7 @@ public class StalePeriodStrategy implements StalenessStrategy
|
|||
/**
|
||||
* The amount of time in seconds that a session can be held
|
||||
* in memory without being refreshed from the cluster.
|
||||
* @param sec
|
||||
* @param sec the time in seconds
|
||||
*/
|
||||
public void setStaleSec (long sec)
|
||||
{
|
||||
|
|
|
@ -18,89 +18,59 @@
|
|||
|
||||
package org.eclipse.jetty.server;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.util.thread.ShutdownThread;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* ShutdownMonitorTest
|
||||
*/
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ShutdownMonitorTest
|
||||
{
|
||||
public class TestableServer extends Server
|
||||
{
|
||||
boolean destroyed = false;
|
||||
boolean stopped = false;
|
||||
@Override
|
||||
protected void doStop() throws Exception
|
||||
{
|
||||
stopped = true;
|
||||
super.doStop();
|
||||
}
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
destroyed = true;
|
||||
super.destroy();
|
||||
}
|
||||
@Override
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
stopped = false;
|
||||
destroyed = false;
|
||||
super.doStart();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testShutdownMonitor() throws Exception
|
||||
{
|
||||
// test port and key assignment
|
||||
ShutdownMonitor.getInstance().setPort(0);
|
||||
ShutdownMonitor.getInstance().setExitVm(false);
|
||||
ShutdownMonitor.getInstance().start();
|
||||
String key = ShutdownMonitor.getInstance().getKey();
|
||||
int port = ShutdownMonitor.getInstance().getPort();
|
||||
ShutdownMonitor monitor = ShutdownMonitor.getInstance();
|
||||
monitor.setDebug(true);
|
||||
monitor.setPort(0);
|
||||
monitor.setExitVm(false);
|
||||
monitor.start();
|
||||
String key = monitor.getKey();
|
||||
int port = monitor.getPort();
|
||||
|
||||
// try starting a 2nd time (should be ignored)
|
||||
ShutdownMonitor.getInstance().start();
|
||||
monitor.start();
|
||||
|
||||
stop("stop", port, key, true);
|
||||
assertTrue(!ShutdownMonitor.getInstance().isAlive());
|
||||
monitor.await();
|
||||
assertTrue(!monitor.isAlive());
|
||||
|
||||
// should be able to change port and key because it is stopped
|
||||
ShutdownMonitor.getInstance().setPort(0);
|
||||
ShutdownMonitor.getInstance().setKey("foo");
|
||||
ShutdownMonitor.getInstance().start();
|
||||
monitor.setPort(0);
|
||||
String newKey = "foo";
|
||||
monitor.setKey(newKey);
|
||||
monitor.start();
|
||||
|
||||
key = ShutdownMonitor.getInstance().getKey();
|
||||
port = ShutdownMonitor.getInstance().getPort();
|
||||
assertTrue(ShutdownMonitor.getInstance().isAlive());
|
||||
key = monitor.getKey();
|
||||
assertEquals(newKey, key);
|
||||
port = monitor.getPort();
|
||||
assertTrue(monitor.isAlive());
|
||||
|
||||
stop("stop", port, key, true);
|
||||
assertTrue(!ShutdownMonitor.getInstance().isAlive());
|
||||
monitor.await();
|
||||
assertTrue(!monitor.isAlive());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testForceStopCommand() throws Exception
|
||||
{
|
||||
//create a testable Server with stop(), destroy() overridden to instrument
|
||||
//start server
|
||||
//call "forcestop" and check that server stopped but not destroyed
|
||||
// test port and key assignment
|
||||
System.setProperty("DEBUG", "true");
|
||||
ShutdownMonitor.getInstance().setPort(0);
|
||||
ShutdownMonitor monitor = ShutdownMonitor.getInstance();
|
||||
monitor.setPort(0);
|
||||
TestableServer server = new TestableServer();
|
||||
server.start();
|
||||
|
||||
|
@ -108,12 +78,13 @@ public class ShutdownMonitorTest
|
|||
assertTrue(!ShutdownThread.isRegistered(server));
|
||||
assertTrue(ShutdownMonitor.isRegistered(server));
|
||||
|
||||
String key = ShutdownMonitor.getInstance().getKey();
|
||||
int port = ShutdownMonitor.getInstance().getPort();
|
||||
String key = monitor.getKey();
|
||||
int port = monitor.getPort();
|
||||
|
||||
stop("forcestop", port, key, true);
|
||||
monitor.await();
|
||||
|
||||
assertTrue(!ShutdownMonitor.getInstance().isAlive());
|
||||
assertTrue(!monitor.isAlive());
|
||||
assertTrue(server.stopped);
|
||||
assertTrue(!server.destroyed);
|
||||
assertTrue(!ShutdownThread.isRegistered(server));
|
||||
|
@ -123,21 +94,10 @@ public class ShutdownMonitorTest
|
|||
@Test
|
||||
public void testOldStopCommandWithStopOnShutdownTrue() throws Exception
|
||||
{
|
||||
ShutdownMonitor monitor = ShutdownMonitor.getInstance();
|
||||
monitor.setExitVm(false);
|
||||
|
||||
//create a testable Server with stop(), destroy() overridden to instrument
|
||||
//call server.setStopAtShudown(true);
|
||||
//start server
|
||||
//call "stop" and check that server stopped but not destroyed
|
||||
|
||||
//stop server
|
||||
|
||||
//call server.setStopAtShutdown(false);
|
||||
//start server
|
||||
//call "stop" and check that the server is not stopped and not destroyed
|
||||
System.setProperty("DEBUG", "true");
|
||||
ShutdownMonitor.getInstance().setExitVm(false);
|
||||
|
||||
ShutdownMonitor.getInstance().setPort(0);
|
||||
monitor.setPort(0);
|
||||
TestableServer server = new TestableServer();
|
||||
server.setStopAtShutdown(true);
|
||||
server.start();
|
||||
|
@ -146,11 +106,13 @@ public class ShutdownMonitorTest
|
|||
assertTrue(ShutdownThread.isRegistered(server));
|
||||
assertTrue(ShutdownMonitor.isRegistered(server));
|
||||
|
||||
String key = ShutdownMonitor.getInstance().getKey();
|
||||
int port = ShutdownMonitor.getInstance().getPort();
|
||||
String key = monitor.getKey();
|
||||
int port = monitor.getPort();
|
||||
|
||||
stop("stop", port, key, true);
|
||||
assertTrue(!ShutdownMonitor.getInstance().isAlive());
|
||||
monitor.await();
|
||||
|
||||
assertTrue(!monitor.isAlive());
|
||||
assertTrue(server.stopped);
|
||||
assertTrue(!server.destroyed);
|
||||
assertTrue(!ShutdownThread.isRegistered(server));
|
||||
|
@ -160,10 +122,9 @@ public class ShutdownMonitorTest
|
|||
@Test
|
||||
public void testOldStopCommandWithStopOnShutdownFalse() throws Exception
|
||||
{
|
||||
//change so stopatshutdown is false, so stop does nothing in this case (as exitVm is false otherwise we couldn't run test)
|
||||
ShutdownMonitor.getInstance().setExitVm(false);
|
||||
System.setProperty("DEBUG", "true");
|
||||
ShutdownMonitor.getInstance().setPort(0);
|
||||
ShutdownMonitor monitor = ShutdownMonitor.getInstance();
|
||||
monitor.setExitVm(false);
|
||||
monitor.setPort(0);
|
||||
TestableServer server = new TestableServer();
|
||||
server.setStopAtShutdown(false);
|
||||
server.start();
|
||||
|
@ -171,20 +132,19 @@ public class ShutdownMonitorTest
|
|||
assertTrue(!ShutdownThread.isRegistered(server));
|
||||
assertTrue(ShutdownMonitor.isRegistered(server));
|
||||
|
||||
String key = ShutdownMonitor.getInstance().getKey();
|
||||
int port = ShutdownMonitor.getInstance().getPort();
|
||||
String key = monitor.getKey();
|
||||
int port = monitor.getPort();
|
||||
|
||||
stop("stop", port, key, true);
|
||||
assertTrue(!ShutdownMonitor.getInstance().isAlive());
|
||||
monitor.await();
|
||||
|
||||
assertTrue(!monitor.isAlive());
|
||||
assertTrue(!server.stopped);
|
||||
assertTrue(!server.destroyed);
|
||||
assertTrue(!ShutdownThread.isRegistered(server));
|
||||
assertTrue(ShutdownMonitor.isRegistered(server));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void stop(String command, int port, String key, boolean check) throws Exception
|
||||
{
|
||||
System.out.printf("Attempting to send " + command + " to localhost:%d (%b)%n", port, check);
|
||||
|
@ -198,16 +158,11 @@ public class ShutdownMonitorTest
|
|||
|
||||
if (check)
|
||||
{
|
||||
// wait a little
|
||||
TimeUnit.MILLISECONDS.sleep(600);
|
||||
|
||||
// check for stop confirmation
|
||||
LineNumberReader lin = new LineNumberReader(new InputStreamReader(s.getInputStream()));
|
||||
String response;
|
||||
if ((response = lin.readLine()) != null)
|
||||
{
|
||||
assertEquals("Stopped", response);
|
||||
}
|
||||
else
|
||||
throw new IllegalStateException("No stop confirmation");
|
||||
}
|
||||
|
@ -215,4 +170,31 @@ public class ShutdownMonitorTest
|
|||
}
|
||||
}
|
||||
|
||||
public class TestableServer extends Server
|
||||
{
|
||||
boolean destroyed = false;
|
||||
boolean stopped = false;
|
||||
|
||||
@Override
|
||||
protected void doStop() throws Exception
|
||||
{
|
||||
stopped = true;
|
||||
super.doStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
destroyed = true;
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
stopped = false;
|
||||
destroyed = false;
|
||||
super.doStart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,22 +18,18 @@
|
|||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.servlet.SessionCookieConfig;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.eclipse.jetty.http.HttpCookie;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* SessionCookieTest
|
||||
*/
|
||||
|
@ -46,7 +42,7 @@ public class SessionCookieTest
|
|||
{
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.SessionStore#newSession(org.eclipse.jetty.server.session.SessionKey, long, long, long, long)
|
||||
* @see org.eclipse.jetty.server.session.SessionStore#newSession(HttpServletRequest, String, long, long)
|
||||
*/
|
||||
@Override
|
||||
public Session newSession(HttpServletRequest request, String key, long time, long maxInactiveMs)
|
||||
|
@ -76,7 +72,7 @@ public class SessionCookieTest
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doGet(org.eclipse.jetty.server.session.SessionKey)
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doGet(String)
|
||||
*/
|
||||
@Override
|
||||
public Session doGet(String key)
|
||||
|
@ -86,7 +82,7 @@ public class SessionCookieTest
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doPutIfAbsent(org.eclipse.jetty.server.session.SessionKey, org.eclipse.jetty.server.session.Session)
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doPutIfAbsent(String, Session)
|
||||
*/
|
||||
@Override
|
||||
public Session doPutIfAbsent(String key, Session session)
|
||||
|
@ -95,7 +91,7 @@ public class SessionCookieTest
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doExists(org.eclipse.jetty.server.session.SessionKey)
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doExists(String)
|
||||
*/
|
||||
@Override
|
||||
public boolean doExists(String key)
|
||||
|
@ -105,7 +101,7 @@ public class SessionCookieTest
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doDelete(org.eclipse.jetty.server.session.SessionKey)
|
||||
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doDelete(String)
|
||||
*/
|
||||
@Override
|
||||
public Session doDelete(String key)
|
||||
|
@ -140,10 +136,6 @@ public class SessionCookieTest
|
|||
|
||||
public class MockSessionIdManager extends AbstractSessionIdManager
|
||||
{
|
||||
|
||||
/**
|
||||
* @param server
|
||||
*/
|
||||
public MockSessionIdManager(Server server)
|
||||
{
|
||||
super(server);
|
||||
|
@ -175,7 +167,7 @@ public class SessionCookieTest
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.SessionIdManager#useId(java.lang.String)
|
||||
* @see org.eclipse.jetty.server.SessionIdManager#useId(Session)
|
||||
*/
|
||||
@Override
|
||||
public void useId(Session session)
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.server.ssl;
|
|||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
@ -152,9 +153,19 @@ public class SslConnectionFactoryTest
|
|||
out.write("Rubbish".getBytes());
|
||||
out.flush();
|
||||
|
||||
Assert.assertThat(socket.getInputStream().read(),Matchers.equalTo(-1));
|
||||
socket.setSoTimeout(1000);
|
||||
InputStream input = socket.getInputStream();
|
||||
int read = input.read();
|
||||
// TLS Alert message type == 21.
|
||||
Assert.assertThat(read, Matchers.equalTo(21));
|
||||
int reads = 0;
|
||||
while (read >= 0)
|
||||
{
|
||||
read = input.read();
|
||||
++reads;
|
||||
}
|
||||
Assert.assertThat(reads, Matchers.lessThan(32));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String getResponse(String sniHost,String reqHost, String cn) throws Exception
|
||||
|
|
|
@ -771,11 +771,15 @@ public class MultiPartInputStreamParser
|
|||
}
|
||||
finally
|
||||
{
|
||||
|
||||
part.close();
|
||||
}
|
||||
}
|
||||
if (!lastPart)
|
||||
if (lastPart)
|
||||
{
|
||||
while(line!=null)
|
||||
line=((ReadLineInputStream)_in).readLine();
|
||||
}
|
||||
else
|
||||
throw new IOException("Incomplete parts");
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -245,12 +245,14 @@ public class ServerContainer extends ClientContainer implements javax.websocket.
|
|||
@Override
|
||||
public void onSessionClosed(WebSocketSession session)
|
||||
{
|
||||
super.onSessionClosed(session);
|
||||
webSocketServerFactory.onSessionClosed(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionOpened(WebSocketSession session)
|
||||
{
|
||||
super.onSessionOpened(session);
|
||||
webSocketServerFactory.onSessionOpened(session);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.jsr356.server.browser;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.websocket.DeploymentException;
|
||||
|
||||
|
@ -30,6 +35,7 @@ import org.eclipse.jetty.servlet.ServletContextHandler;
|
|||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
|
||||
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
|
||||
|
||||
|
@ -78,7 +84,7 @@ public class JsrBrowserDebugTool
|
|||
server.join();
|
||||
}
|
||||
|
||||
private void setupServer(int port) throws DeploymentException, ServletException
|
||||
private void setupServer(int port) throws DeploymentException, ServletException, URISyntaxException, MalformedURLException
|
||||
{
|
||||
server = new Server();
|
||||
|
||||
|
@ -89,10 +95,16 @@ public class JsrBrowserDebugTool
|
|||
connector.setPort(port);
|
||||
server.addConnector(connector);
|
||||
|
||||
String resourcePath = "/jsr-browser-debug-tool/index.html";
|
||||
URL urlStatics = JsrBrowserDebugTool.class.getResource(resourcePath);
|
||||
Objects.requireNonNull(urlStatics,"Unable to find " + resourcePath + " in classpath");
|
||||
String urlBase = urlStatics.toURI().toASCIIString().replaceFirst("/[^/]*$","/");
|
||||
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/");
|
||||
context.setBaseResource(Resource.newResource(urlBase));
|
||||
|
||||
ServletHolder holder = context.addServlet(DefaultServlet.class,"/");
|
||||
holder.setInitParameter("resourceBase","src/test/resources/jsr-browser-debug-tool");
|
||||
holder.setInitParameter("dirAllowed","true");
|
||||
server.setHandler(context);
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.text.SimpleDateFormat;
|
|||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.websocket.CloseReason;
|
||||
import javax.websocket.OnClose;
|
||||
|
@ -129,6 +130,14 @@ public class JsrBrowserSocket
|
|||
{
|
||||
writeMessage("Client Sec-WebSocket-Extensions: " + this.requestedExtensions);
|
||||
}
|
||||
|
||||
Set<Session> openSessions = session.getOpenSessions();
|
||||
writeMessage("OpenSessions.size() = " + openSessions.size());
|
||||
int i = 0;
|
||||
for (Session open : openSessions)
|
||||
{
|
||||
writeMessage(" OpenSession[%d] = %s", i++, open);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "many":
|
||||
|
|
|
@ -6,9 +6,6 @@ org.eclipse.jetty.LEVEL=WARN
|
|||
# org.eclipse.jetty.websocket.LEVEL=WARN
|
||||
# org.eclipse.jetty.websocket.common.io.LEVEL=DEBUG
|
||||
|
||||
org.eclipse.jetty.websocket.common.WebSocketSession.LEVEL=DEBUG
|
||||
org.eclipse.jetty.websocket.jsr356.LEVEL=DEBUG
|
||||
|
||||
### Show state changes on BrowserDebugTool
|
||||
# -- LEAVE THIS AT DEBUG LEVEL --
|
||||
org.eclipse.jetty.websocket.jsr356.server.browser.LEVEL=DEBUG
|
||||
|
|
5
pom.xml
5
pom.xml
|
@ -368,15 +368,16 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.8</version>
|
||||
<configuration>
|
||||
<docfilessubdirs>true</docfilessubdirs>
|
||||
<detectLinks>false</detectLinks>
|
||||
<detectLinks>true</detectLinks>
|
||||
<detectJavaApiLink>true</detectJavaApiLink>
|
||||
<show>protected</show>
|
||||
<excludePackageNames>com.acme.*;org.slf4j.*;org.mortbay.*</excludePackageNames>
|
||||
<links>
|
||||
<link>http://docs.oracle.com/javase/8/docs/api/</link>
|
||||
<link>http://docs.oracle.com/javaee/7/api/</link>
|
||||
<link>http://junit.org/javadoc/latest/</link>
|
||||
<link>http://download.eclipse.org/jetty/stable-9/apidocs/</link>
|
||||
</links>
|
||||
<tags>
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.http.client;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -39,7 +40,10 @@ import org.eclipse.jetty.http.HttpStatus;
|
|||
import org.eclipse.jetty.http2.FlowControlStrategy;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HttpClientTest extends AbstractTest
|
||||
|
@ -285,6 +289,33 @@ public class HttpClientTest extends AbstractTest
|
|||
Assert.assertEquals(response.getStatus(), 200);
|
||||
}
|
||||
|
||||
@Test(expected = ExecutionException.class)
|
||||
public void testClientCannotValidateServerCertificate() throws Exception
|
||||
{
|
||||
// Only run this test for transports over TLS.
|
||||
Assume.assumeTrue(EnumSet.of(Transport.HTTPS, Transport.H2).contains(transport));
|
||||
|
||||
startServer(new AbstractHandler()
|
||||
{
|
||||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
baseRequest.setHandled(true);
|
||||
}
|
||||
});
|
||||
|
||||
// Use a default SslContextFactory, requests should fail because the server certificate is unknown.
|
||||
client = newHttpClient(provideClientTransport(transport), new SslContextFactory());
|
||||
QueuedThreadPool clientThreads = new QueuedThreadPool();
|
||||
clientThreads.setName("client");
|
||||
client.setExecutor(clientThreads);
|
||||
client.start();
|
||||
|
||||
client.newRequest(newURI())
|
||||
.timeout(5, TimeUnit.SECONDS)
|
||||
.send();
|
||||
}
|
||||
|
||||
private void sleep(long time) throws IOException
|
||||
{
|
||||
try
|
||||
|
|
|
@ -139,7 +139,7 @@ public abstract class AbstractSessionInvalidateAndCreateTest
|
|||
assertTrue(listener.destroys.contains("session1"));
|
||||
assertTrue(listener.destroys.contains("session2"));
|
||||
//session2's HttpSessionBindingListener should have been called when it was scavenged
|
||||
assertTrue(servlet.unbound);
|
||||
assertTrue(servlet.listener.unbound);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -152,13 +152,17 @@ public abstract class AbstractSessionInvalidateAndCreateTest
|
|||
}
|
||||
}
|
||||
|
||||
public static class TestServlet extends HttpServlet
|
||||
public static class Foo implements Serializable
|
||||
{
|
||||
public boolean bar = false;
|
||||
|
||||
public boolean getBar() { return bar;};
|
||||
}
|
||||
|
||||
public static class MySessionBindingListener implements HttpSessionBindingListener, Serializable
|
||||
{
|
||||
private boolean unbound = false;
|
||||
|
||||
public class MySessionBindingListener implements HttpSessionBindingListener, Serializable
|
||||
{
|
||||
|
||||
public void valueUnbound(HttpSessionBindingEvent event)
|
||||
{
|
||||
unbound = true;
|
||||
|
@ -170,6 +174,11 @@ public abstract class AbstractSessionInvalidateAndCreateTest
|
|||
}
|
||||
}
|
||||
|
||||
public static class TestServlet extends HttpServlet
|
||||
{
|
||||
public MySessionBindingListener listener = new MySessionBindingListener();
|
||||
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse httpServletResponse) throws ServletException, IOException
|
||||
{
|
||||
|
@ -190,7 +199,7 @@ public abstract class AbstractSessionInvalidateAndCreateTest
|
|||
//now make a new session
|
||||
session = request.getSession(true);
|
||||
session.setAttribute("identity", "session2");
|
||||
session.setAttribute("listener", new MySessionBindingListener());
|
||||
session.setAttribute("listener", listener);
|
||||
}
|
||||
else
|
||||
fail("Session already missing");
|
||||
|
|
|
@ -129,6 +129,14 @@
|
|||
</loginServices>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- must deploy: required for jetty-distribution -->
|
||||
<skip>false</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
|
|
|
@ -24,6 +24,14 @@
|
|||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- must deploy: required for jetty-distribution -->
|
||||
<skip>false</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
|
|
Loading…
Reference in New Issue