Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Calling ejb from jsp

  Asked By: Boell    Date: Nov 27    Category: Java    Views: 887
  

I m tring to create a session ejb which prints some text in both server aswellas client side.
I have just compiled following .java file in to following directory and created ejb-jar.xml file
in the same.I have created a jar file named 'HelloWorld.jarContent' in the same directory.
This is where ur help is requested, I dont know
1. How the created ejb is invoked from client(Please get me exact coding)
2. Is any changes in ejb-jar.xml needed
3. Where these files r stored(directory structure)
4. How could I run the program for testing
Tools I m using
---------------
Netbeans 3.6


working directory
-----------------
D:\ER\config\sumaria\applications\DefaultWebApp\WEB-INF\classes\examples\
Present contents
----------------
1. Hello.class
2. HelloBean.class
3. HelloClient.class
4. HelloHome.class
5. HelloLocal.class
6. HelloLocalHome.class
7. ejb-jar.xml
8. HelloWorld.jarContent
My file contents
================
1. Hello.java
package examples;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface Hello extends javax.ejb.EJBObject
{
public String hello() throws java.rmi.RemoteException;
}
2. HelloBean.java
package examples;
import javax.ejb.*;
public class HelloBean implements javax.ejb.SessionBean {
private SessionContext ctx;

public void ejbCreate()
{
System.out.println("ejbCreate()");
}

public void ejbRemove()
{
System.out.println("ejbRemove()");
}
public void ejbActivate()
{
System.out.println("ejbActivate()");
}
public void ejbPassivate()
{
System.out.println("ejbPassivate()");
}
public void setSessionContext(javax.ejb.SessionContext ctx)
{
this.ctx = ctx;
}
public String hello()
{
System.out.println("hello()");
return "Hello World";
}
}
3. HelloClient.java
package examples;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Properties;
public class HelloClient
{
public static void main(String[] args) throws Exception
{ Properties props = System.getProperties();
Context ctx = new InitialContext(props);
Object obj = ctx.lookup("HelloHome");
HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class);
Hello hello = home.create();
System.out.println(hello.hello());
hello.remove();
}
}
4. HelloHome.java
package examples;
public interface HelloHome extends javax.ejb.EJBHome
{
Hello create() throws java.rmi.RemoteException,javax.ejb.CreateException;
}
5. HelloLocal.java
package examples;
public interface HelloLocal extends javax.ejb.EJBLocalObject
{
public String hello();
}
6. HelloLocalHome.java
package examples;
public interface HelloLocalHome extends javax.ejb.EJBLocalHome
{
HelloLocal create() throws javax.ejb.CreateException;
}
7. ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Document : web.xml
Created on : July 4, 2004, 7:13 AM
Author : Administrator
Description:
Purpose of the document follows.
-->
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>Hello</ejb-name>
<home>examples.HelloHome</home>
<remote>examples.Hello</remote>
<local-home>examples.HelloLocalHome</local-home>
<local>examples.HelloLocal</local>
<ejb-class>examples.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
8. HelloWorld.jarContent

Share: 



Tagged: