?
Solved

Java: How to call EJB methods using InitialContext

Posted on 2014-01-30
8
Medium Priority
?
518 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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 1500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Upgrading Tomcat – There are a couple of methods to upgrade Tomcat is to use The Apache Installer is to download and unzip and run the services.bat remove|install Tomcat6 Because of the App that we are working with, we can only use Tomcat 6.…
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…
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month15 days, 23 hours left to enroll

850 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