6 Replies Latest reply on Jul 1, 2009 4:21 AM by rmz

    Interface inheritence / SessionContext.getInvokedBusinessInt

    rmz

      Hi everyone,

      I'm encountering the following problem. I have six interfaces in order to access a Stateful Session Bean, say a bean named "Person". The interface inheritence structure is:

      IPerson
      |
      --- IPersonInt
      | |
      | ---- IPersonIntRemote
      | |
      | ---- IPersonIntLocal
      |
      --- IPersonRemote
      |
      --- IPersonLocal


      The bean class Person is declared to implement IPersonLocal, IPersonRemote, IPersonIntLocal and IPersonIntRemote, including the corresponding @Local and @Remote annotations. Also, for the local and remote interfaces the corresponding annotations are in place.

      The problem now is that whatever real interface is used to call the Person bean, SessionContext.getInvokedBusinessInterface() always returns IPerson. In particular, I cannot distinguish between local and remote calls.

      I have to say, my experience is quite limited but I would consider this a bug in the code that generates the client stub classes. The spec requires this method to deliver the invoking interface.

      Please share your opinions on this issue with me. Maybe there is another way to identify whether the bean has been called remotely or locally?

      Thanks,
      -Rainer

        • 1. Re: Interface inheritence / SessionContext.getInvokedBusines
          jaikiran

          Which version of JBossAS and can you post the lookup code and also the JNDI names that you see for your beans in the jmx-console?

          • 2. Re: Interface inheritence / SessionContext.getInvokedBusines
            rmz

            well, actually there is some context about this. I have constructed a simplifed example for which I'll list all relevant code. Please substitute the bean name "Person" --> "ErstesBean".

            The following are the interface definitions:

            public interface IErstesBean
            {
             public String getCallingInterface();
            }
            

            @Local
            public interface IErstesBeanLocal extends IErstesBean
            {
            }
            

            @Remote
            public interface IErstesBeanRemote extends IErstesBean
            {
            }
            

            public interface IErstesBeanInt extends IErstesBean
            {
             public Object getLocalReference();
             public Object getIntLocalReference();
             public Object getRemoteReference();
             public Object getIntRemoteReference();
            }
            

            @Local
            public interface IErstesBeanIntLocal extends IErstesBeanInt
            {
            }
            

            @Remote
            public interface IErstesBeanIntRemote extends IErstesBeanInt
            {
            }
            


            The relevant part of the bean implementation looks like the following:

            @Stateful
            @Local({ IErstesBeanLocal.class,
             IErstesBeanIntLocal.class
             })
            @Remote({ IErstesBeanRemote.class,
             IErstesBeanIntRemote.class
             })
            public class ErstesBean implements
            IErstesBeanRemote,
            IErstesBeanIntRemote
            {
             ...
            
             @Resource
             private SessionContext sessionContextM;
            
             ...
            
             public String getCallingInterface()
             {
             if ( sessionContextM == null )
             {
             return null;
             }
             return sessionContextM.getInvokedBusinessInterface().getName();
             }
            
             ...
            }
            


            I see the following registration messages on the server console when deploying:

            09:42:14,286 INFO [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:
            
             ErstesBean/remote - EJB3.x Default Remote Business Interface
             ErstesBean/remote-server.kap02.IErstesBeanRemote - EJB3.x Remote Business Interface
             ErstesBean/remote-server.kap02.IErstesBeanIntRemote - EJB3.x Remote Business Interface
             ErstesBean/local - EJB3.x Default Local Business Interface
             ErstesBean/local-server.kap02.IErstesBeanIntLocal - EJB3.x Local Business Interface
             ErstesBean/local-server.kap02.IErstesBeanLocal - EJB3.x Local Business Interface
            


            The client code used to allocte and invoke the bean is:
             Properties propsL = new Properties();
             propsL.put( Context.INITIAL_CONTEXT_FACTORY,
             "org.jnp.interfaces.NamingContextFactory");
             propsL.put( Context.URL_PKG_PREFIXES,
             "org.jboss.naming:org.jnp.interfaces");
             propsL.put( Context.PROVIDER_URL,
             "jnp://localhost:1099");
             Context contextL = new InitialContext( propsL);
            
             Object refL = contextL.lookup("ErstesBean/remote");
             //IErstesBean ebrL = (IErstesBeanRemote) PortableRemoteObject.narrow( refL, IErstesBeanRemote.class);
             IErstesBeanRemote ebrL = (IErstesBeanRemote) PortableRemoteObject.narrow( refL, IErstesBeanRemote.class);
            
             System.out.println( "Calling interface: " + ebrL.getCallingInterface());
            


            The commented source line here is what ideally I want to do, namely associate the returned interface (stub class) the most generic data type. However I used the specific interface here in order to show what happens more clearly.

            When this code is executed, I encounter the following exception:

            javax.ejb.EJBException: java.lang.IllegalStateException: Cannot invoke javax.ejb.SessionContext.getInvokedBusinessInterface() from outside of an EJB3 Business View - EJB 3.0 Core Specification 4.5.2; Used: server.kap02.IErstesBean
             at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:77)
             at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
             at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:201)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:159)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:65)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.stateful.StatefulContainer.dynamicInvoke(StatefulContainer.java:660)
             at org.jboss.ejb3.session.InvokableContextClassProxyHack._dynamicInvoke(InvokableContextClassProxyHack.java:56)
             at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:91)
             at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
             at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:908)
             at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:742)
             at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:695)
             at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:522)
             at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:230)
            Caused by: java.lang.IllegalStateException: Cannot invoke javax.ejb.SessionContext.getInvokedBusinessInterface() from outside of an EJB3 Business View - EJB 3.0 Core Specification 4.5.2; Used: server.kap02.IErstesBean
             at org.jboss.ejb3.session.SessionSpecContainer.getInvokedBusinessInterface(SessionSpecContainer.java:303)
             at org.jboss.ejb3.session.SessionContextDelegateBase.getInvokedBusinessInterface(SessionContextDelegateBase.java:73)
             at org.jboss.ejb3.stateful.StatefulSessionContextImpl.getInvokedBusinessInterface(StatefulSessionContextImpl.java:147)
             at server.kap02.ErstesBean.getCallingInterface(ErstesBean.java:114)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:597)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)
             at org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:69)
             at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:73)
             at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:59)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:597)
             at org.jboss.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod(InvocationContextInterceptor.java:72)
             at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_19305075.invoke(InvocationContextInterceptor_z_fillMethod_19305075.java)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:88)
             at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_19305075.invoke(InvocationContextInterceptor_z_setup_19305075.java)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:62)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:60)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:56)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:81)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
             at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:201)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:159)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:65)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.stateful.StatefulContainer.dynamicInvoke(StatefulContainer.java:660)
             at org.jboss.ejb3.session.InvokableContextClassProxyHack._dynamicInvoke(InvokableContextClassProxyHack.java:56)
             at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:91)
             at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
             at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:908)
             at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:742)
             at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:695)
             at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:522)
             at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:230)
             at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:206)
             at org.jboss.remoting.Client.invoke(Client.java:1708)
             at org.jboss.remoting.Client.invoke(Client.java:612)
             at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:60)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.security.client.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:65)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:76)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)
             at $Proxy2.invoke(Unknown Source)
             at org.jboss.ejb3.proxy.handler.ProxyInvocationHandlerBase.invoke(ProxyInvocationHandlerBase.java:261)
             at org.jboss.ejb3.proxy.handler.session.SessionSpecProxyInvocationHandlerBase.invoke(SessionSpecProxyInvocationHandlerBase.java:101)
             at $Proxy1.getCallingInterface(Unknown Source)
             at client.kap02.ErstesBeanClient.main(ErstesBeanClient.java:53)
             at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:72)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.security.client.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:65)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:76)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
             at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)
             at $Proxy2.invoke(Unknown Source)
             at org.jboss.ejb3.proxy.handler.ProxyInvocationHandlerBase.invoke(ProxyInvocationHandlerBase.java:261)
             at org.jboss.ejb3.proxy.handler.session.SessionSpecProxyInvocationHandlerBase.invoke(SessionSpecProxyInvocationHandlerBase.java:101)
             at $Proxy1.getCallingInterface(Unknown Source)
             at client.kap02.ErstesBeanClient.main(ErstesBeanClient.java:53)
            


            So, in summary, what happens is that the server thinks it was called by a business interface called "IErstesBean" which actually is not true. Even if the variable to hold the reference (ebrL) would be of that interface type, the real runtime type should be returned by the session context.

            This happens of JBossAS 5.0.0 GA and I also checked on JBoss 5.1.0 GA which shows the same behavior.

            Thanks,
            -Rainer

            • 3. Re: Interface inheritence / SessionContext.getInvokedBusines
              rmz

              Is there really noone who experienced such problems?

              Is there a forum better suited for this problem?

              Thanks,
              -Rainer

              • 4. Re: Interface inheritence / SessionContext.getInvokedBusines
                jaikiran

                Rainer,

                Sorry, i forgot to look into this. I'll do it today and update this thread.

                • 5. Re: Interface inheritence / SessionContext.getInvokedBusines
                  jaikiran

                   

                  ErstesBean/remote - EJB3.x Default Remote Business Interface
                   ErstesBean/remote-server.kap02.IErstesBeanRemote - EJB3.x Remote Business Interface
                   ErstesBean/remote-server.kap02.IErstesBeanIntRemote - EJB3.x Remote Business Interface
                   ErstesBean/local - EJB3.x Default Local Business Interface
                   ErstesBean/local-server.kap02.IErstesBeanIntLocal - EJB3.x Local Business Interface
                   ErstesBean/local-server.kap02.IErstesBeanLocal - EJB3.x Local Business Interface
                  


                  Use the business interface specific JNDI name to lookup the business interface specific proxy:

                  IErstesBean ebrL = (IErstesBean) contextL.lookup("ErstesBean/remote-server.kap02.IErstesBeanRemote");
                  System.out.println( "Calling interface: " + ebrL.getCallingInterface());
                  


                  • 6. Re: Interface inheritence / SessionContext.getInvokedBusines
                    rmz

                    Thanks a lot, this solves the problem, the failure was on my side.

                    But still I do not understand this fully. It is true that the beans do not explicitly implement the default business interface, so I thought since the server says it registered that interface it would provide some kind of automatic interface / stub to that bean. Shouldn't I get an exception when trying to lookup an interface that does not really exist? Or at least, when narrowing to a particular existing interface?

                    Anyhow, this helps me a lot, thanks again,
                    -Rainer