Welcome!

Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Weblogic

Weblogic: Article

Out with the Old, In with the New

Out with the Old, In with the New

As one of the two Sun J2EE Blueprints applications, the Java Smart Ticket Demo application, like its well-known sibling, Pet Store, illustrates best practices for designing J2EE applications.

Pet Store illustrates best practices for larger J2EE applications, and the Java Smart Ticket application illustrates best practices for designing wireless applications. Both Blueprints applications were designed with portability in mind. The Java Smart Ticket application is a less complicated example application for showing what it takes to port an application to WebLogic Server 7.0.

The Java Smart Ticket application runs without modification on the J2EE 1.3 Reference Implementation server. Since WebLogic Server 7.0 is fully compliant with the J2EE 1.3 specifications, getting the Java Smart Ticket application to run on WebLogic Server requires minimal effort.

The porting takes place in three stages:

  1. Porting the EJB tier
  2. Porting the Web Application (WebApp) tier
  3. Putting it all together.
The last step, which is the most involved, includes building the Enterprise Application Archives (EAR) file, creating tables and uploading them to the PointBase server, and deploying and configuring the application for WebLogic Server 7.0. Very little Java code has to be changed in order to port the Smart Ticket application to WebLogic Server 7.0. In fact, only one Java class file must be changed, and this has more to do with the differences in the databases than with application servers. WebLogic Server 7.0 ships with PointBase 4.2, a pure Java RDBMS; the J2EE Reference Implementation server ships with Cloudscape.

The last section of this article will discuss running the application with the help of the phone emulator in the Java 2 Micro Edition (J2ME) Tool Kit.

Now let's start porting!

Getting Started
The instructions given here are for Windows. If you're using UNIX, please substitute / for \ in path names and % with $ in variables appropriately.

Download and install WebLogic Server 7.0 from http://commerce.bea.com/downloads/products.jsp. Throughout the article, I will use %SAMPLES_HOME% to refer to the samples home directory, bea_home\weblogic700\samples.

Download and install the J2ME Tool Kit from http://java.sun.com/products/j2mewtoolkit.

Download the Java Smart Ticket Demo 1.1 from http://developer.java.sun.com/developer/releases/smarticket. Wherever you unzip smarticket-1_1.zip, we will refer to that as %SMARTICKET_HOME%. I placed mine under the %SAMPLES_HOME%\server\src directory.

How to Port the Enterprise JavaBeans
Note: The ejb-jar.xml file that Sun ships uses an EJB 1.1 dtd, which does not support the <unchecked> element in the <method-permission> stanzas. The <unchecked> element can be found instead in the EJB 2.0 specification. Since the four <method-permission> stanzas don't restrict access to any of the methods on the beans, they can safely be commented out without affecting the application (see Listing 1; the code for this article can be found on our Web site at www.sys-con.com/weblogic/sourcec.cfm).

The first task in porting any Enterprise JavaBeans (EJB) is to determine the type of EJB. This can be done by looking in the ejb-jar.xml for any bean. The Java Smart Ticket ejb-jar.xml file is located in %SMARTICKET_HOME%\src. The application employs three 1.1 stateless session beans and one Bean Managed Persistence (BMP) entity bean. These are relatively easy to port.

WebLogic-specific EJB settings are contained within the weblogic-ejb-jar.xml and weblogic-cmp-rdbms-jar.xml files. These files contain configuration information specific to WebLogic and are not included with the Java Smart Ticket application. In WebLogic Server 7.0, the weblogic-ejb-jar.xml file is no longer required by all EJBs. However, the weblogic-cmp-rdbms-jar.xml file is still required by all container managed persistent beans. We will need only the weblogic-ejb-jar.xml file.

Each of the EJBs should have a similar XML stanza contained in the weblogic-ejb-jar.xml file. The MovieInfo EJB, for example, has the following XML stanza in its weblogic-ejb-jar.xml file (see also Listing 2):

<weblogic-enterprise-bean>
<ejb-name>MovieInfo</ejb-name>
<reference-descriptor>
<resource-description>
<res-ref-name>jdbc/MovieInfoDataSource</res-ref-name>
<jndi-name>MovieInfoDataSource</jndi-name>
</resource-description>
</reference-descriptor>
<jndi-name>Smarticket.MovieInfoEJB</jndi-name>
</weblogic-enterprise-bean>
Here the ejb-name element, MovieInfo, corresponds to the ejb-name element with the same name in the ejb-jar.xml file. This is how you specify which of the EJBs defined in the ejb-jar.xml file you wish to extend in the weblogic-ejb-jar.xml file. The reference-descriptor stanza may contain one or more resource-factory or EJB reference mappings. This EJB needs to map a jdbc/MovieInfoDataSource to a JDBC TX data source that you will later define as MoveInfoDataSource by using the WebLogic Administration Console. You'll also need to have a <jndi-name> entry for your bean to bind it to WebLogic Server's global JNDI tree.

Although the Java Smart Ticket application was designed to run with Cloudscape, very little effort is needed to modify the BMP bean classes to get them to run with PointBase 4.2 server. In the original CustomerEJB bean class, the SQL statement to find a customer uses parentheses in the join clause. PointBase doesn't support this. You can code around that; I did so by rewriting the dbFindCustomer method to drop the join (see Listing 3).

When all the EJB descriptors are done, you must jar and compile the EJBs by modifying the %SMARTICKET_HOME%\build.xml. In the %SMARTICKET_HOME%\build.xml file, I added the Ant target weblogic.compile.ejb to supercede j2ee.compile.ejb and j2ee.package.ejb (see Listing 4). What I would like to highlight is shown below:

<target name="weblogic.compile.ejb">
...
<copy file="${src.dir}/ejb-jar.xml" tofile="${smarticket.buildjardir}/META-INF/ejb-jar.xml"/>
<copy file="${src.dir}/weblogic-ejb-jar.xml" tofile="${smarticket.buildjardir}/META-INF/weblogic-ejb-jar.xml"/>
<jar jarfile="${smarticket.ejbjar}"
basedir="${smarticket.buildjardir}"
update="yes"/>
<java classname="weblogic.ejbc"
fork="yes"
classpath="${java.class.path}">
<arg line="-compiler javac -keepgenerated ${smarticket.ejbjar}"/>
<java>
...
<target>

The first thing this does is copy the weblogic-ejb-jar.xml file to the ${smarticket.buildjardir}/META-INF directory where the ejb-jar.xml file is. Next, instead of just simply jarring up your compiled classes and descriptors and deploying the resulting jar, run weblogic.ejbc utility on the jar. The output jar, ejb_st.jar, is symbolized by ${smarticket.ejbjar}.

Although not required, running weblogic.ejbc before deployment yields several benefits. The most immediate advantage is that it provides validation on the EJBs according to the EJB specification. Errors in the EJB class files and descriptors can be detected and fixed before the EJB is deployed to a WebLogic server. Another benefit is that EJB compiling and stub generation are decoupled from server startup.

Smart compilation is a new feature of the weblogic.ejbc utility in WebLogic Server 7.0. In previous versions, an input and output JAR were both required as arguments to the weblogic.ejbc utility. This is no longer true. Instead, you can simply pass one JAR to the weblogic.ejbc utility. The next time the weblogic.ejbc utility is run on the JAR file, it can determine whether or not the bean classes within the JAR file need to be regenerated.

To use smart compilation, remove the Sun prebuilt %SMARTICKET_HOME%\bin\ejb_st.jar file, but at the same time disallow immediate deletion of the ejb_st.jar file when we build it for the first time. I commented out the second delete in this Ant target in the %SMARTICKET_HOME%\ build.xml file (Listing 4):

<target name="j2ee.clean">
<delete dir="${j2ee.build.dir}" />
<!-- <delete dir="${j2ee.dist.dir}" /> -->
<target>

We will not build the EJBs just yet, as a few more changes are required in the %SMARTICKET_HOME%\build.xml file. We will go over these changes in later on.

How to Port the Web Application
Porting the Web application component of the Java Smart Ticket application is very similar to porting the EJB component. In addition to having the Java Smart Ticket web.xml file, we need to create a corresponding weblogic.xml file. Whereas the weblogic-ejb-jar.xml file is required for all EJBs and weblogic-cmp-rdbms-jar.xml files for CMP EJBs, the weblogic.xml file is needed only if you have attributes to set. It allows you to map security names to a security realm and to map resources to JNDI. It also allows you to define JSP, session, container, and character set parameters.

The weblogic.xml file will make two types of references in the reference-descriptor stanza: resource factory and EJB. Like the weblogic-ejb-jar.xml file, we need to map the jdbc/MovieInfoDataSource to the MovieInfoDataSource transactional datasource. After all the resource-description elements are defined, we then define the EJB references that the Web application needs. The ejb-ref-name, ejb/MovieInfo, is mapped to Smarticket.MovieInfoEJB. As you know, this is the jndi name I had assigned the MovieInfo EJB in the weblogic-ejb-jar.xml file. Here is what it would look like in the weblogic.xml file (see Listing 5):

