Call Session Bean business method
bmateus Nov 30, 2005 2:52 PMHi all,
I'm new to J2EE and i'm having a problem calling a business method on a stateless session bean TCM. Here is my bean code:
public class SbbComunicatorBean implements javax.ejb.SessionBean {
private javax.ejb.SessionContext context;
public void setSessionContext(javax.ejb.SessionContext aContext) {
context = aContext;
}
public void ejbActivate() {}
public void ejbPassivate() {}
public void ejbRemove() {}
public void ejbCreate() {
try{
InitialContext ctx = new InitialContext();
SleeConnectionFactory factory = (SleeConnectionFactory)ctx.lookup("java:/MobicentsConnectionFactory");
connection = factory.getConnection();
}
catch (Exception ex){
System.out.println("[SbbCommunicatorBean]Error in EJB: " + ex);
ex.printStackTrace();
}
}
public void endRemoteCall(String callId) {
System.out.println("[SbbCommunicatorBean] End remote call");
}
}
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Here is the application that i'm using to test my bean:
public class ControlApplication {
public static void main(String[] args) {
try {
InitialContext ctx = new InitialContext();
Object ref = ctx.lookup("ejb/jainslee/SbbCommunicatorBean");
SbbComunicatorHome home = (SbbComunicatorHome)PortableRemoteObject.narrow(ref,SbbComunicatorHome.class);
SbbComunicatorRemote remote = home.create();
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
String option = null;
while(true){
System.out.println("...Swing EJB Test Application...");
System.out.print("Cancel call. Insert CallId >> ");
option = buf.readLine();
if(option.equalsIgnoreCase("exit"))
break;
System.out.println("------- SEND 1 --------");
remote.endRemoteCall(option);
System.out.println("------- SEND 2 --------");
remote.endRemoteCall(option);
System.out.println("------- SEND 3 --------");
remote.endRemoteCall(option);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
After the second call to remote.endRemoteCall(option) the EJB??? crashes with the following exception:
...Swing EJB Test Application...
Cancel call. Insert CallId >> 123
------- SEND 1 --------
------- SEND 2 --------
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.ServerException: RuntimeException; nested exception is:
java.lang.IllegalStateException: Wrong transaction association: expected TransactionImpl:XidImpl [FormatId=257, GlobalId=estpc1//31, BranchQual=] was null
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:292)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:534)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:135)
at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:96)
at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:55)
at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:100)
at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
at $Proxy1.endRemoteCall(Unknown Source)
at com.ptin.xmas.control.app.ControlApplication.main(ControlApplication.java:44)
Caused by: java.rmi.ServerException: RuntimeException; nested exception is:
java.lang.IllegalStateException: Wrong transaction association: expected TransactionImpl:XidImpl [FormatId=257, GlobalId=estpc1//31, BranchQual=] was null
at org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.java:385)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:331)
at org.jboss.ejb.Container.invoke(Container.java:709)
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:324)
at org.jboss.mx.server.ReflectedDispatcher.dispatch(ReflectedDispatcher.java:60)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:62)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:54)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:82)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:197)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:473)
at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:360)
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:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.IllegalStateException: Wrong transaction association: expected TransactionImpl:XidImpl [FormatId=257, GlobalId=estpc1//31, BranchQual=] was null
at org.jboss.ejb.plugins.TxInterceptorCMT.endTransaction(TxInterceptorCMT.java:441)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:324)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:148)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:111)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
... 25 more
It seems like a nested transaction??? but i don't know how to solve this. Can anyone point me some ideias.
My configuration: JBoss 3.2.6, JDK 1.4.2_06-b03
Regards,
Bruno Mateus