Sample Client Code for an EJB Client for WebLogic

Rather than using the Business Component Browser, you can also choose to test your BC4J project with the following sample client code for connecting to an AppModule deployed as an EJB session bean to BEA WebLogic:


package mypackage;

import oracle.jbo.*;
import oracle.jbo.client.Configuration;

public class sampleClient
{
  public sampleClient()
  {
  }
  public static void main(String arg[]) {

  String _am = "mypackage.MypackageModule"; //App Module name
  String _wcf = "MypackageModuleWLS"; //Weblogic EJB config name
  String voMemberName = "DeptView"; // Name of the View Object

 //Use _wcf if you are accessing BC4J application deployed as
 //as EJB session bean in weblogic

  ApplicationModule myam =
    (ApplicationModule)Configuration.createRootApplicationModule(_am,_wcf);

  // Find the viewobject included in the appmodule
    ViewObject vo = myam.findViewObject(voMemberName);

  // Iterate over the viewobject to get the rows

        Row r = vo.first();
         while (r != null)
         {
            // Iterate over the current row and get 
            // all the attributes
            for (int i = 0; i < vo.getAttributeCount(); i++)
            {
               String attrName = vo.getAttributeDef(i).getName();
               String attrVal  = r.getAttribute(i).toString();
               System.out.println(attrName + " = " + attrVal);
            }
            r = vo.next();             
         }


  Configuration.releaseRootApplicationModule(myam, true);

  }
}

Note: When redeploying an EJB service session facade bean (BMT), the client code must call appmodule.remove() or appmodule.getTransaction().disconnect() to close the JDBC connection. Otherwise an exception occurs.


Related topics

About J2EE Applications and How They Are Packaged and Deployed
About Business Components for Java (BC4J) Deployment
Deploying EJB JARs to WebLogic
Editing weblogic-ejb-jar.xml
Loading BC4J Runtime Libraries to WebLogic