Merged branch 'jetty-9.4.x' into 'jetty-9.4.x-4443-alpn-backport-8u252'.

This commit is contained in:
Simone Bordet 2020-03-18 10:57:23 +01:00
commit 6df47dd183
6 changed files with 840 additions and 198 deletions

View File

@ -19,9 +19,12 @@
package org.eclipse.jetty.plus.webapp;
import java.util.Iterator;
import java.util.Objects;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import org.eclipse.jetty.jndi.NamingUtil;
import org.eclipse.jetty.plus.annotation.Injection;
@ -35,6 +38,7 @@ import org.eclipse.jetty.plus.jndi.EnvEntry;
import org.eclipse.jetty.plus.jndi.Link;
import org.eclipse.jetty.plus.jndi.NamingEntry;
import org.eclipse.jetty.plus.jndi.NamingEntryUtil;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -121,14 +125,6 @@ public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
String type = node.getString("env-entry-type", false, true);
String valueStr = node.getString("env-entry-value", false, true);
//if there's no value there's no point in making a jndi entry
//nor processing injection entries
if (valueStr == null || valueStr.equals(""))
{
LOG.warn("No value for env-entry-name " + name);
return;
}
Origin o = context.getMetaData().getOrigin("env-entry." + name);
switch (o)
{
@ -136,14 +132,7 @@ public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
{
//no descriptor has configured an env-entry of this name previously
context.getMetaData().setOrigin("env-entry." + name, descriptor);
//the javaee_5.xsd says that the env-entry-type is optional
//if there is an <injection> element, because you can get
//type from the element, but what to do if there is more
//than one <injection> element, do you just pick the type
//of the first one?
addInjections(context, descriptor, node, name, TypeUtil.fromName(type));
Object value = TypeUtil.valueOf(type, valueStr);
bindEnvEntry(name, value);
makeEnvEntryInjectionsAndBindings(context, descriptor, node, name, type, valueStr);
break;
}
case WebXml:
@ -158,9 +147,7 @@ public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
//We're processing web-defaults, web.xml or web-override. Any of them can
//set or change the env-entry.
context.getMetaData().setOrigin("env-entry." + name, descriptor);
addInjections(context, descriptor, node, name, TypeUtil.fromName(type));
Object value = TypeUtil.valueOf(type, valueStr);
bindEnvEntry(name, value);
makeEnvEntryInjectionsAndBindings(context, descriptor, node, name, type, valueStr);
}
else
{
@ -705,6 +692,9 @@ public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
*/
public void addInjections(WebAppContext context, Descriptor descriptor, XmlParser.Node node, String jndiName, Class<?> valueClass)
{
Objects.requireNonNull(context);
Objects.requireNonNull(node);
Iterator<XmlParser.Node> itor = node.iterator("injection-target");
while (itor.hasNext())
@ -755,31 +745,59 @@ public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
*/
public void bindEnvEntry(String name, Object value) throws Exception
{
InitialContext ic = null;
boolean bound = false;
//check to see if we bound a value and an EnvEntry with this name already
//when we processed the server and the webapp's naming environment
//@see EnvConfiguration.bindEnvEntries()
ic = new InitialContext();
InitialContext ic = new InitialContext();
Context envCtx = (Context)ic.lookup("java:comp/env");
NamingUtil.bind(envCtx, name, value);
}
/**
* Make injections and any java:comp/env bindings necessary given an env-entry declaration.
* The handling of env-entries is different to other resource declarations like resource-ref, resource-env-ref etc
* because we allow the EnvEntry (@see org.eclipse.jetty.plus.jndi.EnvEntry) class that is configured externally to the webapp
* to specify a value that can override a value present in a web.xml descriptor.
*
* @param context the WebAppContext of the env-entry
* @param descriptor the web.xml, web-default.xml, web-override.xml or web-fragment.xml
* @param node the parsed xml representation of the env-entry declaration
* @param name the name field of the env-entry
* @param type the type field of the env-entry
* @param value the value field of the env-entry
* @throws Exception
*/
public void makeEnvEntryInjectionsAndBindings(WebAppContext context, Descriptor descriptor, XmlParser.Node node, String name, String type, String value) throws Exception
{
InitialContext ic = new InitialContext();
try
{
NamingEntry ne = (NamingEntry)ic.lookup("java:comp/env/" + NamingEntryUtil.makeNamingEntryName(ic.getNameParser(""), name));
if (ne != null && ne instanceof EnvEntry)
EnvEntry envEntry = (EnvEntry)ic.lookup("java:comp/env/" + NamingEntryUtil.makeNamingEntryName(ic.getNameParser(""), name));
if (StringUtil.isEmpty(value))
{
EnvEntry ee = (EnvEntry)ne;
bound = ee.isOverrideWebXml();
//There is an empty or missing value in the env-entry:
//If there is an existing EnvEntry (eg from a declaration in jetty-env.xml) that is override=true, then
//we make the injection, but we can skip the rebinding becase we want to use the value already bound.
//If there isn't an existing EnvEntry then there is nothing to do: according to the spec we do not make
//an injection if the env-entry value is missing, and of course there is no value to rebind.
if (envEntry != null && envEntry.isOverrideWebXml())
addInjections(context, descriptor, node, name, TypeUtil.fromName(type));
}
else
{
//There is a value for the env-entry:
//According to the spec, we need to make an injection (if one is present).
//If there is an existing EnvEntry(eg from a declaration in jetty-env.xml) that is override=false, then
//we need to rebind name with the value from web.xml.
addInjections(context, descriptor, node, name, TypeUtil.fromName(type));
if (envEntry == null || !envEntry.isOverrideWebXml())
bindEnvEntry(name, TypeUtil.valueOf(type, value));
}
}
catch (NameNotFoundException e)
{
bound = false;
}
if (!bound)
{
//either nothing was bound or the value from web.xml should override
Context envCtx = (Context)ic.lookup("java:comp/env");
NamingUtil.bind(envCtx, name, value);
//No matching EnvEntry has previously been bound so make the injection and do the binding with the value from web.xml
addInjections(context, descriptor, node, name, TypeUtil.fromName(type));
bindEnvEntry(name, TypeUtil.valueOf(type, value));
}
}

View File

@ -22,7 +22,14 @@ import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.Name;
import org.eclipse.jetty.jndi.NamingUtil;
import org.eclipse.jetty.plus.annotation.Injection;
import org.eclipse.jetty.plus.annotation.InjectionCollection;
import org.eclipse.jetty.plus.jndi.EnvEntry;
import org.eclipse.jetty.plus.jndi.NamingEntryUtil;
import org.eclipse.jetty.util.IntrospectionUtil;
import org.eclipse.jetty.webapp.Descriptor;
import org.eclipse.jetty.webapp.FragmentDescriptor;
import org.eclipse.jetty.webapp.Origin;
@ -39,6 +46,7 @@ import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
@ -48,6 +56,7 @@ import static org.junit.jupiter.api.Assertions.fail;
*/
public class PlusDescriptorProcessorTest
{
protected static final Class<?>[] STRING_ARG = new Class[]{String.class};
protected WebDescriptor webDescriptor;
protected FragmentDescriptor fragDescriptor1;
protected FragmentDescriptor fragDescriptor2;
@ -55,19 +64,95 @@ public class PlusDescriptorProcessorTest
protected FragmentDescriptor fragDescriptor4;
protected WebAppContext context;
public static class TestInjections
{
private String foo;
private String bah;
private String empty;
private String vacuum;
private String webXmlOnly;
public String getWebXmlOnly()
{
return webXmlOnly;
}
public void setWebXmlOnly(String webXmlOnly)
{
this.webXmlOnly = webXmlOnly;
}
public String getVacuum()
{
return vacuum;
}
public void setVacuum(String val)
{
vacuum = val;
}
public String getEmpty()
{
return empty;
}
public void setEmpty(String val)
{
empty = val;
}
public void setFoo(String val)
{
foo = val;
}
public String getFoo()
{
return foo;
}
public String getBah()
{
return bah;
}
public void setBah(String val)
{
bah = val;
}
}
@BeforeEach
public void setUp() throws Exception
{
context = new WebAppContext();
context.setClassLoader(new WebAppClassLoader(Thread.currentThread().getContextClassLoader(), context));
context.getServerClasspathPattern().add("-org.eclipse.jetty.plus.webapp."); //need visbility of the TestInjections class
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(context.getClassLoader());
Context icontext = new InitialContext();
Context compCtx = (Context)icontext.lookup("java:comp");
compCtx.createSubcontext("env");
Thread.currentThread().setContextClassLoader(oldLoader);
Context envCtx = compCtx.createSubcontext("env");
@SuppressWarnings("unused")
org.eclipse.jetty.plus.jndi.Resource ds = new org.eclipse.jetty.plus.jndi.Resource(context, "jdbc/mydatasource", new Object());
//An EnvEntry that should override any value supplied in a web.xml file
org.eclipse.jetty.plus.jndi.EnvEntry fooStringEnvEntry = new org.eclipse.jetty.plus.jndi.EnvEntry("foo", "FOO", true);
doEnvConfiguration(envCtx, fooStringEnvEntry);
//An EnvEntry that should NOT override any value supplied in a web.xml file
org.eclipse.jetty.plus.jndi.EnvEntry bahStringEnvEntry = new org.eclipse.jetty.plus.jndi.EnvEntry("bah", "BAH", false);
doEnvConfiguration(envCtx, bahStringEnvEntry);
//An EnvEntry that will override an empty value in web.xml
org.eclipse.jetty.plus.jndi.EnvEntry emptyStringEnvEntry = new org.eclipse.jetty.plus.jndi.EnvEntry("empty", "EMPTY", true);
doEnvConfiguration(envCtx, emptyStringEnvEntry);
//An EnvEntry that will NOT override an empty value in web.xml
org.eclipse.jetty.plus.jndi.EnvEntry vacuumStringEnvEntry = new org.eclipse.jetty.plus.jndi.EnvEntry("vacuum", "VACUUM", false);
doEnvConfiguration(envCtx, vacuumStringEnvEntry);
URL webXml = Thread.currentThread().getContextClassLoader().getResource("web.xml");
webDescriptor = new WebDescriptor(org.eclipse.jetty.util.resource.Resource.newResource(webXml));
@ -85,6 +170,22 @@ public class PlusDescriptorProcessorTest
URL frag4Xml = Thread.currentThread().getContextClassLoader().getResource("web-fragment-4.xml");
fragDescriptor4 = new FragmentDescriptor(org.eclipse.jetty.util.resource.Resource.newResource(frag4Xml));
fragDescriptor4.parse();
Thread.currentThread().setContextClassLoader(oldLoader);
}
/**
* Do the kind of processing that EnvConfiguration would do.
*
* @param envCtx the java:comp/env context
* @param envEntry the EnvEntry
* @throws Exception
*/
private void doEnvConfiguration(Context envCtx, EnvEntry envEntry) throws Exception
{
envEntry.bindToENC(envEntry.getJndiName());
Name namingEntryName = NamingEntryUtil.makeNamingEntryName(null, envEntry);
NamingUtil.bind(envCtx, namingEntryName.toString(), envEntry);
}
@AfterEach
@ -140,6 +241,59 @@ public class PlusDescriptorProcessorTest
Thread.currentThread().setContextClassLoader(oldLoader);
}
}
@Test
public void testEnvEntries() throws Exception
{
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(context.getClassLoader());
try
{
PlusDescriptorProcessor pdp = new PlusDescriptorProcessor();
//process web.xml
pdp.process(context, webDescriptor);
InjectionCollection injections = (InjectionCollection)context.getAttribute(InjectionCollection.INJECTION_COLLECTION);
assertNotNull(injections);
//check that there is an injection for "foo" with the value from the overriding EnvEntry of "FOO"
Injection foo = injections.getInjection("foo", TestInjections.class,
IntrospectionUtil.findMethod(TestInjections.class, "setFoo", STRING_ARG, false, true),
String.class);
assertNotNull(foo);
assertEquals("FOO", foo.lookupInjectedValue());
//check that there is an injection for "bah" with the value from web.xml of "beer"
Injection bah = injections.getInjection("bah", TestInjections.class,
IntrospectionUtil.findMethod(TestInjections.class, "setBah", STRING_ARG, false, true),
String.class);
assertNotNull(bah);
assertEquals("beer", bah.lookupInjectedValue());
//check that there is an injection for "empty" with the value from the overriding EnvEntry of "EMPTY"
Injection empty = injections.getInjection("empty", TestInjections.class,
IntrospectionUtil.findMethod(TestInjections.class, "setEmpty", STRING_ARG, false, true),
String.class);
assertNotNull(empty);
assertEquals("EMPTY", empty.lookupInjectedValue());
//check that there is NOT an injection for "vacuum"
Injection vacuum = injections.getInjection("vacuum", TestInjections.class,
IntrospectionUtil.findMethod(TestInjections.class, "setVacuum", STRING_ARG, false, true),
String.class);
assertNull(vacuum);
//check that there is an injection for "webxmlonly" with the value from web.xml of "WEBXMLONLY"
Injection webXmlOnly = injections.getInjection("webxmlonly", TestInjections.class,
IntrospectionUtil.findMethod(TestInjections.class, "setWebXmlOnly", STRING_ARG, false, true),
String.class);
assertNotNull(webXmlOnly);
assertEquals("WEBXMLONLY", webXmlOnly.lookupInjectedValue());
}
finally
{
Thread.currentThread().setContextClassLoader(oldLoader);
}
}
@Test
public void testMismatchedFragmentResourceDeclarations()

View File

@ -1,136 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
// ------------------------------------------------------------------------
// 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.plus.webapp;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.eclipse.jetty.plus.jndi.EnvEntry;
import org.eclipse.jetty.plus.jndi.NamingEntry;
import org.eclipse.jetty.plus.jndi.NamingEntryUtil;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.MetaData;
import org.eclipse.jetty.webapp.WebAppClassLoader;
import org.eclipse.jetty.webapp.WebAppContext;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class TestConfiguration
{
@Test
public void testIt() throws Exception
{
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
try
{
InitialContext ic = new InitialContext();
Server server = new Server();
WebAppContext wac = new WebAppContext();
wac.setServer(server);
wac.setClassLoader(new WebAppClassLoader(Thread.currentThread().getContextClassLoader(), wac));
MetaData metaData = new MetaData();
PlusDescriptorProcessor plusProcessor = new PlusDescriptorProcessor();
//bind some EnvEntrys at the server level
EnvEntry ee1 = new EnvEntry(server, "xxx/a", "100", true);
EnvEntry ee2 = new EnvEntry(server, "yyy/b", "200", false);
EnvEntry ee3 = new EnvEntry(server, "zzz/c", "300", false);
EnvEntry ee4 = new EnvEntry(server, "zzz/d", "400", false);
EnvEntry ee5 = new EnvEntry(server, "zzz/f", "500", true);
//bind some EnvEntrys at the webapp level
EnvEntry ee6 = new EnvEntry(wac, "xxx/a", "900", true);
EnvEntry ee7 = new EnvEntry(wac, "yyy/b", "910", true);
EnvEntry ee8 = new EnvEntry(wac, "zzz/c", "920", false);
EnvEntry ee9 = new EnvEntry(wac, "zzz/e", "930", false);
assertNotNull(NamingEntryUtil.lookupNamingEntry(server, "xxx/a"));
assertNotNull(NamingEntryUtil.lookupNamingEntry(server, "yyy/b"));
assertNotNull(NamingEntryUtil.lookupNamingEntry(server, "zzz/c"));
assertNotNull(NamingEntryUtil.lookupNamingEntry(server, "zzz/d"));
assertNotNull(NamingEntryUtil.lookupNamingEntry(wac, "xxx/a"));
assertNotNull(NamingEntryUtil.lookupNamingEntry(wac, "yyy/b"));
assertNotNull(NamingEntryUtil.lookupNamingEntry(wac, "zzz/c"));
assertNotNull(NamingEntryUtil.lookupNamingEntry(wac, "zzz/e"));
//make a new env configuration
EnvConfiguration envConfig = new EnvConfiguration();
Thread.currentThread().setContextClassLoader(wac.getClassLoader());
MetaData metadata = new MetaData();
envConfig.preConfigure(wac);
envConfig.configure(wac);
envConfig.bindEnvEntries(wac);
String val = (String)ic.lookup("java:comp/env/xxx/a");
assertEquals("900", val); //webapp naming overrides server
val = (String)ic.lookup("java:comp/env/yyy/b");
assertEquals("910", val);//webapp overrides server
val = (String)ic.lookup("java:comp/env/zzz/c");
assertEquals("920", val);//webapp overrides server
val = (String)ic.lookup("java:comp/env/zzz/d");
assertEquals("400", val);//from server naming
val = (String)ic.lookup("java:comp/env/zzz/e");
assertEquals("930", val);//from webapp naming
NamingEntry ne = (NamingEntry)ic.lookup("java:comp/env/" + NamingEntry.__contextName + "/xxx/a");
assertNotNull(ne);
ne = (NamingEntry)ic.lookup("java:comp/env/" + NamingEntry.__contextName + "/yyy/b");
assertNotNull(ne);
ne = (NamingEntry)ic.lookup("java:comp/env/" + NamingEntry.__contextName + "/zzz/c");
assertNotNull(ne);
ne = (NamingEntry)ic.lookup("java:comp/env/" + NamingEntry.__contextName + "/zzz/d");
assertNotNull(ne);
ne = (NamingEntry)ic.lookup("java:comp/env/" + NamingEntry.__contextName + "/zzz/e");
assertNotNull(ne);
plusProcessor.bindEnvEntry("foo", "99");
assertEquals("99", ic.lookup("java:comp/env/foo"));
plusProcessor.bindEnvEntry("xxx/a", "7");
assertEquals("900", ic.lookup("java:comp/env/xxx/a")); //webapp overrides web.xml
plusProcessor.bindEnvEntry("yyy/b", "7");
assertEquals("910", ic.lookup("java:comp/env/yyy/b"));//webapp overrides web.xml
plusProcessor.bindEnvEntry("zzz/c", "7");
assertEquals("7", ic.lookup("java:comp/env/zzz/c"));//webapp does NOT override web.xml
plusProcessor.bindEnvEntry("zzz/d", "7");
assertEquals("7", ic.lookup("java:comp/env/zzz/d"));//server does NOT override web.xml
plusProcessor.bindEnvEntry("zzz/e", "7");
assertEquals("7", ic.lookup("java:comp/env/zzz/e"));//webapp does NOT override web.xml
plusProcessor.bindEnvEntry("zzz/f", "7");
assertEquals("500", ic.lookup("java:comp/env/zzz/f"));//server overrides web.xml
((Context)ic.lookup("java:comp")).destroySubcontext("env");
ic.destroySubcontext("xxx");
ic.destroySubcontext("yyy");
ic.destroySubcontext("zzz");
}
finally
{
Thread.currentThread().setContextClassLoader(oldLoader);
}
}
}

View File

@ -4,20 +4,70 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="false"
version="3.0">
version="3.0">
<display-name>Test WebApp</display-name>
<display-name>Test WebApp</display-name>
<resource-ref>
<res-ref-name>jdbc/mydatasource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<!--
<injection-target>
<injection-target-class>com.acme.JNDITest</injection-target-class>
<injection-target-name>myDatasource</injection-target-name>
</injection-target>
-->
<!-- <injection-target> <injection-target-class>com.acme.JNDITest</injection-target-class>
<injection-target-name>myDatasource</injection-target-name> </injection-target> -->
</resource-ref>
<!-- env entry for which is there is an overriding EnvEntry -->
<env-entry>
<env-entry-name>foo</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>beer</env-entry-value>
<injection-target>
<injection-target-class>org.eclipse.jetty.plus.webapp.PlusDescriptorProcessorTest$TestInjections</injection-target-class>
<injection-target-name>foo</injection-target-name>
</injection-target>
</env-entry>
<!-- env entry for which the EnvEntry does not override -->
<env-entry>
<env-entry-name>bah</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>beer</env-entry-value>
<injection-target>
<injection-target-class>org.eclipse.jetty.plus.webapp.PlusDescriptorProcessorTest$TestInjections</injection-target-class>
<injection-target-name>bah</injection-target-name>
</injection-target>
</env-entry>
<!-- env entry with no value for which the EnvEntry should override -->
<env-entry>
<env-entry-name>empty</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value></env-entry-value>
<injection-target>
<injection-target-class>org.eclipse.jetty.plus.webapp.PlusDescriptorProcessorTest$TestInjections</injection-target-class>
<injection-target-name>empty</injection-target-name>
</injection-target>
</env-entry>
<!-- env entry with no value and EnvEntry does not override -->
<env-entry>
<env-entry-name>vacuum</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value></env-entry-value>
<injection-target>
<injection-target-class>org.eclipse.jetty.plus.webapp.PlusDescriptorProcessorTest$TestInjections</injection-target-class>
<injection-target-name>vacuum</injection-target-name>
</injection-target>
</env-entry>
<!-- env entry with no matching EnvEntry -->
<env-entry>
<env-entry-name>webxmlonly</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>WEBXMLONLY</env-entry-value>
<injection-target>
<injection-target-class>org.eclipse.jetty.plus.webapp.PlusDescriptorProcessorTest$TestInjections</injection-target-class>
<injection-target-name>webXmlOnly</injection-target-name>
</injection-target>
</env-entry>
</web-app>

View File

@ -64,6 +64,7 @@ import org.eclipse.jetty.websocket.common.scopes.WebSocketSessionScope;
public class WebSocketSession extends ContainerLifeCycle implements Session, RemoteEndpointFactory, WebSocketSessionScope, IncomingFrames, OutgoingFrames, Connection.Listener
{
private static final Logger LOG = Log.getLogger(WebSocketSession.class);
private static final RemoteEndpointFactory defaultRemoteEndpointFactory;
private final WebSocketContainerScope containerScope;
private final URI requestURI;
private final LogicalConnection connection;
@ -71,9 +72,9 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Rem
private final Executor executor;
private final WebSocketPolicy policy;
private final AtomicBoolean onCloseCalled = new AtomicBoolean(false);
private final RemoteEndpointFactory remoteEndpointFactory;
private ClassLoader classLoader;
private ExtensionFactory extensionFactory;
private RemoteEndpointFactory remoteEndpointFactory;
private String protocolVersion;
private Map<String, String[]> parameterMap = new HashMap<>();
private RemoteEndpoint remote;
@ -83,6 +84,15 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Rem
private UpgradeResponse upgradeResponse;
private CompletableFuture<Session> openFuture;
static
{
// Attempt to discover a RemoteEndpointFactory with the SerivceLoader.
Iterator<RemoteEndpointFactory> iter = ServiceLoader.load(RemoteEndpointFactory.class).iterator();
defaultRemoteEndpointFactory = iter.hasNext() ? iter.next() : null;
if (LOG.isDebugEnabled())
LOG.debug("Discovered default RemoteEndpointFactory: {}", defaultRemoteEndpointFactory);
}
public WebSocketSession(WebSocketContainerScope containerScope, URI requestURI, EventDriver websocket, LogicalConnection connection)
{
Objects.requireNonNull(containerScope, "Container Scope cannot be null");
@ -98,6 +108,10 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Rem
this.incomingHandler = websocket;
this.policy = websocket.getPolicy();
remoteEndpointFactory = (defaultRemoteEndpointFactory == null) ? this : defaultRemoteEndpointFactory;
if (LOG.isDebugEnabled())
LOG.debug("Using RemoteEndpointFactory: {}", remoteEndpointFactory);
this.connection.setSession(this);
addBean(this.connection);
@ -168,16 +182,6 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Rem
if (LOG.isDebugEnabled())
LOG.debug("starting - {}", this);
Iterator<RemoteEndpointFactory> iter = ServiceLoader.load(RemoteEndpointFactory.class).iterator();
if (iter.hasNext())
remoteEndpointFactory = iter.next();
if (remoteEndpointFactory == null)
remoteEndpointFactory = this;
if (LOG.isDebugEnabled())
LOG.debug("Using RemoteEndpointFactory: {}", remoteEndpointFactory);
super.doStart();
}

560
pom.xml
View File

@ -27,7 +27,7 @@
<jsp.version>8.5.49</jsp.version>
<infinispan.version>9.4.8.Final</infinispan.version>
<alpn.agent.version>2.0.10</alpn.agent.version>
<conscrypt.version>2.1.0</conscrypt.version>
<conscrypt.version>2.4.0</conscrypt.version>
<asm.version>7.2</asm.version>
<jmh.version>1.21</jmh.version>
<jmhjar.name>benchmarks</jmhjar.name>
@ -665,7 +665,7 @@
<configuration>
<rerunFailingTestsCount>${surefire.rerunFailingTestsCount}</rerunFailingTestsCount>
<forkedProcessTimeoutInSeconds>3600</forkedProcessTimeoutInSeconds>
<argLine>@{argLine} -Dfile.encoding=UTF-8 -Duser.language=en -Duser.region=US -showversion -Xmx4g -Xms4g -XX:+PrintGCDetails</argLine>
<argLine>@{argLine} -Dfile.encoding=UTF-8 -Duser.language=en -Duser.region=US -showversion -Xmx1g -Xms1g -XX:+PrintGCDetails</argLine>
<failIfNoTests>false</failIfNoTests>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks> <!-- to work around crash at https://github.com/junit-team/junit5/issues/801 -->
@ -1222,7 +1222,7 @@
<profile>
<id>jdk8</id>
<activation>
<jdk>[1.8,9)</jdk>
<jdk>[1.8,1.9)</jdk>
</activation>
<build>
<pluginManagement>
@ -1494,10 +1494,562 @@
</plugins>
</build>
</profile>
<profile>
<id>8u00</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0</value>
</property>
</activation>
<properties>
<alpn.version>8.1.0.v20141016</alpn.version>
</properties>
</profile>
<profile>
<id>8u05</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_05</value>
</property>
</activation>
<properties>
<alpn.version>8.1.0.v20141016</alpn.version>
</properties>
</profile>
<profile>
<id>8u11</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_11</value>
</property>
</activation>
<properties>
<alpn.version>8.1.0.v20141016</alpn.version>
</properties>
</profile>
<profile>
<id>8u20</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_20</value>
</property>
</activation>
<properties>
<alpn.version>8.1.0.v20141016</alpn.version>
</properties>
</profile>
<profile>
<id>8u25</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_25</value>
</property>
</activation>
<properties>
<alpn.version>8.1.2.v20141202</alpn.version>
</properties>
</profile>
<profile>
<id>8u31</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_31</value>
</property>
</activation>
<properties>
<alpn.version>8.1.3.v20150130</alpn.version>
</properties>
</profile>
<profile>
<id>8u40</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_40</value>
</property>
</activation>
<properties>
<alpn.version>8.1.3.v20150130</alpn.version>
</properties>
</profile>
<profile>
<id>8u45</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_45</value>
</property>
</activation>
<properties>
<alpn.version>8.1.3.v20150130</alpn.version>
</properties>
</profile>
<profile>
<id>8u51</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_51</value>
</property>
</activation>
<properties>
<alpn.version>8.1.4.v20150727</alpn.version>
</properties>
</profile>
<profile>
<id>8u60</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_60</value>
</property>
</activation>
<properties>
<alpn.version>8.1.5.v20150921</alpn.version>
</properties>
</profile>
<profile>
<id>8u65</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_65</value>
</property>
</activation>
<properties>
<alpn.version>8.1.6.v20151105</alpn.version>
</properties>
</profile>
<profile>
<id>8u66</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_66</value>
</property>
</activation>
<properties>
<alpn.version>8.1.6.v20151105</alpn.version>
</properties>
</profile>
<profile>
<id>8u71</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_71</value>
</property>
</activation>
<properties>
<alpn.version>8.1.7.v20160121</alpn.version>
</properties>
</profile>
<profile>
<id>8u72</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_72</value>
</property>
</activation>
<properties>
<alpn.version>8.1.7.v20160121</alpn.version>
</properties>
</profile>
<profile>
<id>8u73</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_73</value>
</property>
</activation>
<properties>
<alpn.version>8.1.7.v20160121</alpn.version>
</properties>
</profile>
<profile>
<id>8u74</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_74</value>
</property>
</activation>
<properties>
<alpn.version>8.1.7.v20160121</alpn.version>
</properties>
</profile>
<profile>
<id>8u77</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_77</value>
</property>
</activation>
<properties>
<alpn.version>8.1.7.v20160121</alpn.version>
</properties>
</profile>
<profile>
<id>8u91</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_91</value>
</property>
</activation>
<properties>
<alpn.version>8.1.7.v20160121</alpn.version>
</properties>
</profile>
<profile>
<id>8u92</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_92</value>
</property>
</activation>
<properties>
<alpn.version>8.1.8.v20160420</alpn.version>
</properties>
</profile>
<profile>
<id>8u101</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_101</value>
</property>
</activation>
<properties>
<alpn.version>8.1.9.v20160720</alpn.version>
</properties>
</profile>
<profile>
<id>8u102</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_102</value>
</property>
</activation>
<properties>
<alpn.version>8.1.9.v20160720</alpn.version>
</properties>
</profile>
<profile>
<id>8u111</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_111</value>
</property>
</activation>
<properties>
<alpn.version>8.1.9.v20160720</alpn.version>
</properties>
</profile>
<profile>
<id>8u112</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_112</value>
</property>
</activation>
<properties>
<alpn.version>8.1.10.v20161026</alpn.version>
</properties>
</profile>
<profile>
<id>8u121</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_121</value>
</property>
</activation>
<properties>
<alpn.version>8.1.11.v20170118</alpn.version>
</properties>
</profile>
<profile>
<id>8u131</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_131</value>
</property>
</activation>
<properties>
<alpn.version>8.1.11.v20170118</alpn.version>
</properties>
</profile>
<profile>
<id>8u141</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_141</value>
</property>
</activation>
<properties>
<alpn.version>8.1.11.v20170118</alpn.version>
</properties>
</profile>
<profile>
<id>8u144</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_144</value>
</property>
</activation>
<properties>
<alpn.version>8.1.11.v20170118</alpn.version>
</properties>
</profile>
<profile>
<id>8u151</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_151</value>
</property>
</activation>
<properties>
<alpn.version>8.1.11.v20170118</alpn.version>
</properties>
</profile>
<profile>
<id>8u152</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_152</value>
</property>
</activation>
<properties>
<alpn.version>8.1.11.v20170118</alpn.version>
</properties>
</profile>
<profile>
<id>8u161</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_161</value>
</property>
</activation>
<properties>
<alpn.version>8.1.12.v20180117</alpn.version>
</properties>
</profile>
<profile>
<id>8u162</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_162</value>
</property>
</activation>
<properties>
<alpn.version>8.1.12.v20180117</alpn.version>
</properties>
</profile>
<profile>
<id>8u171</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_171</value>
</property>
</activation>
<properties>
<alpn.version>8.1.12.v20180117</alpn.version>
</properties>
</profile>
<profile>
<id>8u172</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_172</value>
</property>
</activation>
<properties>
<alpn.version>8.1.12.v20180117</alpn.version>
</properties>
</profile>
<profile>
<id>8u181</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_181</value>
</property>
</activation>
<properties>
<alpn.version>8.1.12.v20180117</alpn.version>
</properties>
</profile>
<profile>
<id>8u191</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_191</value>
</property>
</activation>
<properties>
<alpn.version>8.1.13.v20181017</alpn.version>
</properties>
</profile>
<profile>
<id>8u192</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_192</value>
</property>
</activation>
<properties>
<alpn.version>8.1.13.v20181017</alpn.version>
</properties>
</profile>
<profile>
<id>8u201</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_201</value>
</property>
</activation>
<properties>
<alpn.version>8.1.13.v20181017</alpn.version>
</properties>
</profile>
<profile>
<id>8u202</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_202</value>
</property>
</activation>
<properties>
<alpn.version>8.1.13.v20181017</alpn.version>
</properties>
</profile>
<profile>
<id>8u211</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_211</value>
</property>
</activation>
<properties>
<alpn.version>8.1.13.v20181017</alpn.version>
</properties>
</profile>
<profile>
<id>8u212</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_212</value>
</property>
</activation>
<properties>
<alpn.version>8.1.13.v20181017</alpn.version>
</properties>
</profile>
<profile>
<id>8u221</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_221</value>
</property>
</activation>
<properties>
<alpn.version>8.1.13.v20181017</alpn.version>
</properties>
</profile>
<profile>
<id>8u222</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_222</value>
</property>
</activation>
<properties>
<alpn.version>8.1.13.v20181017</alpn.version>
</properties>
</profile>
<profile>
<id>8u231</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_231</value>
</property>
</activation>
<properties>
<alpn.version>8.1.13.v20181017</alpn.version>
</properties>
</profile>
<profile>
<id>8u232</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_232</value>
</property>
</activation>
<properties>
<alpn.version>8.1.13.v20181017</alpn.version>
</properties>
</profile>
<profile>
<id>8u241</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_241</value>
</property>
</activation>
<properties>
<alpn.version>8.1.13.v20181017</alpn.version>
</properties>
</profile>
<profile>
<id>8u242</id>
<activation>
<property>
<name>java.version</name>
<value>1.8.0_242</value>
</property>
</activation>
<properties>
<alpn.version>8.1.13.v20181017</alpn.version>
</properties>
</profile>
<profile>
<id>jdk9</id>
<activation>
<jdk>[9,)</jdk>
<jdk>[1.9,)</jdk>
</activation>
<build>
<plugins>