Merge branch `jetty-9.4.x` into `jetty-10.0.x`
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
commit
c7b6110267
|
@ -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>10.0.0-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>
|
|
|
@ -6,12 +6,32 @@
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.eclipse.jetty.cdi</groupId>
|
<groupId>org.eclipse.jetty.cdi</groupId>
|
||||||
<artifactId>jetty-cdi-parent</artifactId>
|
<artifactId>cdi-2</artifactId>
|
||||||
<name>Jetty :: CDI :: Parent</name>
|
<name>Jetty :: CDI 2</name>
|
||||||
<url>http://www.eclipse.org/jetty</url>
|
<url>http://www.eclipse.org/jetty</url>
|
||||||
<packaging>pom</packaging>
|
<packaging>jar</packaging>
|
||||||
|
<properties>
|
||||||
<modules>
|
<bundle-symbolic-name>${project.groupId}.cdi2</bundle-symbolic-name>
|
||||||
<module>cdi-2</module>
|
</properties>
|
||||||
</modules>
|
<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>
|
</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]
|
[description]
|
||||||
Jetty setup to support Weld/CDI2 with WELD inside the webapp
|
Jetty setup to support Weld/CDI2 with WELD inside the webapp
|
||||||
|
@ -6,6 +6,11 @@ Jetty setup to support Weld/CDI2 with WELD inside the webapp
|
||||||
[depend]
|
[depend]
|
||||||
annotations
|
annotations
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
lib/apache-jsp/org.mortbay.jasper.apache-el-*.jar
|
||||||
|
|
||||||
|
[xml]
|
||||||
|
etc/cdi2/jetty-cdi2.xml
|
||||||
|
|
||||||
[ini]
|
[ini]
|
||||||
jetty.webapp.addServerClasses+=,-org.eclipse.jetty.util.Decorator,-org.eclipse.jetty.util.DecoratedObjectFactory
|
jetty.webapp.addServerClasses+=,-org.eclipse.jetty.util.Decorator,-org.eclipse.jetty.util.DecoratedObjectFactory
|
|
@ -56,19 +56,6 @@ Modules for tag '*':
|
||||||
LIB: lib/apache-jstl/*.jar
|
LIB: lib/apache-jstl/*.jar
|
||||||
Enabled: transitive provider of apache-jstl for jstl
|
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
|
Module: cdi2
|
||||||
: Jetty setup to support Weld/CDI2 with WELD inside the webapp
|
: Jetty setup to support Weld/CDI2 with WELD inside the webapp
|
||||||
Depend: deploy
|
Depend: deploy
|
||||||
|
|
|
@ -163,7 +163,7 @@ public class IncludeExcludeSet<T,P> implements Predicate<P>
|
||||||
/**
|
/**
|
||||||
* Test Included and not Excluded
|
* Test Included and not Excluded
|
||||||
* @param item The item to test
|
* @param item The item to test
|
||||||
* @return Boolean.TRUE if item is included, Boolean.FALSE if item is excluded and null if neither
|
* @return Boolean.TRUE if item is included, Boolean.FALSE if item is excluded or null if neither
|
||||||
*/
|
*/
|
||||||
public Boolean isIncludedAndNotExcluded(P item)
|
public Boolean isIncludedAndNotExcluded(P item)
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,23 +19,35 @@
|
||||||
package org.eclipse.jetty.util;
|
package org.eclipse.jetty.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.invoke.MethodHandle;
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
|
import java.lang.invoke.MethodType;
|
||||||
|
import java.lang.module.Configuration;
|
||||||
|
import java.lang.module.ModuleReference;
|
||||||
|
import java.lang.module.ResolvedModule;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.security.AccessController;
|
||||||
import java.security.CodeSource;
|
import java.security.CodeSource;
|
||||||
|
import java.security.PrivilegedAction;
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
|
||||||
|
import static java.lang.invoke.MethodType.methodType;
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
|
@ -171,6 +183,29 @@ public class TypeUtil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final MethodHandle[] LOCATION_METHODS;
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
List<MethodHandle> locationMethods = new ArrayList<>();
|
||||||
|
|
||||||
|
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||||
|
MethodType type = methodType(URI.class, Class.class);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
locationMethods.add(lookup.findStatic(TypeUtil.class, "getCodeSourceLocation", type));
|
||||||
|
locationMethods.add(lookup.findStatic(TypeUtil.class, "getModuleLocation", type));
|
||||||
|
locationMethods.add(lookup.findStatic(TypeUtil.class, "getClassLoaderLocation", type));
|
||||||
|
locationMethods.add(lookup.findStatic(TypeUtil.class, "getSystemClassLoaderLocation", type));
|
||||||
|
LOCATION_METHODS = locationMethods.toArray(new MethodHandle[0]);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException("Unable to establish Location Lookup Handles", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/** Array to List.
|
/** Array to List.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -564,11 +599,89 @@ public class TypeUtil
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to find the Location of a loaded Class.
|
||||||
|
* <p>
|
||||||
|
* This can be null for primitives, void, and in-memory classes.
|
||||||
|
* </p>
|
||||||
|
* @param clazz the loaded class to find a location for.
|
||||||
|
* @return the location as a URI (this is a URI pointing to a holder of the class: a directory,
|
||||||
|
* a jar file, a {@code jrt://} resource, etc), or null of no location available.
|
||||||
|
*/
|
||||||
public static URI getLocationOfClass(Class<?> clazz)
|
public static URI getLocationOfClass(Class<?> clazz)
|
||||||
|
{
|
||||||
|
URI location;
|
||||||
|
|
||||||
|
for (MethodHandle locationMethod : LOCATION_METHODS)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ProtectionDomain domain = clazz.getProtectionDomain();
|
location = (URI)locationMethod.invoke(clazz);
|
||||||
|
if (location != null)
|
||||||
|
{
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Throwable cause)
|
||||||
|
{
|
||||||
|
cause.printStackTrace(System.err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static URI getClassLoaderLocation(Class<?> clazz)
|
||||||
|
{
|
||||||
|
return getClassLoaderLocation(clazz, clazz.getClassLoader());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static URI getSystemClassLoaderLocation(Class<?> clazz)
|
||||||
|
{
|
||||||
|
return getClassLoaderLocation(clazz, ClassLoader.getSystemClassLoader());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static URI getClassLoaderLocation(Class<?> clazz, ClassLoader loader)
|
||||||
|
{
|
||||||
|
if (loader == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String resourceName = TypeUtil.toClassReference(clazz);
|
||||||
|
if (loader != null)
|
||||||
|
{
|
||||||
|
URL url = loader.getResource(resourceName);
|
||||||
|
if (url != null)
|
||||||
|
{
|
||||||
|
URI uri = url.toURI();
|
||||||
|
String uriStr = uri.toASCIIString();
|
||||||
|
if(uriStr.startsWith("jar:file:"))
|
||||||
|
{
|
||||||
|
uriStr = uriStr.substring(4);
|
||||||
|
int idx = uriStr.indexOf("!/");
|
||||||
|
if (idx > 0)
|
||||||
|
{
|
||||||
|
return URI.create(uriStr.substring(0, idx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (URISyntaxException ignore)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static URI getCodeSourceLocation(Class<?> clazz)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ProtectionDomain domain = AccessController.doPrivileged((PrivilegedAction<ProtectionDomain>)() -> clazz.getProtectionDomain());
|
||||||
if (domain != null)
|
if (domain != null)
|
||||||
{
|
{
|
||||||
CodeSource source = domain.getCodeSource();
|
CodeSource source = domain.getCodeSource();
|
||||||
|
@ -577,22 +690,56 @@ public class TypeUtil
|
||||||
URL location = source.getLocation();
|
URL location = source.getLocation();
|
||||||
|
|
||||||
if (location != null)
|
if (location != null)
|
||||||
|
{
|
||||||
return location.toURI();
|
return location.toURI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (URISyntaxException ignore)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
String resourceName = TypeUtil.toClassReference(clazz);
|
public static URI getModuleLocation(Class<?> clazz)
|
||||||
ClassLoader loader = clazz.getClassLoader();
|
|
||||||
URL url = (loader == null ? ClassLoader.getSystemClassLoader() : loader).getResource(resourceName);
|
|
||||||
if (url != null)
|
|
||||||
{
|
{
|
||||||
return URIUtil.getJarSource(url.toURI());
|
Module module = clazz.getModule();
|
||||||
}
|
if (module == null)
|
||||||
}
|
|
||||||
catch (URISyntaxException e)
|
|
||||||
{
|
{
|
||||||
LOG.debug(e);
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ModuleLayer layer = module.getLayer();
|
||||||
|
if (layer == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Configuration configuration = layer.configuration();
|
||||||
|
if (configuration == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<ResolvedModule> resolvedModule = configuration.findModule(module.getName());
|
||||||
|
if ((resolvedModule == null) || !resolvedModule.isPresent())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ModuleReference moduleReference = resolvedModule.get().reference();
|
||||||
|
if (moduleReference == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<URI> location = moduleReference.location();
|
||||||
|
if (location.isPresent())
|
||||||
|
{
|
||||||
|
return location.get();
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,9 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.util;
|
package org.eclipse.jetty.util;
|
||||||
|
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.condition.DisabledOnJre;
|
import org.junit.jupiter.api.condition.DisabledOnJre;
|
||||||
import org.junit.jupiter.api.condition.EnabledOnJre;
|
import org.junit.jupiter.api.condition.EnabledOnJre;
|
||||||
|
@ -105,7 +102,7 @@ public class TypeUtilTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsTrue() throws Exception
|
public void testIsTrue()
|
||||||
{
|
{
|
||||||
assertTrue(TypeUtil.isTrue(Boolean.TRUE));
|
assertTrue(TypeUtil.isTrue(Boolean.TRUE));
|
||||||
assertTrue(TypeUtil.isTrue(true));
|
assertTrue(TypeUtil.isTrue(true));
|
||||||
|
@ -120,7 +117,7 @@ public class TypeUtilTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsFalse() throws Exception
|
public void testIsFalse()
|
||||||
{
|
{
|
||||||
assertTrue(TypeUtil.isFalse(Boolean.FALSE));
|
assertTrue(TypeUtil.isFalse(Boolean.FALSE));
|
||||||
assertTrue(TypeUtil.isFalse(false));
|
assertTrue(TypeUtil.isFalse(false));
|
||||||
|
@ -135,19 +132,21 @@ public class TypeUtilTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Disabled // TODO fails if the mavenRepo is a symbolic link
|
public void testGetLocationOfClass_FromMavenRepo()
|
||||||
public void testGetLocationOfClass() throws Exception
|
|
||||||
{
|
{
|
||||||
String mavenRepoPathProperty = System.getProperty("mavenRepoPath");
|
String mavenRepoPathProperty = System.getProperty("mavenRepoPath");
|
||||||
assumeTrue(mavenRepoPathProperty != null);
|
assumeTrue(mavenRepoPathProperty != null);
|
||||||
Path mavenRepoPath = Paths.get(mavenRepoPathProperty);
|
Path mavenRepoPath = Paths.get(mavenRepoPathProperty);
|
||||||
|
|
||||||
System.err.println("mavenRepoPath "+mavenRepoPath);
|
|
||||||
String mavenRepo = mavenRepoPath.toFile().getPath().replaceAll("\\\\", "/");
|
String mavenRepo = mavenRepoPath.toFile().getPath().replaceAll("\\\\", "/");
|
||||||
|
|
||||||
// Classes from maven dependencies
|
// Classes from maven dependencies
|
||||||
assertThat(TypeUtil.getLocationOfClass(Assertions.class).toASCIIString(),containsString(mavenRepo));
|
assertThat(TypeUtil.getLocationOfClass(org.junit.jupiter.api.Assertions.class).toASCIIString(), containsString(mavenRepo));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLocationOfClass_ClassDirectory()
|
||||||
|
{
|
||||||
// Class from project dependencies
|
// Class from project dependencies
|
||||||
assertThat(TypeUtil.getLocationOfClass(TypeUtil.class).toASCIIString(),containsString("/classes/"));
|
assertThat(TypeUtil.getLocationOfClass(TypeUtil.class).toASCIIString(),containsString("/classes/"));
|
||||||
}
|
}
|
||||||
|
@ -157,10 +156,19 @@ public class TypeUtilTest
|
||||||
public void testGetLocation_JvmCore_JPMS()
|
public void testGetLocation_JvmCore_JPMS()
|
||||||
{
|
{
|
||||||
// Class from JVM core
|
// Class from JVM core
|
||||||
String expectedJavaBase = "/java.base/";
|
String expectedJavaBase = "/java.base";
|
||||||
assertThat(TypeUtil.getLocationOfClass(String.class).toASCIIString(),containsString(expectedJavaBase));
|
assertThat(TypeUtil.getLocationOfClass(String.class).toASCIIString(),containsString(expectedJavaBase));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisabledOnJre(JRE.JAVA_8)
|
||||||
|
public void testGetLocation_JavaLangThreadDeath_JPMS()
|
||||||
|
{
|
||||||
|
// Class from JVM core
|
||||||
|
String expectedJavaBase = "/java.base";
|
||||||
|
assertThat(TypeUtil.getLocationOfClass(java.lang.ThreadDeath.class).toASCIIString(),containsString(expectedJavaBase));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnabledOnJre(JRE.JAVA_8)
|
@EnabledOnJre(JRE.JAVA_8)
|
||||||
public void testGetLocation_JvmCore_Java8RT()
|
public void testGetLocation_JvmCore_Java8RT()
|
||||||
|
@ -169,4 +177,13 @@ public class TypeUtilTest
|
||||||
String expectedJavaBase = "/rt.jar";
|
String expectedJavaBase = "/rt.jar";
|
||||||
assertThat(TypeUtil.getLocationOfClass(String.class).toASCIIString(),containsString(expectedJavaBase));
|
assertThat(TypeUtil.getLocationOfClass(String.class).toASCIIString(),containsString(expectedJavaBase));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnabledOnJre(JRE.JAVA_8)
|
||||||
|
public void testGetLocation_JavaLangThreadDeath_Java8RT()
|
||||||
|
{
|
||||||
|
// Class from JVM core
|
||||||
|
String expectedJavaBase = "/rt.jar";
|
||||||
|
assertThat(TypeUtil.getLocationOfClass(java.lang.ThreadDeath.class).toASCIIString(),containsString(expectedJavaBase));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,28 +18,27 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.util.resource;
|
package org.eclipse.jetty.util.resource;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.util.IO;
|
||||||
|
import org.eclipse.jetty.util.TypeUtil;
|
||||||
|
import org.hamcrest.Matchers;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.condition.DisabledOnJre;
|
||||||
|
import org.junit.jupiter.api.condition.JRE;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.endsWith;
|
import static org.hamcrest.Matchers.endsWith;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.startsWith;
|
import static org.hamcrest.Matchers.startsWith;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
|
||||||
import org.eclipse.jetty.util.IO;
|
|
||||||
import org.eclipse.jetty.util.TypeUtil;
|
|
||||||
import org.hamcrest.Matchers;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.condition.DisabledOnJre;
|
|
||||||
import org.junit.jupiter.api.condition.JRE;
|
|
||||||
|
|
||||||
|
|
||||||
public class JrtResourceTest
|
public class JrtResourceTest
|
||||||
{
|
{
|
||||||
private String testResURI = MavenTestingUtils.getTestResourcesDir().getAbsoluteFile().toURI().toASCIIString();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisabledOnJre(JRE.JAVA_8)
|
@DisabledOnJre(JRE.JAVA_8)
|
||||||
|
@Disabled("Not supported on Java 9+ Module API")
|
||||||
public void testResourceFromUriForString()
|
public void testResourceFromUriForString()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -57,6 +56,7 @@ public class JrtResourceTest
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisabledOnJre(JRE.JAVA_8)
|
@DisabledOnJre(JRE.JAVA_8)
|
||||||
|
@Disabled("Not supported on Java 9+ Module API")
|
||||||
public void testResourceFromStringForString()
|
public void testResourceFromStringForString()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -73,6 +73,7 @@ public class JrtResourceTest
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisabledOnJre(JRE.JAVA_8)
|
@DisabledOnJre(JRE.JAVA_8)
|
||||||
|
@Disabled("Not supported on Java 9+ Module API")
|
||||||
public void testResourceFromURLForString()
|
public void testResourceFromURLForString()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -111,7 +112,4 @@ public class JrtResourceTest
|
||||||
assertThat(resource.isDirectory(), is(false));
|
assertThat(resource.isDirectory(), is(false));
|
||||||
assertThat(resource.length(),is(-1L));
|
assertThat(resource.length(),is(-1L));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -354,6 +354,8 @@ public class ClassMatcher extends AbstractSet<String>
|
||||||
@Override
|
@Override
|
||||||
public boolean test(URI uri)
|
public boolean test(URI uri)
|
||||||
{
|
{
|
||||||
|
if ((uri == null) || (!uri.isAbsolute()))
|
||||||
|
return false;
|
||||||
if (!uri.getScheme().equals("file"))
|
if (!uri.getScheme().equals("file"))
|
||||||
return false;
|
return false;
|
||||||
Path path = Paths.get(uri);
|
Path path = Paths.get(uri);
|
||||||
|
@ -391,6 +393,8 @@ public class ClassMatcher extends AbstractSet<String>
|
||||||
@Override
|
@Override
|
||||||
public boolean test(URI uri)
|
public boolean test(URI uri)
|
||||||
{
|
{
|
||||||
|
if ((uri == null) || (!uri.isAbsolute()))
|
||||||
|
return false;
|
||||||
if (!uri.getScheme().equalsIgnoreCase("jrt"))
|
if (!uri.getScheme().equalsIgnoreCase("jrt"))
|
||||||
return false;
|
return false;
|
||||||
String module = uri.getPath();
|
String module = uri.getPath();
|
||||||
|
@ -444,6 +448,8 @@ public class ClassMatcher extends AbstractSet<String>
|
||||||
@Override
|
@Override
|
||||||
public boolean test(URI name)
|
public boolean test(URI name)
|
||||||
{
|
{
|
||||||
|
if ((name == null) || (!name.isAbsolute()))
|
||||||
|
return false;
|
||||||
return _byLocation.test(name) || _byModule.test(name);
|
return _byLocation.test(name) || _byModule.test(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -749,7 +755,10 @@ public class ClassMatcher extends AbstractSet<String>
|
||||||
if (Boolean.FALSE==byName)
|
if (Boolean.FALSE==byName)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Boolean byLocation = locations.isIncludedAndNotExcluded(location.get());
|
URI uri = location.get();
|
||||||
|
if (uri != null)
|
||||||
|
{
|
||||||
|
Boolean byLocation = locations.isIncludedAndNotExcluded(uri);
|
||||||
if (Boolean.FALSE == byLocation)
|
if (Boolean.FALSE == byLocation)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -757,5 +766,7 @@ public class ClassMatcher extends AbstractSet<String>
|
||||||
|| Boolean.TRUE.equals(byLocation)
|
|| Boolean.TRUE.equals(byLocation)
|
||||||
|| !(names.hasIncludes() || locations.hasIncludes());
|
|| !(names.hasIncludes() || locations.hasIncludes());
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,7 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.webapp;
|
package org.eclipse.jetty.webapp;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.TypeUtil;
|
import org.eclipse.jetty.util.TypeUtil;
|
||||||
|
@ -34,6 +29,10 @@ import org.junit.jupiter.api.condition.DisabledOnJre;
|
||||||
import org.junit.jupiter.api.condition.EnabledOnJre;
|
import org.junit.jupiter.api.condition.EnabledOnJre;
|
||||||
import org.junit.jupiter.api.condition.JRE;
|
import org.junit.jupiter.api.condition.JRE;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ClassMatcherTest
|
public class ClassMatcherTest
|
||||||
{
|
{
|
||||||
private final ClassMatcher _pattern = new ClassMatcher();
|
private final ClassMatcher _pattern = new ClassMatcher();
|
||||||
|
@ -122,15 +121,12 @@ public class ClassMatcherTest
|
||||||
{
|
{
|
||||||
// jar from JVM classloader
|
// jar from JVM classloader
|
||||||
URI loc_string = TypeUtil.getLocationOfClass(String.class);
|
URI loc_string = TypeUtil.getLocationOfClass(String.class);
|
||||||
// System.err.println(loc_string);
|
|
||||||
|
|
||||||
// a jar from maven repo jar
|
// a jar from maven repo jar
|
||||||
URI loc_junit = TypeUtil.getLocationOfClass(Test.class);
|
URI loc_junit = TypeUtil.getLocationOfClass(Test.class);
|
||||||
// System.err.println(loc_junit);
|
|
||||||
|
|
||||||
// class file
|
// class file
|
||||||
URI loc_test = TypeUtil.getLocationOfClass(ClassMatcherTest.class);
|
URI loc_test = TypeUtil.getLocationOfClass(ClassMatcherTest.class);
|
||||||
// System.err.println(loc_test);
|
|
||||||
|
|
||||||
ClassMatcher pattern = new ClassMatcher();
|
ClassMatcher pattern = new ClassMatcher();
|
||||||
pattern.include("something");
|
pattern.include("something");
|
||||||
|
@ -139,7 +135,7 @@ public class ClassMatcherTest
|
||||||
assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(false));
|
assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(false));
|
||||||
|
|
||||||
// Add directory for both JVM classes
|
// Add directory for both JVM classes
|
||||||
pattern.include(Paths.get(loc_string).getParent().toUri().toString());
|
pattern.include(loc_string.toASCIIString());
|
||||||
|
|
||||||
// Add jar for individual class and classes directory
|
// Add jar for individual class and classes directory
|
||||||
pattern.include(loc_junit.toString(), loc_test.toString());
|
pattern.include(loc_junit.toString(), loc_test.toString());
|
||||||
|
@ -220,7 +216,7 @@ public class ClassMatcherTest
|
||||||
assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(true));
|
assertThat(pattern.match(ClassMatcherTest.class), Matchers.is(true));
|
||||||
|
|
||||||
// Add directory for both JVM classes
|
// Add directory for both JVM classes
|
||||||
pattern.exclude(Paths.get(loc_string).getParent().toUri().toString());
|
pattern.exclude(loc_string.toString());
|
||||||
|
|
||||||
// Add jar for individual class and classes directory
|
// Add jar for individual class and classes directory
|
||||||
pattern.exclude(loc_junit.toString(), loc_test.toString());
|
pattern.exclude(loc_junit.toString(), loc_test.toString());
|
||||||
|
|
|
@ -75,6 +75,13 @@
|
||||||
<type>war</type>
|
<type>war</type>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</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>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||||
<artifactId>jetty-test-helper</artifactId>
|
<artifactId>jetty-test-helper</artifactId>
|
||||||
|
@ -91,6 +98,13 @@
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty.tests</groupId>
|
||||||
|
<artifactId>test-felix-webapp</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
<type>war</type>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -191,15 +191,17 @@ public class DistributionTester
|
||||||
*
|
*
|
||||||
* @param warFile the war file to install
|
* @param warFile the war file to install
|
||||||
* @param context the context path
|
* @param context the context path
|
||||||
|
* @return the path to the installed webapp exploded directory
|
||||||
* @throws IOException if the installation fails
|
* @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
|
//webapps
|
||||||
Path webapps = config.jettyBase.resolve("webapps").resolve(context);
|
Path webapps = config.jettyBase.resolve("webapps").resolve(context);
|
||||||
if (!Files.exists(webapps))
|
if (!Files.exists(webapps))
|
||||||
Files.createDirectories(webapps);
|
Files.createDirectories(webapps);
|
||||||
unzip(warFile, webapps.toFile());
|
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,69 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// 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 OsgiAppTests extends AbstractDistributionTest
|
||||||
|
{
|
||||||
|
@Test
|
||||||
|
public void testFelixWebappStart() 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,plus,resources"
|
||||||
|
};
|
||||||
|
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-felix-webapp:war:" + jettyVersion);
|
||||||
|
distribution.installWarFile(war, "test");
|
||||||
|
|
||||||
|
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 + "/test/info");
|
||||||
|
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||||
|
assertThat(response.getContentAsString(), containsString("Framework: org.apache.felix.framework"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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>
|
|
@ -40,5 +40,7 @@
|
||||||
<module>test-jndi-webapp</module>
|
<module>test-jndi-webapp</module>
|
||||||
<module>test-http2-webapp</module>
|
<module>test-http2-webapp</module>
|
||||||
<module>test-simple-webapp</module>
|
<module>test-simple-webapp</module>
|
||||||
|
<module>test-felix-webapp</module>
|
||||||
|
<module>test-cdi2-webapp</module>
|
||||||
</modules>
|
</modules>
|
||||||
</project>
|
</project>
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?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>10.0.0-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>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
<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>
|
|
@ -0,0 +1,33 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// 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.test;
|
||||||
|
|
||||||
|
import javax.enterprise.inject.Produces;
|
||||||
|
import javax.enterprise.inject.spi.InjectionPoint;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
public class FriendlyGreetings
|
||||||
|
{
|
||||||
|
@Produces
|
||||||
|
@Named("friendly")
|
||||||
|
public Greetings getGreetings(InjectionPoint ip)
|
||||||
|
{
|
||||||
|
return () -> "Hello " + ip.getMember().getDeclaringClass().getSimpleName();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// 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.test;
|
||||||
|
|
||||||
|
public interface Greetings
|
||||||
|
{
|
||||||
|
String getGreeting();
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// 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.test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@WebServlet("/greetings")
|
||||||
|
public class GreetingsServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
@Inject
|
||||||
|
@Named("friendly")
|
||||||
|
public Greetings greetings;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
|
||||||
|
{
|
||||||
|
resp.setContentType("text/plain");
|
||||||
|
resp.getWriter().println("[" + greetings.getGreeting() + "]");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// 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.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.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
@WebServlet("/info")
|
||||||
|
public class InfoServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
@Inject
|
||||||
|
BeanManager beanManager;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
|
||||||
|
{
|
||||||
|
resp.setContentType("text/plain");
|
||||||
|
resp.setCharacterEncoding("utf-8");
|
||||||
|
|
||||||
|
PrintWriter out = resp.getWriter();
|
||||||
|
out.println("Bean Manager: " + beanManager);
|
||||||
|
Set<Bean<?>> beans = beanManager.getBeans("");
|
||||||
|
for (Bean<?> bean : beans)
|
||||||
|
{
|
||||||
|
out.println(" " + bean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// 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.test;
|
||||||
|
|
||||||
|
import javax.enterprise.inject.Produces;
|
||||||
|
|
||||||
|
public class ManifestServerID
|
||||||
|
{
|
||||||
|
@Produces
|
||||||
|
public ServerID getServerID()
|
||||||
|
{
|
||||||
|
return () ->
|
||||||
|
{
|
||||||
|
String implVersion = this.getClass().getPackage().getImplementationVersion();
|
||||||
|
if(implVersion == null)
|
||||||
|
implVersion = this.getClass().getPackage().getName();
|
||||||
|
if(implVersion == null)
|
||||||
|
implVersion = "unknown";
|
||||||
|
return "CDI-Demo-" + implVersion;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// 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.test;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.servlet.ServletContextEvent;
|
||||||
|
import javax.servlet.ServletContextListener;
|
||||||
|
import javax.servlet.annotation.WebListener;
|
||||||
|
|
||||||
|
@WebListener
|
||||||
|
public class MyContextListener implements ServletContextListener
|
||||||
|
{
|
||||||
|
@Inject
|
||||||
|
public ServerID serverId;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contextInitialized(ServletContextEvent sce)
|
||||||
|
{
|
||||||
|
sce.getServletContext().setAttribute("ServerID", serverId.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contextDestroyed(ServletContextEvent sce)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// 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.test;
|
||||||
|
|
||||||
|
import javax.enterprise.inject.Produces;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
public class OldGreetings
|
||||||
|
{
|
||||||
|
@Produces
|
||||||
|
@Named("old")
|
||||||
|
public Greetings getGreeting()
|
||||||
|
{
|
||||||
|
return () -> "Salutations!";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// 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.test;
|
||||||
|
|
||||||
|
public interface ServerID
|
||||||
|
{
|
||||||
|
String get();
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// 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.test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import javax.servlet.Filter;
|
||||||
|
import javax.servlet.FilterChain;
|
||||||
|
import javax.servlet.FilterConfig;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.ServletResponse;
|
||||||
|
import javax.servlet.annotation.WebFilter;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Web Filter that doesn't use CDI.
|
||||||
|
*/
|
||||||
|
@WebFilter("/*")
|
||||||
|
public class ServerIDFilter implements Filter
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void init(FilterConfig filterConfig)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
|
||||||
|
{
|
||||||
|
if (response instanceof HttpServletResponse)
|
||||||
|
{
|
||||||
|
String serverID = (String)request.getServletContext().getAttribute("ServerID");
|
||||||
|
((HttpServletResponse)response).setHeader("Server", serverID);
|
||||||
|
}
|
||||||
|
chain.doFilter(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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>
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<web-app 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/web-app_3_1.xsd"
|
||||||
|
version="3.1">
|
||||||
|
<display-name>CDI Integration Test WebApp</display-name>
|
||||||
|
|
||||||
|
<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>
|
|
@ -0,0 +1,53 @@
|
||||||
|
<?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>10.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>test-felix-webapp</artifactId>
|
||||||
|
<name>Test :: Jetty Felix Webapp</name>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<bundle-symbolic-name>${project.groupId}.felix</bundle-symbolic-name>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>org.apache.felix.framework</artifactId>
|
||||||
|
<version>6.0.3</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,82 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// 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.demo;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.ServiceLoader;
|
||||||
|
import javax.servlet.ServletContextEvent;
|
||||||
|
import javax.servlet.ServletContextListener;
|
||||||
|
import javax.servlet.annotation.WebListener;
|
||||||
|
|
||||||
|
import org.osgi.framework.Constants;
|
||||||
|
import org.osgi.framework.launch.Framework;
|
||||||
|
import org.osgi.framework.launch.FrameworkFactory;
|
||||||
|
|
||||||
|
@WebListener
|
||||||
|
public class AppListener implements ServletContextListener
|
||||||
|
{
|
||||||
|
public void contextInitialized(ServletContextEvent sce)
|
||||||
|
{
|
||||||
|
Framework framework = initFelix();
|
||||||
|
sce.getServletContext().setAttribute(Framework.class.getName(), framework);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Framework initFelix()
|
||||||
|
{
|
||||||
|
Map<String, String> properties = new HashMap<>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Path cacheDir = Files.createTempDirectory("felix-cache");
|
||||||
|
properties.put(Constants.FRAMEWORK_STORAGE, cacheDir.toAbsolutePath().toString());
|
||||||
|
properties.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
|
||||||
|
properties.put(Constants.FRAMEWORK_BUNDLE_PARENT, Constants.FRAMEWORK_BUNDLE_PARENT_FRAMEWORK);
|
||||||
|
properties.put(Constants.FRAMEWORK_BOOTDELEGATION, "*");
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException("Unable to configure Felix", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Framework framework = ServiceLoader.load(FrameworkFactory.class).iterator().next().newFramework(properties);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
System.err.println("Initializing felix");
|
||||||
|
framework.init();
|
||||||
|
System.err.println("Starting felix");
|
||||||
|
framework.start();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace(System.err);
|
||||||
|
throw new RuntimeException("Unable to start Felix", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return framework;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void contextDestroyed(ServletContextEvent sce)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// 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.demo;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.osgi.framework.Bundle;
|
||||||
|
import org.osgi.framework.BundleContext;
|
||||||
|
import org.osgi.framework.launch.Framework;
|
||||||
|
|
||||||
|
@WebServlet("/info")
|
||||||
|
public class InfoServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
|
||||||
|
{
|
||||||
|
resp.setStatus(HttpServletResponse.SC_OK);
|
||||||
|
resp.setContentType("text/plain");
|
||||||
|
resp.setCharacterEncoding("utf-8");
|
||||||
|
|
||||||
|
PrintWriter out = resp.getWriter();
|
||||||
|
Framework framework = (Framework)getServletContext().getAttribute(Framework.class.getName());
|
||||||
|
out.printf("Framework: %s\n", framework);
|
||||||
|
BundleContext bundleContext = framework.getBundleContext();
|
||||||
|
out.printf("BundleContext: %s\n", bundleContext);
|
||||||
|
Bundle bundleSelf = bundleContext.getBundle();
|
||||||
|
out.printf("BundleContext.bundle: %s\n", bundleSelf);
|
||||||
|
for (Bundle bundle : bundleContext.getBundles())
|
||||||
|
{
|
||||||
|
out.printf("bundle[]: %s\n", bundle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue