Apart from the JSP client, a standalone Java application can access your Business Components application module which is deployed on the JBoss application server as an EJB Session Bean.
We will create a new class to talk to the Business Components
application module deployed as a session bean. This will be a standalone
Java application which will lookup the session bean and then use an
ApplicationModuleProxy
class to obtain a reference to the application
module.
To create a JBoss test client for an EJB session bean:
If the category or item isn't found, make sure the correct project is selected, and choose All Technologies in the Filter By dropdown list.
Add the following import statements to the newly created Java source file:
import oracle.jbo.*;
import javax.naming.*;
import java.util.*;
import mypackage2.common.ejb.beanmanaged.Mypackage2ModuleHome;
import oracle.jbo.client.remote.ejb.ApplicationModuleProxy;
Add the following main method to the class:
public static void main(String[] args)
{
try
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "localhost");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces" );
Context ctx = new InitialContext(env);
Mypackage2ModuleHome beanHome = (Mypackage2ModuleHome )ctx.lookup("mypackage2.Mypackage2Module");
// Create the proxy. If you have exported methods then you can cast it to your common am interface.
ApplicationModule am = ApplicationModuleProxy.create(beanHome, env);
//
// Note: Change this connect string to the connect string you use to connect to your database
//
am.getTransaction().connectToDataSource( null, "java:/OracleDS", null, null, false );
System.out.println( am.getClass() );
String[] voNames = am.getViewObjectNames();
ViewObject vo = am.findViewObject("DeptView");
Row row;
while ( ( row = vo.next() ) != null )
{
int numAttrs = row.getAttributeCount();
for ( int i=0; i numAttrs; i++ )
{
System.out.println( "Name= " + vo.getAttributeDef(i).getName() +
" Value= " + row.getAttribute(i) );
}
System.out.println("");
}
am.getTransaction().disconnect();
}
catch ( Exception ex )
{
ex.printStackTrace();
}
}
To run the test client:
DEPT
database table are
displayed in the Log window of your application.
Copyright © 1997, 2004, Oracle. All rights reserved.