使用osgi bundle重启服务器时,Glassfish崩溃了

时间:2012-07-11 19:19:58

标签: java glassfish osgi glassfish-3

我有一个osgi包,我成功部署在Glassfish 3.1.2上。这是捆绑激活器:

import javax.sql.DataSource;
import java.sql.SQLException;

import java.util.Properties;
import org.DX_57.osgi.SH_27.api.SessionHandle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.util.tracker.ServiceTracker;

public class SessionHandleActivator implements BundleActivator {

    // Define Datasource name
    public static final String DSNAME = "jdbc/Oracle";
    public ServiceTracker st;

    // Register the Java method as OSGI Service when the bundle is deployed
    @Override
    public void start(final BundleContext bc) throws Exception {
        debug("Session Handle 27 Activator started");

        /*
         * Register the Datasource as Service in order to be used into the
         * bundle later from the Java methods
         */
        Filter filter = bc.createFilter("(&" + "(" + Constants.OBJECTCLASS
                + "=" + DataSource.class.getName() + ")" + "(jndi-name="
                + DSNAME + ")" + ")");
        st = new ServiceTracker(bc, filter, null) {

            @Override
            public Object addingService(ServiceReference reference) {

                DataSource ds = (DataSource) bc.getService(reference);
                try {
                    debug(ds.getConnection().toString());
                    // For session handle 
                    SessionHandle sh = new SessionHandleImpl();
                    sh.setDataSource(ds);
                    /*
                     * Register the Java methods insight the bundle in order to
                     * be used
                     */
                    ServiceRegistration registerService = bc.registerService(SessionHandle.class.getName(), sh, new Properties());

                } catch (SQLException e) {
                }

                return super.addingService(reference);
            }

            @Override
            public void removedService(ServiceReference reference,
                    Object service) {
                super.removedService(reference, service);
            }
        };
        st.open();
    }

    // Remove the OSGI service when the bundle is undeployed
    @Override
    public void stop(BundleContext bc) throws Exception {
        boolean ungetService = bc.ungetService(bc.getServiceReference(SessionHandle.class.getName()));
        st.close();
        debug("Session Handle 27 Activator stopped");
    }

    // Show debug information when the OSGI bundle is deployed
    private void debug(String msg) {
        System.out.println("BundleActivator: " + msg);
    }
}

当我重新启动Glassfish服务器时,服务器崩溃,我得到了这个错误堆栈:

[#|2012-07-08T12:38:16.568+0300|INFO|glassfish3.1.2|org.glassfish.osgijavaeebase|_ThreadID=67;_ThreadName=Thread-2;|Expanded at file:/tmp/osgiapp5717459413008665895/|#]

[#|2012-07-08T12:38:17.205+0300|SEVERE|glassfish3.1.2|javax.enterprise.resource.webcontainer.jsf.config|_ThreadID=50;_ThreadName=Thread-2;|Critical error during deployment: 
com.sun.faces.config.ConfigurationException: java.util.concurrent.ExecutionException: java.net.MalformedURLException: Unknown protocol: jndi
    at com.sun.faces.config.ConfigManager.getConfigDocuments(ConfigManager.java:674)
    at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:324)
    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:225)
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:4750)
    at com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:550)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5366)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:498)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2018)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
    at com.sun.enterprise.v3.server.ApplicationLoaderService.processApplication(ApplicationLoaderService.java:375)
    at com.sun.enterprise.v3.admin.adapter.InstallerThread.load(InstallerThread.java:210)
    at com.sun.enterprise.v3.admin.adapter.InstallerThread.run(InstallerThread.java:108)
Caused by: java.util.concurrent.ExecutionException: java.net.MalformedURLException: Unknown protocol: jndi
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)
    at java.util.concurrent.FutureTask.get(FutureTask.java:111)
    at com.sun.faces.config.ConfigManager.getConfigDocuments(ConfigManager.java:672)
    ... 19 more
Caused by: java.net.MalformedURLException: Unknown protocol: jndi
    at java.net.URL.<init>(URL.java:617)
    at java.net.URL.<init>(URL.java:480)
    at java.net.URL.<init>(URL.java:429)
    at java.net.URI.toURL(URI.java:1096)
    at com.sun.faces.config.ConfigManager$ParseTask.call(ConfigManager.java:922)
    at com.sun.faces.config.ConfigManager$ParseTask.call(ConfigManager.java:867)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at com.sun.faces.config.ConfigManager.getConfigDocuments(ConfigManager.java:658)
    ... 19 more
Caused by: java.lang.IllegalStateException: Unknown protocol: jndi
    at org.apache.felix.framework.URLHandlersStreamHandlerProxy.parseURL(URLHandlersStreamHandlerProxy.java:372)
    at java.net.URL.<init>(URL.java:612)
    ... 27 more
|#]

[#|2012-07-08T12:38:17.233+0300|SEVERE|glassfish3.1.2|org.apache.catalina.core.StandardContext|_ThreadID=50;_ThreadName=Thread-2;|PWC1306: Startup of context  failed due to previous errors|#]

[#|2012-07-08T12:38:17.244+0300|SEVERE|glassfish3.1.2|org.apache.catalina.core.StandardContext|_ThreadID=50;_ThreadName=Thread-2;|PWC1305: Exception during cleanup after start failed
org.apache.catalina.LifecycleException: PWC2769: Manager has not yet been started
    at org.apache.catalina.session.StandardManager.stop(StandardManager.java:873)
    at org.apache.catalina.core.StandardContext.stop(StandardContext.java:5571)
    at com.sun.enterprise.web.WebModule.stop(WebModule.java:527)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5384)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:498)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2018)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
    at com.sun.enterprise.v3.server.ApplicationLoaderService.processApplication(ApplicationLoaderService.java:375)
    at com.sun.enterprise.v3.admin.adapter.InstallerThread.load(InstallerThread.java:210)
    at com.sun.enterprise.v3.admin.adapter.InstallerThread.run(InstallerThread.java:108)
