diff options
author | Jan Bartel | 2014-09-05 07:49:17 +0000 |
---|---|---|
committer | Jan Bartel | 2014-09-05 07:49:17 +0000 |
commit | e4454965d4ecdfefd4a2d3395ce3635808642157 (patch) | |
tree | f0e29ca4a9cef021766d079fb7d95c086341df76 | |
parent | c0aef8975d67610b2aad3c0077075a6e242cdff7 (diff) | |
download | org.eclipse.jetty.project-e4454965d4ecdfefd4a2d3395ce3635808642157.tar.gz org.eclipse.jetty.project-e4454965d4ecdfefd4a2d3395ce3635808642157.tar.xz org.eclipse.jetty.project-e4454965d4ecdfefd4a2d3395ce3635808642157.zip |
Make annotations and JNDI wortk with OSGi
28 files changed, 355 insertions, 182 deletions
diff --git a/jetty-osgi/jetty-osgi-boot/pom.xml b/jetty-osgi/jetty-osgi-boot/pom.xml index 4545bc5f5c..a6fb613150 100644 --- a/jetty-osgi/jetty-osgi-boot/pom.xml +++ b/jetty-osgi/jetty-osgi-boot/pom.xml @@ -112,8 +112,9 @@ javax.servlet.http;version="[3.1,3.2)", javax.transaction;version="1.1.0";resolution:=optional, javax.transaction.xa;version="1.1.0";resolution:=optional, + org.eclipse.jetty.annotations;version="9.1";resolution:=optional, + org.eclipse.jetty.plus.webapp;version="9.1";resolution:=optional, org.objectweb.asm;version=4;resolution:=optional, - org.eclipse.jetty.annotations;version="9.0.0";resolution:=optional, org.osgi.framework, org.osgi.service.cm;version="1.2.0", org.osgi.service.packageadmin, diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractContextProvider.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractContextProvider.java index 89621a2284..726aa694d9 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractContextProvider.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractContextProvider.java @@ -143,63 +143,12 @@ public abstract class AbstractContextProvider extends AbstractLifeCycle implemen { //apply the contextFile, creating the ContextHandler, the DeploymentManager will register it in the ContextHandlerCollection Resource res = null; - - //try to find the context file in the filesystem - if (_contextFile.startsWith("/")) - res = getFileAsResource(_contextFile); - - //try to find it relative to jetty home - if (res == null) - { - //See if the specific server we are related to has jetty.home set - String jettyHome = (String)getServerInstanceWrapper().getServer().getAttribute(OSGiServerConstants.JETTY_HOME); - if (jettyHome != null) - res = getFileAsResource(jettyHome, _contextFile); - - //try to see if a SystemProperty for jetty.home is set - if (res == null) - { - jettyHome = System.getProperty(OSGiServerConstants.JETTY_HOME); - - if (jettyHome != null) - { - if (jettyHome.startsWith("\"") || jettyHome.startsWith("'")) - jettyHome = jettyHome.substring(1); - if (jettyHome.endsWith("\"") || (jettyHome.endsWith("'"))) - jettyHome = jettyHome.substring(0,jettyHome.length()-1); - - res = getFileAsResource(jettyHome, _contextFile); - LOG.debug("jetty home context file: {}",res); - } - } - } - - //try to find it relative to an override location that has been specified - if (res == null) - { - if (bundleOverrideLocation != null) - { - try(Resource location=Resource.newResource(bundleOverrideLocation)) - { - res=location.addPath(_contextFile); - } - LOG.debug("Bundle override location context file: {}",res); - } - } - - //try to find it relative to the bundle in which it is being deployed - if (res == null) - { - if (_contextFile.startsWith("./")) - _contextFile = _contextFile.substring(1); - - if (!_contextFile.startsWith("/")) - _contextFile = "/" + _contextFile; - - URL contextURL = _bundle.getEntry(_contextFile); - if (contextURL != null) - res = Resource.newResource(contextURL); - } + + String jettyHome = (String)getServerInstanceWrapper().getServer().getAttribute(OSGiServerConstants.JETTY_HOME); + if (jettyHome == null) + jettyHome = System.getProperty(OSGiServerConstants.JETTY_HOME); + + res = findFile(_contextFile, jettyHome, bundleOverrideLocation, _bundle); //apply the context xml file, either to an existing ContextHandler, or letting the //it create the ContextHandler as necessary @@ -266,38 +215,6 @@ public abstract class AbstractContextProvider extends AbstractLifeCycle implemen } - - private Resource getFileAsResource (String dir, String file) - { - Resource r = null; - try - { - File asFile = new File (dir, file); - if (asFile.exists()) - r = Resource.newResource(asFile); - } - catch (Exception e) - { - r = null; - } - return r; - } - - private Resource getFileAsResource (String file) - { - Resource r = null; - try - { - File asFile = new File (file); - if (asFile.exists()) - r = Resource.newResource(asFile); - } - catch (Exception e) - { - r = null; - } - return r; - } } /* ------------------------------------------------------------ */ diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractOSGiApp.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractOSGiApp.java index 185d0f1ae6..7ffc9b4c66 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractOSGiApp.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractOSGiApp.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.osgi.boot; +import java.io.File; +import java.net.URL; import java.util.Dictionary; import java.util.Hashtable; @@ -25,6 +27,9 @@ import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.AppProvider; import org.eclipse.jetty.deploy.DeploymentManager; import org.eclipse.jetty.server.handler.ContextHandler; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.resource.Resource; import org.osgi.framework.Bundle; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceRegistration; @@ -39,6 +44,8 @@ import org.osgi.framework.ServiceRegistration; */ public abstract class AbstractOSGiApp extends App { + private static final Logger LOG = Log.getLogger(AbstractOSGiApp.class); + protected Bundle _bundle; protected Dictionary _properties; protected ServiceRegistration _registration; @@ -118,4 +125,91 @@ public abstract class AbstractOSGiApp extends App _registration = null; } + protected Resource getFileAsResource (String dir, String file) + { + Resource r = null; + try + { + File asFile = new File (dir, file); + if (asFile.exists()) + r = Resource.newResource(asFile); + } + catch (Exception e) + { + r = null; + } + return r; + } + + protected Resource getFileAsResource (String file) + { + Resource r = null; + try + { + File asFile = new File (file); + if (asFile.exists()) + r = Resource.newResource(asFile); + } + catch (Exception e) + { + r = null; + } + return r; + } + + protected Resource findFile (String fileName, String jettyHome, String bundleOverrideLocation, Bundle containingBundle) + { + Resource res = null; + + //try to find the context file in the filesystem + if (fileName.startsWith("/")) + res = getFileAsResource(fileName); + if (res != null) + return res; + + //try to find it relative to jetty home + if (jettyHome != null) + { + if (jettyHome.startsWith("\"") || jettyHome.startsWith("'")) + jettyHome = jettyHome.substring(1); + if (jettyHome.endsWith("\"") || (jettyHome.endsWith("'"))) + jettyHome = jettyHome.substring(0,jettyHome.length()-1); + + res = getFileAsResource(jettyHome, fileName); + } + if (res != null) + return res; + + + //try to find it relative to an override location that has been specified + if (bundleOverrideLocation != null) + { + try(Resource location=Resource.newResource(bundleOverrideLocation)) + { + res=location.addPath(fileName); + } + catch (Exception e) + { + LOG.warn(e); + } + } + if (res != null) + return res; + + //try to find it relative to the bundle in which it is being deployed + if (containingBundle != null) + { + if (fileName.startsWith("./")) + fileName = fileName.substring(1); + + if (!fileName.startsWith("/")) + fileName = "/" + fileName; + + URL entry = _bundle.getEntry(fileName); + if (entry != null) + res = Resource.newResource(entry); + } + + return res; + } } diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractWebAppProvider.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractWebAppProvider.java index 97f9296114..849a00c55c 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractWebAppProvider.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractWebAppProvider.java @@ -20,10 +20,12 @@ package org.eclipse.jetty.osgi.boot; import java.io.File; import java.net.URL; +import java.util.ArrayList; import java.util.Arrays; import java.util.Dictionary; import java.util.Enumeration; import java.util.HashMap; +import java.util.List; import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.AppProvider; @@ -32,7 +34,9 @@ import org.eclipse.jetty.osgi.boot.internal.serverfactory.ServerInstanceWrapper; import org.eclipse.jetty.osgi.boot.internal.webapp.OSGiWebappClassLoader; import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelperFactory; import org.eclipse.jetty.server.handler.ContextHandler; +import org.eclipse.jetty.util.ArrayUtil; import org.eclipse.jetty.util.component.AbstractLifeCycle; +import org.eclipse.jetty.util.Loader; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.resource.JarResource; @@ -73,17 +77,23 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement public static String[] getDefaultConfigurations () { + List<String> configs = ArrayUtil.asMutableList(__defaultConfigurations); if (annotationsAvailable()) { - String[] configs = new String[__defaultConfigurations.length+1]; - System.arraycopy(__defaultConfigurations, 0, configs, 0, 4); - configs[4] = "org.eclipse.jetty.osgi.annotations.AnnotationConfiguration"; - configs[5] = __defaultConfigurations[__defaultConfigurations.length-1]; - return configs; + //add before JettyWebXmlConfiguration + int i = configs.indexOf("org.eclipse.jetty.webapp.JettyWebXmlConfiguration"); + configs.add(i, "org.eclipse.jetty.osgi.annotations.AnnotationConfiguration"); + } + + if (jndiAvailable()) + { + //add in EnvConfiguration and PlusConfiguration just after FragmentConfiguration + int i = configs.indexOf("org.eclipse.jetty.webapp.FragmentConfiguration"); + configs.add(++i, "org.eclipse.jetty.plus.webapp.EnvConfiguration"); + configs.add(++i, "org.eclipse.jetty.plus.webapp.PlusConfiguration"); } - - return Arrays.copyOf(__defaultConfigurations, __defaultConfigurations.length); + return configs.toArray(new String[configs.size()]); } private static boolean annotationsAvailable() @@ -91,7 +101,7 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement boolean result = false; try { - Thread.currentThread().getContextClassLoader().loadClass("org.eclipse.jetty.annotations.AnnotationConfiguration"); + Loader.loadClass(AbstractWebAppProvider.class,"org.eclipse.jetty.annotations.AnnotationConfiguration"); result = true; LOG.debug("Annotation support detected"); } @@ -104,6 +114,23 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement return result; } + + private static boolean jndiAvailable() + { + try + { + Loader.loadClass(AbstractWebAppProvider.class, "org.eclipse.jetty.plus.jndi.Resource"); + Loader.loadClass(AbstractWebAppProvider.class, "org.eclipse.jetty.plus.webapp.EnvConfiguration"); + LOG.debug("JNDI support detected"); + return true; + } + catch (ClassNotFoundException e) + { + LOG.debug("No JNDI support detected"); + return false; + } + } + private boolean _parentLoaderPriority; @@ -268,7 +295,6 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement //Sets the location of the war file // converts bundleentry: protocol if necessary - System.err.println("WAR : "+BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(url).toString()); _webApp.setWar(BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(url).toString()); // Set up what has been configured on the provider @@ -329,7 +355,7 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement // apply any META-INF/context.xml file that is found to configure // the webapp first - applyMetaInfContextXml(rootResource); + applyMetaInfContextXml(rootResource, overrideBundleInstallLocation); _webApp.setAttribute(OSGiWebappConstants.REQUIRE_TLD_BUNDLE, requireTldBundles); @@ -385,7 +411,7 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement } - protected void applyMetaInfContextXml(Resource rootResource) + protected void applyMetaInfContextXml(Resource rootResource, String overrideBundleInstallLocation) throws Exception { if (_bundle == null) return; @@ -399,8 +425,31 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement Thread.currentThread().setContextClassLoader(_webApp.getClassLoader()); //TODO replace this with getting the InputStream so we don't cache in URL - // find if there is a META-INF/context.xml file + //Try looking for a context xml file in META-INF with a specific name URL contextXmlUrl = _bundle.getEntry("/META-INF/jetty-webapp-context.xml"); + + if (contextXmlUrl == null) + { + //Didn't find specially named file, try looking for a property that names a context xml file to use + if (_properties != null) + { + String tmp = (String)_properties.get(OSGiWebappConstants.JETTY_CONTEXT_FILE_PATH); + if (tmp != null) + { + String[] filenames = tmp.split(",;"); + if (filenames != null && filenames.length > 0) + { + String filename = filenames[0]; //should only be 1 filename in this usage + String jettyHome = (String)getServerInstanceWrapper().getServer().getAttribute(OSGiServerConstants.JETTY_HOME); + if (jettyHome == null) + jettyHome = System.getProperty(OSGiServerConstants.JETTY_HOME); + Resource res = findFile(filename, jettyHome, overrideBundleInstallLocation, _bundle); + if (res != null) + contextXmlUrl = res.getURL(); + } + } + } + } if (contextXmlUrl == null) return; // Apply it just as the standard jetty ContextProvider would do diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/BundleContextProvider.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/BundleContextProvider.java index 1cd720b601..65466f506a 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/BundleContextProvider.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/BundleContextProvider.java @@ -106,6 +106,13 @@ public class BundleContextProvider extends AbstractContextProvider implements Bu if (bundle == null) return false; + //If the bundle defines a Web-ContextPath then its probably a webapp and the BundleWebAppProvider should deploy it + if ((String)bundle.getHeaders().get(OSGiWebappConstants.RFC66_WEB_CONTEXTPATH) != null) + { + if (LOG.isDebugEnabled()) LOG.debug("BundleContextProvider ignoring bundle {} with {} set", bundle.getSymbolicName(), OSGiWebappConstants.RFC66_WEB_CONTEXTPATH); + return false; + } + String contextFiles = (String)bundle.getHeaders().get(OSGiWebappConstants.JETTY_CONTEXT_FILE_PATH); if (contextFiles == null) contextFiles = (String)bundle.getHeaders().get(OSGiWebappConstants.SERVICE_PROP_CONTEXT_FILE_PATH); @@ -113,6 +120,7 @@ public class BundleContextProvider extends AbstractContextProvider implements Bu if (contextFiles == null) return false; + boolean added = false; //bundle defines JETTY_CONTEXT_FILE_PATH header, //a comma separated list of context xml files that each define a ContextHandler diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/OSGiWebappClassLoader.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/OSGiWebappClassLoader.java index bdd52ac537..62d9f0b341 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/OSGiWebappClassLoader.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/OSGiWebappClassLoader.java @@ -100,7 +100,6 @@ public class OSGiWebappClassLoader extends WebAppClassLoader implements BundleRe @Override public Class<?> loadClass(String name) throws ClassNotFoundException { - System.err.println("LOADING CLASS: "+name); return super.loadClass(name); } diff --git a/jetty-osgi/test-jetty-osgi/pom.xml b/jetty-osgi/test-jetty-osgi/pom.xml index 2a734b968b..dda7984dc6 100644 --- a/jetty-osgi/test-jetty-osgi/pom.xml +++ b/jetty-osgi/test-jetty-osgi/pom.xml @@ -353,6 +353,20 @@ </dependency> <dependency> + <groupId>org.eclipse.jetty.tests</groupId> + <artifactId>test-container-initializer</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + + + <dependency> + <groupId>org.eclipse.jetty.tests</groupId> + <artifactId>test-mock-resources</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> <groupId>org.eclipse.jetty.osgi</groupId> <artifactId>test-jetty-osgi-context</artifactId> <version>${project.version}</version> diff --git a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootCore.java b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootCore.java index b5035fadff..48e018b9c6 100644 --- a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootCore.java +++ b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootCore.java @@ -106,7 +106,7 @@ public class TestJettyOSGiBootCore res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-servlets" ).versionAsInProject().noStart()); res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-client" ).versionAsInProject().noStart()); res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-jndi" ).versionAsInProject().noStart()); - res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-plus" ).versionAsInProject().noStart()); + res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-plus" ).versionAsInProject()); res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-annotations" ).versionAsInProject().start()); res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-api" ).versionAsInProject().noStart()); res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-common" ).versionAsInProject().noStart()); diff --git a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootWithAnnotations.java b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootWithAnnotations.java index e1bdd8b2c4..156d8e4f8c 100644 --- a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootWithAnnotations.java +++ b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootWithAnnotations.java @@ -33,6 +33,7 @@ import javax.inject.Inject; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.api.ContentResponse; +import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.osgi.boot.OSGiServerConstants; import org.junit.Ignore; @@ -50,7 +51,7 @@ import org.osgi.framework.BundleContext; * top of this. */ @RunWith(PaxExam.class) -@Ignore + public class TestJettyOSGiBootWithAnnotations { private static final String LOG_LEVEL = "WARN"; @@ -65,7 +66,7 @@ public class TestJettyOSGiBootWithAnnotations ArrayList<Option> options = new ArrayList<Option>(); options.add(CoreOptions.junitBundles()); options.addAll(configureJettyHomeAndPort("jetty-selector.xml")); - options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*", "org.w3c.*", "javax.xml.*", "javax.activation.*")); + options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*", "org.w3c.*", "javax.sql.*","javax.xml.*", "javax.activation.*")); options.add(CoreOptions.systemPackages("com.sun.org.apache.xalan.internal.res","com.sun.org.apache.xml.internal.utils", "com.sun.org.apache.xml.internal.utils", "com.sun.org.apache.xpath.internal", "com.sun.org.apache.xpath.internal.jaxp", "com.sun.org.apache.xpath.internal.objects")); @@ -73,10 +74,10 @@ public class TestJettyOSGiBootWithAnnotations options.addAll(TestJettyOSGiBootCore.coreJettyDependencies()); options.addAll(Arrays.asList(options(systemProperty("pax.exam.logging").value("none")))); options.addAll(Arrays.asList(options(systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value(LOG_LEVEL)))); - options.addAll(Arrays.asList(options(systemProperty("org.eclipse.jetty.LEVEL").value(LOG_LEVEL)))); + options.addAll(Arrays.asList(options(systemProperty("org.eclipse.jetty.annotations.LEVEL").value(LOG_LEVEL)))); //options.addAll(TestJettyOSGiBootCore.consoleDependencies()); options.addAll(jspDependencies()); - + options.addAll(annotationDependencies()); return options.toArray(new Option[options.size()]); } @@ -107,15 +108,18 @@ public class TestJettyOSGiBootWithAnnotations public static List<Option> jspDependencies() { - List<Option> res = new ArrayList<Option>(); - res.addAll(TestJettyOSGiBootCore.jspDependencies()); + return TestJettyOSGiBootCore.jspDependencies(); + } + public static List<Option> annotationDependencies() + { + List<Option> res = new ArrayList<Option>(); + res.add(mavenBundle().groupId("org.eclipse.jetty.tests").artifactId("test-container-initializer").versionAsInProject()); + res.add(mavenBundle().groupId("org.eclipse.jetty.tests").artifactId("test-mock-resources").versionAsInProject()); //test webapp bundle res.add(mavenBundle().groupId("org.eclipse.jetty.tests").artifactId("test-spec-webapp").classifier("webbundle").versionAsInProject()); - return res; } - @Ignore @@ -135,26 +139,6 @@ public class TestJettyOSGiBootWithAnnotations } - @Ignore - @Test - public void testJspDump() throws Exception - { - HttpClient client = new HttpClient(); - try - { - client.start(); - ContentResponse response = client.GET("http://127.0.0.1:" + TestJettyOSGiBootCore.DEFAULT_JETTY_HTTP_PORT + "/jsp/dump.jsp"); - assertEquals(HttpStatus.OK_200, response.getStatus()); - - String content = new String(response.getContent()); - assertTrue(content.contains("<tr><th>ServletPath:</th><td>/jsp/dump.jsp</td></tr>")); - - } - finally - { - client.stop(); - } - } @Test public void testIndex() throws Exception @@ -164,11 +148,15 @@ public class TestJettyOSGiBootWithAnnotations { client.start(); ContentResponse response = client.GET("http://127.0.0.1:" + TestJettyOSGiBootCore.DEFAULT_JETTY_HTTP_PORT + "/index.html"); - //assertEquals(HttpStatus.OK_200, response.getStatus()); + assertEquals(HttpStatus.OK_200, response.getStatus()); String content = new String(response.getContent()); - System.err.println(content); - + assertTrue(content.contains("<h1>Servlet 3.1 Test WebApp</h1>")); + + Request req = client.POST("http://127.0.0.1:" + TestJettyOSGiBootCore.DEFAULT_JETTY_HTTP_PORT + "/test"); + response = req.send(); + content = new String(response.getContent()); + assertTrue(content.contains("<p><b>Result: <span class=\"pass\">PASS</span></p>")); } finally { diff --git a/jetty-plus/pom.xml b/jetty-plus/pom.xml index 6c556a9304..375590a1a5 100644 --- a/jetty-plus/pom.xml +++ b/jetty-plus/pom.xml @@ -25,10 +25,17 @@ </goals> <configuration> <instructions> - <_versionpolicy> </_versionpolicy> + <_nouses>true</_nouses> + <!-- Export-Package> + org.eclipse.jetty.plus.annotation;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}", + org.eclipse.jetty.plus.webapp;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}", + org.eclipse.jetty.plus.jndi;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}", + org.eclipse.jetty.plus.security;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}" + </Export-Package --> <Import-Package>javax.sql.*,javax.security.*,javax.naming.*, javax.servlet.*;version="[2.6.0,3.2)",javax.transaction.*;version="[1.1,1.3)", - *</Import-Package> + * + </Import-Package> </instructions> </configuration> </execution> diff --git a/tests/test-webapps/test-mock-resources/pom.xml b/tests/test-webapps/test-mock-resources/pom.xml index 846de1e310..2f88be8ffb 100644 --- a/tests/test-webapps/test-mock-resources/pom.xml +++ b/tests/test-webapps/test-mock-resources/pom.xml @@ -16,6 +16,51 @@ <verbose>false</verbose> </configuration> </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <executions> + <execution> + <id>generate-manifest</id> + <goals> + <goal>manifest</goal> + </goals> + <configuration> + <instructions> + <Bundle-SymbolicName>org.eclipse.jetty.tests.test-mock-resources</Bundle-SymbolicName> + <Bundle-Description>Mock resources used for testing </Bundle-Description> + <Export-Package> + com.acme;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}" + </Export-Package> + <Import-Package> + javax.sql, + javax.transaction;version="1.1", + javax.mail;version="1.4.1" + </Import-Package> + <_nouses>true</_nouses> + </instructions> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <executions> + <execution> + <id>artifact-jar</id> + <goals> + <goal>jar</goal> + </goals> + </execution> + </executions> + <configuration> + <archive> + <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> + </archive> + </configuration> + </plugin> </plugins> </build> <dependencies> diff --git a/tests/test-webapps/test-servlet-spec/test-container-initializer/pom.xml b/tests/test-webapps/test-servlet-spec/test-container-initializer/pom.xml index 158d51c131..e832bacbaa 100644 --- a/tests/test-webapps/test-servlet-spec/test-container-initializer/pom.xml +++ b/tests/test-webapps/test-servlet-spec/test-container-initializer/pom.xml @@ -16,6 +16,47 @@ <verbose>false</verbose> </configuration> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <executions> + <execution> + <id>artifact-jar</id> + <goals> + <goal>jar</goal> + </goals> + </execution> + </executions> + <configuration> + <archive> + <manifestFile>target/classes/META-INF/MANIFEST.MF</manifestFile> + </archive> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <executions> + <execution> + <id>bundle-manifest</id> + <phase>process-classes</phase> + <goals> + <goal>manifest</goal> + </goals> + </execution> + </executions> + <configuration> + <instructions> + <Bundle-SymbolicName>org.eclipse.jetty.tests.test-servlet-container-initializer;singleton:=true</Bundle-SymbolicName> + <Bundle-Description>A bundle containing a ServletContainerInitializer for testing</Bundle-Description> + <Require-Capability>osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"</Require-Capability> + <Provide-Capability>osgi.serviceloader; osgi.serviceloader=javax.servlet.ServletContainerInitializer</Provide-Capability> + <Export-Package>com.acme.initializer;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}"</Export-Package> + <_nouses>true</_nouses> + </instructions> + </configuration> + </plugin> </plugins> </build> <dependencies> @@ -24,13 +65,5 @@ <artifactId>javax.servlet-api</artifactId> <scope>provided</scope> </dependency> - -<!-- - <dependency> - <groupId>org.eclipse.jetty.orbit</groupId> - <artifactId>javax.servlet</artifactId> - <scope>provided</scope> - </dependency> ---> </dependencies> </project> diff --git a/tests/test-webapps/test-servlet-spec/test-container-initializer/src/main/java/com/acme/Foo.java b/tests/test-webapps/test-servlet-spec/test-container-initializer/src/main/java/com/acme/initializer/Foo.java index bae5e96b1d..935a55756b 100644 --- a/tests/test-webapps/test-servlet-spec/test-container-initializer/src/main/java/com/acme/Foo.java +++ b/tests/test-webapps/test-servlet-spec/test-container-initializer/src/main/java/com/acme/initializer/Foo.java @@ -16,7 +16,7 @@ // ======================================================================== // -package com.acme; +package com.acme.initializer; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/tests/test-webapps/test-servlet-spec/test-container-initializer/src/main/java/com/acme/FooInitializer.java b/tests/test-webapps/test-servlet-spec/test-container-initializer/src/main/java/com/acme/initializer/FooInitializer.java index 59ca8e1d4f..9f4c181c02 100644 --- a/tests/test-webapps/test-servlet-spec/test-container-initializer/src/main/java/com/acme/FooInitializer.java +++ b/tests/test-webapps/test-servlet-spec/test-container-initializer/src/main/java/com/acme/initializer/FooInitializer.java @@ -16,7 +16,7 @@ // ======================================================================== // -package com.acme; +package com.acme.initializer; import java.util.ArrayList; import java.util.Set; diff --git a/tests/test-webapps/test-servlet-spec/test-container-initializer/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer b/tests/test-webapps/test-servlet-spec/test-container-initializer/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer index 264910bf91..622cbd0121 100644 --- a/tests/test-webapps/test-servlet-spec/test-container-initializer/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer +++ b/tests/test-webapps/test-servlet-spec/test-container-initializer/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer @@ -1 +1 @@ -com.acme.FooInitializer +com.acme.initializer.FooInitializer diff --git a/tests/test-webapps/test-servlet-spec/test-spec-webapp/pom.xml b/tests/test-webapps/test-servlet-spec/test-spec-webapp/pom.xml index 43e496ac68..b8bc0cfc83 100644 --- a/tests/test-webapps/test-servlet-spec/test-spec-webapp/pom.xml +++ b/tests/test-webapps/test-servlet-spec/test-spec-webapp/pom.xml @@ -47,6 +47,15 @@ <archive> <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> </archive> + <webResources> + <resource> + <directory>target</directory> + <includes> + <include>plugin-context.xml</include> + </includes> + <targetPath>META-INF</targetPath> + </resource> + </webResources> </configuration> </plugin> @@ -70,10 +79,22 @@ <configuration> <instructions> <Bundle-SymbolicName>org.eclipse.jetty.tests.test-spec-webapp</Bundle-SymbolicName> - <Import-Package>javax.servlet.jsp.*;version="[2.2.0, 3.0)",javax.transaction.*;version="[1.1, 2.0)", javax.servlet.*;version="3.0",org.eclipse.jetty.*;version="9.2",*</Import-Package> - <Export-Package>!com.acme*</Export-Package> + <Bundle-Description>Test Webapp for Servlet 3.1 Features</Bundle-Description> + <Import-Package> + javax.servlet.jsp.*;version="[2.2.0, 3.0)", + javax.transaction.*;version="[1.1, 2.0)", + javax.servlet.*;version="3.0", + javax.sql, + org.eclipse.jetty.webapp;version="9.2",org.eclipse.jetty.plus.jndi;version="9.2", + org.eclipse.jetty.security;version="9.2", + com.acme;version="9.2", + * + </Import-Package> + <Export-Package>com.acme.test;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}"</Export-Package> <Web-ContextPath>/</Web-ContextPath> <Bundle-ClassPath>.,WEB-INF/classes,WEB-INF/lib</Bundle-ClassPath> + <Jetty-ContextFilePath>./META-INF/plugin-context.xml</Jetty-ContextFilePath> + <_nouses>true</_nouses> </instructions> </configuration> </execution> diff --git a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/AnnotatedListener.java b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/test/AnnotatedListener.java index 2a5caf276a..0b05fa7af4 100644 --- a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/AnnotatedListener.java +++ b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/test/AnnotatedListener.java @@ -16,7 +16,7 @@ // ======================================================================== // -package com.acme; +package com.acme.test; import javax.annotation.Resource; import javax.servlet.ServletContextAttributeEvent; diff --git a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/AnnotationTest.java b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/test/AnnotationTest.java index 502e4b1c48..7ec4c8f413 100644 --- a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/AnnotationTest.java +++ b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/test/AnnotationTest.java @@ -16,7 +16,7 @@ // ======================================================================== // -package com.acme; +package com.acme.test; import java.io.IOException; import java.util.ArrayList; @@ -110,7 +110,7 @@ public class AnnotationTest extends HttpServlet try { InitialContext ic = new InitialContext(); - envLookupResult = "java:comp/env/com.acme.AnnotationTest/maxAmount="+ic.lookup("java:comp/env/com.acme.AnnotationTest/maxAmount"); + envLookupResult = "java:comp/env/com.acme.test.AnnotationTest/maxAmount="+ic.lookup("java:comp/env/com.acme.test.AnnotationTest/maxAmount"); } catch (Exception e) { @@ -131,7 +131,7 @@ public class AnnotationTest extends HttpServlet try { InitialContext ic = new InitialContext(); - envLookupResult3 = "java:comp/env/com.acme.AnnotationTest/avgAmount="+ic.lookup("java:comp/env/com.acme.AnnotationTest/avgAmount"); + envLookupResult3 = "java:comp/env/com.acme.test.AnnotationTest/avgAmount="+ic.lookup("java:comp/env/com.acme.test.AnnotationTest/avgAmount"); } catch (Exception e) { @@ -143,7 +143,7 @@ public class AnnotationTest extends HttpServlet try { InitialContext ic = new InitialContext(); - dsLookupResult = "java:comp/env/com.acme.AnnotationTest/myDatasource="+ic.lookup("java:comp/env/com.acme.AnnotationTest/myDatasource"); + dsLookupResult = "java:comp/env/com.acme.test.AnnotationTest/myDatasource="+ic.lookup("java:comp/env/com.acme.test.AnnotationTest/myDatasource"); } catch (Exception e) { @@ -154,7 +154,7 @@ public class AnnotationTest extends HttpServlet try { InitialContext ic = new InitialContext(); - txLookupResult = "java:comp/env/com.acme.AnnotationTest/myUserTransaction="+ic.lookup("java:comp/env/com.acme.AnnotationTest/myUserTransaction"); + txLookupResult = "java:comp/env/com.acme.test.AnnotationTest/myUserTransaction="+ic.lookup("java:comp/env/com.acme.test.AnnotationTest/myUserTransaction"); } catch (Exception e) { @@ -209,14 +209,14 @@ public class AnnotationTest extends HttpServlet __HandlesTypes = Arrays.asList( "javax.servlet.GenericServlet", "javax.servlet.http.HttpServlet", - "com.acme.AsyncListenerServlet", - "com.acme.AnnotationTest", - "com.acme.RoleAnnotationTest", - "com.acme.MultiPartTest", - "com.acme.FragmentServlet", - "com.acme.TestListener", - "com.acme.SecuredServlet", - "com.acme.Bar"); + "com.acme.test.AsyncListenerServlet", + "com.acme.test.AnnotationTest", + "com.acme.test.RoleAnnotationTest", + "com.acme.test.MultiPartTest", + "com.acme.fragment.FragmentServlet", + "com.acme.test.TestListener", + "com.acme.test.SecuredServlet", + "com.acme.test.Bar"); out.println("<h2>@ContainerInitializer</h2>"); out.println("<pre>"); out.println("@HandlesTypes({javax.servlet.Servlet.class, Foo.class})"); diff --git a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/AsyncListenerServlet.java b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/test/AsyncListenerServlet.java index 4f78352109..e89378c524 100644 --- a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/AsyncListenerServlet.java +++ b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/test/AsyncListenerServlet.java @@ -16,7 +16,7 @@ // ======================================================================== // -package com.acme; +package com.acme.test; import java.io.IOException; import java.io.PrintWriter; diff --git a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/Bar.java b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/test/Bar.java index bbb083fb08..f3bf8beda0 100644 --- a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/Bar.java +++ b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/test/Bar.java @@ -16,12 +16,12 @@ // ======================================================================== // -package com.acme; +package com.acme.test; public class Bar { - @Foo(2) + @com.acme.initializer.Foo(2) public void someMethod () { } diff --git a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/MultiPartTest.java b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/test/MultiPartTest.java index 12cbee865d..ba3f4ab3e6 100644 --- a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/MultiPartTest.java +++ b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/test/MultiPartTest.java @@ -16,7 +16,7 @@ // ======================================================================== // -package com.acme; +package com.acme.test; import java.io.IOException; import java.util.Collection; diff --git a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/RoleAnnotationTest.java b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/test/RoleAnnotationTest.java index 0958f61015..5e87c6da5a 100644 --- a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/RoleAnnotationTest.java +++ b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/test/RoleAnnotationTest.java @@ -16,7 +16,7 @@ // ======================================================================== // -package com.acme; +package com.acme.test; import java.io.IOException; diff --git a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/SecuredServlet.java b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/test/SecuredServlet.java index d542615d35..82b187022e 100644 --- a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/SecuredServlet.java +++ b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/test/SecuredServlet.java @@ -16,7 +16,7 @@ // ======================================================================== // -package com.acme; +package com.acme.test; import java.io.IOException; import java.io.PrintWriter; diff --git a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/TestListener.java b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/test/TestListener.java index e92f449138..c3107dce9e 100644 --- a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/TestListener.java +++ b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/java/com/acme/test/TestListener.java @@ -16,7 +16,7 @@ // ======================================================================== // -package com.acme; +package com.acme.test; import java.util.EventListener; import javax.annotation.PostConstruct; @@ -38,7 +38,7 @@ import javax.servlet.http.HttpSessionIdListener; import javax.servlet.http.HttpSessionListener; -@Foo(1) +@com.acme.initializer.Foo(1) @WebListener public class TestListener implements HttpSessionListener, HttpSessionAttributeListener, HttpSessionActivationListener, ServletContextListener, ServletContextAttributeListener, ServletRequestListener, ServletRequestAttributeListener { diff --git a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/webapp/META-INF/MANIFEST.MF b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/webapp/META-INF/MANIFEST.MF deleted file mode 100644 index 5e9495128c..0000000000 --- a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/webapp/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0
-Class-Path:
-
diff --git a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/webapp/WEB-INF/web.xml b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/webapp/WEB-INF/web.xml index e81ecc1ab4..c03d5c83d4 100644 --- a/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/webapp/WEB-INF/web.xml +++ b/tests/test-webapps/test-servlet-spec/test-spec-webapp/src/main/webapp/WEB-INF/web.xml @@ -9,7 +9,7 @@ <display-name>Test Annotations WebApp</display-name> <listener> - <listener-class>com.acme.TestListener</listener-class> + <listener-class>com.acme.test.TestListener</listener-class> </listener> @@ -25,7 +25,7 @@ <servlet> <servlet-name>RoleAnnotationTest</servlet-name> - <servlet-class>com.acme.RoleAnnotationTest</servlet-class> + <servlet-class>com.acme.test.RoleAnnotationTest</servlet-class> <load-on-startup>1</load-on-startup> <security-role-ref> <role-name>manager</role-name> @@ -40,7 +40,7 @@ <servlet> <servlet-name>Multi</servlet-name> - <servlet-class>com.acme.MultiPartTest</servlet-class> + <servlet-class>com.acme.test.MultiPartTest</servlet-class> <load-on-startup>2</load-on-startup> </servlet> @@ -50,7 +50,7 @@ </servlet-mapping> <env-entry> - <env-entry-name>com.acme.AnnotationTest/avgAmount</env-entry-name> + <env-entry-name>com.acme.test.AnnotationTest/avgAmount</env-entry-name> <env-entry-type>java.lang.Double</env-entry-type> <env-entry-value>1.25</env-entry-value> </env-entry> diff --git a/tests/test-webapps/test-servlet-spec/test-web-fragment/src/main/java/com/acme/FragmentServlet.java b/tests/test-webapps/test-servlet-spec/test-web-fragment/src/main/java/com/acme/fragment/FragmentServlet.java index 236a53a122..bfb28ec2bc 100644 --- a/tests/test-webapps/test-servlet-spec/test-web-fragment/src/main/java/com/acme/FragmentServlet.java +++ b/tests/test-webapps/test-servlet-spec/test-web-fragment/src/main/java/com/acme/fragment/FragmentServlet.java @@ -16,7 +16,7 @@ // ======================================================================== // -package com.acme; +package com.acme.fragment; import java.io.IOException; diff --git a/tests/test-webapps/test-servlet-spec/test-web-fragment/src/main/resources/META-INF/web-fragment.xml b/tests/test-webapps/test-servlet-spec/test-web-fragment/src/main/resources/META-INF/web-fragment.xml index e932576d74..a85aea5f03 100644 --- a/tests/test-webapps/test-servlet-spec/test-web-fragment/src/main/resources/META-INF/web-fragment.xml +++ b/tests/test-webapps/test-servlet-spec/test-web-fragment/src/main/resources/META-INF/web-fragment.xml @@ -14,7 +14,7 @@ <servlet> <servlet-name>AnnotationTest</servlet-name> - <servlet-class>com.acme.AnnotationTest</servlet-class> + <servlet-class>com.acme.test.AnnotationTest</servlet-class> <init-param> <param-name>extra1</param-name><param-value>123</param-value> </init-param> @@ -25,7 +25,7 @@ <servlet> <servlet-name>Fragment</servlet-name> - <servlet-class>com.acme.FragmentServlet</servlet-class> + <servlet-class>com.acme.fragment.FragmentServlet</servlet-class> </servlet> <servlet-mapping> |