Hi,

I think there is a bug in the handling of local-home-jndi-name when using the 
ejb3 deployer.

I am trying to set up some local SLSB beans to respond to a legacy SLSB. 
Initally when I tried this I get ClassCastExceptions on the proxy returned from 
JNDI. I corrected this on remote connections by replacing the jndi-name with 
home-jndi-name in jboss.xml.

Logically I thought the fix for local connections would be to use 
local-home-jndi-name, this deploys fine but the corresponding JNDI entry is 
actually a proxy to the local interface, not the local home interface.

Below is the test code I am using to verify this:

Remote bean:

  | public class RemoteHomeTestEJB implements SessionBean {
  | 
  |     private SessionContext context = null;
  | 
  |     /*
  |      * (non-Javadoc)
  |      * 
  |      * @see javax.ejb.SessionBean#ejbActivate()
  |      */
  |     public void ejbActivate() throws EJBException, RemoteException {
  |             // TODO Auto-generated method stub
  | 
  |     }
  | 
  |     /*
  |      * (non-Javadoc)
  |      * 
  |      * @see javax.ejb.SessionBean#ejbPassivate()
  |      */
  |     public void ejbPassivate() throws EJBException, RemoteException {
  |             // TODO Auto-generated method stub
  | 
  |     }
  | 
  |     /*
  |      * (non-Javadoc)
  |      * 
  |      * @see javax.ejb.SessionBean#ejbRemove()
  |      */
  |     public void ejbRemove() throws EJBException, RemoteException {
  |             // TODO Auto-generated method stub
  | 
  |     }
  |     
  |     public void ejbCreate() {
  |             //Do nothing.
  |     }
  | 
  |     /*
  |      * (non-Javadoc)
  |      * 
  |      * @see 
javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
  |      */
  |     public void setSessionContext(SessionContext ctx) throws EJBException,
  |                     RemoteException {
  |             context = ctx;
  |     }
  | 
  |     public String getHello() {
  |             try {
  |                     LocalHomeTestHome home = null;
  |                     home = 
ServiceLocator.locateHome(LocalHomeTestHome.class,
  |                                     "java:comp/env/local/LocalHomeTest");
  |                     return home.create().getHello();
  |             } catch (Exception e) {
  |                     StringWriter stringWriter = new StringWriter();
  |                     PrintWriter writer = new PrintWriter(stringWriter);
  |                     e.printStackTrace(writer);
  |                     return stringWriter.toString();
  |             }
  |     }
  | }
  | 

ServiceLocater.java

  | public class ServiceLocator {
  |     private static final Logger LOG = 
Logger.getLogger(ServiceLocator.class);
  | 
  |     @SuppressWarnings("unchecked")
  |     public static <T> T locateHome(Class<T> clazz, String location)
  |                     throws NamingException {
  |             T home = null;
  |             Context ic = new InitialContext();
  | 
  |             Object potentialHome = ic.lookup(location);
  |             if (clazz.isInstance(potentialHome)) {
  |                     home = (T) potentialHome;
  |             } else {
  |                     home = (T) PortableRemoteObject.narrow(potentialHome, 
clazz);
  |             }
  |             return home;
  |     }
  | }
  | 

Local bean:

  | public class LocalHomeTestEJB implements SessionBean {
  | 
  |     /* (non-Javadoc)
  |      * @see javax.ejb.SessionBean#ejbActivate()
  |      */
  |     public void ejbActivate() throws EJBException, RemoteException {
  |             // TODO Auto-generated method stub
  | 
  |     }
  | 
  |     /* (non-Javadoc)
  |      * @see javax.ejb.SessionBean#ejbPassivate()
  |      */
  |     public void ejbPassivate() throws EJBException, RemoteException {
  |             // TODO Auto-generated method stub
  | 
  |     }
  |     
  |     public void ejbCreate() {
  |             //Do nothing.
  |     }
  | 
  |     /* (non-Javadoc)
  |      * @see javax.ejb.SessionBean#ejbRemove()
  |      */
  |     public void ejbRemove() throws EJBException, RemoteException {
  |             // TODO Auto-generated method stub
  | 
  |     }
  | 
  |     /* (non-Javadoc)
  |      * @see 
javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
  |      */
  |     public void setSessionContext(SessionContext ctx) throws EJBException,
  |                     RemoteException {
  |             // TODO Auto-generated method stub
  | 
  |     }
  | 
  |     public String getHello() {
  |             return "Hello from Aerosystems";
  |     }
  | 
  | }
  | 
ejb-jar.xml:

  | <ejb-jar version="3.0"  xmlns="http://java.sun.com/xml/ns/javaee"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  | xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd";>
  | 
  |    <description>Simple migration testing to see how to move to EJB 
3</description>
  |    <display-name>EjbMigration</display-name>
  |    
  |    <enterprise-beans>
  |       <session>
  |          <description><![CDATA[EcardGenerationFacadeSessionEJB 
Bean]]></description>
  |          <display-name>LocalHomeTest</display-name>
  | 
  |          <ejb-name>LocalHomeTest</ejb-name>
  |          <remote>com.aeroint.ejbtest.common.RemoteHomeTestInterface</remote>
  |          
<local-home>com.aeroint.ejbtest.server.session.LocalHomeTestHome</local-home>
  |          
<local>com.aeroint.ejbtest.server.session.LocalHomeTestInterface</local>
  |          
<ejb-class>com.aeroint.ejbtest.server.session.LocalHomeTestEJB</ejb-class>
  |          
  |          <session-type>Stateless</session-type>
  |          <transaction-type>Container</transaction-type>
  |       </session>
  |       
  |     <session>
  |          <description><![CDATA[EcardUpdateFacadeSessionEJB 
Bean]]></description>
  |          <display-name>RemoteHomeTest</display-name>
  | 
  |          <ejb-name>RemoteHomeTest</ejb-name>
  | 
  |          <home>com.aeroint.ejbtest.common.RemoteHomeTestHome</home>
  |          <remote>com.aeroint.ejbtest.common.RemoteHomeTestInterface</remote>
  |          
<ejb-class>com.aeroint.ejbtest.server.facade.RemoteHomeTestEJB</ejb-class>
  |          <session-type>Stateless</session-type>
  |          <transaction-type>Container</transaction-type>
  | 
  |          <ejb-local-ref >
  |             <ejb-ref-name>local/LocalHomeTest</ejb-ref-name>
  |             <ejb-ref-type>Session</ejb-ref-type>
  |             
<local-home>com.aeroint.ejbtest.server.session.LocalHomeTestHome</local-home>
  |             
<local>com.aeroint.ejbtest.server.session.LocalHomeTestInterface</local>
  |                 <ejb-link>LocalHomeTest</ejb-link>
  |          </ejb-local-ref>
  | 
  |       </session>
  |    </enterprise-beans>
  | </ejb-jar>
  | 

jboss.xml

  | <jboss xmlns="http://java.sun.com/xml/ns/javaee";
  |     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  |     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  | http://www.jboss.org/j2ee/schema/jboss_5_0.xsd";
  |     version="3.0">
  |     <enterprise-beans>
  |             <session>
  |                     <ejb-name>RemoteHomeTest</ejb-name>
  |                     <home-jndi-name>remote/RemoteHomeTest</home-jndi-name>
  |             </session>
  |             <session>
  |                     <ejb-name>LocalHomeTest</ejb-name>
  |                     
<local-home-jndi-name>local/LocalHomeTest</local-home-jndi-name>
  |             </session>
  |     </enterprise-beans>
  | </jboss>
  | 

Thanks in advance,
Shane

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

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4101224
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to