Vakils
asked on
Java: How to call EJB methods using InitialContext
Hi
I have a Java class from which I need to access local EJB bean class methods using InitialContext. How can I achieve it.
I have a Java class from which I need to access local EJB bean class methods using InitialContext. How can I achieve it.
ArDnUnionFile dnUnionFile = null; //Bean
Hashtable ht = new Hashtable();
ht.put(Context.SECURITY_PRINCIPAL, FwComCredentialManager.getInstance().getUsername());
ht.put(Context.SECURITY_CREDENTIALS, FwComCredentialManager.getInstance().getPassword());
InitialContext ic = new InitialContext(ht);
ArDnUnionFileHome dnUnionFileHome = (ArDnUnionFileHome) ic.lookup("ArDnUnionFile");
// need to call method below. Need to initialize dnUnionFile from above
// dnUnionFile.insertEuSigContractDetail(euSigContractDetailsArray);
ASKER
Hi
Thanks for reply.
The create method takes parameters:
serviceMeta is intialized by XML ( for client to call EJB). Mine is local call.
Thanks for reply.
The create method takes parameters:
public ArDnUnionFile create(FwWebService serviceMeta) throws CreateException, RemoteException;
serviceMeta is intialized by XML ( for client to call EJB). Mine is local call.
Can you post the file that has this line?
public ArDnUnionFile create(FwWebService serviceMeta) throws CreateException, RemoteException;
ASKER
No: bound to non-disclosure
But if it helps:
But if it helps:
public class ArDnUnionFileBean extends FwDnBaseSfsBean implements ArDnConstants
public FwDnBaseSfsBean()
{
}
/**
*
* @throws CreateException
*/
public void ejbCreate(FwWebService serviceMeta) throws CreateException
{
this.serviceMeta = serviceMeta;
initResources();
}
/**
* ejbActivate
*
* @throws EJBException
* @throws RemoteException
* @todo Implement this javax.ejb.SessionBean method
*/
public void ejbActivate() throws EJBException, RemoteException
{
initResources();
}
// for request from client via xml
public class FwWebService extends FwComBaseNode
{
public static final String ATTRIB_NAME_ID = "id";
public static final String ATTRIB_NAME_CLASS = "class";
public static final String ATTRIB_NAME_EJB_NAME = "ejbName";
public static final String ATTRIB_NAME_METHOD = "method";
public static final String ATTRIB_NAME_MSGIN = "msgIn";
public static final String ATTRIB_NAME_MSGOUT = "msgOut";
for local calls class below is used, but I will lose ability to call remotely
This is where create() would work
public abstract class FwDnBaseSlsBean implements SessionBean
{
protected SessionContext sessionContext;
protected FwDmDbOperation dbOperation = null;
protected FwComLog log = null;
public FwDnBaseSlsBean()
{
}
/**
*
* @throws CreateException
*/
public void ejbCreate() throws CreateException
{
initResources();
}
You say that
so why don't you just use the FwDnBaseSlsBean class? Yo will need to extend it with another class.
for local calls class below is used, but I will lose ability to call remotely
This is where create() would work
so why don't you just use the FwDnBaseSlsBean class? Yo will need to extend it with another class.
ASKER
I will not be able to call methods remotely via client from FwDnBaseSlsBean extended class.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Agreed. There is no other way. Confirmed by the author who designed it and will work on it.
Anyway, thanks for looking in to the complex code.
Anyway, thanks for looking in to the complex code.
Open in new window