7 Replies Latest reply on May 22, 2008 9:48 PM by Senthilkumar Peelikkampatti

    EJB (SLSB) Injection Issues

    Senthilkumar Peelikkampatti Newbie

      Seam 2.0.1CR1 on Glassfish-V2ur2.
      I have 2 SLSBs.


      From Ejb1, I am injecting with @In(create=true) Ejb2 ejb2.
      When I use JSP and InitialContext to access Ejb1, I got
      org.jboss.seam.InstantiationException: Could not instantiate Seam component: ejb2. And further down the error stack I got below message,
      Caused by: javax.naming.NameNotFoundException: No object bound to name java:comp/env/ejb/ejb2.


      If I use @Ejb, it is working perfectly.



        • 1. Re: EJB (SLSB) Injection Issues
          Benjamin Graf Novice

          Please post some code and exception stack trace, otherwise it's hard to find the underlying problem!


          Greets Benjamin

          • 2. Re: EJB (SLSB) Injection Issues
            Senthilkumar Peelikkampatti Newbie

            It is simple to reproduce in Glassfish v2. Please have 2 dummy ejbs. Inject 2nd ejb into first one using @In.


            Here is the code,

            @Stateless
            @Name("master")
            public class MasterBean implements MasterLocal {
                @In(create=true)
            /*    @EJB */
                SlaveLocal slave;
                public void checkDetails() {
                    slave.asignedWork();
                }
            }

            Local Interface

            @Local
            public interface MasterLocal {

                void checkDetails();
               
            }

            Here is the code for referenced (@In injected) Ejb,



            @Stateless
            @Name("slave")
            public class SlaveBean implements SlaveLocal {

                public void asignedWork() {
                    System.out.println("Asigned work called.");
                }

            }



            Here is the code for referenced (@In injected) Ejb,
            @Local
            public interface SlaveLocal {

                void asignedWork();
               
            }

            • 3. Re: EJB (SLSB) Injection Issues
              Senthilkumar Peelikkampatti Newbie

              Senthilkumar Peelikkampatti wrote on May 22, 2008 17:03:


              It is simple to reproduce in Glassfish v2. Please have 2 dummy ejbs. Inject 2nd ejb into first one using @In.

              Here is the code,

              @Stateless
              @Name("master")
              public class MasterBean implements MasterLocal {
                  @In(create=true)
              /*    @EJB */
                  SlaveLocal slave;
                  public void checkDetails() {
                      slave.asignedWork();
                  }
              }

              Local Interface

              @Local
              public interface MasterLocal {

                  void checkDetails();
                 
              }

              Here is the code for referenced (@In injected) Ejb,


              @Stateless
              @Name("slave")
              public class SlaveBean implements SlaveLocal {

                  public void asignedWork() {
                      System.out.println("Asigned work called.");
                  }

              }



              Here is the code for referenced (@In injected) Ejb,
              @Local
              public interface SlaveLocal {

                  void asignedWork();
                 
              }



              It is working with @EJB but not working with @In.
              Click HELP for text formatting instructions. Then edit this text and check the preview.

              • 4. Re: EJB (SLSB) Injection Issues
                Benjamin Graf Novice
                @Stateless
                @Name("master")
                public class MasterBean implements MasterLocal {
                    @In(create=true) /* @EJB */ SlaveLocal slave;
                    public void checkDetails() {
                        slave.asignedWork();
                    }
                }
                @Local public interface MasterLocal {
                    void checkDetails();
                }


                @Stateless
                 @Name("slave")
                 public class SlaveBean implements SlaveLocal {
                     public void asignedWork() {
                         System.out.println("Asigned work called.");
                     }
                }
                
                @Local public interface SlaveLocal {
                    void asignedWork();
                }


                First a short reformat for better reading. Well can you post your configuration files for jndi binding in glassfish.

                • 5. Re: EJB (SLSB) Injection Issues
                  Senthilkumar Peelikkampatti Newbie

                  Thanks, I am aware of code formating...:)


                  Here is ejb local reference from web.xml


                  <ejb-local-ref>
                  
                          <ejb-ref-name>evolve/MasterBean/local</ejb-ref-name>
                  
                          <ejb-ref-type>Session</ejb-ref-type>
                  
                          <local>seam.test.ejb.MasterLocal</local>
                  
                          <ejb-link>MasterBean</ejb-link>
                  
                      </ejb-local-ref>
                  
                      <ejb-local-ref>
                  
                          <ejb-ref-name>evolve/SlaveBean/local</ejb-ref-name>
                  
                          <ejb-ref-type>Session</ejb-ref-type>
                  
                          <local>seam.test.ejb.SlaveLocal</local>
                  
                          <ejb-link>SlaveBean</ejb-link>
                  
                      </ejb-local-ref>



                  Here is the components.xml


                  <?xml version="1.0" encoding="UTF-8"?>
                  
                  <components xmlns="http://jboss.com/products/seam/components"
                  
                              xmlns:core="http://jboss.com/products/seam/core"
                  
                              xmlns:security="http://jboss.com/products/seam/security"
                  
                              xmlns:transaction="http://jboss.com/products/seam/transaction"
                  
                              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  
                              xsi:schemaLocation=
                  
                                  "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd 
                  
                                   http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                  
                                   http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.0.xsd
                  
                                   http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">
                  
                  
                      <core:init jndi-pattern="java:comp/env/evolve/#{ejbName}/local" debug="true"/>    
                  
                  
                      <transaction:ejb-transaction/>
                  
                  
                      <core:manager conversation-timeout="120000" 
                  
                                    concurrent-request-timeout="500"
                  
                                    conversation-id-parameter="cid"/>
                  
                  
                      <component name="org.jboss.seam.remoting.remoting">
                  
                        <property name="debug">true</property>
                  
                      </component>
                  
                      <security:identity authenticate-method="#{serviceAuthenticator.authenticate}"/> 
                  
                  
                  </components>



                  Here is the jsp which calls the ejb using InitialContext.


                  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
                  
                              "http://www.w3.org/TR/html4/strict.dtd">
                  
                  <html>
                  
                  <head>
                  
                      <%@ page import="javax.naming.*, seam.test.ejb.*" %>
                  
                  </head>
                  
                  <body>
                  
                  <%
                  
                               InitialContext ctx;
                  
                          try {
                  
                              ctx = new InitialContext();
                  
                              MasterLocal nr = (MasterLocal) ctx.lookup("java:comp/env/evolve/MasterBean/local");
                  
                              nr.checkDetails();;
                  
                          } catch (Exception ex) {
                  
                             ex.printStackTrace();
                  
                          }
                  
                  %>
                  
                  
                  </body>
                  
                  
                  </html>



                  Some Log4j Traces....


                  [#|2008-05-22T11:34:59.235-0500|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=16;_ThreadName=httpWorkerThread-4848-1;|11:34:59,235 INFO  [Component] Component: master, scope: STATELESS, type: STATELESS_SESSION_BEAN, class: seam.test.ejb.MasterBean, JNDI: java:comp/env/evolve/MasterBean/local
                  
                  .
                  
                  .
                  
                  .
                  
                  [#|2008-05-22T11:35:00.407-0500|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=16;_ThreadName=httpWorkerThread-4848-1;|11:35:00,407 INFO  [Component] Component: slave, scope: STATELESS, type: STATELESS_SESSION_BEAN, class: seam.test.ejb.SlaveBean, JNDI: java:comp/env/evolve/SlaveBean/local
                  
                  |#]
                  
                  
                  


                  • 6. Re: EJB (SLSB) Injection Issues
                    Benjamin Graf Novice

                    Well, now I understand. You try to get the first ejb by native lookup which tries to get another ejb through the seam container. Since you get the first through ejb container the seam container does not get involved correctly. Try to get the master bean by Component.getInstance(MasterBean.class). It should work.

                    • 7. Re: EJB (SLSB) Injection Issues
                      Senthilkumar Peelikkampatti Newbie

                      Actually JNDI reference is my mistake as Seam Document says to Use either 

                      Component.getInstance()  or @In(create=true)



                      But the above code is still not working with JSP even after I use Component.getInstance() .
                      My code in JSP is as below as you told in your earlier post,


                      MasterLocal nr = (MasterLocal) Component.getInstance(MasterBean.class) ;



                      I got the below exception after the above change,


                      java.lang.IllegalStateException: No application context active
                      
                              at org.jboss.seam.Component.forName(Component.java:1807)
                      
                              at org.jboss.seam.Component.getInstance(Component.java:1857)
                      
                              at org.jboss.seam.Component.getInstance(Component.java:1840)
                      
                              at org.jboss.seam.Component.getInstance(Component.java:1819)
                      
                              at org.jboss.seam.Component.getInstance(Component.java:1814)
                      
                              at org.apache.jsp.ejbTest_jsp._jspService(ejbTest_jsp.java from :64)
                      
                              at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:93)
                      
                              at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
                      
                              at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
                      
                              at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:470)
                      
                              at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:364)
                      
                              at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
                      
                              at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
                      
                              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
                      
                              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
                      
                              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                      
                              at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
                      
                              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      
                              at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
                      
                              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      
                              at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                      
                              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      
                              at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                      
                              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      
                              at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)