1 Reply Latest reply on Feb 11, 2009 2:13 AM by jaikiran pai

    Is it possible to inject a Remote bean in a client servlet?

    Ross Nicholson Apprentice

      I'm using a remote bean from a servlet to make a remote call. The code snippet below works. But I'm wondering is it possible to inject this bean without needing to do the remote JNDI lookup.

      When using JMS I setup a RemoteJMSProvider and can inject both the connection factory and destination queue from a servlet (I'm using the web 2.5 spec).

      Is something similar possible with EJB's? Or am I stuck with the JNDI lookup code. Maybe some kind of mbean provider where I can specify the remote machine IP?

      Cheers,

      Ross

      P.S. I've commented out the @EJB annotation as it does nothing.

      //@EJB
      private MyTestBeanRemote remoteBean;
      
      protected void doGet(HttpServletRequest request,
       HttpServletResponse response) throws ServletException, IOException {
      
       try {
       Properties properties = new Properties();
       properties.put(Context.INITIAL_CONTEXT_FACTORY,
       "org.jnp.interfaces.NamingContextFactory");
       properties.put(Context.URL_PKG_PREFIXES,
       "org.jboss.naming:org.jnp.interfaces");
       properties.put(Context.PROVIDER_URL, "jnp://172.16.8.52:1099");
      
       Context ctx = new InitialContext(props);
       remoteBean = (MyTestBeanRemote) ctx.lookup("TestEAR/MyTestBeanRemote/remote");
      
      
       } catch (Exception ex) {
       System.out.println("Could not create bean. "+
       ex.getMessage());
       }
      
       if (remoteBean != null) remoteBean.doSomething();
      }