Beehive Integration in WebLogic Server 9.0
This tutorial will show you how to create and deploy a Beehive application on WebLogic Server.
The tutorial shows you how to build the three basic Beehive components:
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.
In this step you will create a new server domain that can support Beehive applications.
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
.
<BEA_HOME>\user_projects\domains\base_domain\startWebLogic.cmd
<BEA_HOME>\user_projects\domains\base_domain\bin\setDomainEnv.cmd
In this step you will create the basic directory structure, and build configuration files for your application.
beehive_tutorial
src
APP-INF
lib
classes
META-INF
beehive_tutorial\src\build.xml
. 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.<?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"/>
<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-incubating-1.0m1/lib/netui">
<include name="**/*.jar"/>
<exclude name="**/beehive-netui-compiler.jar"/>
</fileset>
</path>
<wlcompile srcdir="${src.dir}" destdir="${dest.dir}"/>
</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>
<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>
beehive_tutorial\src\META-INF\weblogic-application.xml
. (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.)<weblogic-application xmlns="http://www.bea.com/ns/weblogic/90">
<library-ref>
<library-name>weblogic-beehive-1.0</library-name>
</library-ref>
</weblogic-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.
<BEA_HOME>
\weblogic90\beehive\apache-beehive-incubating-1.0m1\samples\netui-blank
netui-blank
to myWebApp
. Before proceeding, ensure that the following directory exists:
beehive_tutorial
src
myWebApp
resources
WEB-INF
Controller.java
index.jsp
beehive_tutorial\src\META-INF\application.xml
so it appears as follows. Code to add appears in bold.<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>
</application>
<web>
<web-uri>myWebApp</web-uri>
<context-root>/myWebApp</context-root>
</web>
</module>
beehive_tutorial\src\myWebApp\index.jsp
so it appears as follows. Code to edit appears in bold.<%@ 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>
<p>
Beehive Tutorial Test Page
</h3>Welcome to the Beehive Tutorial!
</p>
</netui:body>
</netui:html>
<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>
<?xml version="1.0" encoding="UTF-8" ?>
<project default="build" basedir=".">
...
<wlcompile srcdir="${src.dir}" destdir="${dest.dir}"excludes="myWebApp"
/>
</target>
. . .
<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>
<build-webapp
webapp.src.dir="${src.dir}/myWebApp"
webapp.build.dir="${dest.dir}/myWebApp"
app.build.classpath="myWebApp.build.classpath"/>
</target>
</project>
Note: You may be wondering, "Why are we excluding myWebApp from the <wlcompile>
step?" The answer is: for our Beehive app, <wlcompile>
is intended to facilitate split-source deployment, not compilation of Java source files. For our purposes, the <wlcompile>
element is present in order to generate the .beabuild
file, which enables split source build/deployment of the application. (Split source build/deployment is an especially clean way to build and deploy an application. It allows the strict separation of the original source files and the generated build-artifacts.) Of course, <wlcompile>
also searches for all Java files in the application and compiles them. But <wlcompile>
will fail if it encounters any Beehive-specific classes. By excluding the myWebApp
directory from the search, we prevent a compile error that would have been caused if <wlcompile>
had encountered the Beehive-specific classes in myWebApp
.
beehive_tutorial\src\
. (Make sure you use the same command window where you ran setDomainEnv.cmd
or setDomainEnv.sh
.) ant clean build pkg.exploded
ant deploy.exploded
You should see the index.jsp
page:
Welcome to the Beehive Tutorial!
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
.
Before proceeding, confirm that the following directory structure exists:
beehive_tutorial
src
controls
pkg
beehive_tutorial\src\controls\pkg\
, create a file named HelloWorld.java
. Edit HelloWorld.java
so it appears as follows:package pkg;
import org.apache.beehive.controls.api.bean.*;
@ControlInterface
public interface HelloWorld
{
String hello();
}
beehive_tutorial\src\controls\pkg\
, create a file named HelloWorldImpl.java
. Edit HelloWorldImpl.java
so it appears as follows:
package pkg;
import org.apache.beehive.controls.api.bean.*;
@ControlImplementation(isTransient=true)
public class HelloWorldImpl implements HelloWorld
{
public String hello()
{
return "hello!";
}
}
beehive_tutorial\src\myWebApp\Controller.java
so it appears as follows. Code to add and edit appears in bold.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)
{
}
}
<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>
</netui:body>
Response from the hello() method on the HelloWorld Control:
<netui:span style="color:#FF0000" value="${pageInput.helloMessage}"/>
</p>
</netui:html>
<?xml version="1.0" encoding="UTF-8" ?>
<project default="build" basedir=".">
...
<wlcompile srcdir="${src.dir}" destdir="${dest.dir}" excludes="myWebApp
,controls
"/>
. . .
<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>
setDomainEnv.cmd
or setDomainEnv.sh
.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
ant deploy.exploded
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!
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.
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;
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<project default="build" basedir=".">
...
<!-- 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>
<wlcompile srcdir="${src.dir}" destdir="${dest.dir}" excludes="myWebApp,controls
,services
"/>
...
<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>
setDomainEnv.cmd
or setDomainEnv.sh
:ant clean build pkg.exploded
ant deploy.exploded
http://localhost:7001/HelloWorldService/HelloWorldService
To see the web service's WSDL, visit the following URL:
http://localhost:7001/HelloWorldService/HelloWorldService?WSDL