[GLASSFISH-21173] Glassfish / Jersey throws NPE on startup for versioned applications Created: 25/Aug/14  Updated: 23/Oct/14

Status: Open
Project: glassfish
Component/s: jax-rs
Affects Version/s: 4.1
Fix Version/s: None

Type: Bug Priority: Critical
Reporter: lprimak Assignee: Marek Potociar
Resolution: Unresolved Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Initiating Jersey application, version Jersey: 2.10.4 2014-08-08 15:09:00…]]
Glassfish 4.1 promoted build downloaded August 20th, 2014


Tags: jersey

 Description   

Application fails to start in a Availability-enabled clustered environment.
The application works in the same domain when not deployed as a versioned application.

The failure only happens when versioned, i.e. my_app:20140824
I think some parts of GF are broken with this naming convention now.
This is crucial for clusters as it supports hot-deployment.
I believe other parts of Glassfish are broken in regards to application versioning

Application versioning is as described here:
https://weblogs.java.net/blog/serli/archive/2010/08/30/how-use-glassfish-application-versioning?force=354

Related issues:
https://java.net/jira/browse/GLASSFISH-21171
https://java.net/jira/browse/JERSEY-2626

Here is the NPE:
[2014-08-24T05:28:38.406-0400] [glassfish 4.1] [INFO] [] [org.glassfish.jersey.server.ApplicationHandler] [tid: _ThreadID=18 _ThreadName=RunLevelControllerThread-1408872414218] [timeMillis: 1408872518406] [l
evelValue: 800] [[
Initiating Jersey application, version Jersey: 2.10.4 2014-08-08 15:09:00...]]
[2014-08-24T05:28:38.787-0400] [glassfish 4.1] [SEVERE] [] [javax.enterprise.web] [tid: _ThreadID=18 _ThreadName=RunLevelControllerThread-1408872414218] [timeMillis: 1408872518787] [levelValue: 1000] [[
WebModule[/stage]StandardWrapper.Throwable
java.lang.NullPointerException
at org.glassfish.jersey.gf.ejb.internal.EjbComponentProvider.registerEjbInterceptor(EjbComponentProvider.java:169)
at org.glassfish.jersey.gf.ejb.internal.EjbComponentProvider.bind(EjbComponentProvider.java:251)
at org.glassfish.jersey.server.ApplicationHandler.bindWithComponentProvider(ApplicationHandler.java:903)
at org.glassfish.jersey.server.ApplicationHandler.bindProvidersAndResources(ApplicationHandler.java:832)
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:435)
at org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:163)
at org.glassfish.jersey.server.ApplicationHandler$3.run(ApplicationHandler.java:323)
at org.glassfish.jersey.internal.Errors$2.call(Errors.java:289)
at org.glassfish.jersey.internal.Errors$2.call(Errors.java:286)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:286)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:320)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:285)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:310)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:358)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1583)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1382)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5704)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5946)
at com.sun.enterprise.web.WebModule.start(WebModule.java:691)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1041)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2286)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1932)
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:139)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:291)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:352)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:500)
at com.sun.enterprise.v3.server.ApplicationLoaderService.processApplication(ApplicationLoaderService.java:406)
at com.sun.enterprise.v3.server.ApplicationLoaderService.postConstruct(ApplicationLoaderService.java:243)
at org.jvnet.hk2.internal.ClazzCreator.postConstructMe(ClazzCreator.java:329)
at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:377)
at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:461)
at org.glassfish.hk2.runlevel.internal.AsyncRunLevelContext.findOrCreate(AsyncRunLevelContext.java:227)
at org.glassfish.hk2.runlevel.RunLevelContext.findOrCreate(RunLevelContext.java:84)
at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2258)
at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:105)
at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:87)
at org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.oneJob(CurrentTaskFuture.java:1162)
at org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.run(CurrentTaskFuture.java:1147)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)



 Comments   
Comment by lprimak [ 26/Aug/14 ]

Looks like the code points to this:

