[jboss-user] [EJB/JBoss] - Re: Interface inheritence / SessionContext.getInvokedBusines

rmz do-not-reply at jboss.com
Wed Jun 17 04:21:16 EDT 2009


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

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4238124#4238124

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4238124



More information about the jboss-user mailing list