Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception on deploy of Fighterfish HTTP HelloWorld Sample to Payara #30

Open
dhubbard-ag opened this issue Feb 22, 2019 · 3 comments
Open
Assignees

Comments

@dhubbard-ag
Copy link

Hi

I am trying to run fighterfish osgihttp example in Payara 5.184 without success.

When deploying the built jar file via asadmin command line to a new domain the following exception

[2019-02-20T03:06:51.282+0000] [Payara 5.184] [SEVERE] [] [] [tid: _ThreadID=46 _ThreadName=admin-thread-pool::admin-listener(1)] [timeMillis: 1550632011282] [levelValue: 1000] [[
  java.lang.NullPointerException
        at com.sun.web.security.RealmAdapter.setVirtualServer(RealmAdapter.java:525)
        at com.sun.enterprise.web.WebModule.setParent(WebModule.java:799)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:953)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:939)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:684)
        at org.glassfish.osgihttp.Activator.createRootWebModule(Activator.java:185)
        at org.glassfish.osgihttp.Activator.doActualWork(Activator.java:124)
        at org.glassfish.osgihttp.Activator.access$300(Activator.java:84)
        at org.glassfish.osgihttp.Activator$OSGiHtttpExtender.start(Activator.java:332)
        at org.glassfish.osgijavaeebase.ExtenderManager$ExtenderTracker.addingService(ExtenderManager.java:144)
        at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)
        at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:870)
        at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
        at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
        at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:901)
        at org.apache.felix.framework.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:990)
        at org.apache.felix.framework.EventDispatcher.fireEventImmediately(EventDispatcher.java:838)
        at org.apache.felix.framework.EventDispatcher.fireServiceEvent(EventDispatcher.java:545)
        at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:4595)
        at org.apache.felix.framework.Felix.registerService(Felix.java:3587)
        at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:348)
        at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:322)
        at org.glassfish.osgihttp.Activator.start(Activator.java:105)
        at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:697)
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:2240)
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2224)
        at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1607)
        at org.apache.felix.framework.BundleWiringImpl.access$200(BundleWiringImpl.java:80)
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2053)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1414)
        at org.apache.felix.framework.BundleWiringImpl.searchImports(BundleWiringImpl.java:1660)
        at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1590)
        at org.apache.felix.framework.BundleWiringImpl.access$200(BundleWiringImpl.java:80)
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2053)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at org.glassfish.fighterfish.sample.osgihttp.helloworld.HelloWorldHttpActivator.start(HelloWorldHttpActivator.java:39)
        at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:697)
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:2240)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:2146)

... deleted serveral lines

org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:33)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:114)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
        at java.lang.Thread.run(Thread.java:748)
]]

The line

at org.glassfish.fighterfish.sample.osgihttp.helloworld.HelloWorldHttpActivator.start(HelloWorldHttpActivator.java:39)

is