<reference-descriptor>
<resource-description>
<res-ref-name>jdbc/MovieInfoDataSource</res-ref- name>
<jndi-name>MovieInfoDataSource</jndi-name>
</resource-description>
...
<ejb-reference-description>
<ejb-ref-name>ejb/MovieInfo</ejb-ref-name>
<jndi-name>Smarticket.MovieInfoEJB</jndi-name>
</ejb-reference-description>
...
</reference-descriptor>

And to the %SMARTICKET_HOME%\build.xml file, I add the following to j2ee.web.package ANT target (see Listing 4):

<copy todir="${j2ee.build.web.dir}/WEB-INF"
file="${src.dir}/weblogic.xml"
overwrite="true" />
I placed this copy stanza right after the stanza that copies the web.xml file to ${j2ee.build.web.- dir}\WEB-INF.

Putting it All Together
Building the smarticket.ear
The Sun J2EE Reference Implementation server isn't needed to build, deploy, or run the ported Java Smart Ticket application.

To properly set up your environment to build the Java Smart Ticket application for WebLogic Server 7.0, you'll need to do several things. In a CMD window, navigate to %SAMPLES_HOME%\server\config\examples and run setExamplesEnv.cmd. This sets up your WebLogic Server development environment. Next, set the J2MEWTK_HOME environment variable equal to the root directory where you installed the J2ME toolkit. For your convenience, I have included setenv.cmd to set J2MEWTK_HOME equal to C:\j2mewtk, the default installation directory.

In the %SMART_TICKET%\build.xml file make sure that this Ant target

<target name="j2ee" depends="j2ee.compile.ejb,
j2ee.compile.web,j2ee.package.ejb,j2ee.package.web,j2ee
.package" />

is changed to

<target name="j2ee" depends="weblogic.compile.ejb,j2ee.compile.web
,j2ee.package.web,weblogic.package" />

to call the new Ant targets that we need: one we discussed in "How to Port the Enterprise Java Beans"; the other, I'll discuss here.

WebLogic server doesn't require its applications to be packaged by the Sun J2EE Reference Implementation tools. This has two consequences for us. First, we must create an application.xml file by hand; I saved mine under %SMARTICKET_HOME%\src (see Listing 6). It's important, as it's the deployment descriptor for the smarticket.ear. Second, I have added a weblogic.package Ant target to supercede j2ee.package. All this target does is jar up ejb_st.jar, web_st.jar, and META-INF/application.xml into smarticket.ear.

I've added the weblogic.package Ant target to supercede the j2ee.package. This target will JAR up ejb_st.jar, web_st.jar, and META_INF/application.xml into smarticket.ear. I've made these changes because we're not using the Sun J2EE Reference Implementation tools for packaging. Consequently, we also need to create an application.xml file; this file will be the deployment descriptor for the smarticket.ear. I saved mine under %SMARTICKET_HOME%\src (see Listing 6).

Uploading Data to the PointBase Database
As you may know, the J2EE Reference Implementation server ships with the Cloudscape RDBMS. By default, the %SMARTICKET_HOME%\populate.bat script uploads the %SMARTICKET_HOME%\src\smarticket.sql ddl to a Cloudscape database. To do the same for the PointBase 4.2 Server, the evaluation RDBMS included with WebLogic Server 7.0, we need to make sure that smarticket.sql and populate.bat are PointBase friendly. The only change you'll need to make to smarticket.sql is to change the 10 "int"data types to "integer." (I've provided a smarticketPointBase.sql with the changes for your convenience. Next, update the %SMARTICKET_HOME%\populate.bat script to use the PointBase driver with the following:

set POINTBASEHOME=%SAMPLES_HOME%\server\eval\pointbase
java utils.Schema
jdbc:pointbase:server://localhost/demo,database.home=%POINTBASEHOME%
com.pointbase.jdbc.jdbcUniversalDriver -u
examples -p examples -verbose
./src/smarticketPointBase.sql

Starting the WebLogic 7.0 Examples server will automatically start the PointBase 4.2 server in a minimized CMD window. You can start the WebLogic 7.0 Examples server by selecting the Start Menu item, "Start Examples Server", in the SERVER EXAMPLES folder or by opening a CMD window and executing %SAMPLES_HOME%\server\config\examples\start ExamplesEnv.cmd.

In another CMD window, source your environment by running %SAMPLES_HOME%\server\config\examples\setExamplesEnv.cmd.

Run %SMARTICKET_HOME%\populate.bat. Your database should now be set up.

