1 2 3 Previous Next 34 Replies Latest reply on May 5, 2009 3:59 AM by jaikiran Go to original post
      • 15. Re: NullPointerException in JavaEEComponentHelper with JBoss

        Hi,

        It can't be true.

        According to Java EE 5 specification web service endpoints can either be defined through "@WebService" annotation inside EJB 3 code (i.e. "@Stateless") _or_ as separate stand alone classes packed as war application, as in our case.
        Of course, our "@EJB" declarations in web service code refer to EJB 3 EJBs.

        BTW: EJB injection in web service endpoints deployed as war application _does_ work in both GlassFish and WebLogic.

        • 16. Re: NullPointerException in JavaEEComponentHelper with JBoss
          jaikiran

          Could you please open a topic in the JBossWS forum for discussing the injection of EJB in WebServices http://www.jboss.org/index.html?module=bb&op=viewforum&f=200? From what i see in the JBossWS JIRA, support for @Resource injection was added in WebServices but it does not mention @EJB injection. Someone from the JBossWS team might be able to provide some clue as to why the injection doesn't happen.

          • 17. Re: NullPointerException in JavaEEComponentHelper with JBoss

            Hi,

            As suggested I've created a new topic regarding the EJB injection in web services (http://www.jboss.org/index.html?module=bb&op=viewtopic&t=154200).

            I've also tried to test different configurations to surround the main problem (I have now a smaller application, but still build upon our framework, which seems behave in the same way as the "big" one, ifsapp.ear; we've also got a newer build of JBoss 5.1 through Red Hat support: 5.1.0.CR1; could it be of interest to get the log files from this version?).

            But during my tests I found it totally impossible to deploy EJBs with mutual dependencies:

            @Stateless
            public class AStatelessSessionBean implements AStatelessSession
            {
             @EJB
             //@EJB(mappedName="ifssimpletest/BStatelessSessionBean/local")
             private BStatelessSession bean;
            
             @TransactionAttribute(TransactionAttributeType.REQUIRED)
             public String sayHello( String name )
             {
             return bean.sayHello(name);
             }
            
             public String greetingPhrase()
             {
             return "Hello there";
             }
            }
            
            @Stateless
            public class BStatelessSessionBean implements BStatelessSession
            {
             @EJB
             //@EJB(mappedName="ifssimpletest/AStatelessSessionBean/local")
             private AStatelessSession bean;
            
             @TransactionAttribute(TransactionAttributeType.REQUIRED)
             public String sayHello( String name )
             {
             return bean.greetingPhrase() + ", " + name + "!\n";
             }
            }
            


            I've tested with and without 'mappedName'; I've also tested to pack both EJBs to a single jar file - nothing helps (I have a very simple test application with two EJBs as above and one servlet calling one of the EJBs - this application works perfectly on both GlassFish 2.1 and webLogic 10.3).


            • 18. Re: NullPointerException in JavaEEComponentHelper with JBoss
              jaikiran

              Ah, you have circular dependency here! AStatelessBean injects BStatelessBean and BStatelessBean injects AStatelessBean.

              Add a @org.jboss.ejb3.annotation.IgnoreDependency (in addition to @EJB) to any one end of the injection. For example:

              import org.jboss.ejb3.annotation.IgnoreDependency;
              
              @Stateless
              public class AStatelessSessionBean implements AStatelessSession
              {
               // we have a circular dependency, so add @IgnoreDependency
               @EJB
               @IgnoreDependency
               private BStatelessSession bean;
              
               @TransactionAttribute(TransactionAttributeType.REQUIRED)
               public String sayHello( String name )
               {
               return bean.sayHello(name);
               }
              
               public String greetingPhrase()
               {
               return "Hello there";
               }
              }
              
              @Stateless
              public class BStatelessSessionBean implements BStatelessSession
              {
               @EJB
               //@EJB(mappedName="ifssimpletest/AStatelessSessionBean/local")
               private AStatelessSession bean;
              
               @TransactionAttribute(TransactionAttributeType.REQUIRED)
               public String sayHello( String name )
               {
               return bean.greetingPhrase() + ", " + name + "!\n";
               }
              }
              


              • 19. Re: NullPointerException in JavaEEComponentHelper with JBoss

                Ok, I'll test it. Which jar file contains this annotation? I can't find it.
                I don't think we have circular dependences in the "real" application, but do you think it can be an idea to test adding this annotation to the generated code anyway?

                But anyway, this can only be a temporary work-around - our application is supposed to work on different application servers, so we can't have any JBoss specific annotations. Is it something you're planning to fix to the final enterprise release?

                • 20. Re: NullPointerException in JavaEEComponentHelper with JBoss
                  jaikiran

                   

                  "japase" wrote:
                  Ok, I'll test it. Which jar file contains this annotation? I can't find it.

                  It's in jboss-ejb3-ext-api.jar

                  "japase" wrote:

                  I don't think we have circular dependences in the "real" application, but do you think it can be an idea to test adding this annotation to the generated code anyway?

                  This annotation is required only if there are circular dependencies. If there are none, then this annotation wont help.

                  "japase" wrote:

                  But anyway, this can only be a temporary work-around - our application is supposed to work on different application servers, so we can't have any JBoss specific annotations.


                  There's a JIRA created for this https://jira.jboss.org/jira/browse/EJBTHREE-1074

                  • 21. Re: NullPointerException in JavaEEComponentHelper with JBoss
                    jaikiran

                    japase,

                    Let's take one step at a time and try to understand what issue we are trying to fix :) This thread

                    1) Started with a deployment ordering issue
                    2) Went on to a NullPointerException with mappedName
                    3) Then to a injection problem in WebServices
                    4) And now a circular @EJB injection.

                    All are valid issues that you have brought up.

                    I think we are trying to solve #2 isn't it? The NullPointerException that's coming up with the mappedName? I have been trying to reproduce this with various combinations of applications to get the NullPointerException (similar to what you attached to the JIRA), but so far haven't been able to do so. I think the exception might be related to a very specific deployment structure. Were you able to reproduce this NullPointerException with the smaller application?



                    • 22. Re: NullPointerException in JavaEEComponentHelper with JBoss

                      Yes, you're absolutely right - let's concentrate us on one issue at time. Just forget #3 (I've created a separated topic at WS forum - so far no answer) and #4 (even if we require this to work in our application, it is not the actual problem right now and there is already a JIRA for that).

                      So the question is if we should go for #1 or for #2?

                      1) Deployment ordering issue - are you sure that the initial problem (NullPointerException in JavaEEComponentHelper) is caused by the deployment order? This is actually what I'd like to solve.

                      2) Usage of mappedName should be just a work-around to #1 above. Actually we don't want to use mappedName at all as it is also application server specific.

                      I have a smaller application, but still containing around 100 different jar files and 5-10 EJBs. And also this version of JBoss I've mentioned previously that, according to Red Hat support people, should give more debugging information.

                      Do you want me to test this smaller application on this particular JBoss version as well? Shall I continue with mappedName, i.e. trying to resolve #2 first or regenerate code without mappedName and go for #1 once again?

                      • 23. Re: NullPointerException in JavaEEComponentHelper with JBoss
                        jaikiran

                         

                        "japase" wrote:

                        1) Deployment ordering issue - are you sure that the initial problem (NullPointerException in JavaEEComponentHelper) is caused by the deployment order? This is actually what I'd like to solve.

                        Going by the logs that you posted and what you described about your application and what some other users have reported, i believe its the deployment ordering issue. So let's concentrate on #2.


                        "japase" wrote:

                        Do you want me to test this smaller application on this particular JBoss version as well?

                        Yes, please. And it would be great to enable TRACE logging on org.jboss.ejb3. You can do it in the jboss-log4j.xml file in the conf folder of the appropriate server configuration.

                        "japase" wrote:

                        Shall I continue with mappedName, i.e. trying to resolve #2 first

                        #2 please.

                        • 24. Re: NullPointerException in JavaEEComponentHelper with JBoss

                          Hi again,

                          I have now recreated the problem with a somewhat smaller application and the previously mentioned version of JBoss. The server.log file and console output are attached, as before, to the JIRA 1751 (japase.zip).

                          Content of the application.xml file:

                          <?xml version="1.0" encoding="UTF-8"?>
                          <!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN' 'http://java.sun.com/dtd/application_1_3.dtd'>
                          <application>
                           <display-name>IFS Connect</display-name>
                           <description>IFS Connect</description>
                           <module>
                           <ejb>applicationsupport-ejb.jar</ejb>
                           </module>
                           <module>
                           <ejb>connectadministration-ejb.jar</ejb>
                           </module>
                           <module>
                           <ejb>connectdevelopment-ejb.jar</ejb>
                           </module>
                           <module>
                           <ejb>connectruntimeservices-ejb.jar</ejb>
                           </module>
                           <module>
                           <ejb>connectsenders-ejb.jar</ejb>
                           </module>
                           <module>
                           <ejb>connecttestorder-ejb.jar</ejb>
                           </module>
                           <module>
                           <ejb>connectivityservices-ejb.jar</ejb>
                           </module>
                           <module>
                           <web>
                           <web-uri>ifsclientgateway.war</web-uri>
                           <context-root>/fndcn</context-root>
                           </web>
                           </module>
                          </application>
                          


                          Content of the ear file:

                          H:\>jar -tf E:\ifs_home_WS\jboss-5.1.0.CR1\server\dev\deploy\ifsapp.ear
                          META-INF/
                          META-INF/MANIFEST.MF
                          META-INF/jboss-app.xml
                          META-INF/orion-application.xml
                          ifs-fnd-j2ee.jar
                          ifs-fnd-common.jar
                          ifs-fnd-connect.jar
                          ifsclientgateway.war
                          applicationsupport-ejb.jar
                          fndbas-enumerations.jar
                          META-INF/application.xml
                          documentlifecycle.jar
                          batchqueuemethod.jar
                          batchqueue.jar
                          batchschedulemethodparameter.jar
                          batchschedulemethod.jar
                          queryhintview.jar
                          reportlayout.jar
                          reportlayoutdefinition.jar
                          reportresultgenconfig.jar
                          reportschema.jar
                          reportdefinition.jar
                          reportfontdefinition.jar
                          installedmodule.jar
                          batchschedulechain.jar
                          batchschedulechainstep.jar
                          batchschedulechainpar.jar
                          batchscheduleparameter.jar
                          batchschedule.jar
                          languagefontmapping.jar
                          termusageidentifier.jar
                          termusagedefinition.jar
                          termtranslateddefinition.jar
                          termtranslatedname.jar
                          languagecode.jar
                          termalertindicator.jar
                          termdomain.jar
                          fnduser.jar
                          languagemodule.jar
                          termowner.jar
                          termstoplist.jar
                          term.jar
                          entitystate.jar
                          filter.jar
                          storageattribute.jar
                          storagepackage.jar
                          tableindex.jar
                          storageobject.jar
                          logicalunit.jar
                          plsqlpackage.jar
                          plsqlparameter.jar
                          plsqlmethod.jar
                          serverpackage.jar
                          view.jar
                          validationobject.jar
                          handlermethod.jar
                          handler.jar
                          clientplugin.jar
                          widget.jar
                          feature.jar
                          clientpackage.jar
                          entitypackage.jar
                          j2eeapplication.jar
                          module.jar
                          activitypackage.jar
                          activity.jar
                          modelimportlog.jar
                          stereotype.jar
                          entityattribute.jar
                          entityassociation.jar
                          searchdomain.jar
                          entity.jar
                          connecttestorder-ejb.jar
                          messagearchivesearch.jar
                          messagearchive.jar
                          messagemedia.jar
                          messagequeue.jar
                          recurrenceagenda.jar
                          recurrencepattern.jar
                          target.jar
                          applicationmessage.jar
                          configparameterinstance.jar
                          configparameterarea.jar
                          fndsessionruntime.jar
                          connectsenders-ejb.jar
                          ftp.jar
                          activation.jar
                          mail.jar
                          xercesImpl.jar
                          jsch-0.1.31.jar
                          routeaddress.jar
                          routecondition.jar
                          connectruntimeservices-ejb.jar
                          messageclass.jar
                          inmessage.jar
                          outmessageline.jar
                          outmessage.jar
                          connectivityservices-ejb.jar
                          connectadministration-ejb.jar
                          connectdevelopment-ejb.jar


                          Log level is set to TRACE for EJB3 in jboss-log4j.xml:
                          <category name="org.jboss.ejb3">
                           <priority value="TRACE"/>
                          </category>
                          



                          • 25. Re: NullPointerException in JavaEEComponentHelper with JBoss
                            jaikiran

                            Thanks. Will take a look and update this thread.

                            • 26. Re: NullPointerException in JavaEEComponentHelper with JBoss
                              jaikiran

                              Some more information - you are injection bean XYZ into bean ABC. What type of beans are XYZ and ABC (ex: slsb or sfsb or mdb or @service)? Can you post those relevant pieces of code for these beans, including import statements (no need to post the methods in those beans) and code from any base class (beans) it extends?

                              • 27. Re: NullPointerException in JavaEEComponentHelper with JBoss

                                An example of a bean declaration and injection with some other typical annotations (all our generated beans are more or less same):

                                package ifs.application.administrateuserprofiles;
                                
                                import ifs.fnd.log.*;
                                import ifs.fnd.record.*;
                                import ifs.fnd.record.serialization.*;
                                import ifs.fnd.remote.*;
                                import ifs.fnd.remote.j2ee.*;
                                import ifs.fnd.sf.j2ee.*;
                                import ifs.fnd.sf.j2ee.meta.*;
                                import ifs.fnd.base.*;
                                import ifs.fnd.sf.*;
                                import ifs.application.manageuserprofile.*;
                                
                                import java.util.Date;
                                import javax.ejb.Stateless;
                                import javax.ejb.EJB;
                                import javax.annotation.PostConstruct;
                                import javax.ejb.TransactionAttribute;
                                import javax.ejb.TransactionAttributeType;
                                
                                @Stateless(name="AdministrateUserProfiles")
                                public class AdministrateUserProfilesBean extends FndActivityBean implements AdministrateUserProfilesLocal {
                                
                                 private AdministrateUserProfiles implementation;
                                
                                 @EJB(mappedName="ifsapp/UserProfileService/local") private UserProfileServiceLocal userProfileService;
                                
                                 @PostConstruct
                                 private void initialize() {
                                 // some code goes here …
                                 }
                                
                                 @Override
                                 public String[] getOperations() {
                                 return operations;
                                 }
                                
                                 @TransactionAttribute(TransactionAttributeType.REQUIRED)
                                 public FndRecordResultWrapper clearClientProfile(ifs.application.manageuserprofile.ClientProfileExt inRecord, FndContext ctx) throws IfsException {
                                 // method code here…
                                 }
                                
                                 // other methods
                                }
                                


                                All the generated beans extend indirectly the following class (complete code):
                                package ifs.fnd.sf.j2ee;
                                
                                import ifs.fnd.base.SystemException;
                                import ifs.fnd.base.IfsException;
                                import ifs.fnd.base.FndConstants;
                                import ifs.fnd.base.FndContext;
                                import ifs.fnd.base.FndFramework;
                                import ifs.fnd.log.*;
                                //import ifs.fnd.service.IfsProperties;
                                
                                import javax.annotation.Resource;
                                import javax.ejb.SessionContext;
                                import javax.interceptor.AroundInvoke;
                                import javax.interceptor.InvocationContext;
                                import javax.sql.DataSource;
                                import javax.annotation.security.DeclareRoles;
                                import javax.annotation.security.RolesAllowed;
                                
                                /**
                                 * Base class for all EJB classes.
                                 */
                                @DeclareRoles({FndConstants.USER_ROLE, FndConstants.TRUSTED_MODULE_ROLE})
                                @RolesAllowed({FndConstants.USER_ROLE})
                                abstract class FndAbstractBean {
                                
                                 //private static final String DATASOURCE_JNDI_PREFIX = IfsProperties.getProperty("fndext.datasource.jndi.prefix");
                                
                                 // this logger may be used during initialization of a bean; it is then recreated by @AroundInvoke method
                                 protected Logger log;
                                
                                 // logger used for debugging of EJB specific events
                                 protected Logger clsLog;
                                
                                 protected FndAbstractBean() {
                                 log = LogMgr.getFrameworkLogger();
                                 clsLog = LogMgr.getClassLogger(FndAbstractBean.class);
                                 if(clsLog.debug)
                                 clsLog.debug("Created bean [&1]", getClass().getName());
                                 }
                                
                                 @Resource
                                 protected SessionContext sessionContext;
                                
                                 @Resource(name="fndbas_en-US", mappedName="java:jdbc/fndbas_en-US")
                                 private DataSource dsEn;
                                
                                 @Resource(name="fndbas-noxa_en-US", mappedName="java:jdbc/fndbas-noxa_en-US")
                                 private DataSource dsNoXaEn;
                                
                                 public DataSource getDataSource(String name) throws SystemException {
                                 if("fndbas_en-US".equals(name))
                                 return dsEn;
                                 else if("fndbas-noxa_en-US".equals(name))
                                 return dsNoXaEn;
                                 throw new SystemException("No dependency to DataSource " + name);
                                 }
                                
                                 protected SessionContext getSessionContext() {
                                 return sessionContext;
                                 }
                                
                                 @AroundInvoke
                                 private Object aroundInvoke(InvocationContext ctx) throws Exception {
                                
                                 // recreate the bean-protected instance of logger
                                 log = LogMgr.getFrameworkLogger();
                                
                                 // prepare current FndContext for invocation of a business method
                                 FndJ2eeContext fndctx;
                                 if(this instanceof FndActivityBean) {
                                 Object[] params = ctx.getParameters();
                                 Object lastParam = params[params.length - 1];
                                 if(lastParam instanceof FndContext) {
                                 // typed invoke(): set passed FndContext as current context
                                 fndctx = (FndJ2eeContext) lastParam;
                                 setCallerAsApplicationUser(fndctx);
                                 FndContext.setCurrentContext(fndctx);
                                 }
                                 else {
                                 // untyped invoke(): create new FndContext and set it as current context
                                 fndctx = (FndJ2eeContext) FndFramework.getFramework().newContext();
                                 FndContext.setCurrentContext(fndctx);
                                 }
                                 }
                                 else {
                                 // for nested beans the current FndContext has been already set
                                 fndctx = FndJ2eeContext.getCurrentJ2eeContext();
                                 }
                                
                                 // push this bean to the stack with current bens
                                 fndctx.pushCurrentBean(this);
                                 if(clsLog.info)
                                 clsLog.info("Pushed current bean [&1]", getClass().getName());
                                
                                 try {
                                 // invoke business method
                                 return ctx.proceed();
                                 }
                                 finally {
                                 // pop this bean from the stack with current bens
                                 fndctx.popCurrentBean(this);
                                 if(log.debug)
                                 log.debug("Poped current bean [&1]", getClass().getName());
                                
                                 // clear the current context after top-level bean method invocation
                                 if(this instanceof FndActivityBean) {
                                 FndContext.setCurrentContext(null);
                                 if(log.debug)
                                 log.debug("Current context cleared on exit from bean [&1]", getClass().getName());
                                 }
                                 }
                                 }
                                
                                 /**
                                 * Sets the authenticated user as application user in the specified context.
                                 */
                                 protected void setCallerAsApplicationUser(FndJ2eeContext ctx) throws IfsException {
                                 try {
                                 String user = sessionContext.getCallerPrincipal().getName();
                                 ctx.setApplicationUser(user);
                                 if(log.debug)
                                 log.debug("Current application user set to authenticated user: &1", user);
                                 }
                                 catch (IllegalStateException e) {
                                 throw new ifs.fnd.base.SecurityException(e,
                                 "FNDSESSIONBEANSEC:No security context set. Check that security has been configured for the application.");
                                 }
                                 }
                                
                                }
                                


                                There are some other levels of inheritance between a generated EJB and the FndAbstractBean class above, but without anything specific for EJB (I think). But, of course, I can post the code for those classes as well, if necessary.


                                • 28. Re: NullPointerException in JavaEEComponentHelper with JBoss
                                  wolfc

                                  There seems to be an illegal configuration in connectadministration-ejb.jar on which the deployment chokes.

                                  Does it contain a jboss.xml? If so, could you post it?
                                  Would it be possible to attach said jar to EJBTHREE-1751?

                                  • 29. Re: NullPointerException in JavaEEComponentHelper with JBoss

                                    Hi,
                                    I have now attached connectadministration-ejb.jar to the JIRA.
                                    Yes, we have jboss.xml:

                                    <?xml version="1.0" encoding="UTF-8"?>
                                    <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">
                                    <jboss>
                                     <security-domain>java:/jaas/IFSApplications</security-domain>
                                    </jboss>
                                    


                                    This file is generated by our framework and included in the same shape in all our *-ejb.jar files in the application.