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):

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}"
<java classname="weblogic.ejbc"
<arg line="-compiler javac -keepgenerated ${smarticket.ejbjar}"/>

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}" /> -->

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):

<res-ref-name>jdbc/MovieInfoDataSource</res-ref- name>

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"
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,
.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
com.pointbase.jdbc.jdbcUniversalDriver -u
examples -p examples -verbose

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).

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) View Comments

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.

Most Recent Comments
Tom Chen 12/27/02 12:52:00 PM EST


There is an error on the rewriting the SQL in Listing 3.

The SQL statements is in:

The original SQL statement shiped by SUN Smarticket-1.1 uses left outer join:

ps = c.prepareStatement("select u.username,u.password," + " u.zipcode, u.creditcard, t.promotext"+ " from (userprefs u left outer join"+ " tickers t on u.zipcode = t.zipcode)"+ " where username = ?",ResultSet.TYPE_SCROLL_INSENSITIVE,

The modified SQL statment in Nick's article uses inner join:

ps = c.prepareStatement("select u.username, u.password," + " u.zipcode, u.creditcard, t.promotext "+ " from userprefs u, tickers t" + " where username = ?" + " AND u.zipcode = t.zipcode", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

As we know, left outer join includes inner join and the rows from left table that are not included in the inner join. The modified SQL statement only returns the user accounts with zipcode that tickers table has. As a result, when we run the application at the first time to create a new account, if we don't create an account with the zipcode that tickers table has then we cannot signin using that account!

As a matter of fact, we don't need to check with the tickers table in this method. So I'd like to suggest the following modification:

ps = c.prepareStatement("select username"+ " from userprefs"+ " where username = ?",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);

After you fixing this error, the application can run well on Weblogic 7.0!

IoT & Smart Cities Stories
The deluge of IoT sensor data collected from connected devices and the powerful AI required to make that data actionable are giving rise to a hybrid ecosystem in which cloud, on-prem and edge processes become interweaved. Attendees will learn how emerging composable infrastructure solutions deliver the adaptive architecture needed to manage this new data reality. Machine learning algorithms can better anticipate data storms and automate resources to support surges, including fully scalable GPU-c...
Machine learning has taken residence at our cities' cores and now we can finally have "smart cities." Cities are a collection of buildings made to provide the structure and safety necessary for people to function, create and survive. Buildings are a pool of ever-changing performance data from large automated systems such as heating and cooling to the people that live and work within them. Through machine learning, buildings can optimize performance, reduce costs, and improve occupant comfort by ...
The explosion of new web/cloud/IoT-based applications and the data they generate are transforming our world right before our eyes. In this rush to adopt these new technologies, organizations are often ignoring fundamental questions concerning who owns the data and failing to ask for permission to conduct invasive surveillance of their customers. Organizations that are not transparent about how their systems gather data telemetry without offering shared data ownership risk product rejection, regu...
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
Poor data quality and analytics drive down business value. In fact, Gartner estimated that the average financial impact of poor data quality on organizations is $9.7 million per year. But bad data is much more than a cost center. By eroding trust in information, analytics and the business decisions based on these, it is a serious impediment to digital transformation.
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...
Predicting the future has never been more challenging - not because of the lack of data but because of the flood of ungoverned and risk laden information. Microsoft states that 2.5 exabytes of data are created every day. Expectations and reliance on data are being pushed to the limits, as demands around hybrid options continue to grow.
Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
Enterprises have taken advantage of IoT to achieve important revenue and cost advantages. What is less apparent is how incumbent enterprises operating at scale have, following success with IoT, built analytic, operations management and software development capabilities - ranging from autonomous vehicles to manageable robotics installations. They have embraced these capabilities as if they were Silicon Valley startups.
As IoT continues to increase momentum, so does the associated risk. Secure Device Lifecycle Management (DLM) is ranked as one of the most important technology areas of IoT. Driving this trend is the realization that secure support for IoT devices provides companies the ability to deliver high-quality, reliable, secure offerings faster, create new revenue streams, and reduce support costs, all while building a competitive advantage in their markets. In this session, we will use customer use cases...