Merge branch `jetty-9.4.x` into `jetty-9.4.x-3700-felix-webapp-testing`
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com> # Conflicts: # tests/test-webapps/pom.xml
This commit is contained in:
commit
6ca87a0de1
|
@ -27,7 +27,9 @@ import org.eclipse.jetty.deploy.bindings.DebugListenerBinding;
|
|||
import org.eclipse.jetty.deploy.providers.WebAppProvider;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.jmx.MBeanContainer;
|
||||
import org.eclipse.jetty.rewrite.handler.MsieSslRule;
|
||||
import org.eclipse.jetty.rewrite.handler.RewriteHandler;
|
||||
import org.eclipse.jetty.rewrite.handler.ValidUrlRule;
|
||||
import org.eclipse.jetty.security.HashLoginService;
|
||||
import org.eclipse.jetty.server.AsyncRequestLogWriter;
|
||||
import org.eclipse.jetty.server.CustomRequestLog;
|
||||
|
@ -103,7 +105,7 @@ public class LikeJettyXml
|
|||
server.setHandler(handlers);
|
||||
|
||||
// Extra options
|
||||
server.setDumpAfterStart(false);
|
||||
server.setDumpAfterStart(true);
|
||||
server.setDumpBeforeStop(false);
|
||||
server.setStopAtShutdown(true);
|
||||
|
||||
|
@ -189,6 +191,8 @@ public class LikeJettyXml
|
|||
RewriteHandler rewrite = new RewriteHandler();
|
||||
rewrite.setHandler(server.getHandler());
|
||||
server.setHandler(rewrite);
|
||||
rewrite.addRule(new MsieSslRule());
|
||||
rewrite.addRule(new ValidUrlRule());
|
||||
|
||||
// === jetty-requestlog.xml ===
|
||||
AsyncRequestLogWriter logWriter = new AsyncRequestLogWriter(jetty_home + "/logs/yyyy_mm_dd.request.log");
|
||||
|
|
|
@ -110,16 +110,6 @@
|
|||
<artifactId>jetty-ant</artifactId>
|
||||
<version>9.4.20-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||
<artifactId>cdi-core</artifactId>
|
||||
<version>9.4.20-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||
<artifactId>cdi-servlet</artifactId>
|
||||
<version>9.4.20-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-client</artifactId>
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||
<artifactId>jetty-cdi-parent</artifactId>
|
||||
<version>9.4.20-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>cdi-2</artifactId>
|
||||
<name>Jetty :: CDI 2</name>
|
||||
<url>http://www.eclipse.org/jetty</url>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<bundle-symbolic-name>${project.groupId}.cdi2</bundle-symbolic-name>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>config</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -1,71 +0,0 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||
<artifactId>jetty-cdi-parent</artifactId>
|
||||
<version>9.4.20-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>cdi-core</artifactId>
|
||||
<name>Jetty :: CDI :: Core</name>
|
||||
<description>
|
||||
Core CDI routines for Jetty (Also useful for CDI/SE applications that dont need a server)
|
||||
</description>
|
||||
<url>http://www.eclipse.org/jetty</url>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<bundle-symbolic-name>${project.groupId}.core</bundle-symbolic-name>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-util</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.enterprise</groupId>
|
||||
<artifactId>cdi-api</artifactId>
|
||||
<version>1.2</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>javax.el</groupId>
|
||||
<artifactId>javax.el-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.weld</groupId>
|
||||
<artifactId>weld-core</artifactId>
|
||||
<version>${weld.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.weld.se</groupId>
|
||||
<artifactId>weld-se-core</artifactId>
|
||||
<version>${weld.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>tests-jar</id>
|
||||
<goals>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -1,46 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.core;
|
||||
|
||||
import javax.enterprise.util.AnnotationLiteral;
|
||||
import javax.inject.Named;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class NamedLiteral extends AnnotationLiteral<Named> implements Named
|
||||
{
|
||||
private final String value;
|
||||
|
||||
@Override
|
||||
public String value()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public NamedLiteral(String name)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
this.value = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.value = name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.core;
|
||||
|
||||
import javax.enterprise.context.spi.CreationalContext;
|
||||
import javax.enterprise.inject.spi.Bean;
|
||||
|
||||
public class ScopedInstance<T>
|
||||
{
|
||||
public Bean<T> bean;
|
||||
public CreationalContext<T> creationalContext;
|
||||
public T instance;
|
||||
|
||||
public void destroy()
|
||||
{
|
||||
bean.destroy(instance,creationalContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append("ScopedInstance[");
|
||||
s.append(bean);
|
||||
s.append(',').append(creationalContext);
|
||||
s.append(']');
|
||||
return s.toString();
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.enterprise.context.spi.Contextual;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
@Deprecated
|
||||
public class SimpleBeanStore
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(SimpleBeanStore.class);
|
||||
|
||||
public Map<Contextual<?>, List<ScopedInstance<?>>> beans = new HashMap<>();
|
||||
|
||||
public void addBean(ScopedInstance<?> instance)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("addBean({})",instance);
|
||||
}
|
||||
List<ScopedInstance<?>> instances = getBeans(instance.bean);
|
||||
if (instances == null)
|
||||
{
|
||||
instances = new ArrayList<>();
|
||||
beans.put(instance.bean,instances);
|
||||
}
|
||||
instances.add(instance);
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
beans.clear();
|
||||
}
|
||||
|
||||
public void destroy()
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("destroy() - {} beans",beans.size());
|
||||
}
|
||||
for (List<ScopedInstance<?>> instances : beans.values())
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("destroying - {} instance(s)",instances.size());
|
||||
}
|
||||
for (ScopedInstance<?> instance : instances)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("destroying instance {}",instance);
|
||||
}
|
||||
instance.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<ScopedInstance<?>> getBeans(Contextual<?> contextual)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("getBeans({})",contextual);
|
||||
}
|
||||
return beans.get(contextual);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s@%X[size=%d]",this.getClass().getSimpleName(),hashCode(),beans.size());
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
||||
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
|
||||
bean-discovery-mode="all">
|
||||
</beans>
|
|
@ -1,78 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.core;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.spi.CreationalContext;
|
||||
import javax.enterprise.inject.spi.Bean;
|
||||
|
||||
import org.jboss.weld.environment.se.Weld;
|
||||
import org.jboss.weld.environment.se.WeldContainer;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
||||
public abstract class AbstractWeldTest
|
||||
{
|
||||
public static class TestBean<T>
|
||||
{
|
||||
public Bean<T> bean;
|
||||
public CreationalContext<T> cCtx;
|
||||
public T instance;
|
||||
|
||||
public void destroy()
|
||||
{
|
||||
bean.destroy(instance,cCtx);
|
||||
}
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
public static void initWeld()
|
||||
{
|
||||
weld = new Weld();
|
||||
container = weld.initialize();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void shutdownWeld()
|
||||
{
|
||||
weld.shutdown();
|
||||
}
|
||||
|
||||
private static WeldContainer container;
|
||||
private static Weld weld;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> TestBean<T> newInstance(Class<T> clazz) throws Exception
|
||||
{
|
||||
TestBean<T> testBean = new TestBean<>();
|
||||
Set<Bean<?>> beans = container.getBeanManager().getBeans(clazz,AnyLiteral.INSTANCE);
|
||||
if (beans.size() > 0)
|
||||
{
|
||||
testBean.bean = (Bean<T>)beans.iterator().next();
|
||||
testBean.cCtx = container.getBeanManager().createCreationalContext(testBean.bean);
|
||||
testBean.instance = (T)container.getBeanManager().getReference(testBean.bean,clazz,testBean.cCtx);
|
||||
return testBean;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(String.format("Can't find class %s",clazz));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.core;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Unit tests for class {@link NamedLiteral}.
|
||||
*
|
||||
* @see NamedLiteral
|
||||
*/
|
||||
public class NamedLiteralTest
|
||||
{
|
||||
|
||||
@Test
|
||||
public void testCreatesNamedLiteralWithNull()
|
||||
{
|
||||
assertEquals("", new NamedLiteral(null).value());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValue()
|
||||
{
|
||||
assertEquals("a b", new NamedLiteral("a b").value());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.core.logging;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class LeanConsoleHandler extends Handler
|
||||
{
|
||||
public static Handler createWithLevel(Level level)
|
||||
{
|
||||
LeanConsoleHandler handler = new LeanConsoleHandler();
|
||||
handler.setLevel(level);
|
||||
return handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SecurityException
|
||||
{
|
||||
/* nothing to do here */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush()
|
||||
{
|
||||
/* nothing to do here */
|
||||
}
|
||||
|
||||
public synchronized String formatMessage(LogRecord record)
|
||||
{
|
||||
String msg = getMessage(record);
|
||||
|
||||
try
|
||||
{
|
||||
Object params[] = record.getParameters();
|
||||
if ((params == null) || (params.length == 0))
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
|
||||
if (Pattern.compile("\\{\\d+\\}").matcher(msg).find())
|
||||
{
|
||||
return MessageFormat.format(msg,params);
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
private String getMessage(LogRecord record)
|
||||
{
|
||||
ResourceBundle bundle = record.getResourceBundle();
|
||||
if (bundle != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
return bundle.getString(record.getMessage());
|
||||
}
|
||||
catch (java.util.MissingResourceException ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return record.getMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord record)
|
||||
{
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("[").append(record.getLevel().getName()).append("] ");
|
||||
String logname = record.getLoggerName();
|
||||
int idx = logname.lastIndexOf('.');
|
||||
if (idx > 0)
|
||||
{
|
||||
logname = logname.substring(idx + 1);
|
||||
}
|
||||
buf.append(logname);
|
||||
buf.append(": ");
|
||||
buf.append(formatMessage(record));
|
||||
|
||||
System.out.println(buf.toString());
|
||||
if (record.getThrown() != null)
|
||||
{
|
||||
record.getThrown().printStackTrace(System.out);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.core.logging;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.enterprise.inject.Produces;
|
||||
import javax.enterprise.inject.spi.InjectionPoint;
|
||||
|
||||
public class LogFactory
|
||||
{
|
||||
@Produces
|
||||
public Logger createLogger(InjectionPoint injectionPoint)
|
||||
{
|
||||
return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.core.logging;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.logging.LogManager;
|
||||
|
||||
public class Logging
|
||||
{
|
||||
public static void config()
|
||||
{
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
URL url = cl.getResource("logging.properties");
|
||||
if (url != null)
|
||||
{
|
||||
try (InputStream in = url.openStream())
|
||||
{
|
||||
LogManager.getLogManager().readConfiguration(in);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
System.setProperty("org.apache.commons.logging.Log","org.apache.commons.logging.impl.Jdk14Logger");
|
||||
}
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
handlers = org.eclipse.jetty.cdi.core.logging.LeanConsoleHandler
|
||||
.level=INFO
|
|
@ -1,53 +0,0 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||
<artifactId>jetty-cdi-parent</artifactId>
|
||||
<version>9.4.20-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>cdi-full-servlet</artifactId>
|
||||
<name>Jetty :: CDI :: Dependencies</name>
|
||||
<url>http://www.eclipse.org/jetty</url>
|
||||
<packaging>pom</packaging>
|
||||
<properties>
|
||||
<weld.version>2.2.9.Final</weld.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||
<artifactId>cdi-servlet</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<!--
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>javax.el</groupId>
|
||||
<artifactId>javax.el-api</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.jboss.spec.javax.el</groupId>
|
||||
<artifactId>jboss-el-api_3.0_spec</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.jboss.spec.javax.annotation</groupId>
|
||||
<artifactId>jboss-annotations-api_1.2_spec</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.jboss.spec.javax.interceptor</groupId>
|
||||
<artifactId>jboss-interceptors-api_1.2_spec</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
-->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>javax.annotation-api</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mortbay.jasper</groupId>
|
||||
<artifactId>apache-jsp</artifactId>
|
||||
<version>${jsp.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -1,90 +0,0 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||
<artifactId>jetty-cdi-parent</artifactId>
|
||||
<version>9.4.20-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>cdi-servlet</artifactId>
|
||||
<name>Jetty :: CDI :: Servlet</name>
|
||||
<url>http://www.eclipse.org/jetty</url>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<weld.version>2.2.9.Final</weld.version>
|
||||
<bundle-symbolic-name>${project.groupId}.servlet</bundle-symbolic-name>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>config</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||
<artifactId>cdi-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-plus</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-deploy</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.weld.servlet</groupId>
|
||||
<artifactId>weld-servlet-core</artifactId>
|
||||
<version>${weld.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>javax.el</groupId>
|
||||
<artifactId>javax.el-api</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.jboss.spec.javax.el</groupId>
|
||||
<artifactId>jboss-el-api_3.0_spec</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.jboss.spec.javax.annotation</groupId>
|
||||
<artifactId>jboss-annotations-api_1.2_spec</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.jboss.spec.javax.interceptor</groupId>
|
||||
<artifactId>jboss-interceptors-api_1.2_spec</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- below here lie testing dragons -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>apache-jsp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -1,19 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
|
||||
|
||||
<!-- =============================================================== -->
|
||||
<!-- Mixin the Weld / CDI classes to the class loader -->
|
||||
<!-- =============================================================== -->
|
||||
|
||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
<Ref refid="DeploymentManager">
|
||||
<Call name="addLifeCycleBinding">
|
||||
<Arg>
|
||||
<New
|
||||
class="org.eclipse.jetty.cdi.servlet.WeldDeploymentBinding">
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
</Ref>
|
||||
</Configure>
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html
|
||||
|
||||
[description]
|
||||
Experimental CDI/Weld integration
|
||||
|
||||
[depend]
|
||||
cdi1
|
|
@ -1,39 +0,0 @@
|
|||
DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html
|
||||
|
||||
[description]
|
||||
Experimental CDI/Weld integration
|
||||
Deprecated in favour of cdi2 module.
|
||||
|
||||
[depend]
|
||||
deploy
|
||||
annotations
|
||||
plus
|
||||
# JSP (and EL) are requirements for CDI and Weld
|
||||
jsp
|
||||
|
||||
[files]
|
||||
lib/cdi/
|
||||
maven://javax.enterprise/cdi-api/1.2|lib/cdi/javax.enterprise.cdi-api-1.2.jar
|
||||
maven://javax.interceptor/javax.interceptor-api/1.2|lib/cdi/javax.interceptor-api-1.2.jar
|
||||
maven://javax.inject/javax.inject/1|lib/cdi/javax.inject-1.0.jar
|
||||
maven://org.jboss.weld.servlet/weld-servlet-core/2.4.3.Final|lib/cdi/weld-servlet-core-2.4.3.Final.jar
|
||||
maven://org.jboss.weld.environment/weld-environment-common/2.4.3.Final|lib/cdi/weld-environment-common-2.4.3.Final.jar
|
||||
maven://org.jboss.weld/weld-core-impl/2.4.3.Final|lib/cdi/weld-core-impl-2.4.3.Final.jar
|
||||
maven://org.jboss.classfilewriter/jboss-classfilewriter/1.1.2.Final|lib/cdi/jboss-classfilewriter-1.1.2.Final.jar
|
||||
maven://org.jboss.weld/weld-spi/2.4.SP1|lib/cdi/weld-spi-2.4.SP1.jar
|
||||
maven://org.jboss.weld/weld-api/2.4.SP1|lib/cdi/weld-api-2.4.SP1.jar
|
||||
maven://org.jboss.logging/jboss-logging/3.2.1.Final|lib/cdi/jboss-logging-3.2.1.Final.jar
|
||||
|
||||
|
||||
[lib]
|
||||
lib/cdi/*.jar
|
||||
lib/cdi-core-${jetty.version}.jar
|
||||
lib/cdi-servlet-${jetty.version}.jar
|
||||
|
||||
[xml]
|
||||
etc/jetty-cdi.xml
|
||||
|
||||
[license]
|
||||
Weld is an open source project hosted on Github and released under the Apache 2.0 license.
|
||||
http://weld.cdi-spec.org/
|
||||
http://www.apache.org/licenses/LICENSE-2.0.html
|
|
@ -1,145 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpSessionActivationListener;
|
||||
import javax.servlet.http.HttpSessionAttributeListener;
|
||||
import javax.servlet.http.HttpSessionBindingListener;
|
||||
import javax.servlet.http.HttpSessionIdListener;
|
||||
import javax.servlet.http.HttpSessionListener;
|
||||
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.jboss.weld.environment.servlet.EnhancedListener;
|
||||
|
||||
/**
|
||||
* Handy {@link ServletContextHandler} implementation that hooks up
|
||||
* all of the various CDI related components and listeners from Weld.
|
||||
*/
|
||||
public class EmbeddedCdiHandler extends ServletContextHandler
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(EmbeddedCdiHandler.class);
|
||||
|
||||
private static final String[] REQUIRED_BEANS_XML_PATHS = new String[] {
|
||||
"/WEB-INF/beans.xml",
|
||||
"/META-INF/beans.xml",
|
||||
"/WEB-INF/classes/META-INF/beans.xml"
|
||||
};
|
||||
|
||||
public EmbeddedCdiHandler()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public EmbeddedCdiHandler(int options)
|
||||
{
|
||||
super(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
// Required of CDI
|
||||
Resource baseResource = getBaseResource();
|
||||
if (baseResource == null)
|
||||
{
|
||||
throw new NullPointerException("baseResource must be set (to so it can find the beans.xml)");
|
||||
}
|
||||
|
||||
boolean foundBeansXml = false;
|
||||
|
||||
// Verify that beans.xml is present, otherwise weld will fail silently.
|
||||
for(String beansXmlPath: REQUIRED_BEANS_XML_PATHS) {
|
||||
Resource res = baseResource.addPath(beansXmlPath);
|
||||
if (res == null)
|
||||
{
|
||||
// not found, skip it
|
||||
continue;
|
||||
}
|
||||
|
||||
if (res.exists())
|
||||
{
|
||||
foundBeansXml = true;
|
||||
}
|
||||
|
||||
if (res.isDirectory())
|
||||
{
|
||||
throw new IOException("Directory conflicts with expected file: " + res.getURI().toASCIIString());
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundBeansXml)
|
||||
{
|
||||
StringBuilder err = new StringBuilder();
|
||||
err.append("Unable to find required beans.xml from the baseResource: ");
|
||||
err.append(baseResource.getURI().toASCIIString()).append(System.lineSeparator());
|
||||
err.append("Searched for: ");
|
||||
for (String beansXmlPath : REQUIRED_BEANS_XML_PATHS)
|
||||
{
|
||||
err.append(System.lineSeparator());
|
||||
err.append(" ").append(beansXmlPath);
|
||||
}
|
||||
LOG.warn("ERROR: {}",err.toString());
|
||||
throw new IOException(err.toString());
|
||||
}
|
||||
|
||||
// Initialize Weld
|
||||
JettyWeldInitializer.initContext(this);
|
||||
|
||||
// Wire up Weld (what's usually done via the ServletContainerInitializer)
|
||||
ServletContext ctx = getServletContext();
|
||||
|
||||
// Fake the call to ServletContainerInitializer
|
||||
ClassLoader orig = Thread.currentThread().getContextClassLoader();
|
||||
try
|
||||
{
|
||||
Thread.currentThread().setContextClassLoader(ctx.getClassLoader());
|
||||
|
||||
EnhancedListener weldListener = new EnhancedListener();
|
||||
Set<Class<?>> classes = Collections.emptySet();
|
||||
weldListener.onStartup(classes,ctx);
|
||||
|
||||
// add the rest of the Weld Listeners
|
||||
ctx.addListener(weldListener);
|
||||
if ((weldListener instanceof HttpSessionActivationListener)
|
||||
|| (weldListener instanceof HttpSessionAttributeListener)
|
||||
|| (weldListener instanceof HttpSessionBindingListener)
|
||||
|| (weldListener instanceof HttpSessionListener)
|
||||
|| (weldListener instanceof HttpSessionIdListener))
|
||||
{
|
||||
if (getSessionHandler() != null)
|
||||
getSessionHandler().addEventListener(weldListener);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Thread.currentThread().setContextClassLoader(orig);
|
||||
}
|
||||
|
||||
// Let normal ServletContextHandler startup continue its merry way
|
||||
super.doStart();
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.servlet;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.Reference;
|
||||
|
||||
import org.eclipse.jetty.plus.jndi.Resource;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.webapp.ClasspathPattern;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
||||
/**
|
||||
* Utility class suitable for initializing CDI/Weld on Embedded Jetty
|
||||
*/
|
||||
public class JettyWeldInitializer
|
||||
{
|
||||
/**
|
||||
* Initialize WebAppContext to support CDI/Weld.
|
||||
* <p>
|
||||
* Initializes Context, then sets up WebAppContext system and server classes to allow Weld to operate from Server
|
||||
* level.
|
||||
* <p>
|
||||
* Includes {@link #initContext(ContextHandler)} behavior as well.
|
||||
* @param webapp the webapp
|
||||
* @throws NamingException if unable to bind BeanManager context
|
||||
*/
|
||||
public static void initWebApp(WebAppContext webapp) throws NamingException
|
||||
{
|
||||
initContext(webapp);
|
||||
|
||||
// webapp cannot change / replace weld classes
|
||||
ClasspathPattern systemClasses = webapp.getSystemClasspathPattern();
|
||||
systemClasses.add("org.jboss.weld.");
|
||||
systemClasses.add("org.jboss.classfilewriter.");
|
||||
systemClasses.add("org.jboss.logging.");
|
||||
systemClasses.add("com.google.common.");
|
||||
systemClasses.add("org.eclipse.jetty.cdi.websocket.annotation.");
|
||||
|
||||
// don't hide weld classes from webapps (allow webapp to use ones from system classloader)
|
||||
ClasspathPattern serverClasses = webapp.getServerClasspathPattern();
|
||||
serverClasses.add("-org.eclipse.jetty.cdi.websocket.annotation.");
|
||||
serverClasses.add("-org.eclipse.jetty.cdi.core.");
|
||||
serverClasses.add("-org.eclipse.jetty.cdi.servlet.");
|
||||
serverClasses.add("-org.jboss.weld.");
|
||||
serverClasses.add("-org.jboss.classfilewriter.");
|
||||
serverClasses.add("-org.jboss.logging.");
|
||||
serverClasses.add("-com.google.common.");
|
||||
}
|
||||
|
||||
public static void initContext(ContextHandler handler) throws NamingException
|
||||
{
|
||||
// Add context specific weld container reference.
|
||||
// See https://issues.jboss.org/browse/WELD-1710
|
||||
// and https://github.com/weld/core/blob/2.2.5.Final/environments/servlet/core/src/main/java/org/jboss/weld/environment/servlet/WeldServletLifecycle.java#L244-L253
|
||||
handler.setInitParameter("org.jboss.weld.environment.container.class","org.jboss.weld.environment.jetty.JettyContainer");
|
||||
|
||||
// Setup Weld BeanManager reference
|
||||
Reference ref = new Reference("javax.enterprise.inject.spi.BeanManager","org.jboss.weld.resources.ManagerObjectFactory",null);
|
||||
new Resource(handler,"BeanManager",ref);
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.servlet;
|
||||
|
||||
import org.eclipse.jetty.deploy.App;
|
||||
import org.eclipse.jetty.deploy.AppLifeCycle;
|
||||
import org.eclipse.jetty.deploy.graph.Node;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
||||
/**
|
||||
* Perform some basic weld configuration of WebAppContext
|
||||
*/
|
||||
@Deprecated
|
||||
public class WeldDeploymentBinding implements AppLifeCycle.Binding
|
||||
{
|
||||
@Override
|
||||
public String[] getBindingTargets()
|
||||
{
|
||||
return new String[] { "deploying" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processBinding(Node node, App app) throws Exception
|
||||
{
|
||||
ContextHandler handler = app.getContextHandler();
|
||||
if (handler == null)
|
||||
{
|
||||
throw new NullPointerException("No Handler created for App: " + app);
|
||||
}
|
||||
|
||||
if (handler instanceof WebAppContext)
|
||||
{
|
||||
// Do webapp specific init
|
||||
WebAppContext webapp = (WebAppContext)handler;
|
||||
JettyWeldInitializer.initWebApp(webapp);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Do general init
|
||||
JettyWeldInitializer.initContext(handler);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.servlet;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
@Named("iso")
|
||||
public class IsoTimeFormatter implements TimeFormatter
|
||||
{
|
||||
@Override
|
||||
public String format(Calendar cal)
|
||||
{
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'",Locale.US);
|
||||
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
return dateFormat.format(cal.getTime());
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.servlet;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
import javax.enterprise.inject.Default;
|
||||
import javax.inject.Named;
|
||||
|
||||
@Named("locale")
|
||||
@Default
|
||||
public class LocaleTimeFormatter implements TimeFormatter
|
||||
{
|
||||
public static final TimeFormatter INSTANCE = new LocaleTimeFormatter();
|
||||
|
||||
@Override
|
||||
public String format(Calendar cal)
|
||||
{
|
||||
return new SimpleDateFormat().format(cal.getTime());
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.enterprise.inject.Any;
|
||||
import javax.enterprise.inject.Instance;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.cdi.core.NamedLiteral;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@WebServlet("/req-info")
|
||||
public class RequestInfoServlet extends HttpServlet
|
||||
{
|
||||
@Inject
|
||||
@Any
|
||||
private Instance<Dumper> dumpers;
|
||||
|
||||
@Inject
|
||||
@Named("params")
|
||||
private Dumper defaultDumper;
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
|
||||
{
|
||||
resp.setContentType("text/plain");
|
||||
PrintWriter out = resp.getWriter();
|
||||
|
||||
Dumper dumper = defaultDumper;
|
||||
|
||||
String dumperId = req.getParameter("dumperId");
|
||||
|
||||
if (dumperId != null)
|
||||
{
|
||||
Instance<Dumper> inst = dumpers.select(new NamedLiteral(dumperId));
|
||||
if (!inst.isAmbiguous() && !inst.isUnsatisfied())
|
||||
{
|
||||
dumper = inst.get();
|
||||
}
|
||||
}
|
||||
|
||||
dumper.dump(out);
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@Named("params")
|
||||
@RequestScoped
|
||||
public class RequestParamsDumper implements Dumper
|
||||
{
|
||||
@Inject
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Override
|
||||
public void dump(PrintWriter out) throws IOException
|
||||
{
|
||||
out.printf("request is %s%n",request == null ? "NULL" : "PRESENT");
|
||||
|
||||
if (request != null)
|
||||
{
|
||||
Map<String, String[]> params = request.getParameterMap();
|
||||
List<String> paramNames = new ArrayList<>();
|
||||
paramNames.addAll(params.keySet());
|
||||
Collections.sort(paramNames);
|
||||
|
||||
out.printf("parameters.size = [%d]%n",params.size());
|
||||
|
||||
for (String name : paramNames)
|
||||
{
|
||||
out.printf(" param[%s] = [",name);
|
||||
boolean delim = false;
|
||||
for (String val : params.get(name))
|
||||
{
|
||||
if (delim)
|
||||
{
|
||||
out.print(", ");
|
||||
}
|
||||
out.print(val);
|
||||
delim = true;
|
||||
}
|
||||
out.println("]");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,121 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.servlet;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.log.JettyLogHandler;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class WeldInitializationTest
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(WeldInitializationTest.class);
|
||||
private static Server server;
|
||||
private static URI serverHttpURI;
|
||||
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
JettyLogHandler.config();
|
||||
|
||||
server = new Server();
|
||||
ServerConnector connector = new ServerConnector(server);
|
||||
connector.setPort(0);
|
||||
server.addConnector(connector);
|
||||
|
||||
EmbeddedCdiHandler context = new EmbeddedCdiHandler(ServletContextHandler.SESSIONS);
|
||||
|
||||
File baseDir = MavenTestingUtils.getTestResourcesDir();
|
||||
|
||||
context.setBaseResource(Resource.newResource(baseDir));
|
||||
context.setContextPath("/");
|
||||
server.setHandler(context);
|
||||
|
||||
// Add some servlets
|
||||
context.addServlet(TimeServlet.class,"/time");
|
||||
context.addServlet(RequestInfoServlet.class,"/req-info");
|
||||
|
||||
server.start();
|
||||
|
||||
String host = connector.getHost();
|
||||
if (host == null)
|
||||
{
|
||||
host = "localhost";
|
||||
}
|
||||
int port = connector.getLocalPort();
|
||||
serverHttpURI = new URI(String.format("http://%s:%d/",host,port));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void stopServer()
|
||||
{
|
||||
try
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestParamServletDefault() throws Exception
|
||||
{
|
||||
HttpURLConnection http = (HttpURLConnection) serverHttpURI.resolve("req-info").toURL().openConnection();
|
||||
assertThat("response code", http.getResponseCode(), is(200));
|
||||
try(InputStream inputStream = http.getInputStream())
|
||||
{
|
||||
String resp = IO.toString(inputStream);
|
||||
assertThat("Response", resp, containsString("request is PRESENT"));
|
||||
assertThat("Response", resp, containsString("parameters.size = [0]"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestParamServletAbc() throws Exception
|
||||
{
|
||||
HttpURLConnection http = (HttpURLConnection) serverHttpURI.resolve("req-info?abc=123").toURL().openConnection();
|
||||
assertThat("response code", http.getResponseCode(), is(200));
|
||||
try(InputStream inputStream = http.getInputStream())
|
||||
{
|
||||
String resp = IO.toString(inputStream);
|
||||
assertThat("Response", resp, containsString("request is PRESENT"));
|
||||
assertThat("Response", resp, containsString("parameters.size = [1]"));
|
||||
assertThat("Response", resp, containsString(" param[abc] = [123]"));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
||||
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
|
||||
bean-discovery-mode="all">
|
||||
</beans>
|
|
@ -1,11 +0,0 @@
|
|||
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
|
||||
# org.jboss.LEVEL=DEBUG
|
||||
org.eclipse.jetty.LEVEL=INFO
|
||||
|
||||
# org.eclipse.jetty.util.DecoratedObjectFactory.LEVEL=DEBUG
|
||||
# org.eclipse.jetty.cdi.LEVEL=DEBUG
|
||||
|
||||
# org.eclipse.jetty.LEVEL=DEBUG
|
||||
# org.eclipse.jetty.websocket.LEVEL=DEBUG
|
||||
# org.eclipse.jetty.websocket.client.LEVEL=DEBUG
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
handlers = org.eclipse.jetty.util.log.JettyLogHandler
|
||||
.level=FINE
|
|
@ -1,71 +0,0 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||
<artifactId>jetty-cdi-parent</artifactId>
|
||||
<version>9.4.20-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>cdi-websocket</artifactId>
|
||||
<name>Jetty :: CDI :: WebSocket</name>
|
||||
<url>http://www.eclipse.org/jetty</url>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<weld.version>2.2.9.Final</weld.version>
|
||||
<bundle-symbolic-name>${project.groupId}.websocket</bundle-symbolic-name>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||
<artifactId>cdi-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>websocket-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!-- below here lie testing dragons -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>apache-jsp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.weld</groupId>
|
||||
<artifactId>weld-core</artifactId>
|
||||
<version>${weld.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.weld.se</groupId>
|
||||
<artifactId>weld-se-core</artifactId>
|
||||
<version>${weld.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||
<artifactId>cdi-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<classifier>tests</classifier>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||
<artifactId>cdi-servlet</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>javax-websocket-server-impl</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -1,74 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket;
|
||||
|
||||
import org.eclipse.jetty.util.component.Container;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
|
||||
/**
|
||||
* Abstract implementation of listener that needs both Container events and LifeCycle events
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractContainerListener implements LifeCycle.Listener, Container.InheritedListener
|
||||
{
|
||||
@Override
|
||||
public void beanAdded(Container parent, Object child)
|
||||
{
|
||||
if (child instanceof LifeCycle)
|
||||
{
|
||||
((LifeCycle)child).addLifeCycleListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beanRemoved(Container parent, Object child)
|
||||
{
|
||||
if (child instanceof LifeCycle)
|
||||
{
|
||||
((LifeCycle)child).removeLifeCycleListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lifeCycleFailure(LifeCycle event, Throwable cause)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lifeCycleStarted(LifeCycle event)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lifeCycleStarting(LifeCycle event)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lifeCycleStopped(LifeCycle event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lifeCycleStopping(LifeCycle event)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket;
|
||||
|
||||
import javax.enterprise.inject.Produces;
|
||||
import javax.enterprise.inject.spi.InjectionPoint;
|
||||
import javax.websocket.Session;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
/**
|
||||
* Producer of {@link javax.websocket.Session} instances
|
||||
*/
|
||||
@Deprecated
|
||||
public class JavaWebSocketSessionProducer
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(JavaWebSocketSessionProducer.class);
|
||||
|
||||
@Produces
|
||||
public Session getSession(InjectionPoint injectionPoint)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("getSession({})",injectionPoint);
|
||||
}
|
||||
org.eclipse.jetty.websocket.api.Session sess = WebSocketScopeContext.current().getSession();
|
||||
if (sess == null)
|
||||
{
|
||||
throw new IllegalStateException("No Session Available");
|
||||
}
|
||||
|
||||
if (sess instanceof javax.websocket.Session)
|
||||
{
|
||||
return (Session)sess;
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Incompatible Session, expected <" + javax.websocket.Session.class.getName() + ">, but got <"
|
||||
+ sess.getClass().getName() + "> instead");
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket;
|
||||
|
||||
import javax.enterprise.inject.Produces;
|
||||
import javax.enterprise.inject.spi.InjectionPoint;
|
||||
|
||||
import org.eclipse.jetty.cdi.websocket.annotation.WebSocketScope;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
|
||||
/**
|
||||
* Producer of {@link org.eclipse.jetty.websocket.api.Session} instances
|
||||
*/
|
||||
@Deprecated
|
||||
public class JettyWebSocketSessionProducer
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(JettyWebSocketSessionProducer.class);
|
||||
|
||||
@Produces
|
||||
public Session getSession(InjectionPoint injectionPoint)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("getSession({})",injectionPoint);
|
||||
}
|
||||
WebSocketScopeContext ctx = WebSocketScopeContext.current();
|
||||
if (ctx == null)
|
||||
{
|
||||
throw new IllegalStateException("Not in a " + WebSocketScope.class.getName());
|
||||
}
|
||||
org.eclipse.jetty.websocket.api.Session sess = ctx.getSession();
|
||||
if (sess == null)
|
||||
{
|
||||
throw new IllegalStateException("No Session Available");
|
||||
}
|
||||
return sess;
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletContainerInitializer;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.util.thread.ThreadClassLoaderScope;
|
||||
|
||||
@Deprecated
|
||||
public class WebSocketCdiInitializer implements ServletContainerInitializer
|
||||
{
|
||||
public static void configureContext(ServletContextHandler context) throws ServletException
|
||||
{
|
||||
try (ThreadClassLoaderScope scope = new ThreadClassLoaderScope(context.getClassLoader()))
|
||||
{
|
||||
addListeners(context);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartup(Set<Class<?>> c, ServletContext context) throws ServletException
|
||||
{
|
||||
ContextHandler handler = ContextHandler.getContextHandler(context);
|
||||
|
||||
if (handler == null)
|
||||
{
|
||||
throw new ServletException("Not running on Jetty, WebSocket+CDI support unavailable");
|
||||
}
|
||||
|
||||
if (!(handler instanceof ServletContextHandler))
|
||||
{
|
||||
throw new ServletException("Not running in Jetty ServletContextHandler, WebSocket+CDI support unavailable");
|
||||
}
|
||||
|
||||
ServletContextHandler jettyContext = (ServletContextHandler)handler;
|
||||
try (ThreadClassLoaderScope scope = new ThreadClassLoaderScope(context.getClassLoader()))
|
||||
{
|
||||
addListeners(jettyContext);
|
||||
}
|
||||
}
|
||||
|
||||
private static void addListeners(ContainerLifeCycle container)
|
||||
{
|
||||
WebSocketCdiListener listener = new WebSocketCdiListener();
|
||||
container.addLifeCycleListener(listener);
|
||||
container.addEventListener(listener);
|
||||
}
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.inject.spi.Bean;
|
||||
import javax.enterprise.inject.spi.BeanManager;
|
||||
import javax.enterprise.inject.spi.CDI;
|
||||
|
||||
import org.eclipse.jetty.cdi.core.AnyLiteral;
|
||||
import org.eclipse.jetty.cdi.core.ScopedInstance;
|
||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope;
|
||||
import org.eclipse.jetty.websocket.common.scopes.WebSocketSessionScope;
|
||||
|
||||
@Deprecated
|
||||
public class WebSocketCdiListener extends AbstractContainerListener
|
||||
{
|
||||
static final Logger LOG = Log.getLogger(WebSocketCdiListener.class);
|
||||
|
||||
@SuppressWarnings(
|
||||
{ "rawtypes", "unchecked" })
|
||||
public static <T> ScopedInstance<T> newInstance(Class<T> clazz)
|
||||
{
|
||||
BeanManager bm = CDI.current().getBeanManager();
|
||||
|
||||
ScopedInstance sbean = new ScopedInstance();
|
||||
Set<Bean<?>> beans = bm.getBeans(clazz,AnyLiteral.INSTANCE);
|
||||
if (!beans.isEmpty())
|
||||
{
|
||||
sbean.bean = beans.iterator().next();
|
||||
sbean.creationalContext = bm.createCreationalContext(sbean.bean);
|
||||
sbean.instance = bm.getReference(sbean.bean,clazz,sbean.creationalContext);
|
||||
return sbean;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RuntimeException(String.format("Can't find class %s",clazz));
|
||||
}
|
||||
}
|
||||
|
||||
public static class ContainerListener extends AbstractContainerListener
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(WebSocketCdiListener.ContainerListener.class);
|
||||
private final WebSocketContainerScope container;
|
||||
private final ScopedInstance<WebSocketScopeContext> wsScope;
|
||||
|
||||
public ContainerListener(WebSocketContainerScope container)
|
||||
{
|
||||
this.container = container;
|
||||
this.wsScope = newInstance(WebSocketScopeContext.class);
|
||||
this.wsScope.instance.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lifeCycleStarted(LifeCycle event)
|
||||
{
|
||||
if (event == container)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("starting websocket container [{}]",event);
|
||||
}
|
||||
wsScope.instance.begin();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event instanceof WebSocketSessionScope)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("starting websocket session [{}]",event);
|
||||
}
|
||||
wsScope.instance.setSession((Session)event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lifeCycleStopped(LifeCycle event)
|
||||
{
|
||||
if (event == container)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("stopped websocket container [{}]",event);
|
||||
}
|
||||
this.wsScope.instance.end();
|
||||
this.wsScope.instance.destroy();
|
||||
this.wsScope.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lifeCycleStarting(LifeCycle event)
|
||||
{
|
||||
if (event instanceof WebSocketContainerScope)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("started websocket container [{}]",event);
|
||||
}
|
||||
ContainerListener listener = new ContainerListener((WebSocketContainerScope)event);
|
||||
if (event instanceof ContainerLifeCycle)
|
||||
{
|
||||
ContainerLifeCycle container = (ContainerLifeCycle)event;
|
||||
container.addLifeCycleListener(listener);
|
||||
container.addEventListener(listener);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RuntimeException("Unable to setup CDI against non-container: " + event.getClass().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,231 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.spi.Context;
|
||||
import javax.enterprise.context.spi.Contextual;
|
||||
import javax.enterprise.context.spi.CreationalContext;
|
||||
import javax.enterprise.inject.spi.Bean;
|
||||
import javax.enterprise.inject.spi.BeanManager;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.jetty.cdi.core.AnyLiteral;
|
||||
import org.eclipse.jetty.cdi.core.ScopedInstance;
|
||||
import org.eclipse.jetty.cdi.core.SimpleBeanStore;
|
||||
import org.eclipse.jetty.cdi.websocket.annotation.WebSocketScope;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
|
||||
/**
|
||||
* WebSocket Scope Context.
|
||||
* <p>
|
||||
* A CDI Context definition for how CDI will use objects defined to belong to the WebSocketScope
|
||||
*/
|
||||
@Deprecated
|
||||
public class WebSocketScopeContext implements Context
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(WebSocketScopeContext.class);
|
||||
|
||||
private static ThreadLocal<WebSocketScopeContext> current = new ThreadLocal<>();
|
||||
|
||||
public static WebSocketScopeContext current()
|
||||
{
|
||||
return current.get();
|
||||
}
|
||||
|
||||
private SimpleBeanStore beanStore;
|
||||
|
||||
@Inject
|
||||
private BeanManager beanManager;
|
||||
|
||||
private ThreadLocal<org.eclipse.jetty.websocket.api.Session> session = new ThreadLocal<>();
|
||||
|
||||
public void begin()
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("{} begin()",this);
|
||||
}
|
||||
current.set(this);
|
||||
}
|
||||
|
||||
public void create()
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("{} create()",this);
|
||||
}
|
||||
current.set(this);
|
||||
beanStore = new SimpleBeanStore();
|
||||
}
|
||||
|
||||
public void destroy()
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("{} destroy()",this);
|
||||
}
|
||||
|
||||
beanStore.destroy();
|
||||
}
|
||||
|
||||
public void end()
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("{} end()",this);
|
||||
}
|
||||
beanStore.clear();
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@Override
|
||||
public <T> T get(Contextual<T> contextual)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("{} get({})",this,contextual);
|
||||
}
|
||||
|
||||
Bean<T> bean = (Bean<T>)contextual;
|
||||
|
||||
if (bean.getBeanClass().isAssignableFrom(Session.class))
|
||||
{
|
||||
return (T)this.session;
|
||||
}
|
||||
|
||||
if (beanStore == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
List<ScopedInstance<?>> beans = beanStore.getBeans(contextual);
|
||||
|
||||
if ((beans != null) && (!beans.isEmpty()))
|
||||
{
|
||||
return (T)beans.get(0).instance;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("{} get({},{})",this,contextual,creationalContext);
|
||||
}
|
||||
|
||||
Bean<T> bean = (Bean<T>)contextual;
|
||||
|
||||
if (bean.getBeanClass().isAssignableFrom(Session.class))
|
||||
{
|
||||
return (T)this.session;
|
||||
}
|
||||
|
||||
if (beanStore == null)
|
||||
{
|
||||
beanStore = new SimpleBeanStore();
|
||||
}
|
||||
|
||||
List<ScopedInstance<?>> beans = beanStore.getBeans(contextual);
|
||||
|
||||
if ((beans != null) && (!beans.isEmpty()))
|
||||
{
|
||||
for (ScopedInstance<?> instance : beans)
|
||||
{
|
||||
if (instance.bean.equals(bean))
|
||||
{
|
||||
return (T)instance.instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// no bean found, create it
|
||||
T t = bean.create(creationalContext);
|
||||
ScopedInstance<T> customInstance = new ScopedInstance<>();
|
||||
customInstance.bean = bean;
|
||||
customInstance.creationalContext = creationalContext;
|
||||
customInstance.instance = t;
|
||||
beanStore.addBean(customInstance);
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getScope()
|
||||
{
|
||||
return WebSocketScope.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public <T> T newInstance(Class<T> clazz)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("newInstance({})",clazz);
|
||||
}
|
||||
Set<Bean<?>> beans = beanManager.getBeans(clazz,AnyLiteral.INSTANCE);
|
||||
if (beans.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Bean bean = beans.iterator().next();
|
||||
CreationalContext cc = beanManager.createCreationalContext(bean);
|
||||
return (T)beanManager.getReference(bean,clazz,cc);
|
||||
}
|
||||
|
||||
public void setSession(org.eclipse.jetty.websocket.api.Session sess)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("{} setSession({})",this,sess);
|
||||
}
|
||||
current.set(this);
|
||||
this.session.set(sess);
|
||||
}
|
||||
|
||||
public org.eclipse.jetty.websocket.api.Session getSession()
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("{} getSession()",this);
|
||||
}
|
||||
return this.session.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s@%X[%s]",this.getClass().getSimpleName(),hashCode(),beanStore);
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket;
|
||||
|
||||
import javax.enterprise.context.Destroyed;
|
||||
import javax.enterprise.context.Initialized;
|
||||
import javax.enterprise.event.Observes;
|
||||
import javax.enterprise.inject.spi.AfterBeanDiscovery;
|
||||
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
|
||||
import javax.enterprise.inject.spi.Extension;
|
||||
|
||||
import org.eclipse.jetty.cdi.websocket.annotation.WebSocketScope;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
/**
|
||||
* Register the various WebSocket specific components for CDI
|
||||
*/
|
||||
@Deprecated
|
||||
public class WebSocketScopeExtension implements Extension
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(WebSocketScopeExtension.class);
|
||||
|
||||
public void addScope(@Observes final BeforeBeanDiscovery event)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("addScope()");
|
||||
}
|
||||
// Add our scope
|
||||
event.addScope(WebSocketScope.class,true,false);
|
||||
}
|
||||
|
||||
public void registerContext(@Observes final AfterBeanDiscovery event)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("registerContext()");
|
||||
}
|
||||
// Register our context
|
||||
event.addContext(new WebSocketScopeContext());
|
||||
}
|
||||
|
||||
public void logWsScopeInit(@Observes @Initialized(WebSocketScope.class) org.eclipse.jetty.websocket.api.Session sess)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("Initialized @WebSocketScope - {}",sess);
|
||||
}
|
||||
}
|
||||
|
||||
public void logWsScopeDestroyed(@Observes @Destroyed(WebSocketScope.class) org.eclipse.jetty.websocket.api.Session sess)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("Destroyed @WebSocketScope - {}",sess);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import javax.inject.Scope;
|
||||
|
||||
/**
|
||||
* A CDI Context Scope for a WebSocket Session / Endpoint
|
||||
* <p>
|
||||
* <em>CAUTION: This is a highly speculative scope defined by Jetty. One that will likely be replaced by a formal spec later</em>
|
||||
* <p>
|
||||
* At the time of implementation (of this scope), no standard scope exists for websocket session lifecycle.
|
||||
*/
|
||||
@Scope
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD })
|
||||
@Inherited
|
||||
@Documented
|
||||
@Deprecated
|
||||
public @interface WebSocketScope
|
||||
{
|
||||
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
<beans xmlns="http://java.sun.com/xml/ns/javaee" 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/beans_1_0.xsd">
|
||||
|
||||
</beans>
|
|
@ -1 +0,0 @@
|
|||
org.eclipse.jetty.cdi.websocket.WebSocketScopeExtension
|
|
@ -1 +0,0 @@
|
|||
org.eclipse.jetty.cdi.websocket.WebSocketCdiInitializer
|
|
@ -1,99 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
|
||||
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
||||
|
||||
@WebSocket
|
||||
public class CheckSocket extends WebSocketAdapter
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(CheckSocket.class);
|
||||
private CountDownLatch closeLatch = new CountDownLatch(1);
|
||||
private CountDownLatch openLatch = new CountDownLatch(1);
|
||||
public LinkedBlockingQueue<String> textMessages = new LinkedBlockingQueue<>();
|
||||
|
||||
public void awaitClose(int timeout, TimeUnit timeunit) throws InterruptedException
|
||||
{
|
||||
assertTrue(closeLatch.await(timeout,timeunit), "Timeout waiting for close");
|
||||
}
|
||||
|
||||
public void awaitOpen(int timeout, TimeUnit timeunit) throws InterruptedException
|
||||
{
|
||||
assertTrue(openLatch.await(timeout,timeunit), "Timeout waiting for open");
|
||||
}
|
||||
|
||||
public LinkedBlockingQueue<String> getTextMessages()
|
||||
{
|
||||
return textMessages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketClose(int statusCode, String reason)
|
||||
{
|
||||
LOG.debug("Close: {}, {}",statusCode,reason);
|
||||
super.onWebSocketClose(statusCode,reason);
|
||||
closeLatch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketConnect(Session sess)
|
||||
{
|
||||
LOG.debug("Open: {}",sess);
|
||||
super.onWebSocketConnect(sess);
|
||||
openLatch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketError(Throwable cause)
|
||||
{
|
||||
LOG.warn("WebSocket Error",cause);
|
||||
super.onWebSocketError(cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketText(String message)
|
||||
{
|
||||
LOG.debug("TEXT: {}",message);
|
||||
textMessages.add(message);
|
||||
}
|
||||
|
||||
public void sendText(String msg) throws IOException
|
||||
{
|
||||
if (isConnected())
|
||||
{
|
||||
getRemote().sendString(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void close(int statusCode, String reason)
|
||||
{
|
||||
getSession().close(statusCode,reason);
|
||||
}
|
||||
}
|
|
@ -1,130 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket.basicapp;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.websocket.server.ServerContainer;
|
||||
|
||||
import org.eclipse.jetty.cdi.servlet.EmbeddedCdiHandler;
|
||||
import org.eclipse.jetty.cdi.websocket.CheckSocket;
|
||||
import org.eclipse.jetty.cdi.websocket.cdiapp.InfoSocket;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.log.JettyLogHandler;
|
||||
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.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class BasicAppTest
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(BasicAppTest.class);
|
||||
|
||||
private static Server server;
|
||||
@SuppressWarnings("unused")
|
||||
private static URI serverHttpURI;
|
||||
private static URI serverWebsocketURI;
|
||||
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
JettyLogHandler.config();
|
||||
|
||||
server = new Server();
|
||||
ServerConnector connector = new ServerConnector(server);
|
||||
connector.setPort(0);
|
||||
server.addConnector(connector);
|
||||
|
||||
EmbeddedCdiHandler context = new EmbeddedCdiHandler();
|
||||
|
||||
File baseDir = MavenTestingUtils.getTestResourcesDir();
|
||||
|
||||
context.setBaseResource(Resource.newResource(baseDir));
|
||||
context.setContextPath("/");
|
||||
server.setHandler(context);
|
||||
|
||||
// Add some websockets
|
||||
ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
|
||||
container.addEndpoint(EchoSocket.class);
|
||||
container.addEndpoint(InfoSocket.class);
|
||||
|
||||
server.start();
|
||||
|
||||
String host = connector.getHost();
|
||||
if (host == null)
|
||||
{
|
||||
host = "localhost";
|
||||
}
|
||||
int port = connector.getLocalPort();
|
||||
serverHttpURI = new URI(String.format("http://%s:%d/",host,port));
|
||||
serverWebsocketURI = new URI(String.format("ws://%s:%d/",host,port));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void stopServer()
|
||||
{
|
||||
try
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWebSocketEcho() throws Exception
|
||||
{
|
||||
WebSocketClient client = new WebSocketClient();
|
||||
try
|
||||
{
|
||||
client.start();
|
||||
CheckSocket socket = new CheckSocket();
|
||||
client.connect(socket,serverWebsocketURI.resolve("/echo"));
|
||||
|
||||
socket.awaitOpen(2,TimeUnit.SECONDS);
|
||||
socket.sendText("Hello World");
|
||||
socket.close(StatusCode.NORMAL,"Test complete");
|
||||
socket.awaitClose(2,TimeUnit.SECONDS);
|
||||
|
||||
assertThat("Messages received",socket.getTextMessages().size(),is(1));
|
||||
String response = socket.getTextMessages().poll();
|
||||
System.err.println(response);
|
||||
|
||||
assertThat("Message[0]",response,is("Hello World"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket.basicapp;
|
||||
|
||||
import javax.websocket.CloseReason;
|
||||
import javax.websocket.OnClose;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
@ServerEndpoint("/echo")
|
||||
public class EchoSocket
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(EchoSocket.class);
|
||||
@SuppressWarnings("unused")
|
||||
private Session session;
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session)
|
||||
{
|
||||
LOG.debug("onOpen(): {}",session);
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@OnClose
|
||||
public void onClose(CloseReason close)
|
||||
{
|
||||
LOG.debug("onClose(): {}",close);
|
||||
this.session = null;
|
||||
}
|
||||
|
||||
@OnMessage
|
||||
public String onMessage(String msg)
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket.basicscope;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
public class Food
|
||||
{
|
||||
private boolean constructed = false;
|
||||
private boolean destroyed = false;
|
||||
private String name;
|
||||
|
||||
@PreDestroy
|
||||
void destroy()
|
||||
{
|
||||
destroyed = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Food other = (Food)obj;
|
||||
if (name == null)
|
||||
{
|
||||
if (other.name != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!name.equals(other.name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = (prime * result) + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
void init()
|
||||
{
|
||||
constructed = true;
|
||||
}
|
||||
|
||||
public boolean isConstructed()
|
||||
{
|
||||
return constructed;
|
||||
}
|
||||
|
||||
public boolean isDestroyed()
|
||||
{
|
||||
return destroyed;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket.basicscope;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.inject.spi.Bean;
|
||||
|
||||
import org.eclipse.jetty.cdi.core.AnyLiteral;
|
||||
import org.eclipse.jetty.cdi.core.ScopedInstance;
|
||||
import org.eclipse.jetty.cdi.core.logging.Logging;
|
||||
import org.jboss.weld.environment.se.Weld;
|
||||
import org.jboss.weld.environment.se.WeldContainer;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ScopeBasicsTest
|
||||
{
|
||||
private static Weld weld;
|
||||
private static WeldContainer container;
|
||||
|
||||
@BeforeAll
|
||||
public static void startWeld()
|
||||
{
|
||||
Logging.config();
|
||||
weld = new Weld();
|
||||
container = weld.initialize();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void stopWeld()
|
||||
{
|
||||
weld.shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation of Scope / Inject logic on non-websocket-scoped classes
|
||||
* @throws Exception on test failure
|
||||
*/
|
||||
@Test
|
||||
public void testBasicBehavior() throws Exception
|
||||
{
|
||||
ScopedInstance<Meal> meal1Bean = newInstance(Meal.class);
|
||||
Meal meal1 = meal1Bean.instance;
|
||||
ScopedInstance<Meal> meal2Bean = newInstance(Meal.class);
|
||||
Meal meal2 = meal2Bean.instance;
|
||||
|
||||
assertThat("Meals are not the same",meal1,not(sameInstance(meal2)));
|
||||
|
||||
assertThat("Meal 1 Entree Constructed",meal1.getEntree().isConstructed(),is(true));
|
||||
assertThat("Meal 1 Side Constructed",meal1.getSide().isConstructed(),is(true));
|
||||
|
||||
assertThat("Meal parts not the same",meal1.getEntree(),not(sameInstance(meal1.getSide())));
|
||||
assertThat("Meal entrees are the same",meal1.getEntree(),not(sameInstance(meal2.getEntree())));
|
||||
assertThat("Meal sides are the same",meal1.getSide(),not(sameInstance(meal2.getSide())));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static <T> ScopedInstance<T> newInstance(Class<T> clazz) throws Exception
|
||||
{
|
||||
ScopedInstance sbean = new ScopedInstance();
|
||||
Set<Bean<?>> beans = container.getBeanManager().getBeans(clazz,AnyLiteral.INSTANCE);
|
||||
if (beans.size() > 0)
|
||||
{
|
||||
sbean.bean = beans.iterator().next();
|
||||
sbean.creationalContext = container.getBeanManager().createCreationalContext(sbean.bean);
|
||||
sbean.instance = container.getBeanManager().getReference(sbean.bean,clazz,sbean.creationalContext);
|
||||
return sbean;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(String.format("Can't find class %s",clazz));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,185 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket.cdiapp;
|
||||
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.websocket.server.ServerContainer;
|
||||
|
||||
import org.eclipse.jetty.cdi.servlet.EmbeddedCdiHandler;
|
||||
import org.eclipse.jetty.cdi.websocket.CheckSocket;
|
||||
import org.eclipse.jetty.cdi.websocket.WebSocketCdiInitializer;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.log.JettyLogHandler;
|
||||
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.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class CdiAppTest
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(CdiAppTest.class);
|
||||
private static Server server;
|
||||
private static URI serverWebsocketURI;
|
||||
|
||||
@BeforeAll
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
JettyLogHandler.config();
|
||||
|
||||
server = new Server();
|
||||
ServerConnector connector = new ServerConnector(server);
|
||||
connector.setPort(0);
|
||||
server.addConnector(connector);
|
||||
|
||||
EmbeddedCdiHandler context = new EmbeddedCdiHandler();
|
||||
WebSocketCdiInitializer.configureContext(context);
|
||||
|
||||
File baseDir = MavenTestingUtils.getTestResourcesDir();
|
||||
|
||||
context.setBaseResource(Resource.newResource(baseDir));
|
||||
context.setContextPath("/");
|
||||
server.setHandler(context);
|
||||
|
||||
// Add some websockets
|
||||
ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
|
||||
container.addEndpoint(EchoSocket.class);
|
||||
container.addEndpoint(InfoSocket.class);
|
||||
|
||||
server.start();
|
||||
|
||||
String host = connector.getHost();
|
||||
if (host == null)
|
||||
{
|
||||
host = "localhost";
|
||||
}
|
||||
int port = connector.getLocalPort();
|
||||
serverWebsocketURI = new URI(String.format("ws://%s:%d/",host,port));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void stopServer()
|
||||
{
|
||||
try
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWebSocketActivated() throws Exception
|
||||
{
|
||||
WebSocketClient client = new WebSocketClient();
|
||||
try
|
||||
{
|
||||
client.start();
|
||||
CheckSocket socket = new CheckSocket();
|
||||
client.connect(socket,serverWebsocketURI.resolve("/echo"));
|
||||
|
||||
socket.awaitOpen(2,TimeUnit.SECONDS);
|
||||
socket.sendText("Hello");
|
||||
socket.close(StatusCode.NORMAL,"Test complete");
|
||||
socket.awaitClose(2,TimeUnit.SECONDS);
|
||||
|
||||
assertThat("Messages received",socket.getTextMessages().size(),is(1));
|
||||
assertThat("Message[0]",socket.getTextMessages().poll(),is("Hello"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWebSocket_Info_FieldPresence() throws Exception
|
||||
{
|
||||
WebSocketClient client = new WebSocketClient();
|
||||
try
|
||||
{
|
||||
client.start();
|
||||
CheckSocket socket = new CheckSocket();
|
||||
client.connect(socket,serverWebsocketURI.resolve("/cdi-info"));
|
||||
|
||||
socket.awaitOpen(2,TimeUnit.SECONDS);
|
||||
socket.sendText("info");
|
||||
socket.close(StatusCode.NORMAL,"Test complete");
|
||||
socket.awaitClose(2,TimeUnit.SECONDS);
|
||||
|
||||
assertThat("Messages received",socket.getTextMessages().size(),is(1));
|
||||
String response = socket.getTextMessages().poll();
|
||||
System.err.println(response);
|
||||
|
||||
assertThat("Message[0]",response,
|
||||
allOf(
|
||||
containsString("websocketSession is PRESENT"),
|
||||
containsString("httpSession is PRESENT"),
|
||||
containsString("servletContext is PRESENT")
|
||||
));
|
||||
}
|
||||
finally
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWebSocket_Info_DataFromCdi() throws Exception
|
||||
{
|
||||
WebSocketClient client = new WebSocketClient();
|
||||
try
|
||||
{
|
||||
client.start();
|
||||
CheckSocket socket = new CheckSocket();
|
||||
client.connect(socket,serverWebsocketURI.resolve("/cdi-info"));
|
||||
|
||||
socket.awaitOpen(2,TimeUnit.SECONDS);
|
||||
socket.sendText("data|stuff");
|
||||
socket.close(StatusCode.NORMAL,"Test complete");
|
||||
socket.awaitClose(2,TimeUnit.SECONDS);
|
||||
|
||||
assertThat("Messages received",socket.getTextMessages().size(),is(2));
|
||||
String response = socket.getTextMessages().poll();
|
||||
System.out.println("[0]" + response);
|
||||
assertThat("Message[0]",response,containsString("Hello there stuff"));
|
||||
System.out.println("[1]" + socket.getTextMessages().poll());
|
||||
}
|
||||
finally
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket.cdiapp;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.jetty.cdi.websocket.annotation.WebSocketScope;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
|
||||
public class DataMaker
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(DataMaker.class);
|
||||
|
||||
@Inject
|
||||
@WebSocketScope
|
||||
private Session session;
|
||||
|
||||
public void processMessage(String msg)
|
||||
{
|
||||
LOG.debug(".processMessage({})",msg);
|
||||
LOG.debug("session = {}",session);
|
||||
|
||||
session.getRemote().sendStringByFuture("Hello there " + msg);
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket.cdiapp;
|
||||
|
||||
import javax.websocket.CloseReason;
|
||||
import javax.websocket.OnClose;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
@ServerEndpoint("/echo")
|
||||
public class EchoSocket
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(EchoSocket.class);
|
||||
@SuppressWarnings("unused")
|
||||
private Session session;
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session)
|
||||
{
|
||||
LOG.debug("onOpen(): {}",session);
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@OnClose
|
||||
public void onClose(CloseReason close)
|
||||
{
|
||||
LOG.debug("onClose(): {}",close);
|
||||
this.session = null;
|
||||
}
|
||||
|
||||
@OnMessage
|
||||
public String onMessage(String msg)
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket.cdiapp;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.enterprise.context.SessionScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.websocket.CloseReason;
|
||||
import javax.websocket.OnClose;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
@ServerEndpoint("/cdi-info")
|
||||
public class InfoSocket
|
||||
{
|
||||
private static final java.util.logging.Logger LOG = java.util.logging.Logger.getLogger(InfoSocket.class.getName());
|
||||
|
||||
@SessionScoped
|
||||
@Inject
|
||||
private HttpSession httpSession;
|
||||
|
||||
@Inject
|
||||
private ServletContext servletContext;
|
||||
|
||||
@Inject
|
||||
private DataMaker dataMaker;
|
||||
|
||||
private Session session;
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session)
|
||||
{
|
||||
LOG.log(Level.INFO,"onOpen(): {0}",session);
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@OnClose
|
||||
public void onClose(CloseReason close)
|
||||
{
|
||||
LOG.log(Level.INFO,"onClose(): {}",close);
|
||||
this.session = null;
|
||||
}
|
||||
|
||||
@OnMessage
|
||||
public String onMessage(String msg)
|
||||
{
|
||||
StringWriter str = new StringWriter();
|
||||
PrintWriter out = new PrintWriter(str);
|
||||
|
||||
String args[] = msg.split("\\|");
|
||||
|
||||
switch (args[0])
|
||||
{
|
||||
case "info":
|
||||
out.printf("websocketSession is %s%n",asPresent(session));
|
||||
out.printf("httpSession is %s%n",asPresent(httpSession));
|
||||
out.printf("servletContext is %s%n",asPresent(servletContext));
|
||||
break;
|
||||
case "data":
|
||||
dataMaker.processMessage(args[1]);
|
||||
break;
|
||||
}
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
private String asPresent(Object obj)
|
||||
{
|
||||
return obj == null ? "NULL" : "PRESENT";
|
||||
}
|
||||
}
|
|
@ -1,150 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket.wsscope;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.CloseStatus;
|
||||
import org.eclipse.jetty.websocket.api.RemoteEndpoint;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.SuspendToken;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeResponse;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
|
||||
/**
|
||||
* A bogus websocket Session concept object.
|
||||
* <p>
|
||||
* Used to test the scope @Inject of this kind of Session. This is important to test, as the BogusSession does not have
|
||||
* a default constructor that CDI itself can use to create this object.
|
||||
* <p>
|
||||
* This object would need to be added to the beanstore for this scope for later @Inject to use.
|
||||
*/
|
||||
public class BogusSession implements Session
|
||||
{
|
||||
private final String id;
|
||||
|
||||
public BogusSession(String id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("BogusSession[id=%s]",id);
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(CloseStatus closeStatus)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(int statusCode, String reason)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect() throws IOException
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getIdleTimeout()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getLocalAddress()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebSocketPolicy getPolicy()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolVersion()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RemoteEndpoint getRemote()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getRemoteAddress()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpgradeRequest getUpgradeRequest()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpgradeResponse getUpgradeResponse()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSecure()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIdleTimeout(long ms)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuspendToken suspend()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket.wsscope;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.jetty.cdi.websocket.annotation.WebSocketScope;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
|
||||
public class BogusSocket
|
||||
{
|
||||
@Inject
|
||||
@WebSocketScope
|
||||
private Session session;
|
||||
|
||||
public Session getSession()
|
||||
{
|
||||
return session;
|
||||
}
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket.wsscope;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.eclipse.jetty.cdi.websocket.annotation.WebSocketScope;
|
||||
|
||||
@WebSocketScope
|
||||
public class Food
|
||||
{
|
||||
private boolean constructed = false;
|
||||
private boolean destroyed = false;
|
||||
private String name;
|
||||
|
||||
public Food()
|
||||
{
|
||||
// default constructor (for CDI use)
|
||||
}
|
||||
|
||||
public Food(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
void destroy()
|
||||
{
|
||||
destroyed = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Food other = (Food)obj;
|
||||
if (name == null)
|
||||
{
|
||||
if (other.name != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!name.equals(other.name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = (prime * result) + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
void init()
|
||||
{
|
||||
constructed = true;
|
||||
}
|
||||
|
||||
public boolean isConstructed()
|
||||
{
|
||||
return constructed;
|
||||
}
|
||||
|
||||
public boolean isDestroyed()
|
||||
{
|
||||
return destroyed;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s@%X[%s]",Food.class.getSimpleName(),hashCode(),name);
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket.wsscope;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class Meal
|
||||
{
|
||||
@Inject
|
||||
private Food entree;
|
||||
|
||||
@Inject
|
||||
private Food side;
|
||||
|
||||
public Food getEntree()
|
||||
{
|
||||
return entree;
|
||||
}
|
||||
|
||||
public Food getSide()
|
||||
{
|
||||
return side;
|
||||
}
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket.wsscope;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.inject.spi.Bean;
|
||||
|
||||
import org.eclipse.jetty.cdi.core.AnyLiteral;
|
||||
import org.eclipse.jetty.cdi.core.ScopedInstance;
|
||||
import org.eclipse.jetty.cdi.core.logging.Logging;
|
||||
import org.eclipse.jetty.cdi.websocket.WebSocketScopeContext;
|
||||
import org.eclipse.jetty.cdi.websocket.annotation.WebSocketScope;
|
||||
import org.jboss.weld.environment.se.Weld;
|
||||
import org.jboss.weld.environment.se.WeldContainer;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class WebSocketScopeBaselineTest
|
||||
{
|
||||
private static Weld weld;
|
||||
private static WeldContainer container;
|
||||
|
||||
@BeforeAll
|
||||
public static void startWeld()
|
||||
{
|
||||
Logging.config();
|
||||
weld = new Weld();
|
||||
container = weld.initialize();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void stopWeld()
|
||||
{
|
||||
weld.shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test behavior of {@link WebSocketScope} in basic operation.
|
||||
* <p>
|
||||
* Food is declared as part of WebSocketScope, and as such, only 1 instance of it can exist.
|
||||
* @throws Exception on test failure
|
||||
*/
|
||||
@Test
|
||||
public void testScopeBehavior() throws Exception
|
||||
{
|
||||
ScopedInstance<WebSocketScopeContext> wsScopeBean = newInstance(WebSocketScopeContext.class);
|
||||
WebSocketScopeContext wsScope = wsScopeBean.instance;
|
||||
|
||||
wsScope.create();
|
||||
Meal meal1;
|
||||
try
|
||||
{
|
||||
wsScope.begin();
|
||||
ScopedInstance<Meal> meal1Bean = newInstance(Meal.class);
|
||||
meal1 = meal1Bean.instance;
|
||||
ScopedInstance<Meal> meal2Bean = newInstance(Meal.class);
|
||||
Meal meal2 = meal2Bean.instance;
|
||||
|
||||
assertThat("Meals are not the same",meal1,not(sameInstance(meal2)));
|
||||
|
||||
assertThat("Meal 1 Entree Constructed",meal1.getEntree().isConstructed(),is(true));
|
||||
assertThat("Meal 1 Side Constructed",meal1.getSide().isConstructed(),is(true));
|
||||
|
||||
/* Since Food is annotated with @WebSocketScope, there can only be one instance of it
|
||||
* in use with the 2 Meal objects.
|
||||
*/
|
||||
assertThat("Meal parts not the same",meal1.getEntree(),sameInstance(meal1.getSide()));
|
||||
assertThat("Meal entrees are the same",meal1.getEntree(),sameInstance(meal2.getEntree()));
|
||||
assertThat("Meal sides are the same",meal1.getSide(),sameInstance(meal2.getSide()));
|
||||
|
||||
meal1Bean.destroy();
|
||||
meal2Bean.destroy();
|
||||
}
|
||||
finally
|
||||
{
|
||||
wsScope.end();
|
||||
}
|
||||
|
||||
Food entree1 = meal1.getEntree();
|
||||
Food side1 = meal1.getSide();
|
||||
|
||||
assertThat("Meal 1 entree destroyed",entree1.isDestroyed(),is(false));
|
||||
assertThat("Meal 1 side destroyed",side1.isDestroyed(),is(false));
|
||||
wsScope.destroy();
|
||||
|
||||
// assertThat("Meal 1 entree destroyed",entree1.isDestroyed(),is(true));
|
||||
// assertThat("Meal 1 side destroyed",side1.isDestroyed(),is(true));
|
||||
wsScopeBean.destroy();
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static <T> ScopedInstance<T> newInstance(Class<T> clazz) throws Exception
|
||||
{
|
||||
ScopedInstance sbean = new ScopedInstance();
|
||||
Set<Bean<?>> beans = container.getBeanManager().getBeans(clazz,AnyLiteral.INSTANCE);
|
||||
if (beans.size() > 0)
|
||||
{
|
||||
sbean.bean = beans.iterator().next();
|
||||
sbean.creationalContext = container.getBeanManager().createCreationalContext(sbean.bean);
|
||||
sbean.instance = container.getBeanManager().getReference(sbean.bean,clazz,sbean.creationalContext);
|
||||
return sbean;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(String.format("Can't find class %s",clazz));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,253 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.cdi.websocket.wsscope;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.enterprise.inject.spi.Bean;
|
||||
|
||||
import org.eclipse.jetty.cdi.core.AnyLiteral;
|
||||
import org.eclipse.jetty.cdi.core.ScopedInstance;
|
||||
import org.eclipse.jetty.cdi.core.logging.Logging;
|
||||
import org.eclipse.jetty.cdi.websocket.WebSocketScopeContext;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.jboss.weld.environment.se.Weld;
|
||||
import org.jboss.weld.environment.se.WeldContainer;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class WebSocketScopeSessionTest
|
||||
{
|
||||
private static Weld weld;
|
||||
private static WeldContainer container;
|
||||
|
||||
@BeforeAll
|
||||
public static void startWeld()
|
||||
{
|
||||
Logging.config();
|
||||
weld = new Weld();
|
||||
container = weld.initialize();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void stopWeld()
|
||||
{
|
||||
weld.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionActivation() throws Exception
|
||||
{
|
||||
ScopedInstance<WebSocketScopeContext> wsScopeBean = newInstance(WebSocketScopeContext.class);
|
||||
WebSocketScopeContext wsScope = wsScopeBean.instance;
|
||||
|
||||
wsScope.create();
|
||||
try
|
||||
{
|
||||
// Scope 1
|
||||
wsScope.begin();
|
||||
BogusSession sess = new BogusSession("1");
|
||||
wsScope.setSession(sess);
|
||||
ScopedInstance<BogusSocket> sock1Bean = newInstance(BogusSocket.class);
|
||||
BogusSocket sock1 = sock1Bean.instance;
|
||||
assertThat("Socket 1 Session",sock1.getSession().toString(),is(sess.toString()));
|
||||
|
||||
sock1Bean.destroy();
|
||||
}
|
||||
finally
|
||||
{
|
||||
wsScope.end();
|
||||
}
|
||||
|
||||
wsScope.destroy();
|
||||
wsScopeBean.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiSession_Sequential() throws Exception
|
||||
{
|
||||
ScopedInstance<WebSocketScopeContext> wsScope1Bean = newInstance(WebSocketScopeContext.class);
|
||||
WebSocketScopeContext wsScope1 = wsScope1Bean.instance;
|
||||
|
||||
ScopedInstance<WebSocketScopeContext> wsScope2Bean = newInstance(WebSocketScopeContext.class);
|
||||
WebSocketScopeContext wsScope2 = wsScope2Bean.instance;
|
||||
|
||||
wsScope1.create();
|
||||
try
|
||||
{
|
||||
// Scope 1
|
||||
wsScope1.begin();
|
||||
BogusSession sess = new BogusSession("1");
|
||||
wsScope1.setSession(sess);
|
||||
ScopedInstance<BogusSocket> sock1Bean = newInstance(BogusSocket.class);
|
||||
BogusSocket sock1 = sock1Bean.instance;
|
||||
assertThat("Socket 1 Session",sock1.getSession(),sameInstance((Session)sess));
|
||||
sock1Bean.destroy();
|
||||
}
|
||||
finally
|
||||
{
|
||||
wsScope1.end();
|
||||
}
|
||||
|
||||
wsScope1.destroy();
|
||||
wsScope1Bean.destroy();
|
||||
|
||||
wsScope2.create();
|
||||
try
|
||||
{
|
||||
// Scope 2
|
||||
wsScope2.begin();
|
||||
BogusSession sess = new BogusSession("2");
|
||||
wsScope2.setSession(sess);
|
||||
ScopedInstance<BogusSocket> sock2Bean = newInstance(BogusSocket.class);
|
||||
BogusSocket sock2 = sock2Bean.instance;
|
||||
assertThat("Socket 2 Session",sock2.getSession(),sameInstance((Session)sess));
|
||||
sock2Bean.destroy();
|
||||
}
|
||||
finally
|
||||
{
|
||||
wsScope2.end();
|
||||
}
|
||||
|
||||
wsScope2.destroy();
|
||||
wsScope2Bean.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiSession_Overlapping() throws Exception
|
||||
{
|
||||
final CountDownLatch midLatch = new CountDownLatch(2);
|
||||
final CountDownLatch end1Latch = new CountDownLatch(1);
|
||||
|
||||
Callable<Session> call1 = new Callable<Session>() {
|
||||
@Override
|
||||
public Session call() throws Exception
|
||||
{
|
||||
Session ret = null;
|
||||
ScopedInstance<WebSocketScopeContext> wsScope1Bean = newInstance(WebSocketScopeContext.class);
|
||||
WebSocketScopeContext wsScope1 = wsScope1Bean.instance;
|
||||
|
||||
wsScope1.create();
|
||||
try
|
||||
{
|
||||
// Scope 1
|
||||
wsScope1.begin();
|
||||
BogusSession sess = new BogusSession("1");
|
||||
wsScope1.setSession(sess);
|
||||
|
||||
midLatch.countDown();
|
||||
midLatch.await(1, TimeUnit.SECONDS);
|
||||
|
||||
ScopedInstance<BogusSocket> sock1Bean = newInstance(BogusSocket.class);
|
||||
BogusSocket sock1 = sock1Bean.instance;
|
||||
assertThat("Socket 1 Session",sock1.getSession(),sameInstance((Session)sess));
|
||||
ret = sock1.getSession();
|
||||
sock1Bean.destroy();
|
||||
}
|
||||
finally
|
||||
{
|
||||
wsScope1.end();
|
||||
}
|
||||
|
||||
wsScope1.destroy();
|
||||
wsScope1Bean.destroy();
|
||||
end1Latch.countDown();
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
final CountDownLatch end2Latch = new CountDownLatch(1);
|
||||
|
||||
Callable<Session> call2 = new Callable<Session>() {
|
||||
@Override
|
||||
public Session call() throws Exception
|
||||
{
|
||||
Session ret = null;
|
||||
ScopedInstance<WebSocketScopeContext> wsScope2Bean = newInstance(WebSocketScopeContext.class);
|
||||
WebSocketScopeContext wsScope2 = wsScope2Bean.instance;
|
||||
|
||||
wsScope2.create();
|
||||
try
|
||||
{
|
||||
// Scope 2
|
||||
wsScope2.begin();
|
||||
BogusSession sess = new BogusSession("2");
|
||||
wsScope2.setSession(sess);
|
||||
ScopedInstance<BogusSocket> sock2Bean = newInstance(BogusSocket.class);
|
||||
|
||||
midLatch.countDown();
|
||||
midLatch.await(1, TimeUnit.SECONDS);
|
||||
|
||||
BogusSocket sock2 = sock2Bean.instance;
|
||||
ret = sock2.getSession();
|
||||
assertThat("Socket 2 Session",sock2.getSession(),sameInstance((Session)sess));
|
||||
sock2Bean.destroy();
|
||||
}
|
||||
finally
|
||||
{
|
||||
wsScope2.end();
|
||||
}
|
||||
|
||||
wsScope2.destroy();
|
||||
wsScope2Bean.destroy();
|
||||
end2Latch.countDown();
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
ExecutorService svc = Executors.newFixedThreadPool(4);
|
||||
Future<Session> fut1 = svc.submit(call1);
|
||||
Future<Session> fut2 = svc.submit(call2);
|
||||
|
||||
Session sess1 = fut1.get(1,TimeUnit.SECONDS);
|
||||
Session sess2 = fut2.get(1,TimeUnit.SECONDS);
|
||||
|
||||
assertThat("Sessions are different", sess1, not(sameInstance(sess2)));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static <T> ScopedInstance<T> newInstance(Class<T> clazz)
|
||||
{
|
||||
ScopedInstance sbean = new ScopedInstance();
|
||||
Set<Bean<?>> beans = container.getBeanManager().getBeans(clazz,AnyLiteral.INSTANCE);
|
||||
if (beans.size() > 0)
|
||||
{
|
||||
sbean.bean = beans.iterator().next();
|
||||
sbean.creationalContext = container.getBeanManager().createCreationalContext(sbean.bean);
|
||||
sbean.instance = container.getBeanManager().getReference(sbean.bean,clazz,sbean.creationalContext);
|
||||
return sbean;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RuntimeException(String.format("Can't find class %s",clazz));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
||||
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
|
||||
bean-discovery-mode="all">
|
||||
</beans>
|
|
@ -1,15 +0,0 @@
|
|||
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
|
||||
org.jetty.LEVEL=INFO
|
||||
org.jboss.LEVEL=INFO
|
||||
# org.eclipse.jetty.LEVEL=INFO
|
||||
|
||||
# org.eclipse.jetty.util.component.LEVEL=DEBUG
|
||||
|
||||
# org.eclipse.jetty.websocket.common.LEVEL=DEBUG
|
||||
# org.eclipse.jetty.util.DecoratedObjectFactory.LEVEL=DEBUG
|
||||
# org.eclipse.jetty.cdi.LEVEL=DEBUG
|
||||
|
||||
# org.eclipse.jetty.LEVEL=DEBUG
|
||||
# org.eclipse.jetty.websocket.LEVEL=DEBUG
|
||||
# org.eclipse.jetty.websocket.client.LEVEL=DEBUG
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
handlers = org.eclipse.jetty.util.log.JettyLogHandler
|
||||
.level=FINE
|
|
@ -6,20 +6,32 @@
|
|||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||
<artifactId>jetty-cdi-parent</artifactId>
|
||||
<name>Jetty :: CDI :: Parent</name>
|
||||
<artifactId>cdi-2</artifactId>
|
||||
<name>Jetty :: CDI 2</name>
|
||||
<url>http://www.eclipse.org/jetty</url>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>cdi-core</module>
|
||||
<module>cdi-servlet</module>
|
||||
<module>cdi-full-servlet</module>
|
||||
<module>cdi-websocket</module>
|
||||
<module>cdi-2</module>
|
||||
<module>test-cdi-webapp</module>
|
||||
<!-- needs to be fixed still
|
||||
<module>test-cdi-it</module>
|
||||
-->
|
||||
</modules>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<bundle-symbolic-name>${project.groupId}.cdi2</bundle-symbolic-name>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>config</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html
|
||||
|
||||
[description]
|
||||
Jetty setup to support Weld/CDI2 with WELD inside the webapp
|
||||
|
||||
[depend]
|
||||
cdi2
|
|
@ -1,4 +1,4 @@
|
|||
DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html
|
||||
# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html
|
||||
|
||||
[description]
|
||||
Jetty setup to support Weld/CDI2 with WELD inside the webapp
|
||||
|
@ -6,6 +6,9 @@ Jetty setup to support Weld/CDI2 with WELD inside the webapp
|
|||
[depend]
|
||||
deploy
|
||||
|
||||
[lib]
|
||||
lib/apache-jsp/org.mortbay.jasper.apache-el-*.jar
|
||||
|
||||
[xml]
|
||||
etc/cdi2/jetty-cdi2.xml
|
||||
|
|
@ -1,204 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||
<artifactId>jetty-cdi-parent</artifactId>
|
||||
<version>9.4.7-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>cdi-webapp-it</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Jetty :: CDI :: Test :: WebApp Integration Tests</name>
|
||||
<url>http://www.eclipse.org/jetty</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<bundle-symbolic-name>${project.groupId}.cdi.webapp.it</bundle-symbolic-name>
|
||||
<scripts-dir>${project.basedir}/src/test/scripts</scripts-dir>
|
||||
<test-base-dir>${project.build.directory}/test-base</test-base-dir>
|
||||
<test-home-dir>${project.build.directory}/test-home</test-home-dir>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-distribution</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>zip</type>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||
<artifactId>test-cdi-webapp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>war</type>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- DO NOT DEPLOY (or Release) -->
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-apps-for-testing</id>
|
||||
<phase>process-test-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<includeArtifactIds>test-cdi-webapp</includeArtifactIds>
|
||||
<includeScope>runtime</includeScope>
|
||||
<includeTypes>war</includeTypes>
|
||||
<overwriteSnapshots>true</overwriteSnapshots>
|
||||
<overwriteReleases>true</overwriteReleases>
|
||||
<stripVersion>true</stripVersion>
|
||||
<outputDirectory>${test-base-dir}/webapps</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>unpack-jetty-distro</id>
|
||||
<phase>process-test-resources</phase>
|
||||
<goals>
|
||||
<goal>unpack-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<includeArtifactIds>jetty-distribution</includeArtifactIds>
|
||||
<includeScope>runtime</includeScope>
|
||||
<includeTypes>zip</includeTypes>
|
||||
<outputAbsoluteArtifactFilename>true</outputAbsoluteArtifactFilename>
|
||||
<outputDirectory>${test-home-dir}</outputDirectory>
|
||||
<overWriteSnapshots>true</overWriteSnapshots>
|
||||
<overWriteIfNewer>true</overWriteIfNewer>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>start-jetty</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<target>
|
||||
<property name="jetty.cdi.home" location="${test-home-dir}/jetty-distribution-${project.version}"/>
|
||||
<property name="jetty.cdi.base" location="${test-base-dir}"/>
|
||||
<echo>Integration Test : Setup Jetty</echo>
|
||||
<exec executable="${run.command}"
|
||||
dir="${scripts-dir}"
|
||||
spawn="false">
|
||||
<arg value="${run.command.xtra}"/>
|
||||
<arg value="${setup.script}"/>
|
||||
<arg file="${java.home}"/>
|
||||
<arg file="${jetty.cdi.home}"/>
|
||||
<arg file="${jetty.cdi.base}"/>
|
||||
</exec>
|
||||
|
||||
<echo>Integration Test : Starting Jetty ...</echo>
|
||||
<exec executable="${run.command}"
|
||||
dir="${scripts-dir}"
|
||||
spawn="true">
|
||||
<arg value="${run.command.xtra}"/>
|
||||
<arg value="${start.script}"/>
|
||||
<arg file="${java.home}"/>
|
||||
<arg file="${jetty.cdi.home}"/>
|
||||
<arg file="${jetty.cdi.base}"/>
|
||||
</exec>
|
||||
<waitfor maxwait="5" maxwaitunit="second"
|
||||
checkevery="100" checkeveryunit="millisecond">
|
||||
<http url="http://localhost:58080/cdi-webapp/"/>
|
||||
</waitfor>
|
||||
<echo>Integration Test : Jetty is now available</echo>
|
||||
</target>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>stop-jetty</id>
|
||||
<phase>post-integration-test</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<target>
|
||||
<property name="jetty.cdi.home" location="${test-home-dir}/jetty-distribution-${project.version}"/>
|
||||
<property name="jetty.cdi.base" location="${test-base-dir}"/>
|
||||
<echo>Integration Test : Stop Jetty</echo>
|
||||
<exec executable="${run.command}"
|
||||
dir="${scripts-dir}"
|
||||
spawn="false">
|
||||
<arg value="${run.command.xtra}"/>
|
||||
<arg value="${stop.script}"/>
|
||||
<arg file="${java.home}"/>
|
||||
<arg file="${jetty.cdi.home}"/>
|
||||
<arg file="${jetty.cdi.base}"/>
|
||||
</exec>
|
||||
</target>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>it-windows</id>
|
||||
<activation>
|
||||
<os>
|
||||
<family>Windows</family>
|
||||
</os>
|
||||
</activation>
|
||||
<properties>
|
||||
<run.command>cmd</run.command>
|
||||
<run.command.xtra>/c</run.command.xtra>
|
||||
<start.script>start-jetty.bat</start.script>
|
||||
<stop.script>stop-jetty.bat</stop.script>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>it-unix</id>
|
||||
<activation>
|
||||
<os>
|
||||
<family>unix</family>
|
||||
</os>
|
||||
</activation>
|
||||
<properties>
|
||||
<run.command>sh</run.command>
|
||||
<run.command.xtra>--</run.command.xtra>
|
||||
<setup.script>setup-jetty.sh</setup.script>
|
||||
<start.script>start-jetty.sh</start.script>
|
||||
<stop.script>stop-jetty.sh</stop.script>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
|
@ -1,41 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.tests;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.SimpleRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Basic tests for a simple @WebServlet with no CDI
|
||||
*/
|
||||
public class HelloIT
|
||||
{
|
||||
@Test
|
||||
public void testBasic() throws Exception
|
||||
{
|
||||
URI serverURI = new URI("http://localhost:58080/cdi-webapp/");
|
||||
SimpleRequest req = new SimpleRequest(serverURI);
|
||||
assertThat(req.getString("hello"),is("Hello World" + System.lineSeparator()));
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.tests;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.SimpleRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ServerInfoIT
|
||||
{
|
||||
@Test
|
||||
public void testGET() throws Exception {
|
||||
URI serverURI = new URI("http://localhost:58080/cdi-webapp/");
|
||||
SimpleRequest req = new SimpleRequest(serverURI);
|
||||
|
||||
// Typical response:
|
||||
// context = ServletContext@o.e.j.w.WebAppContext@37cb63fd{/cdi-webapp,
|
||||
// file:///tmp/jetty-0.0.0.0-58080-cdi-webapp.war-_cdi-webapp-any-417759194514596377.dir/webapp/,AVAILABLE}
|
||||
// {/cdi-webapp.war}\ncontext.contextPath = /cdi-webapp\ncontext.effective-version = 3.1\n
|
||||
assertThat(req.getString("serverinfo"),
|
||||
allOf(
|
||||
containsString("context = ServletContext@"),
|
||||
containsString("context.contextPath = /cdi-webapp"),
|
||||
containsString("context.effective-version = 3.1")
|
||||
));
|
||||
}
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.tests.ws;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.websocket.ClientEndpoint;
|
||||
import javax.websocket.CloseReason;
|
||||
import javax.websocket.ContainerProvider;
|
||||
import javax.websocket.OnClose;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.WebSocketContainer;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.EventQueue;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class SessionInfoIT
|
||||
{
|
||||
@ClientEndpoint
|
||||
public static class ClientSessionInfoSocket
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(SessionInfoIT.ClientSessionInfoSocket.class);
|
||||
|
||||
public CountDownLatch openLatch = new CountDownLatch(1);
|
||||
public CountDownLatch closeLatch = new CountDownLatch(1);
|
||||
public Session session;
|
||||
public EventQueue<String> messages = new EventQueue<>();
|
||||
public CloseReason closeReason;
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session)
|
||||
{
|
||||
LOG.info("onOpen(): {}", session);
|
||||
this.session = session;
|
||||
this.openLatch.countDown();
|
||||
}
|
||||
|
||||
@OnClose
|
||||
public void onClose(CloseReason close)
|
||||
{
|
||||
LOG.info("onClose(): {}", close);
|
||||
this.session = null;
|
||||
this.closeReason = close;
|
||||
this.closeLatch.countDown();
|
||||
}
|
||||
|
||||
@OnMessage
|
||||
public void onMessage(String message)
|
||||
{
|
||||
LOG.info("onMessage(): {}", message);
|
||||
this.messages.offer(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionInfo() throws Exception
|
||||
{
|
||||
URI serverURI = new URI("ws://localhost:58080/cdi-webapp/");
|
||||
|
||||
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
|
||||
|
||||
ClientSessionInfoSocket socket = new ClientSessionInfoSocket();
|
||||
|
||||
container.connectToServer(socket,serverURI.resolve("sessioninfo"));
|
||||
|
||||
assertThat("Await open", socket.openLatch.await(1,TimeUnit.SECONDS), is(true));
|
||||
|
||||
socket.session.getBasicRemote().sendText("info");
|
||||
socket.messages.awaitEventCount(1,2,TimeUnit.SECONDS);
|
||||
|
||||
System.out.printf("socket.messages.size = %s%n",socket.messages.size());
|
||||
|
||||
String msg = socket.messages.poll();
|
||||
System.out.printf("Message is [%s]%n",msg);
|
||||
|
||||
assertThat("Message", msg, containsString("HttpSession = HttpSession"));
|
||||
|
||||
socket.session.getBasicRemote().sendText("close");
|
||||
assertThat("Await close", socket.closeLatch.await(1,TimeUnit.SECONDS),is(true));
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
|
||||
# org.jboss.LEVEL=DEBUG
|
||||
org.eclipse.jetty.LEVEL=INFO
|
||||
|
||||
# org.eclipse.jetty.util.DecoratedObjectFactory.LEVEL=DEBUG
|
||||
|
||||
# org.eclipse.jetty.LEVEL=DEBUG
|
||||
# org.eclipse.jetty.websocket.LEVEL=DEBUG
|
||||
# org.eclipse.jetty.websocket.client.LEVEL=DEBUG
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
JAVA_HOME=$1
|
||||
JETTY_HOME=$2
|
||||
JETTY_BASE=$3
|
||||
|
||||
echo \${java.home} : $JAVA_HOME
|
||||
echo \${jetty.home} : $JETTY_HOME
|
||||
echo \${jetty.base} : $JETTY_BASE
|
||||
|
||||
cd "$JETTY_BASE"
|
||||
|
||||
"$JAVA_HOME/bin/java" -jar "$JETTY_HOME/start.jar" \
|
||||
--approve-all-licenses \
|
||||
--add-to-start=deploy,http,annotations,websocket,cdi,logging
|
||||
|
||||
"$JAVA_HOME/bin/java" -jar "$JETTY_HOME/start.jar" \
|
||||
--version
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
JAVA_HOME=$1
|
||||
JETTY_HOME=$2
|
||||
JETTY_BASE=$3
|
||||
|
||||
echo \${java.home} : $JAVA_HOME
|
||||
echo \${jetty.home} : $JETTY_HOME
|
||||
echo \${jetty.base} : $JETTY_BASE
|
||||
|
||||
cd "$JETTY_BASE"
|
||||
|
||||
"$JAVA_HOME/bin/java" -jar "$JETTY_HOME/start.jar" \
|
||||
jetty.http.port=58080 \
|
||||
STOP.PORT=58181 STOP.KEY=it
|
||||
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
JAVA_HOME=$1
|
||||
JETTY_HOME=$2
|
||||
JETTY_BASE=$3
|
||||
|
||||
cd "$JETTY_BASE"
|
||||
"$JAVA_HOME/bin/java" -jar "$JETTY_HOME/start.jar" \
|
||||
--stop STOP.PORT=58181 STOP.KEY=it
|
||||
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||
<artifactId>jetty-cdi-parent</artifactId>
|
||||
<version>9.4.20-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>test-cdi-webapp</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<name>Jetty :: CDI :: Test :: WebApp</name>
|
||||
<url>http://www.eclipse.org/jetty</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<bundle-symbolic-name>${project.groupId}.cdi.webapp.noweld</bundle-symbolic-name>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.websocket</groupId>
|
||||
<artifactId>javax.websocket-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.enterprise</groupId>
|
||||
<artifactId>cdi-api</artifactId>
|
||||
<version>1.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.weld.servlet</groupId>
|
||||
<artifactId>weld-servlet</artifactId>
|
||||
<version>${weld.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>cdi-webapp</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- DO NOT DEPLOY (or Release) -->
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>with-weld</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>src/assembly/with-weld.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<configuration>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||
<artifactId>cdi-full-servlet</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -1,31 +0,0 @@
|
|||
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
|
||||
<id>with-weld</id>
|
||||
<formats>
|
||||
<format>war</format>
|
||||
</formats>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>${project.basedir}/src/main/webapp</directory>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>${project.build.outputDirectory}</directory>
|
||||
<outputDirectory>/WEB-INF/classes</outputDirectory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
<dependencySets>
|
||||
<dependencySet>
|
||||
<outputDirectory>/WEB-INF/lib</outputDirectory>
|
||||
<useProjectArtifact>true</useProjectArtifact>
|
||||
<unpack>false</unpack>
|
||||
<scope>test</scope>
|
||||
<includes>
|
||||
<include>*:cdi-api</include>
|
||||
<include>*:weld-servlet</include>
|
||||
</includes>
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
</assembly>
|
|
@ -1,47 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.tests.logging;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class JULog
|
||||
{
|
||||
private final Logger log;
|
||||
|
||||
public JULog(Class<?> clazz)
|
||||
{
|
||||
this.log = Logger.getLogger(clazz.getName());
|
||||
}
|
||||
|
||||
public void info(String msg)
|
||||
{
|
||||
log.log(Level.INFO, msg);
|
||||
}
|
||||
|
||||
public void info(String msg, Object ... args)
|
||||
{
|
||||
log.log(Level.INFO, msg, args);
|
||||
}
|
||||
|
||||
public void warn(Throwable t)
|
||||
{
|
||||
log.log(Level.WARNING, "", t);
|
||||
}
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.tests.ws;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.RemoteEndpoint;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
import org.eclipse.jetty.tests.logging.JULog;
|
||||
|
||||
@ServerEndpoint(value = "/sessioninfo")
|
||||
public class SessionInfoSocket
|
||||
{
|
||||
@Inject
|
||||
private JULog LOG;
|
||||
|
||||
@Inject
|
||||
private HttpSession httpSession;
|
||||
|
||||
private Session wsSession;
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session)
|
||||
{
|
||||
LOG.info("onOpen({0})",asClassId(session));
|
||||
this.wsSession = session;
|
||||
}
|
||||
|
||||
@OnMessage
|
||||
public void onMessage(String message)
|
||||
{
|
||||
LOG.info("onMessage({0})",quoted(message));
|
||||
|
||||
try
|
||||
{
|
||||
RemoteEndpoint.Basic remote = wsSession.getBasicRemote();
|
||||
LOG.info("Remote.Basic: {0}", remote);
|
||||
|
||||
if ("info".equalsIgnoreCase(message))
|
||||
{
|
||||
LOG.info("returning 'info' details");
|
||||
remote.sendText("HttpSession = " + httpSession);
|
||||
}
|
||||
else if ("close".equalsIgnoreCase(message))
|
||||
{
|
||||
LOG.info("closing session");
|
||||
wsSession.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG.info("echoing message as-is");
|
||||
remote.sendText(message);
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
LOG.warn(t);
|
||||
}
|
||||
}
|
||||
|
||||
private String asClassId(Object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return "<null>";
|
||||
}
|
||||
return String.format("%s@%X",obj.getClass().getName(),obj.hashCode());
|
||||
}
|
||||
|
||||
private String quoted(String str)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return "<null>";
|
||||
}
|
||||
return '"' + str + '"';
|
||||
}
|
||||
}
|
|
@ -56,19 +56,6 @@ Modules for tag '*':
|
|||
LIB: lib/apache-jstl/*.jar
|
||||
Enabled: transitive provider of apache-jstl for jstl
|
||||
|
||||
Module: cdi
|
||||
: Experimental CDI/Weld integration
|
||||
Depend: cdi1
|
||||
|
||||
Module: cdi1
|
||||
: Experimental CDI/Weld integration
|
||||
: Deprecated in favour of cdi2 module.
|
||||
Depend: deploy, annotations, plus, jsp
|
||||
LIB: lib/cdi/*.jar
|
||||
LIB: lib/cdi-core-${jetty.version}.jar
|
||||
LIB: lib/cdi-servlet-${jetty.version}.jar
|
||||
XML: etc/jetty-cdi.xml
|
||||
|
||||
Module: cdi2
|
||||
: Jetty setup to support Weld/CDI2 with WELD inside the webapp
|
||||
Depend: deploy
|
||||
|
|
|
@ -672,11 +672,6 @@
|
|||
<artifactId>jetty-spring</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||
<artifactId>cdi-servlet</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.logging</groupId>
|
||||
<artifactId>jboss-logging</artifactId>
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.eclipse.jetty.rewrite.handler;
|
|||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -179,6 +178,7 @@ public class RewriteHandler extends HandlerWrapper
|
|||
public RewriteHandler()
|
||||
{
|
||||
_rules = new RuleContainer();
|
||||
addBean(_rules);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -219,6 +219,7 @@ public class RewriteHandler extends HandlerWrapper
|
|||
*/
|
||||
public void setRuleContainer(RuleContainer rules)
|
||||
{
|
||||
updateBean(_rules, rules);
|
||||
_rules = rules;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
package org.eclipse.jetty.rewrite.handler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.util.ArrayUtil;
|
||||
import org.eclipse.jetty.util.URIUtil;
|
||||
import org.eclipse.jetty.util.component.Dumpable;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
|
@ -33,7 +33,7 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
* Base container to group rules. Can be extended so that the contained rules
|
||||
* will only be applied under certain conditions
|
||||
*/
|
||||
public class RuleContainer extends Rule
|
||||
public class RuleContainer extends Rule implements Dumpable
|
||||
{
|
||||
public static final String ORIGINAL_QUERYSTRING_ATTRIBUTE_SUFFIX = ".QUERYSTRING";
|
||||
private static final Logger LOG = Log.getLogger(RuleContainer.class);
|
||||
|
@ -214,4 +214,10 @@ public class RuleContainer extends Rule
|
|||
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dump(Appendable out, String indent) throws IOException
|
||||
{
|
||||
Dumpable.dumpObjects(out, indent, this, _rules);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,6 +75,13 @@
|
|||
<type>war</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-cdi2-webapp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>war</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
|
|
|
@ -191,15 +191,17 @@ public class DistributionTester
|
|||
*
|
||||
* @param warFile the war file to install
|
||||
* @param context the context path
|
||||
* @return the path to the installed webapp exploded directory
|
||||
* @throws IOException if the installation fails
|
||||
*/
|
||||
public void installWarFile(File warFile, String context) throws IOException
|
||||
public Path installWarFile(File warFile, String context) throws IOException
|
||||
{
|
||||
//webapps
|
||||
Path webapps = config.jettyBase.resolve("webapps").resolve(context);
|
||||
if (!Files.exists(webapps))
|
||||
Files.createDirectories(webapps);
|
||||
unzip(warFile, webapps.toFile());
|
||||
return webapps;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,144 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 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.tests.distribution;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class CDITests extends AbstractDistributionTest
|
||||
{
|
||||
/**
|
||||
* Tests a WAR file that is CDI complete as it includes the weld
|
||||
* library in its WEB-INF/lib directory.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testCDI2_IncludedInWebapp() throws Exception
|
||||
{
|
||||
String jettyVersion = System.getProperty("jettyVersion");
|
||||
DistributionTester distribution = DistributionTester.Builder.newInstance()
|
||||
.jettyVersion(jettyVersion)
|
||||
.mavenLocalRepository(System.getProperty("mavenRepoPath"))
|
||||
.build();
|
||||
|
||||
String[] args1 = {
|
||||
"--create-startd",
|
||||
"--approve-all-licenses",
|
||||
"--add-to-start=http,deploy,annotations,jsp"
|
||||
};
|
||||
try (DistributionTester.Run run1 = distribution.start(args1))
|
||||
{
|
||||
assertTrue(run1.awaitFor(5, TimeUnit.SECONDS));
|
||||
assertEquals(0, run1.getExitValue());
|
||||
|
||||
File war = distribution.resolveArtifact("org.eclipse.jetty.tests:test-cdi2-webapp:war:" + jettyVersion);
|
||||
distribution.installWarFile(war, "demo");
|
||||
|
||||
distribution.installBaseResource("cdi/demo_context.xml", "webapps/demo.xml");
|
||||
|
||||
int port = distribution.freePort();
|
||||
try (DistributionTester.Run run2 = distribution.start("jetty.http.port=" + port))
|
||||
{
|
||||
assertTrue(run2.awaitConsoleLogsFor("Started @", 10, TimeUnit.SECONDS));
|
||||
|
||||
startHttpClient();
|
||||
ContentResponse response = client.GET("http://localhost:" + port + "/demo/greetings");
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
// Confirm Servlet based CDI
|
||||
assertThat(response.getContentAsString(), containsString("Hello GreetingsServlet"));
|
||||
// Confirm Listener based CDI (this has been a problem in the past, keep this for regression testing!)
|
||||
assertThat(response.getHeaders().get("Server"), containsString("CDI-Demo-org.eclipse.jetty.test"));
|
||||
|
||||
run2.stop();
|
||||
assertTrue(run2.awaitFor(5, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a WAR file that is expects CDI to be configured by the server.
|
||||
*
|
||||
* <p>
|
||||
* This means the WAR has the weld libs in its
|
||||
* WEB-INF/lib directory.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The expectation is that a context xml deployable file is not
|
||||
* required when using this `cdi2` module, and the appropriate
|
||||
* server side libs are made available to allow weld to function.
|
||||
* (the required server side javax.el support comes from the cdi2 module)
|
||||
* </p>
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testCDI2_ConfiguredByServer() throws Exception
|
||||
{
|
||||
String jettyVersion = System.getProperty("jettyVersion");
|
||||
DistributionTester distribution = DistributionTester.Builder.newInstance()
|
||||
.jettyVersion(jettyVersion)
|
||||
.mavenLocalRepository(System.getProperty("mavenRepoPath"))
|
||||
.build();
|
||||
|
||||
String[] args1 = {
|
||||
"--create-startd",
|
||||
"--approve-all-licenses",
|
||||
// standard entries
|
||||
"--add-to-start=http,deploy,annotations",
|
||||
// cdi2 specific entry (should transitively pull in what it needs, the user should not be expected to know the transitive entries)
|
||||
"--add-to-start=cdi2"
|
||||
};
|
||||
try (DistributionTester.Run run1 = distribution.start(args1))
|
||||
{
|
||||
assertTrue(run1.awaitFor(5, TimeUnit.SECONDS));
|
||||
assertEquals(0, run1.getExitValue());
|
||||
|
||||
File war = distribution.resolveArtifact("org.eclipse.jetty.tests:test-cdi2-webapp:war:" + jettyVersion);
|
||||
distribution.installWarFile(war, "demo");
|
||||
|
||||
int port = distribution.freePort();
|
||||
try (DistributionTester.Run run2 = distribution.start("jetty.http.port=" + port))
|
||||
{
|
||||
assertTrue(run2.awaitConsoleLogsFor("Started @", 10, TimeUnit.SECONDS));
|
||||
|
||||
startHttpClient();
|
||||
ContentResponse response = client.GET("http://localhost:" + port + "/demo/greetings");
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
// Confirm Servlet based CDI
|
||||
assertThat(response.getContentAsString(), containsString("Hello GreetingsServlet"));
|
||||
// Confirm Listener based CDI (this has been a problem in the past, keep this for regression testing!)
|
||||
assertThat(response.getHeaders().get("Server"), containsString("CDI-Demo-org.eclipse.jetty.test"));
|
||||
|
||||
run2.stop();
|
||||
assertTrue(run2.awaitFor(5, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
|
||||
|
||||
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
|
||||
<Set name="contextPath">/demo</Set>
|
||||
<Set name="war"><Property name="jetty.webapps"/>/demo/</Set>
|
||||
<Get name="serverClasspathPattern">
|
||||
<Call name="add">
|
||||
<Arg>-org.eclipse.jetty.util.Decorator</Arg>
|
||||
</Call>
|
||||
<Call name="add">
|
||||
<Arg>-org.eclipse.jetty.util.DecoratedObjectFactory</Arg>
|
||||
</Call>
|
||||
<Call name="add">
|
||||
<Arg>-org.eclipse.jetty.server.handler.ContextHandler.</Arg>
|
||||
</Call>
|
||||
<Call name="add">
|
||||
<Arg>-org.eclipse.jetty.server.handler.ContextHandler</Arg>
|
||||
</Call>
|
||||
<Call name="add">
|
||||
<Arg>-org.eclipse.jetty.servlet.ServletContextHandler</Arg>
|
||||
</Call>
|
||||
</Get>
|
||||
</Configure>
|
|
@ -41,5 +41,6 @@
|
|||
<module>test-http2-webapp</module>
|
||||
<module>test-simple-webapp</module>
|
||||
<module>test-felix-webapp</module>
|
||||
<module>test-cdi2-webapp</module>
|
||||
</modules>
|
||||
</project>
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-webapps-parent</artifactId>
|
||||
<version>9.4.20-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>test-cdi2-webapp</artifactId>
|
||||
<name>Test :: CDI2 On Jetty :: Included in WebApp</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<properties>
|
||||
<bundle-symbolic-name>${project.groupId}.cdi2.webapp</bundle-symbolic-name>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<finalName>cdi2-demo</finalName>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- provided by container -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- included in webapp -->
|
||||
<dependency>
|
||||
<groupId>org.jboss.weld.servlet</groupId>
|
||||
<artifactId>weld-servlet</artifactId>
|
||||
<version>${weld.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -16,16 +16,18 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.tests.logging;
|
||||
package org.eclipse.jetty.test;
|
||||
|
||||
import javax.enterprise.inject.Produces;
|
||||
import javax.enterprise.inject.spi.InjectionPoint;
|
||||
import javax.inject.Named;
|
||||
|
||||
public class JULogFactory
|
||||
public class FriendlyGreetings
|
||||
{
|
||||
@Produces
|
||||
public JULog createJULog(InjectionPoint injectionPoint)
|
||||
@Named("friendly")
|
||||
public Greetings getGreetings(InjectionPoint ip)
|
||||
{
|
||||
return new JULog(injectionPoint.getMember().getDeclaringClass());
|
||||
return () -> "Hello " + ip.getMember().getDeclaringClass().getSimpleName();
|
||||
}
|
||||
}
|
|
@ -16,11 +16,9 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.cdi.servlet;
|
||||
package org.eclipse.jetty.test;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
public interface TimeFormatter
|
||||
public interface Greetings
|
||||
{
|
||||
public String format(Calendar cal);
|
||||
String getGreeting();
|
||||
}
|
|
@ -16,27 +16,27 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.tests;
|
||||
package org.eclipse.jetty.test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* The most basic servlet here, no CDI use.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
@WebServlet("/hello")
|
||||
public class HelloServlet extends HttpServlet
|
||||
@WebServlet("/greetings")
|
||||
public class GreetingsServlet extends HttpServlet
|
||||
{
|
||||
@Inject
|
||||
@Named("friendly")
|
||||
public Greetings greetings;
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
|
||||
{
|
||||
resp.setContentType("text/plain");
|
||||
resp.getWriter().println("Hello World");
|
||||
resp.getWriter().println("[" + greetings.getGreeting() + "]");
|
||||
}
|
||||
}
|
|
@ -16,39 +16,37 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.tests;
|
||||
package org.eclipse.jetty.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import java.util.Set;
|
||||
import javax.enterprise.inject.spi.Bean;
|
||||
import javax.enterprise.inject.spi.BeanManager;
|
||||
import javax.inject.Inject;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@WebServlet("/serverinfo")
|
||||
public class ServerInfoServlet extends HttpServlet
|
||||
@WebServlet("/info")
|
||||
public class InfoServlet extends HttpServlet
|
||||
{
|
||||
@Inject
|
||||
private ServletContext context;
|
||||
BeanManager beanManager;
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
|
||||
{
|
||||
resp.setContentType("text/plain");
|
||||
resp.setCharacterEncoding("utf-8");
|
||||
|
||||
PrintWriter out = resp.getWriter();
|
||||
if (context == null)
|
||||
out.println("Bean Manager: " + beanManager);
|
||||
Set<Bean<?>> beans = beanManager.getBeans("");
|
||||
for (Bean<?> bean : beans)
|
||||
{
|
||||
out.println("context = null");
|
||||
return;
|
||||
out.println(" " + bean);
|
||||
}
|
||||
out.printf("context = %s%n",context);
|
||||
out.printf("context.contextPath = %s%n",context.getContextPath());
|
||||
out.printf("context.effective-version = %d.%d%n",context.getEffectiveMajorVersion(),context.getEffectiveMinorVersion());
|
||||
}
|
||||
}
|
|
@ -16,22 +16,23 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.cdi.core;
|
||||
package org.eclipse.jetty.test;
|
||||
|
||||
import javax.enterprise.inject.Produces;
|
||||
import javax.enterprise.inject.spi.InjectionPoint;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
/**
|
||||
* CDI Producer of Jetty Logging instances.
|
||||
*/
|
||||
public class JettyLogFactory
|
||||
public class ManifestServerID
|
||||
{
|
||||
@Produces
|
||||
public Logger createLogger(InjectionPoint injectionPoint)
|
||||
public ServerID getServerID()
|
||||
{
|
||||
return Log.getLogger(injectionPoint.getMember().getDeclaringClass());
|
||||
return () ->
|
||||
{
|
||||
String implVersion = this.getClass().getPackage().getImplementationVersion();
|
||||
if(implVersion == null)
|
||||
implVersion = this.getClass().getPackage().getName();
|
||||
if(implVersion == null)
|
||||
implVersion = "unknown";
|
||||
return "CDI-Demo-" + implVersion;
|
||||
};
|
||||
}
|
||||
}
|
|
@ -16,25 +16,27 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.cdi.websocket.basicscope;
|
||||
package org.eclipse.jetty.test;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.servlet.annotation.WebListener;
|
||||
|
||||
public class Meal
|
||||
@WebListener
|
||||
public class MyContextListener implements ServletContextListener
|
||||
{
|
||||
@Inject
|
||||
private Food entree;
|
||||
public ServerID serverId;
|
||||
|
||||
@Inject
|
||||
private Food side;
|
||||
|
||||
public Food getEntree()
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce)
|
||||
{
|
||||
return entree;
|
||||
sce.getServletContext().setAttribute("ServerID", serverId.get());
|
||||
}
|
||||
|
||||
public Food getSide()
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce)
|
||||
{
|
||||
return side;
|
||||
}
|
||||
}
|
|
@ -16,13 +16,17 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.cdi.core;
|
||||
package org.eclipse.jetty.test;
|
||||
|
||||
import javax.enterprise.inject.Any;
|
||||
import javax.enterprise.util.AnnotationLiteral;
|
||||
import javax.enterprise.inject.Produces;
|
||||
import javax.inject.Named;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class AnyLiteral extends AnnotationLiteral<Any>
|
||||
public class OldGreetings
|
||||
{
|
||||
public static final AnyLiteral INSTANCE = new AnyLiteral();
|
||||
@Produces
|
||||
@Named("old")
|
||||
public Greetings getGreeting()
|
||||
{
|
||||
return () -> "Salutations!";
|
||||
}
|
||||
}
|
|
@ -16,12 +16,9 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.cdi.servlet;
|
||||
package org.eclipse.jetty.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public interface Dumper
|
||||
public interface ServerID
|
||||
{
|
||||
public void dump(PrintWriter out) throws IOException;
|
||||
String get();
|
||||
}
|
|
@ -16,44 +16,42 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.cdi.servlet;
|
||||
package org.eclipse.jetty.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Calendar;
|
||||
|
||||
import javax.enterprise.inject.Any;
|
||||
import javax.enterprise.inject.Instance;
|
||||
import javax.inject.Inject;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.annotation.WebFilter;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.cdi.core.NamedLiteral;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@WebServlet(urlPatterns = "/time")
|
||||
public class TimeServlet extends HttpServlet
|
||||
/**
|
||||
* A Web Filter that doesn't use CDI.
|
||||
*/
|
||||
@WebFilter("/*")
|
||||
public class ServerIDFilter implements Filter
|
||||
{
|
||||
@Inject
|
||||
@Any
|
||||
Instance<TimeFormatter> formatters;
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
|
||||
{
|
||||
resp.setContentType("text/plain");
|
||||
|
||||
String timeType = req.getParameter("type");
|
||||
TimeFormatter time = LocaleTimeFormatter.INSTANCE;
|
||||
|
||||
Instance<TimeFormatter> inst = formatters.select(new NamedLiteral(timeType));
|
||||
if (!inst.isAmbiguous() && !inst.isUnsatisfied())
|
||||
if (response instanceof HttpServletResponse)
|
||||
{
|
||||
time = inst.get();
|
||||
String serverID = (String)request.getServletContext().getAttribute("ServerID");
|
||||
((HttpServletResponse)response).setHeader("Server", serverID);
|
||||
}
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
resp.getWriter().println(time.format(Calendar.getInstance()));
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<beans
|
||||
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://xmlns.jcp.org/xml/ns/javaee
|
||||
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
|
||||
bean-discovery-mode="all">
|
||||
</beans>
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
|
||||
|
||||
<Configure id="webAppCtx" class="org.eclipse.jetty.webapp.WebAppContext">
|
||||
<New id="BeanManager" class="org.eclipse.jetty.plus.jndi.Resource">
|
||||
<Arg>
|
||||
<Ref refid="webAppCtx"/>
|
||||
</Arg>
|
||||
<Arg>BeanManager</Arg>
|
||||
<Arg>
|
||||
<New class="javax.naming.Reference">
|
||||
<Arg>javax.enterprise.inject.spi.BeanManager</Arg>
|
||||
<Arg>org.jboss.weld.resources.ManagerObjectFactory</Arg>
|
||||
<Arg/>
|
||||
</New>
|
||||
</Arg>
|
||||
</New>
|
||||
</Configure>
|
|
@ -8,11 +8,10 @@
|
|||
<listener>
|
||||
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
|
||||
</listener>
|
||||
|
||||
|
||||
<resource-env-ref>
|
||||
<description>Object factory for the CDI Bean Manager</description>
|
||||
<resource-env-ref-name>BeanManager</resource-env-ref-name>
|
||||
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
|
||||
</resource-env-ref>
|
||||
|
||||
</web-app>
|
Loading…
Reference in New Issue