From 7557f558014df0d00920fabeb10728fa670fdc39 Mon Sep 17 00:00:00 2001 From: Jakub Podlesak Date: Thu, 6 Sep 2012 23:48:01 +0200 Subject: [PATCH] Fix for JERSEY-1404 Change-Id: Id3df1a27664caaeb594e74b9f67b4d261cf54565 --- .gitignore | 4 +++- .../glassfish/jersey/internal/OsgiRegistry.java | 17 +++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 0b52e8972f..68444167c1 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,6 @@ examples/helloworld-pure-jax-rs/nb-configuration.xml examples/helloworld/nb-configuration.xml examples/osgi-http-service/bundle/nb-configuration.xml examples/osgi-http-service/functional-test/nb-configuration.xml -tests/e2e/nb-configuration.xml \ No newline at end of file +tests/e2e/nb-configuration.xml +core-server/nb-configuration.xml +tests/integration/servlet-tests/nb-configuration.xml \ No newline at end of file diff --git a/core-common/src/main/java/org/glassfish/jersey/internal/OsgiRegistry.java b/core-common/src/main/java/org/glassfish/jersey/internal/OsgiRegistry.java index b7a6da032c..7187abc4b1 100644 --- a/core-common/src/main/java/org/glassfish/jersey/internal/OsgiRegistry.java +++ b/core-common/src/main/java/org/glassfish/jersey/internal/OsgiRegistry.java @@ -66,6 +66,7 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleReference; +import org.osgi.framework.FrameworkUtil; import org.osgi.framework.SynchronousBundleListener; /** @@ -105,7 +106,10 @@ public static synchronized OsgiRegistry getInstance() { if (instance == null) { final ClassLoader classLoader = ReflectionHelper.class.getClassLoader(); if (classLoader instanceof BundleReference) { - instance = new OsgiRegistry(classLoader); + BundleContext context = FrameworkUtil.getBundle(OsgiRegistry.class).getBundleContext(); + if (context != null) { // context could be still null in GlassFish + instance = new OsgiRegistry(context); + } } } return instance; @@ -337,15 +341,12 @@ public Class classForNameWithException(final String className) throws ClassNo /** * Creates a new OsgiRegistry instance bound to a particular OSGi runtime. - * The only parameter must be an instance of a {@link BundleReference}. - * The parameter is typed as an Object to protect callers from having - * to load OSGi classes directly. + * The only parameter must be an instance of a {@link BundleContext}. * - * @param bundleReference must be a non-null instance of a BundleReference + * @param bundleContext must be a non-null instance of a BundleContext */ - private OsgiRegistry(Object bundleReference) { - BundleReference br = (BundleReference)bundleReference; - bundleContext = br.getBundle().getBundleContext(); + private OsgiRegistry(BundleContext bundleContext) { + this.bundleContext = bundleContext; } /**