aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Calling a stateless bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Calling a stateless bean" Watch "Calling a stateless bean" New topic
Author

Calling a stateless bean

ray frid
Ranch Hand

Joined: Dec 23, 2010
Posts: 79
Hi,
Is there a way with annotations to call an EJB stateless bean from servlet? if there is, anyone could past some example? thanks.

this is what I tried to do:


public class StartUpServlet extends HttpServlet
{
@EJB
RequestHandlerBean requestHandlerBean;

/**
* Constructor of the object.
*/
public StartUpServlet()
{
super();
System.out.print("Servlet, start up");
requestHandlerBean.start();
}
}

error:

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.RuntimeException: Could not find InvokerLocator URL at JNDI address "ECMS/RequestHandlerBean/local-beans.RequestHandlerBeanLocal"; looking up local Proxy from Remote JVM?
org.jboss.ejb3.proxy.impl.objectfactory.ProxyObjectFactory.createProxyFactoryProxy(ProxyObjectFactory.java:187)
org.jboss.ejb3.proxy.impl.objectfactory.ProxyObjectFactory.getObjectInstance(ProxyObjectFactory.java:148)
javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1479)
org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1496)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:822)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
javax.naming.InitialContext.lookup(InitialContext.java:392)
org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1346)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:817)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
org.jboss.ejb3.JndiUtil.lookup(JndiUtil.java:44)
org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.java:75)
org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:99)
org.jboss.web.tomcat.service.TomcatInjectionContainer.processInjectors(TomcatInjectionContainer.java:366)
org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:271)
org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:265)
org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:256)
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Thread.java:619)
note The full stack trace of the root cause is available in the JBoss Web/2.1.3.GA logs.


any idea?
thanks,

ray.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

public class StartUpServlet extends HttpServlet
{
@EJB
RequestHandlerBean requestHandlerBean;



On to your servlet , are you sure that you need to refer to your Bean class or the Remote Interface ?? I guess this shoud be your Remote Object and not Bean class

@EJB
private RequestHandlerRemote RequestHandler;

Save India From Corruption - Anna Hazare.
ray frid
Ranch Hand

Joined: Dec 23, 2010
Posts: 79
Ravi Kiran Va wrote:
public class StartUpServlet extends HttpServlet
{
@EJB
RequestHandlerBean requestHandlerBean;



On to your servlet , are you sure that you need to refer to your Bean class or the Remote Interface ?? I guess this shoud be your Remote Object and not Bean class

@EJB
private RequestHandlerRemote RequestHandler;


this is how I have implemented my beans:


import javax.annotation.PostConstruct;
import javax.ejb.Local;
import javax.ejb.Stateless;

import org.jboss.annotation.ejb.LocalBinding;

@Stateless
@Local ({RequestHandlerBeanLocal.class})
@LocalBinding (jndiBinding="RequestHandlerBean")
public class RequestHandlerBean implements RequestHandlerBeanLocal
{

public void getAllClocksFromDB()
{
}

public void start()
{
System.out.print("RequestHandlerBean, start here");
}

}





import javax.ejb.Local;

@Local
public interface RequestHandlerBeanLocal
{
public void getAllClocksFromDB();
public void start();
}
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

I have never used local beans in Annotations way , so not sure but try this way




and remove all the unnecesary things like

@Local ({RequestHandlerBeanLocal.class})
@LocalBinding (jndiBinding="RequestHandlerBean") for the time being on RequestHandlerBean class , until everything works fine .

If doesn't work , refer to the mappedName attribute also .

 
jQuery in Action, 2nd edition
 
subject: Calling a stateless bean