tracker = new ServiceTracker(context, HttpService.class.getName(), null) {

I created a new domain

./asadmin create-domain --portbase 16000 osgi-sample

and Deployed OSGI bundle via command line

./asadmin --port 16048 deploy --type osgi --force /usr/local/gfdeploy/sample.osgihttp.helloworld.jar

I posted this initially in the Payara forum

@ErikEngerd
Copy link

I have the same issue. In my case I am using the default domain domain1 and I get this exception after deploying the OSGI admin console web interface.

The installation was done by unpacking glassfish-osgi-gui-5.0-b24.zip and glassfish-osgi-http-5.0-b24.zip into the payara installation. Both of these zip files where obtained from maven.glassfish.org.

@bjetal
Copy link
Contributor

bjetal commented Jan 7, 2020

Payara has changed several things in the web application code where the current approach to creating the WebModule used by the HttpService will not work. Instead it appears to be necessary to use WebContainer.loadWebModule to create the WebModule. The following patch works for us on both Payara 5.194 and Glassfish 5.1:

diff --git a/module/osgi-http/src/main/java/org/glassfish/osgihttp/Activator.java b/module/osgi-http/src/main/java/org/glassfish/osgihttp/Activator.java
index bc711f0..7af6f22 100644
--- a/module/osgi-http/src/main/java/org/glassfish/osgihttp/Activator.java
+++ b/module/osgi-http/src/main/java/org/glassfish/osgihttp/Activator.java
@@ -19,17 +19,22 @@ import com.sun.enterprise.config.serverbeans.Config;
 import com.sun.enterprise.config.serverbeans.Domain;
 import com.sun.enterprise.config.serverbeans.Server;
 import com.sun.enterprise.config.serverbeans.VirtualServer;
+import com.sun.enterprise.deployment.Application;
+import com.sun.enterprise.util.Result;
 import com.sun.enterprise.web.WebContainer;
 import com.sun.enterprise.web.WebModule;
 import com.sun.enterprise.web.WebModuleConfig;
+import java.io.File;
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.session.StandardManager;
-import org.apache.catalina.startup.ContextConfig;
 import org.glassfish.api.admin.ServerEnvironment;
 import org.glassfish.embeddable.GlassFish;
 import org.glassfish.embeddable.GlassFishException;
 import org.glassfish.internal.api.ClassLoaderHierarchy;
 import org.glassfish.osgijavaeebase.Extender;
+import org.glassfish.web.deployment.descriptor.SessionConfigDescriptor;
+import org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl;
+import org.glassfish.web.loader.WebappClassLoader;
 import org.glassfish.web.valve.GlassFishValve;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
@@ -138,11 +143,12 @@ public final class Activator implements BundleActivator {
         String defaultVsId = getDefaultVirtualServer();
         final StringTokenizer vsIds = new StringTokenizer(
                 getAllVirtualServers(), ",");
+        WebModuleConfig wmConfig = createConfiguration();
         while (vsIds.hasMoreTokens()) {
             String vsId = vsIds.nextToken().trim();
             try {
                 WebModule standardContext = createRootWebModule(webContainer,
-                        vsId);
+                        wmConfig, vsId);
                 if (standardContext == null) {
                     LOGGER.logp(Level.WARNING, "Activator", "doActualWork",
                             "GlassFishHttpService will not be available"
@@ -169,16 +175,50 @@ public final class Activator implements BundleActivator {
         }
     }
 
+    /**
+     * Create a web module configuration for the /osgi context
+     * @return The created configuration
+     * @throws GlassFishException on failure to determine the root class loader
+     */
+    private WebModuleConfig createConfiguration() throws GlassFishException {
+        contextPath = bctx.getProperty(CONTEXT_PATH_PROP);
+        if (contextPath == null) {
+            contextPath = "/osgi"; // default value
+        }
+        // create a new context under which all OSGi HTTP wrappers
+        // will be registered.
+        WebModuleConfig wmConfig = new WebModuleConfig();
+        wmConfig.setWorkDirBase(System.getProperty("java.io.tmpdir"));
+        WebBundleDescriptorImpl wbd = new WebBundleDescriptorImpl();
+        Application app = Application.createApplication();
+        app.setVirtual(true);
+        app.setName(contextPath);
+        wbd.setApplication(app);
+        wbd.setContextRoot(contextPath);
+        wbd.setModuleID(contextPath);
+        wbd.setSessionConfig(new SessionConfigDescriptor());
+        wmConfig.setDescriptor(wbd);
+        WebappClassLoader appClassLoader =
+                new WebappClassLoader(getCommonClassLoader(gf));
+        appClassLoader.start();
+        wmConfig.setAppClassLoader(appClassLoader);
+        // TODO(Sahoo): Need to set proper values for these directories
+        wmConfig.setLocation(new File(System.getProperty("java.io.tmpdir")));
+        wmConfig.setWorkDir(System.getProperty("java.io.tmpdir"));
+        return wmConfig;
+    }
+
     /**
      * Create the root web module.
      * @param webContainer the glassfish web container
+     * @param wmConfig the configuration for the module
      * @param vsId the virtual server id
      * @return WebModule
-     * @throws Exception if an error occurs
+     * @throws GlassFishException if an error occurs
      */
-    private WebModule createRootWebModule(final WebContainer webContainer,
-            final String vsId) throws Exception {
-
+    private WebModule createRootWebModule(WebContainer webContainer,
+                                          WebModuleConfig wmConfig,
+                                          String vsId) {
         Engine engine = webContainer.getEngine();
         Host vs = (Host) engine.findChild(vsId);
         if (vs == null) {
@@ -187,45 +227,24 @@ public final class Activator implements BundleActivator {
             return null;
         }
         vss.put(vsId, vs);
-        contextPath = bctx.getProperty(CONTEXT_PATH_PROP);
-        if (contextPath == null) {
-            contextPath = "/osgi"; // default value
+        List<Result<WebModule>> results = webContainer.loadWebModule(wmConfig, "null", null);
+        for (Result<WebModule> r : results) {
+            if (r.isFailure()) {
+                LOGGER.logp(Level.WARNING, "Activator", "doActualWork",
+                        "GlassFishHttpService will not be available for for virtual server, " +
+                                "because we are not able to create root web app.", r.exception());
+                continue;
+            }
+            WebModule standardContext = r.result();
+            // Force the module to fall back on the virtual server security
+            standardContext.setRealm(null);
+            standardContext.addValve((GlassFishValve) new OSGiHttpContextValve());
+            switchOffSessionPersistence(standardContext);
+            LOGGER.logp(Level.INFO, "Activator", "createRootWebModule", "standardContext = {0}",
+                    new Object[]{standardContext});
+            return standardContext;
         }
-        // create a new context under which all OSGi HTTP wrappers
-        // will be registered.
-        final WebModule standardContext = new WebModule();
-        standardContext.setWebContainer(webContainer);
-        standardContext.setName(contextPath);
-        standardContext.setPath(contextPath);
-        // TODO(Sahoo): Need to set proper values for these directories
-        standardContext.setDocBase(System.getProperty("java.io.tmpdir"));
-        standardContext.setWorkDir(System.getProperty("java.io.tmpdir"));
-//         standardContext.setJ2EEServer(
-//                 System.getProperty("com.sun.aas.instanceName"));
-        standardContext.setJ2EEServer(getInstanceName());
-        standardContext.addLifecycleListener(new ContextConfig());
-        Realm realm = gf.getService(Realm.class);
-        standardContext.setRealm(realm);
-        WebModuleConfig wmConfig = new WebModuleConfig();
-        wmConfig.setWorkDirBase(System.getProperty("java.io.tmpdir"));
-        wmConfig.setVirtualServers(vsId);
-
-        // Setting it in WebModuleConfig does not work, Ceck with Jan.
-//        wmConfig.setAppClassLoader(getCommonClassLoader());
-        standardContext.setParentClassLoader(getCommonClassLoader(gf));
-        standardContext.setWebModuleConfig(wmConfig);
-
-        // See  See GLASSFISH-16764 for more details about this valve
-        standardContext.addValve((GlassFishValve) new OSGiHttpContextValve());
-        // Since there is issue about locating user classes that are part
-        // of some OSGi bundle while deserializing, we switch off session
-        // persistence.
-        switchOffSessionPersistence(standardContext);
-        vs.addChild(standardContext);
-        LOGGER.logp(Level.INFO, "Activator", "createRootWebModule",
-                "standardContext = {0}",
-                new Object[]{standardContext});
-        return standardContext;
+        return null;
     }
 
     /**
diff --git a/module/osgi-http/src/main/java/org/glassfish/osgihttp/GlassFishHttpService.java b/module/osgi-http/src/main/java/org/glassfish/osgihttp/GlassFishHttpService.java
index be72949..b50e59e 100644
--- a/module/osgi-http/src/main/java/org/glassfish/osgihttp/GlassFishHttpService.java
+++ b/module/osgi-http/src/main/java/org/glassfish/osgihttp/GlassFishHttpService.java
@@ -16,6 +16,7 @@
 package org.glassfish.osgihttp;
 
 import com.sun.enterprise.web.WebModule;
+import com.sun.web.server.J2EEInstanceListener;
 import org.apache.catalina.Container;
 import org.osgi.service.http.HttpContext;
 import org.osgi.service.http.NamespaceException;
@@ -90,6 +91,9 @@ public final class GlassFishHttpService {
                 wrapperName, servlet, servletConfig, convert(alias),
                 servletContext);
         wrapper.addValve((GlassFishValve) new OSGiSecurityValve(httpContext));
+        // We need this for Payara to ensure that invocation contexts are set
+        // up during servlet execution.
+        wrapper.addInstanceListener(new J2EEInstanceListener());
         context.addChild(wrapper);
         try {
             wrapper.initializeServlet();
@@ -131,6 +135,9 @@ public final class GlassFishHttpService {
                 wrapperName, servlet, servletConfig, convert(alias),
                 servletContext);
         wrapper.addValve((GlassFishValve) new OSGiSecurityValve(httpContext));
+        // We need this for Payara to ensure that invocation contexts are set up
+        // during servlet execution.
+        wrapper.addInstanceListener(new J2EEInstanceListener());
         context.addChild(wrapper);
         try {
             wrapper.initializeServlet();

@bshannon
Copy link

@romain-grecourt can you review this?

@romain-grecourt romain-grecourt self-assigned this Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants