This document covers the following topics:
To program a client which uses an enterprise bean, perform the following tasks:
Create the initial context
Context initial=new InitialContext();
Get the object bound to the JNDI name EJBExample
Context myEnv=(Context) initial.lookup("EJBExample");
Narrow the reference to an EJBExampleHome object
EJBExampleHome home=(EJBExampleHome)PortableRemoteObject.narrow(objref,EJBExampleHome.class)
Declare the bean object
EJBExample ejbExample=null;
Create the bean object with default settings
ejbExample=home.create();
Or create the bean object with default settings except for the user name
ejbExample=home.create("myUserName");
Or create the bean object with default settings except for the user name and password
ejbExample=home.create("myUserName","myPassword");
Create the input and output objects
ExampleSquareInput input=new ExampleSquareInput(); ExampleSquareOutput output=new ExampleSquareOutput();
Set the input value
input.operand=9;
Show the input value
System.out.println( "square (input) >>> "+intput.operand );
Call the EntireX RPC method
output = ejbExample.square(input);
Show the output value
System.out.println( "square (input) >>> "+output.result );
Remove the bean object
ejbExample.remove();
Compile the client with the client JAR
It will be packed by the Application Server or by the Ant
script.
Get the build.xml file from the example
directory
Set antfile to your current XML file.
Replace Client.java by your client class name.
To run the client
Enter
ant jboss_run_client