Beehive Integration in BEA WebLogic Server 9.2

     Previous  Next    Open TOC in new window  Open Index in new window  View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Beehive Tutorial

The following sections provide information on how to create and deploy a Beehive application on WebLogic Server

Note: If this is your second time going through the tutorial, be aware that if you change the location of the application source files you will not be able to deploy to the same server domain. To avoid this problem either (1) create a new server domain from scratch (= the first step of the tutorial) or, if you want to skip this step, (2) undeploy the application from the server first. To undeploy, run the undeploy Ant target.

 


Create a Beehive-enabled Server Domain

In this step you will create a new server domain that can support Beehive applications.

  1. Start the domain configuration wizard: Start > All Programs > BEA Products > Tools > Configuration Wizard.
  2. Click Next on each page without changing any values, except for the second page (named Select Domain Source) and the third page (named Configure Administrator Username and Password).
  3. On the second page, place a check in the Apache Beehive checkbox before clicking the Next button.

    On the third page, in the User password and Confirm user password fields, enter weblogic.

    At the conclusion of the wizard, a domain named base_domain is created at <BEA_HOME>\user_projects\domains\base_domain.

  4. Start a server instance in the domain by running
  5. <BEA_HOME>\user_projects\domains\base_domain\startWebLogic.cmd

    on Windows or

    <BEA_HOME>/user_projects/domains/base_domain/startWebLogic.sh 

    on UNIX.

  6. Open a new command window. Set the development environment in the command window by running
  7. <BEA_HOME>\user_projects\domains\base_domain\bin\setDomainEnv.cmd

    on Windows or

    <BEA_HOME>/user_projects/domains/base_domain/bin/setDomainEnv.sh

    on UNIX.

 


Create a New J2EE Application

In this step you will create the basic directory structure, and build configuration files for your application.

  1. Underneath base_domain, create the following directory structure:
  2. beehive_tutorial
      src
        APP-INF
          lib
          classes
        META-INF
  3. In the beehive_tutorial\src directory, create an Ant build file named build.xml and enter the following text in it. Note that the properties user/password have the values weblogic/weblogic; these values are designed to match the Beehive-enabled server domain created in Create a Beehive-enabled Server Domain.
  4. <?xml version="1.0" encoding="UTF-8" ?>
    <project default="build" basedir=".">
    <property environment="env"/>
    <!-- provide overrides -->
    <property file="build.properties"/>
    <property name="src.dir" value="${basedir}"/>
    <property name="dest.dir" value="${basedir}/../build"/>
    <property name="dist.dir" value="${basedir}/../dist"/>
    <property name="app.name" value="beehive_tutorial"/>
    <property name="ear.path" value="${dist.dir}/${app.name}.ear"/>
    <property name="tmp.dir" value="${java.io.tmpdir}"/>
    <property name="weblogic.home" value="${env.WL_HOME}"/>
    <property name="user" value="weblogic"/>
    <property name="password" value="weblogic"/>
    <fail unless="weblogic.home" message="WL_HOME not set in environment"/>
    <property name="beehive.home" value="${weblogic.home}/beehive"/>
    <!-- beehive-imports defines dependency paths that are required by beehive-tools.xml -->
    <import file="${beehive.home}/weblogic-beehive/ant/weblogic-beehive-imports.xml"/>
    <!-- defines macros for build-schemas, build-controls, build-pageflows -->
    <import file="${beehive.home}/weblogic-beehive/ant/weblogic-beehive-tools.xml"/>
    <!-- defines macros for build-webapp -->
    <import file="${beehive.home}/weblogic-beehive/ant/weblogic-beehive-buildmodules.xml"/>
    <taskdef name="libclasspath" classname="weblogic.ant.taskdefs.build.LibClasspathTask"/>
    <!-- Builds classpath based on the libraries defined in weblogic-application.xml. -->
    <target name="init.app.libs">
      <libclasspath basedir="${src.dir}" tmpdir="${tmp.dir}" property="app.lib.classpath">
        <librarydir dir="${weblogic.home}/common/deployable-libraries/" />
      </libclasspath>
      <echo message="app.lib.claspath is ${app.lib.classpath}" level="info"/>
    </target>
    <target name="init.dirs">
      <mkdir dir="${dest.dir}/APP-INF/classes"/>
      <mkdir dir="${dest.dir}/APP-INF/lib"/>
      <mkdir dir="${dist.dir}"/>
    </target>
    <target name="init" depends="init.app.libs,init.dirs">
      <path id="app.classpath">
        <pathelement location="${src.dir}/APP-INF/classes"/>
        <pathelement location="${dest.dir}/APP-INF/classes"/>
        <pathelement path="${app.lib.classpath}"/>
        <fileset dir="${src.dir}/APP-INF/lib">
          <include name="**/*.jar"/>
        </fileset>
        <fileset dir="${dest.dir}/APP-INF/lib">
          <include name="**/*.jar"/>
        </fileset>
        <fileset dir="${beehive.home}/apache-beehive-svn-snapshot/lib/netui">
          <include name="**/*.jar"/>
          <exclude name="**/beehive-netui-compiler.jar"/>
        </fileset>
      </path>
    </target>
    <target name="build" depends="compile,appc"/>
    <target name="compile" depends="init"/>
    <target name="clean" depends="init.dirs,clean.dest,clean.dist"/>
    <target name="clean.dest">
      <echo message="deleting dest.dir:${dest.dir}"/>
      <delete includeemptydirs="true" >
        <fileset dir="${dest.dir}" excludes=".beabuild.txt" includes="**/*" />
      </delete>
    </target>
    <target name="clean.dist">
      <echo message="deleting dist.dir:${dist.dir}"/>
      <delete includeemptydirs="true" >
        <fileset dir="${dist.dir}" includes="**/*" />
      </delete>
    </target>
    <target name="appc" depends="init" >
      <wlappc source="${dest.dir}" librarydir="${weblogic.home}/common/deployable-libraries/"/>
    </target>
    <target name="pkg.exploded">
      <antcall target="clean.dist"></antcall>
      <wlpackage toDir="${dist.dir}" srcdir="${src.dir}" destdir="${dest.dir}" />
    </target>
    <target name="deploy.exploded" >
      <wldeploy user="${user}" password="${password}" action="deploy" name="${app.name}" source="${dist.dir}"/>
    </target>
    <target name="deploy" >
      <wldeploy user="${user}" password="${password}" action="deploy" name="${app.name}" source="${dest.dir}"/>
    </target>
    <target name="redeploy">
      <wldeploy user="${user}" password="${password}" action="redeploy" name="${app.name}"/>
    </target>
    <!-- This target is useful if you want to move the location of the 
    tutorial source files. Undeploy the app from the server, move the
    source files, and then deploy the app again to the server.-->
    <target name="undeploy">
      <wldeploy user="${user}" password="${password}" action="undeploy" name="${app.name}"/>
    </target>
    </project>
  5. In the beehive_tutorial\src\META-INF directory, create a configuration file named application.xml and enter the following text in it.
  6. <application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.4">
      <display-name>beehive_tutorial</display-name>
    </application>
  7. In the beehive_tutorial\src\META-INF directory, create a configuration file named weblogic-application.xml and enter the following text in it. This configuration file informs WebLogic Server that your application uses Beehive functionality, so that the appropriate libraries, in the form of JAR files, are made available at build-time and run-time.
  8. <weblogic-application xmlns="http://www.bea.com/ns/weblogic/90">
      <library-ref>
        <library-name>weblogic-controls-1.0</library-name>
      </library-ref>
      <library-ref>
        <library-name>beehive-controls-1.0</library-name>
      </library-ref>
    </weblogic-application>

 


Create a New Page Flow Web Application

