commit 583eca8519ef918000904f8ba9d38e67ce3f4876 Author: Sanjeeb Sahoo Date: Tue Oct 16 23:22:29 2012 +0530 GLASSFISH-18880: Fail to open OSGi console from GF admin console or URL Starting with gf3.1.2, under certain circumastances, adminconsole by a postStartup service [1]. Starting with gf3.1.2, we also started usig start levels to start autostart bundles. Autostart bundles start by a startlevel thread. So, once server is up, there are two threads which are running concurrently - one the start level thread which is changing the start level to final start level and the other one is loading adminconsole. This is resulting in all sorts of issues. First - the org.osgi.framework.BundleException: Cannot start bundle org.glassfish.admingui.glassfish-osgi-console-plugin [329] because its start level is 2, which is greater than the framework's start level of 1. This is happening because glassfish-osgi-console-plugin.jar is installed in autostart dir and it gets a start level of 2. It can be activated even at framework start level of 1 when adminconsole installer thread is trying to load the console. So, we should really fix the package to install this jar in modules/ dir. Second - once we get past the first issue, we see the second issue of "Unknown protocol: jndi." It happens because of a combination of issues. One of the glassfish modules called web-glue has an activator which registers a URL handler service in OSGi service registry. Until this service is registered, we can't use URLs with jndi scheme. Our web container relies on jndi URL scheme internally. We expected web-glue to be activated before web container is used. We have code in HK2/osgi-adapter that actually starts a bundle if a bundle is not started yet before it loads a HK2 service from a bundle. But, due to this Felix bug [2], our bundle is not getting activated. What we noticed is that when webconsole is installed, osgi-http module gets activated when start level changes to 2. During osgi-http module activation, it loads WebContainer. But due to this Felix bug, web-glue's activator is not called, yet WebContainer service has been made available. Later on when console thread tried to start console, it never tried to start web-glue again. As a result, the activator of web-glue never got called and hence nobody registered jndi protocol handler. To fix the second issue, I propose that we register jndi protocol handler via a GlassFish startup service. Since we can't start web-glue by default, I have moved the activator to web-naming. web-naming has very few dependencies and as such it is the right module to register the url handler service. [1] https://blogs.oracle.com/anilam/entry/glassfish_3_1_2_admin [2] https://issues.apache.org/jira/browse/FELIX-3713 diff --git a/appserver/packager/glassfish-osgi-gui/pom.xml b/appserver/packager/glassfish-osgi-gui/pom.xml index 0164a76..8974ce7 100644 --- a/appserver/packager/glassfish-osgi-gui/pom.xml +++ b/appserver/packager/glassfish-osgi-gui/pom.xml @@ -75,19 +75,34 @@ copy-dependencies - copy-dependencies + copy - ${project.build.directory}/stage/${install.dir.name}/glassfish/modules/autostart false true true - compile - runtime true - - - + + + org.apache.felix + org.apache.felix.webconsole + ${project.build.directory}/stage/${install.dir.name}/glassfish/modules/autostart + + + org.glassfish.main.osgi-platforms + felix-webconsole-extension + ${project.build.directory}/stage/${install.dir.name}/glassfish/modules/autostart + + + + org.glassfish.main.admingui + glassfish-osgi-console-plugin + ${project.build.directory}/stage/${install.dir.name}/glassfish/modules + + + + + diff --git a/appserver/web/web-glue/osgi.bundle b/appserver/web/web-glue/osgi.bundle index 6854748..55a007c 100644 --- a/appserver/web/web-glue/osgi.bundle +++ b/appserver/web/web-glue/osgi.bundle @@ -81,8 +81,6 @@ Import-Package: \ net.sf.cglib.core, \ * -Bundle-Activator: org.glassfish.web.DirContextURLStreamHandlerService - # This is required because WebContainer requires JavaEEUtils service which is provided by ejb-container. # Having this forces resolver to also pull in ejb-container. # web-ha is required because web container might require this when ha is enabled. diff --git a/appserver/web/web-glue/pom.xml b/appserver/web/web-glue/pom.xml index 4a9d1be..337dd40 100755 --- a/appserver/web/web-glue/pom.xml +++ b/appserver/web/web-glue/pom.xml @@ -222,12 +222,6 @@ ${project.version} - - org.osgi - org.osgi.core - provided - - org.glassfish.main.web web-gui-plugin-common ${project.version} diff --git a/appserver/web/web-glue/src/main/java/org/glassfish/web/DirContextURLStreamHandlerService.java b/appserver/web/web-glue/src/main/java/org/glassfish/web/DirContextURLStreamHandlerService.java deleted file mode 100644 index 2061ec8..0000000 --- a/appserver/web/web-glue/src/main/java/org/glassfish/web/DirContextURLStreamHandlerService.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) 2008-2011 Oracle and/or its affiliates. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can - * obtain a copy of the License at - * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html - * or packager/legal/LICENSE.txt. See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at packager/legal/LICENSE.txt. - * - * GPL Classpath Exception: - * Oracle designates this particular file as subject to the "Classpath" - * exception as provided by Oracle in the GPL Version 2 section of the License - * file that accompanied this code. - * - * Modifications: - * If applicable, add the following below the License Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyright [year] [name of copyright owner]" - * - * Contributor(s): - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - */ - -package org.glassfish.web; - -import org.apache.naming.resources.DirContextURLStreamHandler; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.service.url.AbstractURLStreamHandlerService; -import org.osgi.service.url.URLConstants; -import org.osgi.service.url.URLStreamHandlerService; - -import java.io.IOException; -import java.net.URL; -import java.net.URLConnection; -import java.util.Properties; - -/** - * This class is responsible for adding {@code DirContextURLStreamHandler} - * to OSGi service registry. - * - * @author Sanjeeb.Sahoo@Sun.COM - */ -public class DirContextURLStreamHandlerService - extends AbstractURLStreamHandlerService - implements BundleActivator { - - // We have to extend DirContextURLStreamHandler so that we - // can make openConnection and toExternalForm available as - // public methods. - private static class DelegatingDirContextURLStreamHandler - extends DirContextURLStreamHandler{ - @Override - public URLConnection openConnection(URL u) throws IOException { - return super.openConnection(u); - } - - @Override - public String toExternalForm(URL u) { - return super.toExternalForm(u); - } - } - - public URLConnection openConnection(URL u) throws IOException { - return new DelegatingDirContextURLStreamHandler().openConnection(u); - } - - @Override - public String toExternalForm(URL u) { - return new DelegatingDirContextURLStreamHandler().toExternalForm(u); - } - - public void start(BundleContext context) throws Exception { - Properties p = new Properties(); - p.put(URLConstants.URL_HANDLER_PROTOCOL, - new String[]{"jndi"}); - context.registerService( - URLStreamHandlerService.class.getName(), - this, - p); - } - - public void stop(BundleContext context) throws Exception { - } -} diff --git a/appserver/web/web-naming/osgi.bundle b/appserver/web/web-naming/osgi.bundle index 83c098c..721a554 100644 --- a/appserver/web/web-naming/osgi.bundle +++ b/appserver/web/web-naming/osgi.bundle @@ -45,3 +45,5 @@ org.apache.naming.resources; \ org.apache.naming.resources.jndi; version=${project.osgi.version} +Bundle-Activator: org.apache.naming.resources.DirContextURLStreamHandlerService + diff --git a/appserver/web/web-naming/pom.xml b/appserver/web/web-naming/pom.xml index aa09397..8d54114 100755 --- a/appserver/web/web-naming/pom.xml +++ b/appserver/web/web-naming/pom.xml @@ -87,5 +87,17 @@ logging-annotation-processor true + + + org.osgi + org.osgi.core + provided + + + + org.glassfish.main.common + glassfish-api + ${project.version} + diff --git a/appserver/web/web-naming/src/main/java/org/apache/naming/resources/DirContextURLStreamHandlerService.java b/appserver/web/web-naming/src/main/java/org/apache/naming/resources/DirContextURLStreamHandlerService.java new file mode 100644 index 0000000..06b5332 --- /dev/null +++ b/appserver/web/web-naming/src/main/java/org/apache/naming/resources/DirContextURLStreamHandlerService.java @@ -0,0 +1,113 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2008-2012 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html + * or packager/legal/LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at packager/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package org.apache.naming.resources; + +import org.apache.naming.resources.DirContextURLStreamHandler; +import org.glassfish.api.Startup; +import org.glassfish.api.StartupRunLevel; +import org.glassfish.hk2.runlevel.RunLevel; +import org.jvnet.hk2.annotations.Service; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.service.url.AbstractURLStreamHandlerService; +import org.osgi.service.url.URLConstants; +import org.osgi.service.url.URLStreamHandlerService; + +import java.io.IOException; +import java.net.URL; +import java.net.URLConnection; +import java.util.Properties; + +/** + * This class is responsible for adding {@code DirContextURLStreamHandler} + * to OSGi service registry. + * + * It is both an activator as well as marked as a Startup service. + * + * The Startup service ensures that this bundle gets activated during server startup and the activator ensures that + * we register a jndi protocol handler. + * + * @author Sanjeeb.Sahoo@Sun.COM + */ +@Service +@RunLevel(StartupRunLevel.VAL) +public class DirContextURLStreamHandlerService + extends AbstractURLStreamHandlerService + implements URLStreamHandlerService, BundleActivator { + + // We have to extend DirContextURLStreamHandler so that we + // can make openConnection and toExternalForm available as + // public methods. + private static class DelegatingDirContextURLStreamHandler + extends DirContextURLStreamHandler{ + @Override + public URLConnection openConnection(URL u) throws IOException { + return super.openConnection(u); + } + + @Override + public String toExternalForm(URL u) { + return super.toExternalForm(u); + } + } + + public URLConnection openConnection(URL u) throws IOException { + return new DelegatingDirContextURLStreamHandler().openConnection(u); + } + + @Override + public String toExternalForm(URL u) { + return new DelegatingDirContextURLStreamHandler().toExternalForm(u); + } + + public void start(BundleContext context) throws Exception { + Properties p = new Properties(); + p.put(URLConstants.URL_HANDLER_PROTOCOL, + new String[]{"jndi"}); + context.registerService( + URLStreamHandlerService.class.getName(), + this, + p); + } + + public void stop(BundleContext context) throws Exception { + } +}