[jboss-user] [EJB 3.0] - Is it possible to inject a Remote bean in a client servlet?

rnicholson10 do-not-reply at jboss.com
Tue Feb 10 10:38:39 EST 2009

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?



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://");
  | 		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();
  | }

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4208628#4208628

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4208628

More information about the jboss-user mailing list