------------------------- EJB class
---------------------------
package ELJBTest2;
import java.rmi.RemoteException;
import
javax.ejb.*;
public class EJBTest2Class implements
SessionBean
{
SessionContext ctx;
public
EJBTest2Class()
{
}
public void ejbCreate() throws
RemoteException, CreateException
{
}
public void ejbActivate() throws
RemoteException
{
}
public void ejbPassivate() throws
RemoteException
{
}
public void ejbRemove() throws
RemoteException
{
}
public void
setSessionContext(SessionContext ctx) throws
RemoteException
{
this.ctx =
ctx;
}
public NewReturnedClass
getNewReturnedClass() throws RemoteException
{
NewReturnedClass aNewReturnedClass = new
NewReturnedClass();
return
aNewReturnedClass;
}
}
---------------------------------------------------------------------
------------------------- EJB Home
---------------------------
package ELJBTest2;
import java.rmi.*;
import
javax.ejb.*;
public interface EJBTest2Home extends
EJBHome
{
EJBTest2 create() throws
java.rmi.RemoteException,
javax.ejb.CreateException;
}
---------------------------------------------------------------------
------------------------- EJB Remote
---------------------------
package ELJBTest2;
import java.rmi.*;
import
javax.ejb.*;
public interface EJBTest2 extends
EJBObject
{
public ELJBTest2.NewReturnedClass
getNewReturnedClass() throws
java.rmi.RemoteException;
}
---------------------------------------------------------------------
------------------------- Client
---------------------------
package ELJBTest2;
import java.sql.*;
import
java.util.*;
import javax.naming.*;
import
oracle.aurora.jndi.sess_iiop.*;
public class EJB_Client {
public
static void main(String[] args) {
String ejbUrl =
"sess_iiop://ranger:2481:e1/test/EJBTest2";
String
username = "bayfis";
String password =
"bayfis";
Hashtable environment = new
Hashtable();
environment.put(javax.naming.Context.URL_PKG_PREFIXES,
"oracle.aurora.jndi");
environment.put(Context.SECURITY_PRINCIPAL, username);
environment.put(Context.SECURITY_CREDENTIALS, password);
environment.put(Context.SECURITY_AUTHENTICATION,
ServiceCtx.NON_SSL_LOGIN);
// Lookup the
URL
ELJBTest2.EJBTest2Home homeInterface =
null;
try {
System.out.println("Creating an initial
context");
Context ic = new
InitialContext(environment);
System.out.println("Looking for the EJB published as
'test/EJBTest2'");
homeInterface =
(ELJBTest2.EJBTest2Home) ic.lookup(ejbUrl);
}
catch (ActivationException e)
{
System.out.println("Unable to activate : "
+ e.getMessage());
e.printStackTrace();
System.exit(1);
}
catch
(CommunicationException e) {
System.out.println("Unable to connect: " +
ejbUrl);
e.printStackTrace();
System.exit(1);
}
catch
(NamingException e) {
System.out.println("Exception occurred!");
System.out.println("Cause: This may be an unknown URL, or some"
+
" classes required by the EJB
are missing from your classpath.");
System.out.println("Suggestion: Check the components of the URL,"
+
" and make sure your project
includes a library containing the"
+
" EJB .jar files generated by
the deployment utility.");
e.printStackTrace();
System.exit(1);
}
// That's
it!
try {
System.out.println("Creating a new EJB
instance");
ELJBTest2.EJBTest2
remoteInterface = homeInterface.create();
System.out.println("Calling ELJBTest2.EJBTest2
methods...\n");
// Method calls go
here!
NewReturnedClass aNewReturnedClass =
new NewReturnedClass();
aNewReturnedClass.aString = "foo"; // just to change the std
value.
aNewReturnedClass =
remoteInterface.getNewReturnedClass(); // recieve a
new
System.out.println(aNewReturnedClass.aString); // show what is inside. if
possible :-(.
System.out.println("...done!");
}
catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
---------------------------------------------------------------------