diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/DefaultJettyAtJettyHomeHelper.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/DefaultJettyAtJettyHomeHelper.java index eaaa3a1ea70..ca30bb18a80 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/DefaultJettyAtJettyHomeHelper.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/DefaultJettyAtJettyHomeHelper.java @@ -31,6 +31,7 @@ import java.util.StringTokenizer; import org.eclipse.jetty.osgi.boot.JettyBootstrapActivator; import org.eclipse.jetty.osgi.boot.OSGiServerConstants; import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelperFactory; +import org.eclipse.jetty.osgi.boot.utils.OSGiClassLoader; import org.eclipse.jetty.osgi.boot.utils.Util; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.util.log.Log; @@ -166,7 +167,16 @@ public class DefaultJettyAtJettyHomeHelper ClassLoader contextCl = Thread.currentThread().getContextClassLoader(); try { - Thread.currentThread().setContextClassLoader(JettyBootstrapActivator.class.getClassLoader()); + ClassLoader cl; + if (jettyHomeBundle != null) + { + cl = new OSGiClassLoader(JettyBootstrapActivator.class.getClassLoader(),jettyHomeBundle); + } + else + { + cl = JettyBootstrapActivator.class.getClassLoader(); + } + Thread.currentThread().setContextClassLoader(cl); // these properties usually are the ones passed to this type of // configuration. diff --git a/jetty-osgi/test-jetty-osgi/pom.xml b/jetty-osgi/test-jetty-osgi/pom.xml index b187acf1780..0fa01522f94 100644 --- a/jetty-osgi/test-jetty-osgi/pom.xml +++ b/jetty-osgi/test-jetty-osgi/pom.xml @@ -64,6 +64,13 @@ ${url.version} test + + + org.ops4j.pax.tinybundles + tinybundles + 2.1.1 + + + + + + + + + + + + + + + 10 + 200 + + + + + + + + + + + + + + + + + + + + + + + + + + + + https + + 32768 + 8192 + 8192 + true + false + 512 + + + + + + + true + 1000 + false + false + + + + + + + org.eclipse.jetty.webapp.configuration + + + + + org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration + org.eclipse.jetty.webapp.WebXmlConfiguration + org.eclipse.jetty.webapp.MetaInfConfiguration + org.eclipse.jetty.webapp.FragmentConfiguration + org.eclipse.jetty.webapp.JettyWebXmlConfiguration + + + + + + + + + java.naming.factory.initial + + + + java.naming.factory.url.pkgs + + + + diff --git a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/SomeCustomBean.java b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/SomeCustomBean.java new file mode 100644 index 00000000000..57a676bb173 --- /dev/null +++ b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/SomeCustomBean.java @@ -0,0 +1,27 @@ +// +// ======================================================================== +// Copyright (c) 1995-2016 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.osgi.test; + +/** + * Just a simple bean + * + * @author laeubi + * + */ +public class SomeCustomBean { + +} diff --git a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootWithBundle.java b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootWithBundle.java new file mode 100644 index 00000000000..6c66d81ff40 --- /dev/null +++ b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootWithBundle.java @@ -0,0 +1,139 @@ +// +// ======================================================================== +// Copyright (c) 1995-2016 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.osgi.test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.inject.Inject; + +import org.codehaus.plexus.util.IOUtil; +import org.eclipse.jetty.client.HttpClient; +import org.eclipse.jetty.client.api.ContentResponse; +import org.eclipse.jetty.http.HttpStatus; +import org.eclipse.jetty.osgi.boot.OSGiServerConstants; +import org.eclipse.jetty.server.handler.ContextHandler; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.CoreOptions; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.tinybundles.core.TinyBundle; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.framework.ServiceReference; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.ops4j.pax.exam.CoreOptions.mavenBundle; +import static org.ops4j.pax.exam.CoreOptions.options; +import static org.ops4j.pax.exam.CoreOptions.systemProperty; + +/** + * TestJettyOSGiBootWithBundle + * + * Tests reading config from a bundle and loading clases from it + * + * Tests the ServiceContextProvider. + * + */ +@RunWith(PaxExam.class) +public class TestJettyOSGiBootWithBundle +{ + private static final String TEST_JETTY_HOME_BUNDLE = "test-jetty-xml-bundle"; + + + private static final String LOG_LEVEL = "WARN"; + + + @Inject + BundleContext bundleContext = null; + + @Configuration + public static Option[] configure() throws IOException + { + ArrayList