I’m trying to implement an ejb-call by using JNDI-naming.
Setup:
- JBoss-6.1.0.Final
- ear-deploy:
- gwt.war
- ejb.jar
My problem is, although the JNDIView shows me the existing ejb, I’m not able to reach it.
In my RemoteServiceServlet I try to reach the ejb, which is deployed in the ejb.jar inside the same ear-package.
I allready tried several calls, as I wasn’t sure about the correct jndi code.
try
{
productLocal = (ProductLocal) context.lookup("ProductHome/local");
}
catch (NamingException e)
{
System.err.println(e.getMessage());
e.printStackTrace();
}
also tried:
productLocal = (ProductLocal) context.lookup("ProductLocal");
productLocal = (ProductLocal) context.lookup("sung_app_kylintv/ProductHome/local");
The stateless ejb is assigned like this:
@Stateless
@Local(ProductLocal.class)
@Remote(ProductRemote.class)
@LocalBinding(jndiBinding="ProductLocal")
@RemoteBinding(jndiBinding="ProductRemote")
public class ProductHome extends HomeBase<ProductEntity> implements SessionBean, Serializable, ProductLocal
The context initiation:
Properties p = new Properties();
p.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
p.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
p.put("java.naming.provider.url","jnp://localhost:1099");
context = new InitialContext(p);
My JNDIView:
+- sung_app_kylintv (class: org.jnp.interfaces.NamingContext)
| +- CategoryHome (class: org.jnp.interfaces.NamingContext)
| | +- local (class: Proxy for: sung.app.kylintv.ejbclient.product.CategoryLocal)
| | +- local-sung.app.kylintv.ejbclient.product.CategoryLocal (class: Proxy for: sung.app.kylintv.ejbclient.product.CategoryLocal)
| | +- remote-sung.app.kylintv.ejbclient.product.CategoryRemote (class: Proxy for: sung.app.kylintv.ejbclient.product.CategoryRemote)
| | +- remote (class: Proxy for: sung.app.kylintv.ejbclient.product.CategoryRemote)
| +- ProductHome (class: org.jnp.interfaces.NamingContext)
| | +- local (class: Proxy for: sung.app.kylintv.ejbclient.product.ProductLocal)
| | +- remote (class: Proxy for: sung.app.kylintv.ejbclient.product.ProductRemote)
| | +- remote-sung.app.kylintv.ejbclient.product.ProductRemote (class: Proxy for: sung.app.kylintv.ejbclient.product.ProductRemote)
| | +- local-sung.app.kylintv.ejbclient.product.ProductLocal (class: Proxy for: sung.app.kylintv.ejbclient.product.ProductLocal)
| +- CustomerHome (class: org.jnp.interfaces.NamingContext)
| | +- local-sung.common.behavior.FindAllBehaviour (class: Proxy for: sung.common.behavior.FindAllBehaviour)
| | +- local (class: Proxy for: sung.common.behavior.FindAllBehaviour)
| +- Option (class: org.jnp.interfaces.NamingContext)
| | +- local-sung.app.kylintv.ejbclient.product.OptionLocal (class: Proxy for: sung.app.kylintv.ejbclient.product.OptionLocal)
| | +- local (class: Proxy for: sung.app.kylintv.ejbclient.product.OptionLocal)
| | +- remote-sung.app.kylintv.ejbclient.product.OptionRemote (class: Proxy for: sung.app.kylintv.ejbclient.product.OptionRemote)
| | +- remote (class: Proxy for: sung.app.kylintv.ejbclient.product.OptionRemote)
| +- DurationHome (class: org.jnp.interfaces.NamingContext)
| | +- local (class: Proxy for: sung.app.kylintv.ejbclient.product.DurationLocal)
| | +- local-sung.app.kylintv.ejbclient.product.DurationLocal (class: Proxy for: sung.app.kylintv.ejbclient.product.DurationLocal)
| | +- remote (class: Proxy for: sung.app.kylintv.ejbclient.product.DurationRemote)
| | +- remote-sung.app.kylintv.ejbclient.product.DurationRemote (class: Proxy for: sung.app.kylintv.ejbclient.product.DurationRemote)
| +- VariantHome (class: org.jnp.interfaces.NamingContext)
| | +- local (class: Proxy for: sung.app.kylintv.ejbclient.product.VariantLocal)
| | +- local-sung.app.kylintv.ejbclient.product.VariantLocal (class: Proxy for: sung.app.kylintv.ejbclient.product.VariantLocal)
| | +- remote (class: Proxy for: sung.app.kylintv.ejbclient.product.VariantRemote)
| | +- remote-sung.app.kylintv.ejbclient.product.VariantRemote (class: Proxy for: sung.app.kylintv.ejbclient.product.VariantRemote)
| +- VelocityBean (class: org.jnp.interfaces.NamingContext)
| | +- local (class: Proxy for: sung.app.kylintv.ejb.velocity.Velocity)
| | +- local-sung.app.kylintv.ejb.velocity.Velocity (class: Proxy for: sung.app.kylintv.ejb.velocity.Velocity)
| +- CustomerAddressHome (class: org.jnp.interfaces.NamingContext)
| | +- local-sung.common.behavior.FindAllBehaviour (class: Proxy for: sung.common.behavior.FindAllBehaviour)
| | +- local (class: Proxy for: sung.common.behavior.FindAllBehaviour)
| +- OrderEntityHome (class: org.jnp.interfaces.NamingContext)
| | +- no-interface (class: sung.app.kylintv.ejbclient.order.OrderEntityHome_$$_javassist_50)
Are there any requirements for jndi to work properly in a case like this?
using
returned a slightly different error message:
After a colleague of mine took a look the error has been identified: I tried an Injection using @EJB inside of that class ProductHome, that used mappedName=”sung/…”. The mappedName isn’t correct and even not required at all, inside the ejb-project the connections do allready exist and work. Hope, this may help others as well.
Solution:
I had to fix my ProductHome by removing the mappedName-Attribute on my ejb-call. After that the class can be instanciated and functions are called.