In this step you will create a page flow web application. Page flows form the user interface for Beehive applications, allowing users to interact with your application through JSPs.

  1. Copy the folder
  2. <BEA_HOME>\weblogic92\beehive\apache-beehive-svn-snapshot\samples\netui-blank 

    into beehive_tutorial\src

    netui-blank is a template web application.

  3. Rename the folder netui-blank to myWebApp. Before proceeding, ensure that the following directory structure exists:
  4. beehive_tutorial
        src
            myWebApp
                src
                web
                    Controller.java
                    index.jsp
                    resources
                     WEB-INF
  5. Edit beehive_tutorial\src\META-INF\application.xml so it appears as follows. Code to add is shown in bold.
  6. <application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.4">
      <display-name>beehive_tutorial</display-name>
      <module>
        <web>
          <web-uri>myWebApp</web-uri>
          <context-root>/myWebApp</context-root>
        </web>
      </module>
    </application>
  7. Edit beehive_tutorial\src\myWebApp\web\index.jsp so it appears as follows. Code to edit appears in bold.
  8. <%@ page language="java" contentType="text/html;charset=UTF-8"%>
    <%@ taglib uri="http://beehive.apache.org/netui/tags-databinding-1.0" prefix="netui-data"%>
    <%@ taglib uri="http://beehive.apache.org/netui/tags-html-1.0" prefix="netui"%>
    <%@ taglib uri="http://beehive.apache.org/netui/tags-template-1.0" prefix="netui-template"%>
    <netui:html>
      <head>
        <title>Beehive Tutorial Test Page</title>
        <netui:base/>
      </head>
      <netui:body>
        <h3>
          Beehive Tutorial Test Page
        </h3>
        <p>
          Welcome to the Beehive Tutorial!
        </p>
      </netui:body>
    </netui:html>
  9. In the directory beehive_tutorial\src\myWebApp\web\WEB-INF, create a configuration named weblogic.xml and enter the following text in it.
  10. <weblogic-web-app
     xmlns="http://www.bea.com/ns/weblogic/90"
     xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.bea.com/ns/weblogic/90
     http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
      <library-ref>
        <library-name>beehive-netui-1.0</library-name>
      </library-ref>
      <library-ref>
        <library-name>struts-1.1</library-name>
      </library-ref>
      <library-ref>
        <library-name>jstl-1.1</library-name>
      </library-ref>
    </weblogic-web-app>
  11. Edit beehive_tutorial\src\build.xml so it appears as follows. Code to add appears in bold.
  12. <?xml version="1.0" encoding="UTF-8" ?>
    <project default="build" basedir=".">

      ...
      <target name="compile" depends="init,compile.myWebApp"/>
    . . .
      <target name="redeploy">
        <wldeploy user="${user}" password="${password}" action="redeploy" name="${app.name}"/>
      </target>
      <target name="compile.myWebApp" depends="init" >
        <libclasspath basedir="${src.dir}/myWebApp" tmpdir="${tmp.dir}" property="myWebApp.lib.classpath">
          <librarydir dir="${weblogic.home}/common/deployable-libraries/" />
        </libclasspath>
        <path id="myWebApp.build.classpath">
          <path refid="app.classpath"/>
          <path path="${myWebApp.lib.classpath}"/>
        </path>
    <copy todir="${src.dir}/myWebApp/">
    <fileset dir="${src.dir}/myWebApp/web/">
    <exclude name="**/*.java"/>
    </fileset>
    </copy>

    <copy todir="${dest.dir}/WEB-INF/classes">
    <fileset dir="${src.dir}/myWebApp/src/">
    <include name="sql/**"/>
    <include name="**/*.properties"/>
    <include name="**/*.xml"/>
    </fileset>
    </copy>

    <copy todir="${src.dir}/myWebApp/WEB-INF/src">
    <fileset dir="${src.dir}/myWebApp/src/">
    <exclude name="**/*.java"/>
    </fileset>
    </copy>

        <build-webapp
         webapp.src.dir="${src.dir}/myWebApp"
         webapp.build.dir="${dest.dir}/myWebApp"
         app.build.classpath="myWebApp.build.classpath"/>
      </target>
    </project>
  13. In the command window, navigate to beehive_tutorial\src\. (Make sure you use the same command window where you ran setDomainEnv.cmd or setDomainEnv.sh.)
  14. To compile the application, run the following Ant command:
  15. ant clean build pkg.exploded
  16. To deploy the application, run the following Ant command:
  17. ant deploy.exploded
  18. To test the application, visit the following URL in a browser:
  19. http://localhost:7001/myWebApp/begin.do

