Link to home
Start Free TrialLog in
Avatar of Vakils
VakilsFlag for United States of America

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.
      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);

Open in new window

Avatar of girionis
girionis
Flag of Greece image

Assuming that you have a remote interface named "ArDnUnionFile" you can do

ArDnUnionFile dnUnionFile = dnUnionFileHome.create();
dnUnionFile.insertEuSigContractDetail(euSigContractDetailsArray);

Open in new window

Avatar of Vakils

ASKER

Hi
Thanks for reply.
The create method takes parameters:
 public ArDnUnionFile create(FwWebService serviceMeta) throws CreateException, RemoteException;

Open in new window


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;

Open in new window

Avatar of Vakils

ASKER

No: bound to non-disclosure
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();

Open in new window

 }
You say that

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.
Avatar of Vakils

ASKER

I will not be able to call methods remotely via client from FwDnBaseSlsBean  extended class.
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vakils

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.