1 2 Previous Next 17 Replies Latest reply on Aug 16, 2012 3:26 AM by fpezzati Go to original post
      • 15. Re: Problem with: No EJB receiver available
        fpezzati

        Hello Wolf,

         

        I got some news. I tried this solution and it works:

         

        package com.myapp.ejb.session.delegates;

         

        import java.util.Properties;

        import javax.naming.Context;

        import javax.naming.InitialContext;

        import javax.naming.NamingException;

         

        public class ANewServerDelegate {

         

            private static Context context;

         

            static public String getJindiLookupName( Class<?> theBeanClass, Class<?> theSessionClass) throws NamingException    {

         

                String jbossServerName = System.getProperty("jboss.server.name");

                System.out.println("jbossServerName "+jbossServerName);

         

                if (jbossServerName == null ||  "".equals(jbossServerName)){

         

                    return "AmbrogioEE/AmbrogioEJB/"+ theBeanClass.getSimpleName() + "!" + theSessionClass.getName();

                }else{

                    return "java:global/AmbrogioEE/AmbrogioEJB/" + theBeanClass.getSimpleName() + "!" + theSessionClass.getName();

                }

            }

         

            static public Context getJndiContext() throws NamingException {

         

        //        if(context == null) {    //if I uncomment this, I got EJBReceiver exception again

                    Properties jndip = new Properties();

                    jndip.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName());

                    jndip.put(Context.PROVIDER_URL, "remote://localhost:4447");

                    jndip.put("jboss.naming.client.ejb.context", true);

                    jndip.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");

                    context = new InitialContext(jndip);

         

        //        }                        //if I uncomment this, I got EJBReceiver exception again

                return context;

            }

         

            protected Object theSession(Class<?> sessionBean, Class<?> sessionFacade) throws ServerDelegateException{

         

                try {

         

                    return getJndiContext().lookup(getJindiLookupName(sessionBean, sessionFacade));

         

                } catch (NamingException e) {

                    throw ServerExceptionFactory.generateException(e,this.getClass().getSimpleName(),0,0);

                }   

            }

        }

         

         

        package com.myapp.ejb.session.delegates;

         

        import java.util.Date;

        import java.util.List;

        import org.apache.log4j.Logger;

        import com.myapp.ejb.session.StuffRemote;

        import com.myapp.ejb.session.StuffSession;

         

        public class ANewStuffServerDelegate extends ANewServerDelegate{

         

            private Logger logger = Logger.getLogger(ANewStuffServerDelegate.class.getName());

         

            public List<StuffDTO> getAllStuff(String codiceStudio, Integer offset, Integer limit) throws ServerDelegateException {

         

                return getAllStuffBy(null,null,null,null, codiceStudio, offset,limit);

         

            }

         

            public List<StuffDTO> getAllStuffBy(Date startDate,

         

                    Date stopDate, Integer idTipoStuff, String intestatario, String codiceStudio, Integer offset,

         

                    Integer limit) throws ServerDelegateException {

         

                return ((StuffRemote) theSession(StuffSession.class, StuffRemote.class)).getAllStuffBy(startDate, stopDate, idTipoStuff, intestatario, codiceStudio, offset, limit);

         

            }

         

            public Integer getCountStuffBy(Date startDate,

         

                    Date stopDate, Integer idTipoStuff, String intestatario, String codiceStudio) throws ServerDelegateException {

         

                return ((StuffRemote) theSession(StuffSession.class, StuffRemote.class)).findByParmsCount(startDate, stopDate, idTipoStuff, intestatario, codiceStudio);

         

            }

         

            public void saveAllStuff(List<StuffDTO> dtoList) throws ServerDelegateException {

         

                for(StuffDTO dto: dtoList) {

         

                    saveStuff(dto);

         

                }

         

            }

         

            public Integer saveStuff(StuffDTO dto) throws ServerDelegateException {

         

                logger.info("StuffServerDelegate.saveStuff id="+dto.getId());

         

                dto = ((StuffRemote) theSession(StuffSession.class, StuffRemote.class)).saveStuff(dto);

         

                logger.info("StuffServerDelegate.saveStuff id="+dto.getId());

         

                return dto.getId();

         

            }

         

            public void updateStuff(StuffDTO dto) throws ServerDelegateException {

         

                ((StuffRemote) theSession(StuffSession.class, StuffRemote.class)).updateStuff(dto);

         

            }

         

            public void removeStuff(StuffDTO dto) throws ServerDelegateException {

         

                ((StuffRemote) theSession(StuffSession.class, StuffRemote.class)).removeStuff(dto);       

         

            }

         

            public StuffDTO findById(int id) throws ServerDelegateException {

         

                return ((StuffRemote) theSession(StuffSession.class, StuffRemote.class)).findById(id);

         

            }

        }

         

        As you can see the ANewStuffServerDelegate class execute a jndi lookup every time the sessionbean is needed. You can also see that a new Context is created every time I made a lookup. I tried uncommenting the "if" in ANewStuffServerDelegate.getJndiContext(), always creating a new Context is bad, but if I uncomment that code I got a EJBReceiver exception again. I provide two log files. The no_error.log report running of this solution. The error.log report about the same solution but with uncommented code in ANewServerDelegate.getJndiContext() method. In the error.log file is reported interaction with a sesssionbean, the first time it was succesfully, the second time interaction with the same sessionbean produce the NoEJBReceiver exception. The log level is ALL in both files. Let me know how to provide you usefull infos. TIA.

         

        Francesco

        • 16. Re: Problem with: No EJB receiver available
          fpezzati

          Ping.

           

          Francesco

          • 17. Re: Problem with: No EJB receiver available
            fpezzati

            A bunch of days passed and this thread did not receive attention anymore. I got the same error. No feedback? Did I post my question in a wrong way or in the wrong place? Are the infos unsufficient?

             

            Francesco

            1 2 Previous Next