Merge branch 'jetty-10.0.x' into jetty-11.0.x

This commit is contained in:
olivier lamy 2020-05-16 20:31:01 +10:00
commit 45690ad09b
24 changed files with 518 additions and 146 deletions

View File

@ -93,4 +93,10 @@ public class HttpAuthenticationStore implements AuthenticationStore
}
return null;
}
@Override
public boolean hasAuthenticationResults()
{
return !results.isEmpty();
}
}

View File

@ -1113,7 +1113,7 @@ public class HttpClient extends ContainerLifeCycle
protected String normalizeHost(String host)
{
if (host != null && host.matches("\\[.*]"))
if (host != null && host.startsWith("[") && host.endsWith("]"))
return host.substring(1, host.length() - 1);
return host;
}

View File

@ -27,6 +27,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
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.api.Response;
import org.eclipse.jetty.client.util.BytesRequestContent;
@ -138,13 +139,15 @@ public abstract class HttpConnection implements IConnection
request.path(path);
}
URI uri = request.getURI();
ProxyConfiguration.Proxy proxy = destination.getProxy();
if (proxy instanceof HttpProxy && !HttpClient.isSchemeSecure(request.getScheme()) && uri != null)
if (proxy instanceof HttpProxy && !HttpClient.isSchemeSecure(request.getScheme()))
{
path = uri.toString();
request.path(path);
URI uri = request.getURI();
if (uri != null)
{
path = uri.toString();
request.path(path);
}
}
// If we are HTTP 1.1, add the Host header
@ -185,9 +188,10 @@ public abstract class HttpConnection implements IConnection
// Cookies
CookieStore cookieStore = getHttpClient().getCookieStore();
if (cookieStore != null)
if (cookieStore != null && cookieStore.getClass() != HttpCookieStore.Empty.class)
{
StringBuilder cookies = null;
URI uri = request.getURI();
if (uri != null)
cookies = convertCookies(HttpCookieStore.matchPath(uri, cookieStore.get(uri)), null);
cookies = convertCookies(request.getCookies(), cookies);
@ -199,8 +203,8 @@ public abstract class HttpConnection implements IConnection
}
// Authentication
applyAuthentication(request, proxy != null ? proxy.getURI() : null);
applyAuthentication(request, uri);
applyProxyAuthentication(request, proxy);
applyRequestAuthentication(request);
}
private StringBuilder convertCookies(List<HttpCookie> cookies, StringBuilder builder)
@ -216,16 +220,31 @@ public abstract class HttpConnection implements IConnection
return builder;
}
private void applyAuthentication(Request request, URI uri)
private void applyProxyAuthentication(Request request, ProxyConfiguration.Proxy proxy)
{
if (uri != null)
if (proxy != null)
{
Authentication.Result result = getHttpClient().getAuthenticationStore().findAuthenticationResult(uri);
Authentication.Result result = getHttpClient().getAuthenticationStore().findAuthenticationResult(proxy.getURI());
if (result != null)
result.apply(request);
}
}
private void applyRequestAuthentication(Request request)
{
AuthenticationStore authenticationStore = getHttpClient().getAuthenticationStore();
if (authenticationStore.hasAuthenticationResults())
{
URI uri = request.getURI();
if (uri != null)
{
Authentication.Result result = authenticationStore.findAuthenticationResult(uri);
if (result != null)
result.apply(request);
}
}
}
public boolean onIdleTimeout(long idleTimeout)
{
synchronized (this)

View File

@ -117,9 +117,9 @@ public class HttpConversation extends AttributesMap
// will notify a listener that may send a new request and trigger
// another call to this method which will build different listeners
// which may be iterated over when the iteration continues.
List<Response.ResponseListener> listeners = new ArrayList<>();
HttpExchange firstExchange = exchanges.peekFirst();
HttpExchange lastExchange = exchanges.peekLast();
List<Response.ResponseListener> listeners = new ArrayList<>(firstExchange.getResponseListeners().size() + lastExchange.getResponseListeners().size());
if (firstExchange == lastExchange)
{
// We don't have a conversation, just a single request.

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.client;
import java.io.IOException;
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@ -31,7 +32,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.LongConsumer;
import java.util.function.LongUnaryOperator;
import java.util.stream.Collectors;
import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.client.api.Result;
@ -693,10 +693,11 @@ public abstract class HttpReceiver
private ContentListeners(List<Response.ResponseListener> responseListeners)
{
listeners = responseListeners.stream()
listeners = new ArrayList<>(responseListeners.size());
responseListeners.stream()
.filter(Response.DemandedContentListener.class::isInstance)
.map(Response.DemandedContentListener.class::cast)
.collect(Collectors.toList());
.forEach(listeners::add);
}
private boolean isEmpty()

View File

@ -75,4 +75,12 @@ public interface AuthenticationStore
* @return the {@link Authentication.Result} that matches the given URI, or null
*/
public Authentication.Result findAuthenticationResult(URI uri);
/**
* @return false if there are no stored authentication results, true if there may be some.
*/
public default boolean hasAuthenticationResults()
{
return true;
}
}

View File

@ -73,7 +73,10 @@ public interface Request
* @param host the URI host of this request, such as "127.0.0.1" or "google.com"
* @return this request object
*/
Request host(String host);
default Request host(String host)
{
return this;
}
/**
* @return the URI port of this request such as 80 or 443
@ -81,11 +84,13 @@ public interface Request
int getPort();
/**
*
* @param port the URI port of this request such as 80 or 443
* @return this request object
*/
Request port(int port);
default Request port(int port)
{
return this;
}
/**
* @return the method of this request, such as GET or POST, as a String

View File

@ -7,12 +7,11 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>infinispan-remote-query</artifactId>
<name>Jetty :: Infinispan Session Manager Remote with Querying</name>
<url>http://www.eclipse.org/jetty</url>
<properties>
<bundle-symbolic-name>${project.groupId}.infinispan.remote.query</bundle-symbolic-name>
<infinispan.docker.image.version>9.4.8.Final</infinispan.docker.image.version>
</properties>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -127,10 +126,20 @@
<artifactId>infinispan-remote-query-client</artifactId>
<version>${infinispan.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>remote</id>
<id>remote-session-tests</id>
<activation>
<property>
<name>hotrod.enabled</name>
@ -144,6 +153,9 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>false</skipTests>
<systemPropertyVariables>
<infinispan.docker.image.version>${infinispan.docker.image.version}</infinispan.docker.image.version>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>

View File

@ -27,6 +27,7 @@ import java.util.Random;
import java.util.Set;
import org.eclipse.jetty.server.session.SessionData;
import org.eclipse.jetty.session.infinispan.InfinispanSessionData;
import org.eclipse.jetty.session.infinispan.QueryManager;
import org.eclipse.jetty.session.infinispan.RemoteQueryManager;
import org.eclipse.jetty.session.infinispan.SessionDataMarshaller;
@ -35,11 +36,23 @@ import org.hibernate.search.cfg.Environment;
import org.hibernate.search.cfg.SearchMapping;
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.ClientIntelligence;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.client.hotrod.marshall.ProtoStreamMarshaller;
import org.infinispan.protostream.FileDescriptorSource;
import org.infinispan.protostream.SerializationContext;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
import org.testcontainers.utility.MountableFile;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -49,8 +62,45 @@ public class RemoteQueryManagerTest
{
public static final String DEFAULT_CACHE_NAME = "remote-session-test";
private static final Logger LOG = LoggerFactory.getLogger(RemoteQueryManagerTest.class);
private static final Logger INFINISPAN_LOG =
LoggerFactory.getLogger("org.eclipse.jetty.server.session.infinispan.infinispanLogs");
private String host;
private int port;
GenericContainer infinispan =
new GenericContainer(System.getProperty("infinispan.docker.image.name", "jboss/infinispan-server") +
":" + System.getProperty("infinispan.docker.image.version", "9.4.8.Final"))
.withEnv("APP_USER","theuser")
.withEnv("APP_PASS","foobar")
.withEnv("MGMT_USER", "admin")
.withEnv("MGMT_PASS", "admin")
.waitingFor(new LogMessageWaitStrategy()
.withRegEx(".*Infinispan Server.*started in.*\\s"))
.withExposedPorts(4712,4713,8088,8089,8443,9990,9993,11211,11222,11223,11224)
.withLogConsumer(new Slf4jLogConsumer(INFINISPAN_LOG));
@BeforeEach
public void setup() throws Exception
{
long start = System.currentTimeMillis();
infinispan.start();
host = infinispan.getContainerIpAddress();
port = infinispan.getMappedPort(11222);
LOG.info("Infinispan container started for {}:{} - {}ms", host, port,
System.currentTimeMillis() - start);
}
@AfterEach
public void stop() throws Exception
{
infinispan.stop();
}
@Test
public void test() throws Exception
public void testQuery() throws Exception
{
SearchMapping mapping = new SearchMapping();
mapping.entity(SessionData.class).indexed().providedId().property("expiry", ElementType.FIELD).field();
@ -59,9 +109,13 @@ public class RemoteQueryManagerTest
properties.put(Environment.MODEL_MAPPING, mapping);
ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
clientBuilder.withProperties(properties).addServer().host("127.0.0.1").marshaller(new ProtoStreamMarshaller());
clientBuilder.withProperties(properties).addServer()
.host(this.host).port(this.port)
.clientIntelligence(ClientIntelligence.BASIC)
.marshaller(new ProtoStreamMarshaller());
RemoteCacheManager remoteCacheManager = new RemoteCacheManager(clientBuilder.build());
remoteCacheManager.administration().getOrCreateCache("remote-session-test", (String)null);
FileDescriptorSource fds = new FileDescriptorSource();
fds.addProtoFiles("/session.proto");
@ -70,20 +124,17 @@ public class RemoteQueryManagerTest
serCtx.registerProtoFiles(fds);
serCtx.registerMarshaller(new SessionDataMarshaller());
RemoteCache<String, SessionData> cache = remoteCacheManager.getCache(DEFAULT_CACHE_NAME);
ByteArrayOutputStream baos;
try (InputStream is = RemoteQueryManagerTest.class.getClassLoader().getResourceAsStream("session.proto"))
try (InputStream is = RemoteQueryManagerTest.class.getClassLoader().getResourceAsStream("session.proto");
ByteArrayOutputStream baos = new ByteArrayOutputStream())
{
if (is == null)
throw new IllegalStateException("inputstream is null");
baos = new ByteArrayOutputStream();
IO.copy(is, baos);
String content = baos.toString("UTF-8");
remoteCacheManager.getCache("___protobuf_metadata").put("session.proto", content);
}
String content = baos.toString("UTF-8");
remoteCacheManager.getCache("___protobuf_metadata").put("session.proto", content);
RemoteCache<String, SessionData> cache = remoteCacheManager.getCache(DEFAULT_CACHE_NAME);
//put some sessions into the remote cache
int numSessions = 10;
@ -97,7 +148,7 @@ public class RemoteQueryManagerTest
String id = "sd" + i;
//create new sessiondata with random expiry time
long expiryTime = r.nextInt(maxExpiryTime);
SessionData sd = new SessionData(id, "", "", 0, 0, 0, 0);
InfinispanSessionData sd = new InfinispanSessionData(id, "", "", 0, 0, 0, 0);
sd.setLastNode("lastNode");
sd.setExpiry(expiryTime);

View File

@ -0,0 +1,3 @@
org.slf4j.simpleLogger.defaultLogLevel=info
org.slf4j.simpleLogger.log.org.eclipse.jetty.server.session.infinispan.infinispanLogs=debug
org.slf4j.simpleLogger.log.org.eclipse.jetty.server.session.infinispan.RemoteQueryManagerTest=debug

View File

@ -0,0 +1,147 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.server;
import java.util.HashSet;
import java.util.Set;
import javax.servlet.AsyncContext;
import javax.servlet.http.HttpServletMapping;
import org.eclipse.jetty.util.Attributes;
class AsyncAttributes extends Attributes.Wrapper
{
private String _requestURI;
private String _contextPath;
private String _servletPath;
private String _pathInfo;
private String _queryString;
private HttpServletMapping _httpServletMapping;
public AsyncAttributes(Attributes attributes, String requestUri, String contextPath, String servletPath, String pathInfo, String queryString, HttpServletMapping httpServletMapping)
{
super(attributes);
// TODO: make fields final in jetty-10 and NOOP when one of these attributes is set.
_requestURI = requestUri;
_contextPath = contextPath;
_servletPath = servletPath;
_pathInfo = pathInfo;
_queryString = queryString;
_httpServletMapping = httpServletMapping;
}
@Override
public Object getAttribute(String key)
{
switch (key)
{
case AsyncContext.ASYNC_REQUEST_URI:
return _requestURI;
case AsyncContext.ASYNC_CONTEXT_PATH:
return _contextPath;
case AsyncContext.ASYNC_SERVLET_PATH:
return _servletPath;
case AsyncContext.ASYNC_PATH_INFO:
return _pathInfo;
case AsyncContext.ASYNC_QUERY_STRING:
return _queryString;
case AsyncContext.ASYNC_MAPPING:
return _httpServletMapping;
default:
return super.getAttribute(key);
}
}
@Override
public Set<String> getAttributeNameSet()
{
Set<String> set = new HashSet<>(super.getAttributeNameSet());
if (_requestURI != null)
set.add(AsyncContext.ASYNC_REQUEST_URI);
if (_contextPath != null)
set.add(AsyncContext.ASYNC_CONTEXT_PATH);
if (_servletPath != null)
set.add(AsyncContext.ASYNC_SERVLET_PATH);
if (_pathInfo != null)
set.add(AsyncContext.ASYNC_PATH_INFO);
if (_queryString != null)
set.add(AsyncContext.ASYNC_QUERY_STRING);
if (_httpServletMapping != null)
set.add(AsyncContext.ASYNC_MAPPING);
return set;
}
@Override
public void setAttribute(String key, Object value)
{
switch (key)
{
case AsyncContext.ASYNC_REQUEST_URI:
_requestURI = (String)value;
break;
case AsyncContext.ASYNC_CONTEXT_PATH:
_contextPath = (String)value;
break;
case AsyncContext.ASYNC_SERVLET_PATH:
_servletPath = (String)value;
break;
case AsyncContext.ASYNC_PATH_INFO:
_pathInfo = (String)value;
break;
case AsyncContext.ASYNC_QUERY_STRING:
_queryString = (String)value;
break;
case AsyncContext.ASYNC_MAPPING:
_httpServletMapping = (HttpServletMapping)value;
break;
default:
super.setAttribute(key, value);
break;
}
}
@Override
public void clearAttributes()
{
_requestURI = null;
_contextPath = null;
_servletPath = null;
_pathInfo = null;
_queryString = null;
_httpServletMapping = null;
super.clearAttributes();
}
public static void applyAsyncAttributes(Attributes attributes, String requestURI, String contextPath, String servletPath, String pathInfo, String queryString, HttpServletMapping httpServletMapping)
{
if (requestURI != null)
attributes.setAttribute(AsyncContext.ASYNC_REQUEST_URI, requestURI);
if (contextPath != null)
attributes.setAttribute(AsyncContext.ASYNC_CONTEXT_PATH, contextPath);
if (servletPath != null)
attributes.setAttribute(AsyncContext.ASYNC_SERVLET_PATH, servletPath);
if (pathInfo != null)
attributes.setAttribute(AsyncContext.ASYNC_PATH_INFO, pathInfo);
if (queryString != null)
attributes.setAttribute(AsyncContext.ASYNC_QUERY_STRING, queryString);
if (httpServletMapping != null)
attributes.setAttribute(AsyncContext.ASYNC_MAPPING, httpServletMapping);
}
}

View File

@ -33,7 +33,7 @@ public class AsyncContextEvent extends AsyncEvent implements Runnable
private final Context _context;
private final AsyncContextState _asyncContext;
private final HttpURI _baseURI;
private volatile HttpChannelState _state;
private final HttpChannelState _state;
private ServletContext _dispatchContext;
private String _dispatchPath;
private volatile Scheduler.Task _timeoutTask;
@ -52,33 +52,9 @@ public class AsyncContextEvent extends AsyncEvent implements Runnable
_state = state;
_baseURI = baseURI;
// If we haven't been async dispatched before
if (baseRequest.getAttribute(AsyncContext.ASYNC_REQUEST_URI) == null)
{
// We are setting these attributes during startAsync, when the spec implies that
// they are only available after a call to AsyncContext.dispatch(...);
// have we been forwarded before?
String uri = (String)baseRequest.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
if (uri != null)
{
baseRequest.setAttribute(AsyncContext.ASYNC_REQUEST_URI, uri);
baseRequest.setAttribute(AsyncContext.ASYNC_CONTEXT_PATH, baseRequest.getAttribute(RequestDispatcher.FORWARD_CONTEXT_PATH));
baseRequest.setAttribute(AsyncContext.ASYNC_SERVLET_PATH, baseRequest.getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH));
baseRequest.setAttribute(AsyncContext.ASYNC_PATH_INFO, baseRequest.getAttribute(RequestDispatcher.FORWARD_PATH_INFO));
baseRequest.setAttribute(AsyncContext.ASYNC_QUERY_STRING, baseRequest.getAttribute(RequestDispatcher.FORWARD_QUERY_STRING));
baseRequest.setAttribute(AsyncContext.ASYNC_MAPPING, baseRequest.getAttribute(RequestDispatcher.FORWARD_MAPPING));
}
else
{
baseRequest.setAttribute(AsyncContext.ASYNC_REQUEST_URI, baseRequest.getRequestURI());
baseRequest.setAttribute(AsyncContext.ASYNC_CONTEXT_PATH, baseRequest.getContextPath());
baseRequest.setAttribute(AsyncContext.ASYNC_SERVLET_PATH, baseRequest.getServletPath());
baseRequest.setAttribute(AsyncContext.ASYNC_PATH_INFO, baseRequest.getPathInfo());
baseRequest.setAttribute(AsyncContext.ASYNC_QUERY_STRING, baseRequest.getQueryString());
baseRequest.setAttribute(AsyncContext.ASYNC_MAPPING, baseRequest.getHttpServletMapping());
}
}
// We are setting these attributes during startAsync, when the spec implies that
// they are only available after a call to AsyncContext.dispatch(...);
baseRequest.setAsyncAttributes();
}
public HttpURI getBaseURI()

View File

@ -338,19 +338,19 @@ public class Dispatcher implements RequestDispatcher
{
case FORWARD_PATH_INFO:
_pathInfo = (String)value;
return;
break;
case FORWARD_REQUEST_URI:
_requestURI = (String)value;
return;
break;
case FORWARD_SERVLET_PATH:
_servletPath = (String)value;
return;
break;
case FORWARD_CONTEXT_PATH:
_contextPath = (String)value;
return;
break;
case FORWARD_QUERY_STRING:
_query = (String)value;
return;
break;
case FORWARD_MAPPING:
_mapping = (HttpServletMapping)value;
return;
@ -359,6 +359,7 @@ public class Dispatcher implements RequestDispatcher
_attributes.removeAttribute(key);
else
_attributes.setAttribute(key, value);
break;
}
}
else if (value == null)
@ -467,27 +468,28 @@ public class Dispatcher implements RequestDispatcher
{
case INCLUDE_PATH_INFO:
_pathInfo = (String)value;
return;
break;
case INCLUDE_REQUEST_URI:
_requestURI = (String)value;
return;
break;
case INCLUDE_SERVLET_PATH:
_servletPath = (String)value;
return;
break;
case INCLUDE_CONTEXT_PATH:
_contextPath = (String)value;
return;
break;
case INCLUDE_QUERY_STRING:
_query = (String)value;
return;
break;
case INCLUDE_MAPPING:
_mapping = (HttpServletMapping)value;
return;
break;
default:
if (value == null)
_attributes.removeAttribute(key);
else
_attributes.setAttribute(key, value);
break;
}
}
else if (value == null)

View File

@ -739,7 +739,7 @@ public class Request implements HttpServletRequest
public Attributes getAttributes()
{
if (_attributes == null)
_attributes = new AttributesMap();
_attributes = new ServletAttributes();
return _attributes;
}
@ -1815,7 +1815,7 @@ public class Request implements HttpServletRequest
_attributes = Attributes.unwrap(_attributes);
if (_attributes != null)
{
if (AttributesMap.class.equals(_attributes.getClass()))
if (ServletAttributes.class.equals(_attributes.getClass()))
_attributes.clearAttributes();
else
_attributes = null;
@ -1896,7 +1896,7 @@ public class Request implements HttpServletRequest
LOG.warn("Deprecated: org.eclipse.jetty.server.sendContent");
if (_attributes == null)
_attributes = new AttributesMap();
_attributes = new ServletAttributes();
_attributes.setAttribute(name, value);
if (!_requestAttributeListeners.isEmpty())
@ -1919,6 +1919,59 @@ public class Request implements HttpServletRequest
_attributes = attributes;
}
public void setAsyncAttributes()
{
// Return if we have been async dispatched before.
if (getAttribute(AsyncContext.ASYNC_REQUEST_URI) != null)
return;
String requestURI;
String contextPath;
String servletPath;
String pathInfo;
String queryString;
HttpServletMapping httpServletMapping;
// Have we been forwarded before?
requestURI = (String)getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
if (requestURI != null)
{
contextPath = (String)getAttribute(RequestDispatcher.FORWARD_CONTEXT_PATH);
servletPath = (String)getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH);
pathInfo = (String)getAttribute(RequestDispatcher.FORWARD_PATH_INFO);
queryString = (String)getAttribute(RequestDispatcher.FORWARD_QUERY_STRING);
httpServletMapping = (HttpServletMapping)getAttribute(RequestDispatcher.FORWARD_MAPPING);
}
else
{
requestURI = getRequestURI();
contextPath = getContextPath();
servletPath = getServletPath();
pathInfo = getPathInfo();
queryString = getQueryString();
httpServletMapping = getHttpServletMapping();
}
// Unwrap the _attributes to get the base attributes instance.
Attributes baseAttributes;
if (_attributes == null)
_attributes = baseAttributes = new ServletAttributes();
else
baseAttributes = Attributes.unwrap(_attributes);
if (baseAttributes instanceof ServletAttributes)
{
// Set the AsyncAttributes on the ServletAttributes.
ServletAttributes servletAttributes = (ServletAttributes)baseAttributes;
servletAttributes.setAsyncAttributes(requestURI, contextPath, servletPath, pathInfo, queryString, httpServletMapping);
}
else
{
// If ServletAttributes has been replaced just set them on the top level Attributes.
AsyncAttributes.applyAsyncAttributes(_attributes, requestURI, contextPath, servletPath, pathInfo, queryString, httpServletMapping);
}
}
/**
* Set the authentication.
*

View File

@ -0,0 +1,73 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.server;
import java.util.Set;
import javax.servlet.http.HttpServletMapping;
import org.eclipse.jetty.util.Attributes;
import org.eclipse.jetty.util.AttributesMap;
public class ServletAttributes implements Attributes
{
private final Attributes _attributes = new AttributesMap();
private AsyncAttributes _asyncAttributes;
public void setAsyncAttributes(String requestURI, String contextPath, String servletPath, String pathInfo, String queryString, HttpServletMapping httpServletMapping)
{
_asyncAttributes = new AsyncAttributes(_attributes, requestURI, contextPath, servletPath, pathInfo, queryString, httpServletMapping);
}
private Attributes getAttributes()
{
return (_asyncAttributes == null) ? _attributes : _asyncAttributes;
}
@Override
public void removeAttribute(String name)
{
getAttributes().removeAttribute(name);
}
@Override
public void setAttribute(String name, Object attribute)
{
getAttributes().setAttribute(name, attribute);
}
@Override
public Object getAttribute(String name)
{
return getAttributes().getAttribute(name);
}
@Override
public Set<String> getAttributeNameSet()
{
return getAttributes().getAttributeNameSet();
}
@Override
public void clearAttributes()
{
getAttributes().clearAttributes();
_asyncAttributes = null;
}
}

View File

@ -111,8 +111,7 @@ public class AttributesMap implements Attributes, Dumpable
if (attrs instanceof AttributesMap)
return Collections.enumeration(((AttributesMap)attrs).keySet());
List<String> names = new ArrayList<>();
names.addAll(Collections.list(attrs.getAttributeNames()));
List<String> names = new ArrayList<>(Collections.list(attrs.getAttributeNames()));
return Collections.enumeration(names);
}

View File

@ -1142,6 +1142,12 @@
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>

View File

@ -109,7 +109,6 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -11,7 +11,10 @@
<url>http://www.eclipse.org/jetty</url>
<properties>
<bundle-symbolic-name>${project.groupId}.sessions.infinispan</bundle-symbolic-name>
<hotrod.host>127.0.0.1</hotrod.host>
<!-- if changing this version please update default in RemoteInfinispanTestSupport you will get thanks from Eclipse IDE users -->
<infinispan.docker.image.version>${infinispan.version}</infinispan.docker.image.version>
<!-- from 10.xx it has changed to jboss/infinispan -->
<infinispan.docker.image.name>jboss/infinispan-server</infinispan.docker.image.name>
</properties>
<build>
<plugins>
@ -141,19 +144,23 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<!-- to test hotrod, configure a cache called "remote-session-test" -->
<profile>
<id>remote</id>
<id>remote-session-tests</id>
<activation>
<property>
<name>hotrod.enabled</name>
@ -166,34 +173,13 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<infinispan.docker.image.version>${infinispan.docker.image.version}</infinispan.docker.image.version>
<infinispan.docker.image.name>${infinispan.docker.image.name}</infinispan.docker.image.name>
</systemPropertyVariables>
<includes>
<include>**/*.java</include>
</includes>
<excludes>
<exclude>**/ClusteredSessionScavengingTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>alltests</id>
<activation>
<property>
<name>alltests</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>FOOBAR</exclude>
</excludes>
</configuration>
</plugin>
</plugins>

View File

@ -30,7 +30,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* InfinispanSessionDataStoreTest
@ -110,15 +110,7 @@ public class InfinispanSessionDataStoreTest extends AbstractSessionDataStoreTest
((InfinispanSessionDataStore)store).setCache(null);
//test that loading it fails
try
{
store.load("222");
fail("Session should be unreadable");
}
catch (UnreadableSessionDataException e)
{
//expected exception
}
assertThrows(UnreadableSessionDataException.class, () -> store.load("222"));
}
/**

View File

@ -30,7 +30,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* SerializedInfinispanSessionDataStoreTest
@ -107,15 +107,7 @@ public class SerializedInfinispanSessionDataStoreTest extends AbstractSessionDat
((InfinispanSessionDataStore)store).setCache(null);
//test that loading it fails
try
{
store.load("222");
fail("Session should be unreadable");
}
catch (UnreadableSessionDataException e)
{
//expected exception
}
assertThrows(UnreadableSessionDataException.class,() -> store.load("222"));
}
/**

View File

@ -39,7 +39,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* RemoteInfinispanSessionDataStoreTest
@ -135,15 +135,7 @@ public class RemoteInfinispanSessionDataStoreTest extends AbstractSessionDataSto
((InfinispanSessionDataStore)store).setCache(null);
//test that loading it fails
try
{
store.load("222");
fail("Session should be unreadable");
}
catch (UnreadableSessionDataException e)
{
//expected exception
}
assertThrows(UnreadableSessionDataException.class, () -> store.load("222"));
}
@Test

View File

@ -31,31 +31,62 @@ import org.hibernate.search.cfg.Environment;
import org.hibernate.search.cfg.SearchMapping;
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.ClientIntelligence;
import org.infinispan.client.hotrod.configuration.Configuration;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.client.hotrod.marshall.ProtoStreamMarshaller;
import org.infinispan.protostream.FileDescriptorSource;
import org.infinispan.protostream.SerializationContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
import org.testcontainers.utility.MountableFile;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
* RemoteInfinispanTestSupport
*/
public class RemoteInfinispanTestSupport
{
private static final Logger LOG = LoggerFactory.getLogger(RemoteInfinispanTestSupport.class);
public static final String DEFAULT_CACHE_NAME = "session_test_cache";
public RemoteCache<String, SessionData> _cache;
private String _name;
public static RemoteCacheManager _manager;
private static final Logger INFINISPAN_LOG =
LoggerFactory.getLogger("org.eclipse.jetty.server.session.remote.infinispanLogs");
static GenericContainer infinispan;
static
{
try
{
String host = System.getProperty("hotrod.host", "127.0.0.1");
//Testcontainers.exposeHostPorts(11222);
long start = System.currentTimeMillis();
String infinispanVersion = System.getProperty("infinispan.docker.image.version", "9.4.8.Final");
infinispan =
new GenericContainer(System.getProperty("infinispan.docker.image.name", "jboss/infinispan-server") +
":" + infinispanVersion)
.withEnv("APP_USER","theuser")
.withEnv("APP_PASS","foobar")
.withEnv("MGMT_USER", "admin")
.withEnv("MGMT_PASS", "admin")
.waitingFor(new LogMessageWaitStrategy()
.withRegEx(".*Infinispan Server.*started in.*\\s"))
.withExposedPorts(4712,4713,8088,8089,8443,9990,9993,11211,11222,11223,11224)
.withLogConsumer(new Slf4jLogConsumer(INFINISPAN_LOG));
infinispan.start();
String host = infinispan.getContainerIpAddress();
System.setProperty("hotrod.host", host);
int port = infinispan.getMappedPort(11222);
LOG.info("Infinispan container started for {}:{} - {}ms", host, port,
System.currentTimeMillis() - start);
SearchMapping mapping = new SearchMapping();
mapping.entity(SessionData.class).indexed().providedId()
.property("expiry", ElementType.METHOD).field();
@ -63,10 +94,25 @@ public class RemoteInfinispanTestSupport
Properties properties = new Properties();
properties.put(Environment.MODEL_MAPPING, mapping);
ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
clientBuilder.withProperties(properties).addServer().host(host).marshaller(new ProtoStreamMarshaller());
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder().withProperties(properties)
.addServer().host(host).port(port)
// we just want to limit connectivity to list of host:port we knows at start
// as infinispan create new host:port dynamically but due to how docker expose host/port we cannot do that
.clientIntelligence(ClientIntelligence.BASIC)
.marshaller(new ProtoStreamMarshaller());
_manager = new RemoteCacheManager(clientBuilder.build());
if (infinispanVersion.startsWith("1"))
{
configurationBuilder.security().authentication()
.realm("default")
.serverName("infinispan")
.saslMechanism("DIGEST-MD5")
.username("theuser").password("foobar");
}
Configuration configuration = configurationBuilder.build();
_manager = new RemoteCacheManager(configuration);
FileDescriptorSource fds = new FileDescriptorSource();
fds.addProtoFiles("/session.proto");
@ -86,11 +132,12 @@ public class RemoteInfinispanTestSupport
}
String content = baos.toString("UTF-8");
_manager.getCache("___protobuf_metadata").put("session.proto", content);
_manager.administration().getOrCreateCache("___protobuf_metadata", (String)null).put("session.proto", content);
}
catch (Exception e)
{
fail(e);
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
@ -114,7 +161,7 @@ public class RemoteInfinispanTestSupport
public void setup() throws Exception
{
_cache = _manager.getCache(_name);
_cache = _manager.administration().getOrCreateCache(_name,(String)null);
}
public void teardown() throws Exception

View File

@ -0,0 +1,3 @@
org.slf4j.simpleLogger.defaultLogLevel=info
org.slf4j.simpleLogger.log.org.eclipse.jetty.server.session.remote.infinispanLogs=info
org.slf4j.simpleLogger.log.org.eclipse.jetty.server.session.remote.RemoteInfinispanTestSupport=info