2 Replies Latest reply on Oct 18, 2012 10:31 PM by Dasari Prasad

    ejb-local lookup not coming properly during migration to Jboss7.1.1

    Dasari Prasad Newbie

      i have a MDB making a local lookup for a local-entity bean that was deployed separately ,i had included local & local home interfaces

      in the current mdb2.1 jar

       

      bean is

      public class MsgReceiveBean implements

             MessageDrivenBean,MessageListener {

       

        protected MessageDrivenContext mtx = null;

        static AtomicInteger  seq = new AtomicInteger(10);

       

        public static int getNextKey() {

          return seq.incrementAndGet();

        }

       

        public void setMessageDrivenContext(MessageDrivenContext mtx) {

          this.mtx = mtx;

        }

       

        public void ejbCreate() {

          System.err.println("ejbCreate() method is called");

        }  

       

        public void onMessage(Message msg) {     

          Integer key = MsgReceiveBean.getNextKey();

          String prodName = "",dateStr = "";

          double prodPrice = 0.0;

          java.sql.Date prodDate = null;

          int prodQty = 0;

          if(msg instanceof MapMessage) {

            MapMessage mm = (MapMessage)msg;

            try {

            

             prodName = mm.getString("PRODNAME");

             prodPrice = mm.getDouble("PRODPRICE");

             dateStr = mm.getString("PRODDATE");

             prodDate = java.sql.Date.valueOf(dateStr);

             prodQty = mm.getInt("PRODQTY");

            

             MessageHelpLocal msgObj = getMessageHelpLocal(key);

             System.out.println("###"+msgObj);

       

             String reply = msgObj.orderProduct(prodName,prodDate,prodQty,prodPrice);

             System.out.println("Received from MessageHelperBean : "+reply);

          }catch(Exception ex) {

             ex.printStackTrace();

          }

         }      

        }

       

        public MessageHelpLocal getMessageHelpLocal(Integer id) {

         System.out.println("****"+id);

         try {

           InitialContext itx = new InitialContext();

           MessageHelpHome  home =

             (MessageHelpHome)itx.lookup("java:comp/env/ejb/msgHelpBean");

           MessageHelpLocal   msgObj = home.create(id.intValue());

           return msgObj;

         }catch(Exception e) {

            e.printStackTrace();

            return null;

         }

      }

       

        public void ejbRemove() {

          System.err.println("Bean being removed...");

        }

       

      }

      ejb-jar.xml is

       

      <?xml  version="1.0" ?>

      <ejb-jar  xmlns="http://java.sun.com/xml/ns/j2ee"

              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

           xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version="2.1">

       

         <enterprise-beans>

          <message-driven>

            <ejb-name>MSGRECEIVER</ejb-name>

            <ejb-class>msgrecpt.MsgReceiveBean</ejb-class>

            <transaction-type>Container</transaction-type>

           

             <message-destination-type>javax.jms.Topic</message-destination-type>

           

            <ejb-local-ref>

              <ejb-ref-name>ejb/msgHelpBean</ejb-ref-name>

              <ejb-ref-type>Entity</ejb-ref-type>

              <local-home>msghelp.MessageHelpHome</local-home>

              <local>msghelp.MessageHelpLocal</local>       

            </ejb-local-ref>

           

            <resource-ref>

              <res-ref-name>tpFactory</res-ref-name>                           

              <res-type>javax.jms.ConnectionFactory</res-type>

              <res-auth>Container</res-auth>

            </resource-ref>  

           </message-driven>

         </enterprise-beans>

         <assembly-descriptor>

            <container-transaction>

            <method>

             <ejb-name>MSGRECEIVER</ejb-name>

             <method-name>*</method-name>

            </method>

           <trans-attribute>Required</trans-attribute>

          </container-transaction>

          </assembly-descriptor>

      </ejb-jar>

       

      jboss-ejb3.xml  is

       

      <?xml version="1.0"?>

      <jboss:ejb-jar  xmlns:jboss="http://www.jboss.com/xml/ns/javaee"

                      xmlns="http://java.sun.com/xml/ns/javaee"

                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                      xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd

                           http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"

                      version="3.1"

                      impl-version="2.1">

      <enterprise-beans>    

        <message-driven>

         <ejb-name>MSGRECEIVER</ejb-name>

         <ejb-class>msgrecpt.MsgReceiveBean</ejb-class>

         <activation-config>

           <activation-config-property>

            <activation-config-property-name>destination

            </activation-config-property-name>

            <activation-config-property-value>java:/topic/test</activation-config-property-value>

           </activation-config-property>

           </activation-config>

            <resource-ref>

               <res-ref-name>tpFactory</res-ref-name>

               <jndi-name>java:/RemoteConnectionFactory</jndi-name>

             </resource-ref>

            

             <ejb-local-ref>

               <ejb-ref-name>ejb/msgHelpBean</ejb-ref-name>

               <local-jndi-name>

                <![CDATA[java:global/msghelp/COS_PRODUCT!msghelp.MessageHelpHome]]>

               </local-jndi-name>

             </ejb-local-ref>

            

          </message-driven>

        </enterprise-beans>

      </jboss:ejb-jar>

       

      in server log

       

      20:23:57,582 ERROR [stderr] (Thread-1 (HornetQ-client-global-threads-23554937)) ejbCreate() method is called

       

      20:23:57,582 INFO  [stdout] (Thread-1 (HornetQ-client-global-threads-23554937)) ****11

       

      20:23:57,582 ERROR [stderr] (Thread-1 (HornetQ-client-global-threads-23554937)) java.lang.ClassCastException: msghelp.MessageHelpHome$$$view2 cannot be cast to msghelp.MessageHelpHome

       

      20:23:57,597 ERROR [stderr] (Thread-1 (HornetQ-client-global-threads-23554937))     at msgrecpt.MsgReceiveBean.getMessageHelpLocal(Unknown Source)

       

      20:23:57,597 ERROR [stderr] (Thread-1 (HornetQ-client-global-threads-23554937))     at msgrecpt.MsgReceiveBean.onMessage(Unknown Source)