here is my session bean class:-
import java.rmi.RemoteException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.CreateException;
/**
* XDoclet-based session bean. The class must be declared
* public according to the EJB specification.
*
* To generate the EJB related files to this EJB:
*- Add Standard EJB module to XDoclet project properties
*- Customize XDoclet configuration for your appserver
*- Run XDoclet
*
* Below are the xdoclet-related tags needed for this EJB.
*
* @ejb.bean name="TruckInv"
* display-name="Name for TruckInv"
* description="Description for TruckInv"
* jndi-name="ejb/TruckInv"
* type="Stateless"
* view-type="both"
*/
public class TruckInvBean implements SessionBean {
/** The session context */
private SessionContext context;
public TruckInvBean() {
super();
// TODO Auto-generated constructor stub
}
/**
* Set the associated session context. The container calls this method
* after the instance creation.
*
* The enterprise bean instance should store the reference to the context
* object in an instance variable.
*
* This method is called with no transaction context.
*
* @throws EJBException Thrown if method fails due to system-level error.
*/
public void setSessionContext(SessionContext newContext)
throws EJBException {
context = newContext;
}
public void ejbRemove() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/**
* An ejbCreate method as required by the EJB specification.
*
* The container calls the instance?s <code>ejbCreate</code> method whose
* signature matches the signature of the <code>create</code> method invoked
* by the client. The input parameters sent from the client are passed to
* the <code>ejbCreate</code> method. Each session bean class must have at
* least one <code>ejbCreate</code> method. The number and signatures
* of a session bean?s <code>create</code> methods are specific to each
* session bean class.
*
* @throws CreateException Thrown if method fails due to system-level error.
*
* @ejb.create-method
*
*/
public void ejbCreate() throws CreateException {
int i=1;
}
/**
* An example business method
*
* @ejb.interface-method view-type = "remote"
*
* @throws EJBException Thrown if method fails due to system-level error.
*/
public String Hello() throws EJBException {
String msg="hello";
return msg;
}
}
Here is the home interface
public interface TruckInvHome
extends javax.ejb.EJBHome
{
public static final String COMP_NAME="java:comp/env/ejb/TruckInv";
public static final String JNDI_NAME="ejb/TruckInv";
public dekalb.warehouse.TruckInv create()
throws javax.ejb.CreateException,java.rmi.RemoteException;
}
here is the remote interface
public interface TruckInv
extends javax.ejb.EJBObject
{
/**
* An example business method
* @throws EJBException Thrown if method fails due to system-level error. */
public java.lang.String Hello( )
throws java.rmi.RemoteException;
}
Here is my struts action class which invokes the bean:-
import javax.naming.*;
import dekalb.warehouse.TruckInv;
import dekalb.warehouse.TruckInvHome;
public class AddTruckInventory extends Action
{
public AddTruckInventory()
{
}
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws SQLException, Exception
{
try{
Properties properties = new Properties();
properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs","org.jboss.naming
rg.jnp.interfaces");
properties.put("java.naming.provider.url", "jnp://localhost:1099");
properties.put("jnp.disableDiscovery", "true");
InitialContext context = new InitialContext(properties);
Object object = context.lookup(TruckInvHome.JNDI_NAME);
servlet.log("line 2");
TruckInvHome TIH = (TruckInvHome)PortableRemoteObject.narrow(object,TruckInvHome.class);
servlet.log("line 3");
TruckInv TI = TIH.create();
servlet.log("Line 4");
String msg=TI.Hello();
request.setAttribute("msg", msg);
}
catch (Exception e)
{
servlet.log("Error"+e);
}
servlet.log("In Add Truck Inventory");
return (mapping.findForward("success"));
}
}
It would be great if you can help me out....
VIK