0

I'm trying to run a remote lookup to another Glassfish from a Servlet. So, I was following the link documentation (http://docs.oracle.com/cd/E19798-01/821-1752/beanv/index.html). First I created a Sateless Session Ben called CalculatorBean, packaged in an EJB JAR of the same name (CalculatorBean), the JNDI name was java:global/CalculatorBean/CalculatorBean.

According to the documentation, I created a Web project and declared my EJB in sub-web.xml the following file:

<ejb-ref>
      <ejb-ref-name>ejb/CalculatorBean</ejb-ref-name>
      <jndi-name>corbaname:iiop:127.0.0.1:3700#CalculatorBean/CalculatorBean</jndi-name>
  </ejb-ref>

where 127.0.0.1 is the host of the machine (local!), 3700 is the default port for querying and, CalculatorBean/CalculatorBean is the global JNDI name. First question, theoretically the JNDI name passes into an interoperable String "CalculatorBean/CalculatorBean" instead of "java: global/CalculatorBean/CalculatorBean", right?

After that, I created a Servlet and put the following code snippet:

ctx = new InitialContext ();
bean = (CalculatorRemote) ctx.lookup ("java:comp/env/ejb/CalculatorBean");

Where, CalculatorRemote is the name of the remote interface that we included in the java project:comp/env/ is the directory section to access Java EE components and ejb/CalculatorBean is the name of my bean in the configuration of the sun-web.xml file   When put to run my Servlet I'm getting the exception:

Caused by: javax.naming.NameNotFoundException: No object bound to name java:comp/env/ejb/CalculatorBean

Obviously, it's not finding the name, however, do not really know what name I should use to set the lookup.

1 Answers1

1

I had the same problem, and I solved it.

By default, your EJB is not visilbe into java:comp/env/ and you can not lookup for an EJB into InitialContext instance. But, you can successful lookup for an EJB after when at least one EJB instance is injected using @EJB annotation, like, for your example:

@EJB(name = "ejb/CalculatorBean")
private CalculatorRemote calc;

After that, CalculatorRemote EJB is visible in InitialContext instance.

Teodor
  • 114
  • 7