You should see the index.jsp page:

Welcome to the Beehive Tutorial!

 


Add a Java Control

A Beehive Java Control allow you to encapsulate functionality in your applications. Typically Java Controls are used to perform the following functions:

Beehive ships with a number of “system controls,” that is, controls that are designed with some particular functionality in mind: these system controls include database, JMS, EJB, and Web Service controls.

In the following step you will add a custom control with a very simple function: it returns the message “Hello, World!”

Inside the directory beehive_tutorial\src\, create a directory named controls.

  1. Inside the directory beehive_tutorial\src\controls, create a directory named pkg.
  2. Before proceeding, confirm that the following directory structure exists:

      beehive_tutorial
        src
          controls
            pkg
  3. In the folder beehive_tutorial\src\controls\pkg\, create a file named HelloWorld.java. Edit HelloWorld.java so it appears as follows:
  4. package pkg;
    import org.apache.beehive.controls.api.bean.*;
    @ControlInterface
    public interface HelloWorld
    {
        String hello();
    }
  5. In the folder beehive_tutorial\src\controls\pkg\, create a file named HelloWorldImpl.java. Edit HelloWorldImpl.java so it appears as follows:
  6. package pkg;
    import org.apache.beehive.controls.api.bean.*;
    @ControlImplementation(isTransient=true)
    public class HelloWorldImpl implements HelloWorld
    {
        public String hello()
        {
            return "hello!";
        }
    }
  7. Edit beehive_tutorial\src\myWebApp\web\Controller.java so it appears as follows. Code to add and edit appears in bold.
  8. import javax.servlet.http.HttpSession;
    import org.apache.beehive.netui.pageflow.Forward;
    import org.apache.beehive.netui.pageflow.PageFlowController;
    import org.apache.beehive.netui.pageflow.annotations.Jpf;
    import org.apache.beehive.controls.api.bean.Control;
    import pkg.HelloWorld;
    @Jpf.Controller(
        simpleActions={
            @Jpf.SimpleAction(name="begin_old", path="index.jsp")
        },
        sharedFlowRefs={
            @Jpf.SharedFlowRef(name="shared", type=shared.SharedFlow.class)
        }
    )
    public class Controller
        extends PageFlowController
    {
        @Jpf.SharedFlowField(name="shared")
        private shared.SharedFlow sharedFlow;
        @Control
        private HelloWorld _helloControl;
        @Jpf.Action(
          forwards={
            @Jpf.Forward(name="success", path="index.jsp")
          }
        )
        protected Forward begin() throws Exception
        {
            Forward f = new Forward("success");
            f.addActionOutput("helloMessage", _helloControl.hello());
            return f;
        }
        /**
         * Callback that is invoked when this controller instance is created.
         */
        protected void onCreate()
        {
        }
        /**
         * Callback that is invoked when this controller instance is
    destroyed.
         */
        protected void onDestroy(HttpSession session)
        {
        }
    }
  9. Edit the file beehive_tutorial\src\myWebApp\web\index.jsp so it appears as follows.
  10. <netui:html>
      <head>
        <title>Beehive Tutorial Test Page</title>
      <netui:base/>
      </head>
      <netui:body>
        <h3>
          Beehive Tutorial Test Page
        </h3>
        <p>
          Welcome to the Beehive Tutorial!
        </p>
        <p>
          Response from the hello() method on the HelloWorld Control:
          <netui:span style="color:#FF0000" value="${pageInput.helloMessage}"/>
        </p>
      </netui:body>
    </netui:html>
  11. Edit beehive_tutorial\src\build.xml so it appears as follows. Code to add appears in bold.
  12. . . .
    <target name="compile" depends="init,compile.helloWorldControl,compile.myWebApp"/>
    . . .
    <target name="compile.helloWorldControl" depends="init">
      <build-controls
       srcdir="${src.dir}"
       destDir="${dest.dir}/APP-INF/classes"
       tempdir="${tmp.dir}/${app.name}/controls/build-controls"
       classpathRef="app.classpath"
      />
      <!-- clean up duplicate myWebApp <apt> output -->
      <delete>
        <fileset dir="${dest.dir}/APP-INF/classes" excludes="pkg/**/*.class"/>
      </delete>
    </target>
    </project> 
  13. To compile the application, run the following Ant command. Make sure that you use the same command window in which you ran setDomainEnv.cmd or setDomainEnv.sh.
  14. Note: In the following build process, you will see some build warnings. These warnings are harmless and do not affect the final product of compilation.
    ant clean build pkg.exploded
  15. To deploy the application, run the following Ant command:
  16. ant deploy.exploded 
  17. To test the application, visit the following URL in a browser:
  18. http://localhost:7001/myWebApp/begin.do

    You should see the following JSP page.

    Beehive Tutorial Test Page 
    Welcome to the Beehive Tutorial! 
    Response from the hello() method on the HelloWorld Control: hello! 

 


