7 Replies Latest reply on Jul 12, 2008 1:21 AM by admin.admin.email.tld

    Call Session Bean between two Seam Projects

      I am new to both Seam and JEE, so fogive me if this seems like a trivial question. If I have two projects deployed on the same JBoss server what are my options for being able to invoke and call a session bean in project A from project B? Is using a @Remote my only options are there ways to invoke the call via the @Local interface?


        • 1. Re: Call Session Bean between two Seam Projects
          jasondlee

          Beans annotated with @Local are not directly accessible outside the application in which it's deployed.  So an @Local in foo.ear is not accessible from bar.ear.  If you want to access it outside the ear, you will need @Remote.

          • 2. Re: Call Session Bean between two Seam Projects
            admin.admin.email.tld

            Please refer to EJB3 in Action, pg. 87:



            A local interface is designed for clients of stateless sesssion beans collocated in the same container (JVM) instance.

            In your case, if you are deploying the two apps (EARs) into the same JBoss AS instance, then there is only one JVM (assuming there is no cluster).  Use @Local.


            Only use RMI to call a method on a SFSB/SLSB if you must (from one JVM to another JVM, or one JBoss instance to another JBoss instance).  There is significant overhead and a performance hit when you use remote interfaces.

            • 3. Re: Call Session Bean between two Seam Projects

              So since they are separate projects I assume I cannot use Seam @In annotation is this correct? To use the @Local interface how do get this? In my unit tests I have:


              MyServiceLocal srv = new MyServiceImpl();



              Within my Seam session bean would I do the same thing?

              • 4. Re: Call Session Bean between two Seam Projects
                admin.admin.email.tld

                When the EJB's are deployed as part of the EAR, they are registered in the JNDI namespace (you can check this in the jmx-console of JBoss after startup and deployment).


                According to JSR220-core:


                A client can obtain a session bean’s business interface through dependency injection or lookup in the
                JNDI namespace.
                For example, the business interface Cart for the CartBean session bean may be obtained using
                dependency injection as follows:
                @EJB Cart cart;
                The Cart business interface could also be looked up using JNDI as shown in the following code seg-
                ment using the lookup method provided by the EJBContext interface. In this example, a reference to
                the client bean’s SessionContext object is obtained through dependency injection:
                @Resource SessionContext ctx;
                ...
                Cart cart = (Cart)ctx.lookup(“cart”);



                In a Seam app, you can use @In instead of @EJB to inject the local interface:


                @In(create=true) PaymentHandler paymentHandler;



                where PaymentHandler is the name of the local interface and paymentHandler is the @Name value of the session bean implementation class.





                • 5. Re: Call Session Bean between two Seam Projects

                  Thanks for your help. When I whether I use the @In or the @EJB to inject the session been I get the same error:


                  07:42:16,798 ERROR [JmsServerSession] Unexpected error delivering message org.jboss.mq.SpyMapMessage {
                  Header { 
                     jmsDestination  : QUEUE.KeyBankCheckImageQueue
                     jmsDeliveryMode : 2
                     jmsExpiration   : 0
                     jmsPriority     : 4
                     jmsMessageID    : ID:3-12157837367671
                     jmsTimeStamp    : 1215783736767
                     jmsCorrelationID: null
                     jmsReplyTo      : null
                     jmsType         : null
                     jmsRedelivered  : false
                     jmsProperties   : {}
                     jmsPropReadWrite: false
                     msgReadOnly     : true
                     producerClientId: ID:3
                  }
                  }
                  java.lang.RuntimeException: Non matching type for inject of field: com.idfbins.nexusevents.services.NexusEventsService com.idfbins.keybank.KeyBankCheckImagesMessageHandler.nexusEventsService for type: $Proxy148 of jndiName env/com.idfbins.keybank.KeyBankCheckImagesMessageHandler/nexusEventsService
                  intfs: , com.idfbins.nexusevents.services.NexusEventsService, org.jboss.ejb3.JBossProxy
                          at org.jboss.injection.JndiFieldInjector.inject(JndiFieldInjector.java:128)
                          at org.jboss.injection.JndiFieldInjector.inject(JndiFieldInjector.java:106)
                          at org.jboss.injection.JndiFieldInjector.inject(JndiFieldInjector.java:63)
                          at org.jboss.ejb3.AbstractPool.create(AbstractPool.java:111)
                          at org.jboss.ejb3.StrictMaxPool.get(StrictMaxPool.java:141)
                          at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:54)
                          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                          at org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:249)
                          at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:268)
                          at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:138)
                          at $Proxy101.onMessage(Unknown Source)
                          at org.jboss.resource.adapter.jms.inflow.JmsServerSession.onMessage(JmsServerSession.java:178)
                          at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:891)
                          at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:170)
                          at org.jboss.mq.SpySession.run(SpySession.java:323)
                          at org.jboss.resource.adapter.jms.inflow.JmsServerSession.run(JmsServerSession.java:237)
                          at org.jboss.resource.work.WorkWrapper.execute(WorkWrapper.java:204)
                          at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:275)
                          at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:756)
                          at java.lang.Thread.run(Thread.java:595)
                  Caused by: java.lang.IllegalArgumentException
                          at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63)
                          at java.lang.reflect.Field.set(Field.java:656)
                          at org.jboss.injection.JndiFieldInjector.inject(JndiFieldInjector.java:116)
                          ... 19 more
                  07:42:16,798 ERROR [JmsServerSession] Unexpected error delivering message org.jboss.mq.SpyMapMessage {
                  Header { 
                     jmsDestination  : QUEUE.KeyBankCheckImageQueue
                     jmsDeliveryMode : 2
                     jmsExpiration   : 0
                     jmsPriority     : 4
                     jmsMessageID    : ID:3-12157837367671
                     jmsTimeStamp    : 1215783736767
                     jmsCorrelationID: null
                     jmsReplyTo      : null
                     jmsType         : null
                     jmsRedelivered  : true
                     jmsProperties   : {JMS_JBOSS_REDELIVERY_COUNT=1}
                     jmsPropReadWrite: false
                     msgReadOnly     : true
                     producerClientId: ID:3
                  }
                  }



                  I am trying to google this to see what this error means, but if you have any idea please let me know.

                  • 6. Re: Call Session Bean between two Seam Projects

                    I found this article:


                    http://wiki.jboss.org/wiki/ClassLoadingConfiguration


                    Per it instructions I changed the jboss-service.xml to use call my value:


                     <attribute name="CallByValue">true</attribute>



                    This solve the problem above. Now the session bean is called successfully. However now I get a class cast exception with the object returned by the session bean method.


                    Will this ever end? This should not be that difficult. I called a session bean in another ear that stange of a use case that it requires all this configuration and debugging?


                    Anyway, in desperation and made sure the object returned by the session bean was serializable and had a versionid, but no dice. I still get the classCastException. I don't understand why I am getting this classCastException. Any help would be appreciated.


                    java.lang.ClassCastException: com.idfbins.nexusevents.vo.NexusEventDefinition
                         at $Proxy175.findNexusEventDefinitionByName(Unknown Source)
                         at com.idfbins.keybank.KeyBankCheckImagesMessageHandler.onMessage(KeyBankCheckImagesMessageHandler.java:76)
                         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.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
                         at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
                         at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
                         at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                         at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
                         at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                         at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
                         at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                         at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
                         at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                         at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:118)
                         at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
                         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.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
                         at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
                         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                         at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
                         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                         at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
                         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                         at org.jboss.aspects.tx.TxPolicy.invokeInNoTx(TxPolicy.java:66)
                         at org.jboss.aspects.tx.TxInterceptor$NotSupported.invoke(TxInterceptor.java:112)
                         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                         at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
                         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                         at org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:249)
                         at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:268)
                         at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:138)
                         at $Proxy103.onMessage(Unknown Source)
                         at org.jboss.resource.adapter.jms.inflow.JmsServerSession.onMessage(JmsServerSession.java:178)
                         at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:891)
                         at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:170)
                         at org.jboss.mq.SpySession.run(SpySession.java:323)
                         at org.jboss.resource.adapter.jms.inflow.JmsServerSession.run(JmsServerSession.java:237)
                         at org.jboss.resource.work.WorkWrapper.execute(WorkWrapper.java:204)
                         at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:275)
                         at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:756)
                         at java.lang.Thread.run(Thread.java:595)

                    • 7. Re: Call Session Bean between two Seam Projects
                      admin.admin.email.tld
                      I've been using JBoss since 3.2.0.

                      I've never changed that value below:

                      <mbean code="org.jboss.naming.NamingService"
                            name="jboss:service=Naming"
                            xmbean-dd="resource:xmdesc/NamingService-xmbean.xml">
                            <!-- The call by value mode. true if all lookups are unmarshalled using
                               the caller's TCL, false if in VM lookups return the value by reference.
                            -->
                            <attribute name="CallByValue">false</attribute>

                      Have you tried a fresh extract of JBoss AS and re-deploy/test???  It's quick and easy to do (assuming you haven't done too many config changes).

                      Hopefully if you're using java generics you shouldn't have to worry about ClassCastExceptions, but not sure where/what the root cause is for your exception above...