Solved

Java: How to call EJB methods using InitialContext

Posted on 2014-01-30
8
502 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

14 Experts available now in Live!

Get 1:1 Help Now