Deploy and Configure the Application
Before installing the Java Smart Ticket application, we need to configure the JDBC Tx Data Sources that it will need.
1. Start the Examples server if you have not already. Browse to http://localhost:7001/console and sign in to the WebLogic Administrative console
2. In the "Service Configurations"section and under the "JDBC"heading, choose "Tx Data Sources."
3. Next, click "Configure a new JDBC Tx Data Source..."and go to the Configuration Tab of a new JDBC Tx Data Source. I'll create a MovieInfoDataSource as an example (see Figure 1).
4. Enter a name for the data source; I call it "MyMovieInfoDataSource".
5. Enter "MovieInfoDataSource"in the JNDI field. Remember, this corresponds to the JNDI references I made in our EJB and Web application descriptors.
6. For the connection pool, enter "demoPool". This corresponds to the connection Pool that ships with the Examples Server. (Verify this by going to the Services\JDBC\Connection Pool node on the left-hand side.)
7. Leave everything else as default and click "Create".
8. Click the Targets Tab.
9. Highlight the examplesServer in the Available column and click the right arrow to move it to the "Chosen"column (see Figure 2).
10. Be sure to click "Apply".

You have successfully configured a JDBC Tx Data Source. Do the same for the three other data sources: TicketSalesDataSource, CustomerDataSource, and LocaleInfoDataSource.

The final task is to configure, or install, the application.
1. In the left pane of the Administration Console, browse to the examples\Deployments\Applications node.
2. Click "Configure a new Application..."and browse to %SMARTICKET_HOME%\bin and select "smarticket.ear" (see Figure 3).
3. Highlight the examplesServer in the "Available Servers"column and click the right arrow to move it to the "Target Servers"column.
4. Click "Apply".
5. Click "Create"and a Configuration tab will appear for the application.
6. Click Deploy "Deploy All"to delpoy all components to the example Server (see Figure 4).

Provided that you have properly configured the JDBC Tx Data Sources and populated the PointBase database, the application should deploy with no errors.

How to Run the App
Now that the Java Smart Ticket application has been successfully ported and deployed, it's time to test it. Locate and edit the %SMARTICKET_HOME%\bin\ smarticket.jad file. Verify that the port number in the three URLs matches the port that the server is listening on. The Examples Server uses 7001 by default. Leave everything else as default and save the Java Application Descriptor (JAD) file. If you have already installed the J2ME toolkit, you should be able to start the application by double-clicking the JAD file to start the phone emulator. The Java Smart Ticket Demo splash screen will appear, waiting for you to sign in (see Figure 5).

Conclusion
As you've seen, porting a J2EE application to WebLogic Server can be easy. Even with an application using exciting, brand-new wireless technology, little had to be changed. Neither the ejb-jar.xml (with the exception of the Sun bug) nor the web.xml files that Sun ships with the application needed modification.

More Stories By Nhu Tran

Nick Tran is an applications engineer at BEA systems and the lead for the WLS samples team. He oversees the development of core API examples for WLS and porting of end-to-end applications to WLS. Before working at BEA, Nick worked as a software consultant building enteprise applications.

Comments (1)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


IoT & Smart Cities Stories
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
IoT is rapidly becoming mainstream as more and more investments are made into the platforms and technology. As this movement continues to expand and gain momentum it creates a massive wall of noise that can be difficult to sift through. Unfortunately, this inevitably makes IoT less approachable for people to get started with and can hamper efforts to integrate this key technology into your own portfolio. There are so many connected products already in place today with many hundreds more on the h...
The standardization of container runtimes and images has sparked the creation of an almost overwhelming number of new open source projects that build on and otherwise work with these specifications. Of course, there's Kubernetes, which orchestrates and manages collections of containers. It was one of the first and best-known examples of projects that make containers truly useful for production use. However, more recently, the container ecosystem has truly exploded. A service mesh like Istio addr...
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As automation and artificial intelligence (AI) power solution development and delivery, many businesses need to build backend cloud capabilities. Well-poised organizations, marketing smart devices with AI and BlockChain capabilities prepare to refine compliance and regulatory capabilities in 2018. Volumes of health, financial, technical and privacy data, along with tightening compliance requirements by...
Charles Araujo is an industry analyst, internationally recognized authority on the Digital Enterprise and author of The Quantum Age of IT: Why Everything You Know About IT is About to Change. As Principal Analyst with Intellyx, he writes, speaks and advises organizations on how to navigate through this time of disruption. He is also the founder of The Institute for Digital Transformation and a sought after keynote speaker. He has been a regular contributor to both InformationWeek and CIO Insight...
Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...
To Really Work for Enterprises, MultiCloud Adoption Requires Far Better and Inclusive Cloud Monitoring and Cost Management … But How? Overwhelmingly, even as enterprises have adopted cloud computing and are expanding to multi-cloud computing, IT leaders remain concerned about how to monitor, manage and control costs across hybrid and multi-cloud deployments. It’s clear that traditional IT monitoring and management approaches, designed after all for on-premises data centers, are falling short in ...
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...