Solved

Java: How to call EJB methods using InitialContext

Posted on 2014-01-30
8
512 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

 

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

Independent Software Vendors: 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!

Question has a verified solution.

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

Most of the developers using Tomcat find it easy to configure the datasource in Server.xml and use the JNDI name in the code to get the connection.  So the default connection pool using DBCP (or any other framework) is made available and the life go…
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.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 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