As per documentation HANA supports ejb3. But my current application is developed using ejb2. The application is huge so migrating to ejb3 takes little time. Meanwhile i want to run my ejb2 application on Hana. I created and deployed sample test application for ejb2 on Hana and i am getting below error when i am making jndi lookup(ctx.lookup("<jndi-name>") is throwing exception). I attached the source code of my test application. I have 2 questions regarding this
1) in which file(web.xml or some other file) and using which tags can i specify the jndi name for my ejb bean ?
2) How can i lookup the ejb bean ?
The exception i am getting is
javax.naming.NamingException: Error while attempting to resolve reference [Root exception is javax.naming.NameNotFoundException: No EJB found for reference "comp/env/testjndiname": ejb-link=null, interface=null]
at org.eclipse.gemini.naming.ProviderAdminImpl.getObjectInstance(ProviderAdminImpl.java:51)
at org.eclipse.gemini.naming.SecurityAwareProviderAdminImpl$GetObjectInstanceAction.run(SecurityAwareProviderAdminImpl.java:88)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.gemini.naming.SecurityUtils.invokePrivilegedAction(SecurityUtils.java:45)
at org.eclipse.gemini.naming.SecurityAwareProviderAdminImpl.invokePrivilegedAction(SecurityAwareProviderAdminImpl.java:70)
at org.eclipse.gemini.naming.SecurityAwareProviderAdminImpl.getObjectInstance(SecurityAwareProviderAdminImpl.java:49)
at org.eclipse.gemini.naming.TraditionalObjectFactoryBuilder$NamingManagerAction.runProviderAdminAction(TraditionalObjectFactoryBuilder.java:148)
at org.eclipse.gemini.naming.TraditionalObjectFactoryBuilder$TraditionalObjectFactory.resolveObjectWithProviderAdmin(TraditionalObjectFactoryBuilder.java:106)
at org.eclipse.gemini.naming.TraditionalObjectFactoryBuilder$TraditionalObjectFactory.getObjectInstance(TraditionalObjectFactoryBuilder.java:74)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:300)
at org.apache.naming.NamingContext.lookup(NamingContext.java:843)
at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
at org.eclipse.gemini.naming.ContextWrapperImpl.lookup(ContextWrapperImpl.java:49)
at sun.reflect.GeneratedMethodAccessor45.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.eclipse.gemini.naming.ReflectionUtils.invokeMethodOnObject(ReflectionUtils.java:77)
at org.eclipse.gemini.naming.ReflectionUtils.invokeMethodOnContext(ReflectionUtils.java:58)
at org.eclipse.gemini.naming.ServiceAwareContextFactory$DefaultServiceAwareInvocationHandler.invokeContextMethod(ServiceAwareContextFactory.java:98)
at org.eclipse.gemini.naming.ServiceAwareContextFactory$DefaultServiceAwareInvocationHandler.invoke(ServiceAwareContextFactory.java:69)
at com.sun.proxy.$Proxy17.lookup(Unknown Source)
at sun.reflect.GeneratedMethodAccessor45.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.eclipse.gemini.naming.ReflectionUtils.invokeMethodOnObject(ReflectionUtils.java:77)
at org.eclipse.gemini.naming.ReflectionUtils.invokeMethodOnContext(ReflectionUtils.java:58)
at org.eclipse.gemini.naming.TraditionalInitialContextFactoryBuilder$TraditionalContextInvocationHandler.invoke(TraditionalInitialContextFactoryBuilder.java:139)
at com.sun.proxy.$Proxy17.lookup(Unknown Source)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at com.hana.ejb2_1.Ejb2_1HelloWorldServlet.doGet(Ejb2_1HelloWorldServlet.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.eclipse.virgo.web.enterprise.security.valve.OpenEjbSecurityInitializationValve.invoke(OpenEjbSecurityInitializationValve.java:44)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at com.sap.security.auth.service.webcontainer.internal.Authenticator.invoke(Authenticator.java:160)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at com.sap.core.tenant.valve.TenantValidationValve.invokeNextValve(TenantValidationValve.java:171)
at com.sap.core.tenant.valve.TenantValidationValve.invoke(TenantValidationValve.java:86)
at com.sap.js.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:25)
at com.sap.core.js.monitoring.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:27)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:789)
Caused by: javax.naming.NameNotFoundException: No EJB found for reference "comp/env/testjndiname": ejb-link=null, interface=null
at org.apache.openejb.assembler.classic.LazyEjbReference.getObject(LazyEjbReference.java:70)
at org.apache.openejb.core.ivm.naming.Reference.getContent(Reference.java:40)
at org.apache.xbean.naming.reference.SimpleReference$SimpleObjectFactory.getObjectInstance(SimpleReference.java:137)
at org.eclipse.gemini.naming.OSGiInitialContextFactoryBuilder.resolveObjectUsingBuilders(OSGiInitialContextFactoryBuilder.java:568)
at org.eclipse.gemini.naming.OSGiInitialContextFactoryBuilder.access$3(OSGiInitialContextFactoryBuilder.java:562)
at org.eclipse.gemini.naming.OSGiInitialContextFactoryBuilder$FactoryNameSpecifiedObjectFactory.getObjectInstance(OSGiInitialContextFactoryBuilder.java:983)
at org.eclipse.gemini.naming.OSGiInitialContextFactoryBuilder$ReturnReferenceInfoObjectFactory.getObjectInstance(OSGiInitialContextFactoryBuilder.java:806)
at org.eclipse.gemini.naming.ProviderAdminImpl.getObjectInstance(ProviderAdminImpl.java:48)
... 57 more
The test application files are
1) HelloWorldHome - Home interface for bean
2)HelloWorldRemote - remote interface for bean
3)HelloWorldBean - actual bean implementation code
4)Ejb2_1HelloWorldServlet - test servlet for making jndi lookup
5)web.xml
-------------------------------------------------------------------------------------------------------------------------------
public interface HelloWorldHome extends EJBHome {
public HelloWorldBean create() throws
CreateException, RemoteException;
}
-------------------------------------------------------------------------------------------------------------------------------
public interface HelloWorldRemote extends EJBObject {
public String sayHello() throws RemoteException;
}
-------------------------------------------------------------------------------------------------------------------------------
public class HelloWorldBean implements SessionBean{
private static final long serialVersionUID = 1L;
public HelloWorldBean() {
}
public String sayHello() {
return "Hello world greeting from ejb 2.1 session bean";
}
public void ejbActivate() throws EJBException, RemoteException {
System.out.println("ejb activate method is called");
}
public void ejbPassivate() throws EJBException, RemoteException { }
public void ejbRemove() throws EJBException, RemoteException {}
protected SessionContext ctx;
public void setSessionContext(SessionContext arg0) throws EJBException,
RemoteException {
this.ctx = arg0;
}
}
-----------------------------------------------------------web.xml file--------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Ejb2_1HelloWorldServlet</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>Ejb2_1HelloWorldServlet</display-name>
<servlet-name>Ejb2_1HelloWorldServlet</servlet-name>
<servlet-class>com.hana.ejb2_1.Ejb2_1HelloWorldServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Ejb2_1HelloWorldServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<ejb-ref>
<ejb-ref-name>testjndiname</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<remote>com.hana.ejb2_1.HelloWorldRemote</remote>
</ejb-ref>
<!-- <resource-env-ref>
<description>Object factory for MyBean instances</description>
<resource-env-ref-name>bean/MyBeanFactory</resource-env-ref-name>
<resource-env-ref-type>com.hana.ejb2_1.HelloWorldBean </resource-env-ref-type>
</resource-env-ref> -->
--------------------------------------------------------------------------test servlet code-------------------------------------------------------------------------------------------
InitialContext ctx = new InitialContext();
String lookupName = "java:comp/env/" + "testjndiname1"; //how to get this lookup name
Object objref;
objref = ctx.lookup(lookupName); // getting error here
HelloWorldHome home = (HelloWorldHome)PortableRemoteObject.narrow(objref, HelloWorldHome.class);
HelloWorldBean myHelloWorld = home.create();
String message = myHelloWorld.sayHello();
response.getWriter().println(message);
-----------------------------------------------------------------------------------------------------------------------------------------------