Solved

Java: How to call EJB methods using InitialContext

Posted on 2014-01-30
8
505 Views
Last Modified: 2014-02-06
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

0
Comment
Question by:vakils
  • 4
  • 4
8 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 39825174
Assuming that you have a remote interface named "ArDnUnionFile" you can do

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

Open in new window

0
 

Author Comment

by:vakils
ID: 39825413
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.
0
 
LVL 35

Expert Comment

by:girionis
ID: 39826185
Can you post the file that has this line?

public ArDnUnionFile create(FwWebService serviceMeta) throws CreateException, RemoteException;

Open in new window

0
 

Author Comment

by:vakils
ID: 39827088
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

 }
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 35

Expert Comment

by:girionis
ID: 39827512
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.
0
 

Author Comment

by:vakils
ID: 39828640
I will not be able to call methods remotely via client from FwDnBaseSlsBean  extended class.
0
 
LVL 35

Accepted Solution

by:
girionis earned 500 total points
ID: 39828914
If you want to call it remotely you will have to provide the same parameter as in the create method. There is no other way. If you want to call it locally you can use another interface instead.
0
 

Author Closing Comment

by:vakils
ID: 39840713
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

-Xmx and -Xms are the two JVM options often used to tune JVM heap size.   Here are some common mistakes made when using them:   Assume BigApp is a java class file for the below examples. 1.         Missing m, M, g or G at the end …
Verbose logging is used to diagnose garbage collector problems. By default, -verbose:gc output is written to either native_stderr.log or native_stdout.log.   It is also possible to redirect the logs to a user-specified file. This article will de…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now