[jboss-user] [Beginners Corner] - Re: jboss-dukes-bank app
pepelara
do-not-reply at jboss.com
Tue Dec 16 12:21:32 EST 2008
Hi,
I was googling and I have solved the problem about the InitialContex: I was needing to add some jar into the prject.
Now I have some problems when callin some local-home interfaces from the ejbCreate mthod of a Session Bean. My code is as followes:
| package com.sun.ebank.util;
|
|
| /**
| * This interface defines names in code used as args for lookup().
| */
| public interface CodedNames {
| public static final String BANK_DATABASE = "java:/DefaultDS";
| public static final String ACCOUNT_EJBHOME = "java:comp/env/ejb/AccountEJB";
| public static final String ACCOUNT_CONTROLLER_EJBHOME = "AccountControllerEJB";
| public static final String ACCOUNT_EJBHOME = "java:comp/env/ejb/CustomerEJB";
| public static final String CUSTOMER_CONTROLLER_EJBHOME = "CustomerControllerEJB";
| public static final String TX_EJBHOME = "java:comp/env/ejb/TxEJB";
| public static final String TX_CONTROLLER_EJBHOME = "TxControllerEJB";
| }
|
where the ACCOUNT_CONTROLLER_EJBHOME, CUSTOMER_CONTROLLER_EJBHOME and TX_CONTROLLER_EJBHOME are the session bean that access to my ACCOUNT_EJBHOME, ACCOUNT_EJBHOME and TX_EJBHOME on their respectively ejbCreate method.
The way to call the diferents EJBs is as followes,
| package com.sun.ebank.util;
|
| import java.util.Properties;
| import javax.rmi.PortableRemoteObject;
| import javax.naming.Context;
| import javax.naming.InitialContext;
| import javax.naming.NamingException;
| import com.sun.ebank.ejb.account.AccountHome;
| import com.sun.ebank.ejb.account.AccountControllerHome;
| import com.sun.ebank.ejb.customer.CustomerHome;
| import com.sun.ebank.ejb.customer.CustomerControllerHome;
| import com.sun.ebank.ejb.tx.TxHome;
| import com.sun.ebank.ejb.tx.TxControllerHome;
|
|
| /**
| * This helper class fetches EJB home references.
| */
| public final class EJBGetter {
| public static AccountHome getAccountHome() throws NamingException {
| Context initial = getInitialContext();
| //InitialContext initial = new InitialContext();
| Object objref = initial.lookup(CodedNames.ACCOUNT_EJBHOME);
|
| //return (AccountHome) PortableRemoteObject.narrow(objref, AccountHome.class);
| return (AccountHome)objref;
| }
|
| public static AccountControllerHome getAccountControllerHome()
| throws NamingException {
| Context initial = getInitialContext();
| //InitialContext initial = new InitialContext();
| Object objref = initial.lookup(CodedNames.ACCOUNT_CONTROLLER_EJBHOME);
|
| return (AccountControllerHome) PortableRemoteObject.narrow(objref,
| AccountControllerHome.class);
| }
|
| public static CustomerHome getCustomerHome() throws NamingException {
| Context initial = getInitialContext();
| //InitialContext initial = new InitialContext();
| Object objref = initial.lookup(CodedNames.CUSTOMER_EJBHOME);
|
| //return (CustomerHome) PortableRemoteObject.narrow(objref, CustomerHome.class);
| return (CustomerHome)objref;
| }
|
| public static CustomerControllerHome getCustomerControllerHome()
| throws NamingException {
| Context initial = getInitialContext();
| //InitialContext initial = new InitialContext();
| Object objref = initial.lookup(CodedNames.CUSTOMER_CONTROLLER_EJBHOME);
|
| return (CustomerControllerHome) PortableRemoteObject.narrow(objref,
| CustomerControllerHome.class);
| }
|
| public static TxHome getTxHome() throws NamingException {
| Context initial = getInitialContext();
| //InitialContext initial = new InitialContext();
| Object objref = initial.lookup(CodedNames.TX_EJBHOME);
|
| //return (TxHome) PortableRemoteObject.narrow(objref, TxHome.class);
| return (TxHome)objref;
| }
|
| public static TxControllerHome getTxControllerHome()
| throws NamingException {
| Context initial = getInitialContext();
| //InitialContext initial = new InitialContext();
| Object objref = initial.lookup(CodedNames.TX_CONTROLLER_EJBHOME);
|
| return (TxControllerHome) PortableRemoteObject.narrow(objref,
| TxControllerHome.class);
| }
|
| private static Context getInitialContext(){
| Context ctx = null;
|
| Properties env = new Properties();
| env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
| env.put(Context.PROVIDER_URL, "localhost:1099");
| env.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
| env.put("j2ee.clientName", "bank-client");
|
| try {
| // Get an initial context
| ctx = new InitialContext(env);
| System.out.println("Got context");
| } catch (NamingException ne) {
| // TODO Auto-generated catch block
| System.out.println("Did not get context");
| ne.printStackTrace();
| }
|
| return ctx;
| }
| }
|
but when I try it, the first call to the session bean works ok, but from the ejbCreate of this session bean I cannot call the entities beans. The system throws an exception,
| java.rmi.ServerException: EJBException:; nested exception is:
| javax.ejb.EJBException: ejbCreate: comp not bound
| at org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.java:365)
| at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:136)
| at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:107)
| at org.jboss.ejb.SessionContainer.internalInvokeHome(SessionContainer.java:637)
| at org.jboss.ejb.Container.invoke(Container.java:981)
| 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:585)
| at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
| at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
| at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
| at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
| at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
| at org.jboss.invocation.unified.server.UnifiedInvoker.invoke(UnifiedInvoker.java:231)
| 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:585)
| at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
| at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
| at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
| at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
| at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
| at javax.management.MBeanServerInvocationHandler.invoke(MBeanServerInvocationHandler.java:201)
| at $Proxy16.invoke(Unknown Source)
| at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:769)
| at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:573)
| at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373)
| at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)
| Caused by: javax.ejb.EJBException: ejbCreate: comp not bound
| at com.sun.ebank.ejb.customer.CustomerControllerBean.ejbCreate(CustomerControllerBean.java:280)
| 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:585)
| at org.jboss.ejb.StatefulSessionContainer.createSession(StatefulSessionContainer.java:278)
| at org.jboss.ejb.StatefulSessionContainer.createHome(StatefulSessionContainer.java:337)
| 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:585)
| at org.jboss.invocation.Invocation.performCall(Invocation.java:359)
| at org.jboss.ejb.StatefulSessionContainer$ContainerInterceptor.invokeHome(StatefulSessionContainer.java:549)
| at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:145)
| at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:189)
| at org.jboss.ejb.plugins.CallValidationInterceptor.invokeHome(CallValidationInterceptor.java:56)
| at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:125)
| at org.jboss.ejb.plugins.AbstractTxInterceptorBMT.invokeNext(AbstractTxInterceptorBMT.java:173)
| at org.jboss.ejb.plugins.TxInterceptorBMT.invokeHome(TxInterceptorBMT.java:71)
| at org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor.invokeHome(StatefulSessionInstanceInterceptor.java:143)
| at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:132)
| at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:107)
| at org.jboss.ejb.SessionContainer.internalInvokeHome(SessionContainer.java:637)
| at org.jboss.ejb.Container.invoke(Container.java:981)
| 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:585)
| at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
| at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
| at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
| at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
| at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
| at org.jboss.invocation.unified.server.UnifiedInvoker.invoke(UnifiedInvoker.java:231)
| 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:585)
| at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
| at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
| at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
| at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
| at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
| at javax.management.MBeanServerInvocationHandler.invoke(MBeanServerInvocationHandler.java:201)
| at $Proxy16.invoke(Unknown Source)
| at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:769)
| at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:573)
| at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373)
| at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)
| at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:163)
| at org.jboss.remoting.Client.invoke(Client.java:1634)
| at org.jboss.remoting.Client.invoke(Client.java:548)
| at org.jboss.invocation.unified.interfaces.UnifiedInvokerProxy.invoke(UnifiedInvokerProxy.java:183)
| at org.jboss.invocation.InvokerInterceptor.invokeInvoker(InvokerInterceptor.java:365)
| at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:197)
| at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:61)
| at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:70)
| at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:184)
| at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:100)
| at $Proxy0.create(Unknown Source)
| at com.sun.ebank.appclient.DataModel.<init>(DataModel.java:127)
| at com.sun.ebank.appclient.EventHandle.<init>(EventHandle.java:51)
| at com.sun.ebank.appclient.BankAdmin.main(BankAdmin.java:587)
This is in case I name the entities "java:comp/env/ejb/myEJB" because if I just name the ejb "myEJB" the exception should be
| java.rmi.ServerException: EJBException:; nested exception is:
| javax.ejb.EJBException: ejbCreate: myEJB not bound
| at etc...
|
The question is that the entities interfaces are locals son I do not know the way to call them.
Any help over there.
Thank you,
Jose Alvarez de Lara
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4196944#4196944
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4196944
More information about the jboss-user
mailing list