|#]

[#|2012-07-08T12:38:17.245+0300|SEVERE|glassfish3.1.2|org.apache.catalina.core.ContainerBase|_ThreadID=50;_ThreadName=Thread-2;|ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: java.util.concurrent.ExecutionException: java.net.MalformedURLException: Unknown protocol: jndi
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5389)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:498)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2018)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
    at com.sun.enterprise.v3.server.ApplicationLoaderService.processApplication(ApplicationLoaderService.java:375)
    at com.sun.enterprise.v3.admin.adapter.InstallerThread.load(InstallerThread.java:210)
    at com.sun.enterprise.v3.admin.adapter.InstallerThread.run(InstallerThread.java:108)
Caused by: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: java.util.concurrent.ExecutionException: java.net.MalformedURLException: Unknown protocol: jndi
    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:292)
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:4750)
    at com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:550)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5366)
    ... 14 more
Caused by: com.sun.faces.config.ConfigurationException: java.util.concurrent.ExecutionException: java.net.MalformedURLException: Unknown protocol: jndi
    at com.sun.faces.config.ConfigManager.getConfigDocuments(ConfigManager.java:674)
    at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:324)
    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:225)
    ... 17 more
Caused by: java.util.concurrent.ExecutionException: java.net.MalformedURLException: Unknown protocol: jndi
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)
    at java.util.concurrent.FutureTask.get(FutureTask.java:111)
    at com.sun.faces.config.ConfigManager.getConfigDocuments(ConfigManager.java:672)
    ... 19 more
Caused by: java.net.MalformedURLException: Unknown protocol: jndi
    at java.net.URL.<init>(URL.java:617)
    at java.net.URL.<init>(URL.java:480)
    at java.net.URL.<init>(URL.java:429)
    at java.net.URI.toURL(URI.java:1096)
    at com.sun.faces.config.ConfigManager$ParseTask.call(ConfigManager.java:922)
    at com.sun.faces.config.ConfigManager$ParseTask.call(ConfigManager.java:867)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at com.sun.faces.config.ConfigManager.getConfigDocuments(ConfigManager.java:658)
    ... 19 more
Caused by: java.lang.IllegalStateException: Unknown protocol: jndi
    at org.apache.felix.framework.URLHandlersStreamHandlerProxy.parseURL(URLHandlersStreamHandlerProxy.java:372)
    at java.net.URL.<init>(URL.java:612)
    ... 27 more
|#]

[#|2012-07-08T12:38:17.250+0300|INFO|glassfish3.1.2|org.apache.catalina.startup.ContextConfig|_ThreadID=12;_ThreadName=Thread-2;|No default web.xml|#]

[#|2012-07-08T12:38:17.253+0300|WARNING|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=50;_ThreadName=Thread-2;|java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: java.util.concurrent.ExecutionException: java.net.MalformedURLException: Unknown protocol: jndi
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: java.util.concurrent.ExecutionException: java.net.MalformedURLException: Unknown protocol: jndi
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:921)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2018)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
    at com.sun.enterprise.v3.server.ApplicationLoaderService.processApplication(ApplicationLoaderService.java:375)
    at com.sun.enterprise.v3.admin.adapter.InstallerThread.load(InstallerThread.java:210)
    at com.sun.enterprise.v3.admin.adapter.InstallerThread.run(InstallerThread.java:108)
|#]

[#|2012-07-08T12:38:17.254+0300|SEVERE|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=50;_ThreadName=Thread-2;|Exception while invoking class com.sun.enterprise.web.WebApplication start method
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: java.util.concurrent.ExecutionException: java.net.MalformedURLException: Unknown protocol: jndi
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:138)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
    at com.sun.enterprise.v3.server.ApplicationLoaderService.processApplication(ApplicationLoaderService.java:375)
    at com.sun.enterprise.v3.admin.adapter.InstallerThread.load(InstallerThread.java:210)
    at com.sun.enterprise.v3.admin.adapter.InstallerThread.run(InstallerThread.java:108)
|#]

[#|2012-07-08T12:38:17.254+0300|SEVERE|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=50;_ThreadName=Thread-2;|Exception while loading the app|#]

[#|2012-07-08T12:38:17.258+0300|INFO|glassfish3.1.2|org.glassfish.osgihttp|_ThreadID=12;_ThreadName=Thread-2;|standardContext = StandardEngine[glassfish-web].StandardHost[__asadmin].StandardContext[/osgi]|#]

[#|2012-07-08T12:38:17.301+0300|SEVERE|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=50;_ThreadName=Thread-2;|Exception while loading the app|#]

你能帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

我认为你的软件包在重新启动时过早启动。有些东西注册了jndi url协议,第一次运行正常,因为在部署它时已经发生了这种情况,但是第二次时间,OSGi环境重新启动,并且在JNDI注册之前更早地重新启动作为有效的协议。

我不是Glassfish的大师,我不确定这里最好的方法是什么,也许你可以通过指定org.osgi.framework.storage.clean来阻止整个复活过程,也许你可以提高开始水平您的捆绑包(因此它将在稍后启动)并防止出现此问题,也许您可​​以以某种方式检测jndi协议何时注册并等待它?