Add a Java Web Service

Web services provide an XML-based interface for your application. In this step you will create an XML-based way to communicate with your application.

  1. In the directory beehive_tutorial\src\ create a folder named services.
  2. In the directory beehive_tutorial\src\services\ create a folder named pkg.
  3. In the directory beehive_tutorial\src\services\pkg\ create a file named HelloWorldService.java.
  4. Edit HelloWorldService.java so it appears as follows:
  5. package pkg; 
    import javax.jws.*;
    import org.apache.beehive.controls.api.bean.Control;
    import pkg.HelloWorld;
    @WebService
    public class HelloWorldService
    {
        @Control
        private HelloWorld _helloControl;
        @WebMethod()
        public String hello()
        {
            String message = _helloControl.hello();
             return message;
        }
    }
  6. Edit beehive_tutorial\src\build.xml so it appears as follows. Code to add appears in bold.
  7. . . .
    <target name="init" depends="init.app.libs,init.dirs">
    <path id="app.classpath">
    <pathelement location="${src.dir}/APP-INF/classes"/>
    <pathelement location="${dest.dir}/APP-INF/classes"/>
    <pathelement path="${app.lib.classpath}"/>
    <fileset dir="${src.dir}/APP-INF/lib">
    <include name="**/*.jar"/>
    </fileset>
    <fileset dir="${dest.dir}/APP-INF/lib">
    <include name="**/*.jar"/>
    </fileset>
    <fileset dir="${beehive.home}/apache-beehive-svn-snapshot/lib/netui">
    <include name="**/*.jar"/>
    <exclude name="**/beehive-netui-compiler.jar"/>
    </fileset>
    </path>
    <!-- Merge the application.xml file with the auto-generated
    application.xml file created by the web service compilation
    process. -->
    <copy todir="${dest.dir}/META-INF">
    <fileset dir="${src.dir}/META-INF"/>
    </copy>
    </target>
    ...
    <target name="compile" depends="init,compile.helloWorldControl,compile.helloWorldService,compile.myWebApp"/>
    ...
    <target name="compile.helloWorldService" depends="init" >
      <taskdef name="jwsc" classname="weblogic.wsee.tools.anttasks.JwscTask"/>
      <jwsc
       verbose="true"
       tempdir="${tmp.dir}"
       destdir="${dest.dir}"
       keepgenerated="true"
       srcdir="${basedir}/services">
        <jws file="pkg/HelloWorldService.java" name="HelloWorldService" explode="true"/>
        <classpath>
          <path refid="app.classpath"/>
        </classpath>
      </jwsc>
    </target>
    </project>
  8. To build the application, run the following Ant command. Make sure that you use the same command window in which you ran setDomainEnv.cmd or setDomainEnv.sh:
  9. ant clean build pkg.exploded
  10. To deploy the application, run the following Ant command:
  11. ant deploy.exploded
  12. To test the web service, visit the following URL in a browser:
  13. http://localhost:7001/HelloWorldService/HelloWorldService

    To see the web service’s WSDL, visit the following URL:

    http://localhost:7001/HelloWorldService/HelloWorldService?WSDL


  Back to Top       Previous  Next