 | Level: Intermediate Kunal Mittal (kunal@kunalmittal.com), Portal/J2EE Architect, Consultant
19 Apr 2005 Beehive is a new Apache project that simplifies Java™ 2
Platform, Enterprise Edition (J2EE) and Web services programming. This article shows
how to get started with Beehive and offers a sneak preview of Pollinate, an Eclipse
plug-in that creates Beehive applications.
On May 25, 2004, BEA Systems Inc. and Apache announced the birth of the Beehive
project. This project focuses on simplifying J2EE and Web services programming by using
a concept of annotations that is fast becoming a part of Java technology.
Service-Oriented Architecture (SOA) development is also a major emphasis of this project.
Beehive was released under the Apache License V2.0, and BEA is widely promoting the
project. Today, about half of Beehive committers are BEA employees, which is clear
evidence other people in the community are contributing to this project.
The Apache Beehive project was created to support:
- Java Page Flow (JPF) technology, also known as (NetUI)
- Controls
- Web services based on JSR 181
Together, these technologies fit into the Model-ViewController (MVC) programming model,
as shown in Figure 1. The JPF technology forms the controller layer. The NetUI tag
libraries participate in the view layer. The model layer is built from Java controls.
Figure 1. MVC model and Apache Beehive technologies
 |
The Pollinate plug-in
Together, NetUI, controls, and Web services are targeted at making J2EE and SOA
development easier. An Eclipse plug-in project called Pollinate is also in progress.
This project will allow developers to use Eclipse to build Apache Beehive applications.
I am confident that other IDEs, such as IntelliJ and JBuilder, will soon start
supporting Apache Beehive, as well.
|
|
Let us take a look at each of the technologies within Apache Beehive in a little more detail.
NetUI or JPFs
If you have used BEA WebLogic Workshop V8.1, you have probably used JPF technology,
which is built directly on top of Struts. As you probably know, Struts is one of the
most widely adopted MVC frameworks in the market today. So, if JPFs are built on top of
Struts, why not just use Struts?
JPFs leverage the core functionality of Struts, but remove a lot of the grunt work that
Struts requires. By grunt work, I mean managing the deployment configuration files
(such as the struts-config.xml file). The original version of Page Flows from BEA
introduced a declarative programming language that BEA WebLogic Workshop automatically
generated and maintained. In contrast, the Apache Beehive version of Page Flows uses
JSR 175 for its metadata definition. JSR 175 is a metadata specification that allows
you to reduce the J2EE coding required.
The JPF technology also comes with a set of tag libraries called NetUI. In the
typical MVC design pattern, JPFs form the controller layer. They are assisted by the
NetUI tag libraries in the presentation layer. JPFs also leverage all the Struts
features, such as the validation framework. You can actually have a single Web
application that has a combination of Struts and JPFs.
Listing 1 shows a simple JPF controller that prints HelloWorld.
Listing 1. Simple JPF controller for HelloWorld
import org.apache.beehive.netui.pageflow.PageFlowController;
import org.apache.beehive.netui.pageflow.annotations.Jpf;
import org.apache.beehive.netui.pageflow.Forward;
@Jpf.Controller (
simpleActions= {
@Jpf.SimpleAction (name="cancel", path="begin.do")
}
)
public class HelloWorldController extends PageFlowController {
@Jpf.Action (
forwards= {
@Jpf.Forward (name="success", path="helloworld.jsp")
}
)
public Forward begin() {
return new Forward("success");
}
} |
Notice the heavy use of annotations. I first use the @Jpf.Controller annotation to define that this class is a JPF
controller. The @Jpf.SimpleAction annotations define the
actions within this controller. These annotations are similar to the concept of actions
in Struts. The @Jpf.Action annotation defines the action
itself. And the @Jpf.Forward annotation defines what happens
next in the flow. This annotation is similar to the information in the Struts configuration files.
The HelloWorld JavaServer Pages (JSP) file referred to in the forward annotation isn't
shown in this article. For purposes of this example, it can be any JSP file with a
single line of code to print HelloWorld on the screen.
The NetUI technologies also include three tag libraries, the basic functionality of
which is to simplify JSP file development and provide automatic data binding between
the view and controller layers. These tags come with JavaScript support, so you can
work with them like you would with the standard HTML tags (such as input and select).
- NetUI
- This tag library contains tags similar to the struts-html tag.
- NetUI-data
- The NetUI-data tag library is used to bind data from forms and the controller to the
JSP file. It allows you to quickly display lists of data, such as search results.
- NetUI-template
- You use the NetUI-template tag library to create subsections (or templates) from your JSP files.
See Resources for more information about the NetUI tag libraries.
Controls
Controls are an interesting technology. A control provides a nice layer of abstraction
and encapsulation for SOA-based development. Controls are pieces of business logic
wrapped up in Enterprise JavaBeans (EJBs) or message-driven beans. They provide a
common client interface to any set of resources -- databases, external systems, and
others. You can also drag and drop controls into a Java application or Web service to
provide the application or Web service with that functionality. They help speed up the
development process.
Like the rest of Apache Beehive, controls use JSR 175 annotations heavily. Controls
reduce the complexity and learning curve associated with acting as a client of J2EE
resources by providing a unified client model that allows access to diverse types of resources.
Listing 2 shows a HelloWorld Java control.
Listing 2. HelloWorld Java control
import org.apache.beehive.controls.api.bean.*;
@ControlInterface
public interface HelloWorld {
String sayHelloWorld ();
} |
In this example, I define a simple ControlInterface. If you remove the @ControlInterface annotation, you are left with a simple Java
interface class. Listing 3 shows the control implementation for the HelloWorld control interface.
Listing 3. HelloWorld Java control implementation
import org.apache.beehive.controls.api.bean.*;
@ControlImplementation
public class HelloImpl implements HelloWorld {
public String sayHelloWorld () {
return "hello!";
}
} |
The code in this listing is pretty simple, right? Now, let's build a Web service out of this example.
Web services using JSR 181
JSR 181 is a metadata standard for Web services based on the JSR 171 annotations
standards. Apache Beehive uses JSR 181 to define a set of annotations you can use to
expose any Java class as a Web service. The idea behind Beehive Web service development
is that the developer writes a simple Java class, then exposes the functionality as a Web service.
Listing 4 shows a simple HelloWorld Web service.
Listing 4. Simple HelloWorld Web service
import javax.jws.WebService;
import javax.jws.WebMethod;
@WebService(
targetNamespace="targetNamespace =
http://www.openuri.org/my/web/service/wsdl"
)
public class HelloWorld {
@WebMethod
public String sayHelloWorld() {
return "Hello world!";
}
} |
In this listing, if you remove the elements in bold, you're left with a simple Java
class. Using the @WebService and the @WebMethod annotations, I've exposed this simple Java class as a Web service.
Now, with the Apache Beehive technology basics out of the way, you can better
understand how you can start using Apache Beehive on your projects.
Using Eclipse to build Beehive applications
The Eclipse Pollinate project is the only integrated development environment (IDE)
today that supports Apache Beehive development. This limitation is bound to change in
the future as Apache Beehive gains more momentum. Basically, Pollinate is a plug-in to
Eclipse that supports the Beehive framework. A combination of the Eclipse IDE and
Pollinate with a server such as Apache Tomcat makes a perfect environment for fast and
easy Beehive application development.
Getting started with Pollinate
If you don't have Eclipse on your machine, download and install that first. To install
Pollinate from Eclipse, launch the Eclipse IDE, then:
- Select Help > Software Updates > Find and Install.
- In the Install/Update window, select Search for new features to install.
- In the next window, click New Remote Site.
- In the New Update Site window, enter
Pollinate and
the URL http://www.software-mirror.com/eclipse/technology/pollinate/update-site/.
- Expand Pollinate in the tree, then select the Integration Builds checkbox.
- In the next window, select the Eclipse Pollinate Tools checkbox and complete
the installation.
After installing the Pollinate plug-in successfully, you can create a new Beehive
project. To do so, in Eclipse, select File > New > Other to launch the New
Wizard, then select Pollinate > Web Application.
Of course, you also need to download and install Apache Beehive.
Summary
The Apache Beehive project seems to be gaining a lot of momentum. BEA Systems made a
wise decision to release this core set of technologies to the open source community,
and doing so will help in the overall maturity of these technologies, as well as in
their adoption. Initially, these technologies were only supported on the BEA WebLogic
platform. However, with the release to open source, you should now be able to leverage
them on the IBM® WebSphere® Application Server, as well as on other
application servers. You can also use Eclipse-based IBM Rational® tools like
IBM Rational Software Architect and IBM Rational Software Modeler to design and develop Beehive applications.
Download | Description | Name | Size | Download method |
|---|
| Code | loggingplugins.zip | 9.5KB | HTTP |
|---|
Resources Learn
-
Download and learn more about Apache Beehive.
-
To learn more about NetUI and JPFs, see Page
Flow Overview.
-
To read more about controls, see the Controls
Overview.
-
You can read the JSR 181 Web services metadata specification at the Java Community Process, as well as the JSR 175 specification.
-
The Apache Wiki is a good source for exchanging information about Beehive.
-
Visit Dev2Dev from BEA Systems for more information about Beehive.
-
Get more information about the Eclipse Pollinate project.
-
See my upcoming book: Pro Apache Beehive: With Eclipse Pollinate and SOA.
-
Get more information about the Eclipse Pollinate project.
-
Get the latest version of NetBeans, an open source IDE for Java application development.
-
Check out the "Recommended Eclipse reading list."
-
Browse all the Eclipse content on developerWorks.
-
New to Eclipse? Read the developerWorks article "Get started with Eclipse Platform" to learn its origin and architecture, and how to extend Eclipse with plug-ins.
-
Expand your Eclipse skills by checking out IBM developerWorks' Eclipse project resources.
-
To listen to interesting interviews and discussions for software developers, check out check out developerWorks podcasts.
-
For an introduction to the Eclipse platform, see "Getting started with the Eclipse Platform."
-
Stay current with developerWorks' Technical events and webcasts.
-
Watch and learn about IBM and open source technologies and product functions with the no-cost developerWorks On demand demos.
-
Check out upcoming conferences, trade shows, webcasts, and other Events around the world that are of interest to IBM open source developers.
-
Visit the developerWorks Open source zone for extensive how-to information, tools, and project updates to help you develop with open source technologies and use them with IBM's products.
Get products and technologies
Discuss
-
The Eclipse Platform newsgroups should be your first stop to discuss questions regarding Eclipse. (Selecting this will launch your default Usenet news reader application and open eclipse.platform.)
-
The Eclipse newsgroups has many resources for people interested in using and extending Eclipse.
-
Participate in developerWorks blogs and get involved in the developerWorks community.
About the author  | 
|  | Kunal Mittal is a consultant specializing in Java, J2EE, and Web services technologies. He is the co-author of and has contributed to several books on these topics. Kunal is currently working on a portal project for Sony Pictures Entertainment. For more information, visit his Web site at http://www.soaconsultant.com. |
Rate this page
|  |