final Object interceptor = new EjbComponentInterceptor(locator);
165 initialContext = getInitialContext();
166 final EjbContainerUtil ejbUtil = EjbContainerUtilImpl.getInstance();
167 final ApplicationInfo appInfo = ejbUtil.getDeployment().get((String)initialContext.lookup("java:app/AppName"));
168 final List<String> tempLibNames = new LinkedList<String>();
169 for (ModuleInfo moduleInfo : appInfo.getModuleInfos()) {
170 final String jarName = moduleInfo.getName();
171 if (jarName.endsWith(".jar")) {
172 final String moduleName = jarName.substring(0, jarName.length() - 4

Comment by lprimak [ 26/Aug/14 ]

Line 169, appInfo is null for versioned application.
Perhaps there needs to be a split / ignore everything from the colon,
i.e. when my_app:20140825, appName should be trimmed to just my_app

Comment by Hong Zhang [ 26/Aug/14 ]

Assign to jersey team to take a look

Comment by lprimak [ 26/Aug/14 ]

This issue is now "unassigned"
Hong,
Can you please assign it to Jersey (or appropriate) team?
It maybe Glassfish core, not Jersdy because
it's EJB Jersey deployer that's failing.

The failed bean is annotated @Stateless @Path("xxx")
thus both a stateless bean and a JAX-RS bean.

Thank you

Comment by lprimak [ 26/Aug/14 ]

I think this issue is a showstopper for GF 4.1 and needs to be fixed in this release.

Comment by Marek Potociar [ 27/Aug/14 ]

The exception is thrown on this code line and is related to line 167, where ApplicationInfo for the application is retrieved.

As noted in an earlier comment, the application does not seem to have an expected loader ApplicationInfo record in the application registry for the versioned applications, at least not under the versioned application name available in the JNDI tree under "java:app/AppName" binding key. It seems to me like a deployment issue - reassigning to deployment component for evaluation. From Jersey perspective, the primary questions to answer in the evaluation are following:

  1. Is Jersey code properly retrieving ApplicationInfo record?
  2. If not, what is the proper, bullet-proof way to retrieve the ApplicationInfo record?
Comment by lprimak [ 07/Sep/14 ]

Perhaps this should be assigned to Marina V so she could clarify how to make this part work correctly?
Thank you

Comment by lprimak [ 13/Sep/14 ]

Now I see it's too late for GF 4.1, can someone take a look so I can at least get a patch / nightly build or something?
Thank you

Comment by lprimak [ 14/Sep/14 ]

I have created a patch to Jersey 2.10.4 that fixes this problem
------------------

diff --git a/containers/glassfish/jersey-gf-ejb/src/main/java/org/glassfish/jersey/gf/ejb/internal/EjbComponentProvider.java b/containers/glassfish/jersey-gf-ejb/src/main/java/org/glassfish/jersey/gf/ejb/internal/EjbComponentProvider.java
index f08c81a..7d429be 100644
— a/containers/glassfish/jersey-gf-ejb/src/main/java/org/glassfish/jersey/gf/ejb/internal/EjbComponentProvider.java
+++ b/containers/glassfish/jersey-gf-ejb/src/main/java/org/glassfish/jersey/gf/ejb/internal/EjbComponentProvider.java
@@ -42,6 +42,8 @@
import com.sun.ejb.containers.BaseContainer;
import com.sun.ejb.containers.EjbContainerUtil;
import com.sun.ejb.containers.EjbContainerUtilImpl;
+import com.sun.enterprise.config.serverbeans.Application;
+import com.sun.enterprise.config.serverbeans.Applications;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
@@ -56,9 +58,11 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
+import java.util.TreeSet;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -87,6 +91,7 @@
import org.glassfish.hk2.utilities.binding.ServiceBindingBuilder;

import org.glassfish.internal.data.ApplicationInfo;
+import org.glassfish.internal.data.ApplicationRegistry;
import org.glassfish.internal.data.ModuleInfo;

/**
@@ -106,7 +111,7 @@
private final List<String> libNames = new CopyOnWriteArrayList<String>();

private boolean ejbInterceptorRegistered = false;
-
+
/**

  • HK2 factory to provide EJB components obtained via JNDI lookup.
    */
    @@ -158,13 +163,51 @@
    Injections.addBinding(Injections.newBinder(this).to(ResourceMethodInvocationHandlerProvider.class), configuration);
    configuration.commit();
    }
    +
    + private ApplicationInfo getApplicationInfo(EjbContainerUtil ejbUtil) throws NamingException
    + {
    + ApplicationRegistry appRegistry = ejbUtil.getServices().getService(ApplicationRegistry.class);
    + Applications applications = ejbUtil.getServices().getService(Applications.class);
    + String appNamePrefix = (String) initialContext.lookup("java:app/AppName");
    + Set<String> appNames = appRegistry.getAllApplicationNames();
    + Set<String> disabledApps = new TreeSet<>();
    + for (String appName : appNames) {
    + if (appName.startsWith(appNamePrefix))
    Unknown macro: {+ Application appDesc = applications.getApplication(appName);+ if (appDesc != null && !ejbUtil.getDeployment().isAppEnabled(appDesc)) { + // skip disabled version of the app + disabledApps.add(appName); + }+ else+ { + return ejbUtil.getDeployment().get(appName); + }+ }

    + }
    +
    + // grab the latest one, there is no way to make
    + // sure which one the user is actually enabling,
    + // so use the best case, i.e. upgrade
    + Iterator<String> it = disabledApps.iterator();
    + String lastDisabledApp = null;
    + while(it.hasNext())
    +

    { + lastDisabledApp = it.next(); + }

    + if(lastDisabledApp != null)

    { + return ejbUtil.getDeployment().get(lastDisabledApp); + }

    +
    + throw new NamingException("Application Information Not Found");
    + }

private void registerEjbInterceptor() {
try {
final Object interceptor = new EjbComponentInterceptor(locator);
initialContext = getInitialContext();
final EjbContainerUtil ejbUtil = EjbContainerUtilImpl.getInstance();

  • final ApplicationInfo appInfo = ejbUtil.getDeployment().get((String)initialContext.lookup("java:app/AppName"));
    + // FL Patch for https://java.net/jira/browse/GLASSFISH-21173
    + final ApplicationInfo appInfo = getApplicationInfo(ejbUtil);
    final List<String> tempLibNames = new LinkedList<String>();
    for (ModuleInfo moduleInfo : appInfo.getModuleInfos()) {
    final String jarName = moduleInfo.getName();
Comment by lprimak [ 05/Oct/14 ]

Any updates on this issue?
Thanks

Comment by Hong Zhang [ 07/Oct/14 ]

Sorry, was not able to get to this due to other higher priority work. I will reassign to Marek to ask him to review the jersey patch to see what he thinks.

Comment by lprimak [ 07/Oct/14 ]

Thanks, Hong. Understand and appreciate it.

Comment by lprimak [ 23/Oct/14 ]

Any progress on this issue?
Thanks





[GLASSFISH-21340] CDI scope annotation on @Provider makes @NameBinding ignored Created: 26/Mar/15  Updated: 30/Mar/15

Status: Open
Project: glassfish
Component/s: jax-rs
Affects Version/s: 4.1
Fix Version/s: None

Type: Bug Priority: Major
Reporter: m-radzikowski Assignee: Marek Potociar
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

1.8.0_40



 Description   

Using CDI scope annotation (e.g. @javax.enterprise.context.RequestScoped) makes annotations with @javax.ws.rs.NameBinding ignored in @javax.ws.rs.ext.Provider.

Sample code:

EnableScopedFilter
@Retention(RUNTIME)
@NameBinding
public @interface EnableScopedFilter {	
}
ScopedFilter
@Provider
@EnableScopedFilter
@RequestScoped
public class ScopedFilter implements ContainerRequestFilter {
	@Override
	public void filter(ContainerRequestContext requestContext) throws IOException {
		System.out.println("Scoped filter triggered on path: " + requestContext.getUriInfo().getPath());
	}
}

This filter is executed on every REST method, not only on these annotated with @EnableScopedFilter. If @RequestScoped is removed everything is ok.

CDI scope annotation is needed is bean-discovery-mode in beans.xml is set to "annotation" and filter needs to @Inject some resources.



 Comments   
Comment by jjsnyder83 [ 30/Mar/15 ]

I don't think this is a CDI issue. I think it is a jax-rs issue. Assigning to jax-rs.





Generated at Tue Jul 07 16:35:01 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.