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!

@ThingsExpo Stories
Leading companies, from the Global Fortune 500 to the smallest companies, are adopting hybrid cloud as the path to business advantage. Hybrid cloud depends on cloud services and on-premises infrastructure working in unison. Successful implementations require new levels of data mobility, enabled by an automated and seamless flow across on-premises and cloud resources. In his general session at 21st Cloud Expo, Greg Tevis, an IBM Storage Software Technical Strategist and Customer Solution Architec...
Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
Product connectivity goes hand and hand these days with increased use of personal data. New IoT devices are becoming more personalized than ever before. In his session at 22nd Cloud Expo | DXWorld Expo, Nicolas Fierro, CEO of MIMIR Blockchain Solutions, will discuss how in order to protect your data and privacy, IoT applications need to embrace Blockchain technology for a new level of product security never before seen - or needed.
Imagine if you will, a retail floor so densely packed with sensors that they can pick up the movements of insects scurrying across a store aisle. Or a component of a piece of factory equipment so well-instrumented that its digital twin provides resolution down to the micrometer.
In his keynote at 18th Cloud Expo, Andrew Keys, Co-Founder of ConsenSys Enterprise, provided an overview of the evolution of the Internet and the Database and the future of their combination – the Blockchain. 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 settle...
BnkToTheFuture.com is the largest online investment platform for investing in FinTech, Bitcoin and Blockchain companies. We believe the future of finance looks very different from the past and we aim to invest and provide trading opportunities for qualifying investors that want to build a portfolio in the sector in compliance with international financial regulations.
No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
When shopping for a new data processing platform for IoT solutions, many development teams want to be able to test-drive options before making a choice. Yet when evaluating an IoT solution, it’s simply not feasible to do so at scale with physical devices. Building a sensor simulator is the next best choice; however, generating a realistic simulation at very high TPS with ease of configurability is a formidable challenge. When dealing with multiple application or transport protocols, you would be...
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
We are given a desktop platform with Java 8 or Java 9 installed and seek to find a way to deploy high-performance Java applications that use Java 3D and/or Jogl without having to run an installer. We are subject to the constraint that the applications be signed and deployed so that they can be run in a trusted environment (i.e., outside of the sandbox). Further, we seek to do this in a way that does not depend on bundling a JRE with our applications, as this makes downloads and installations rat...
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
DX World EXPO, LLC, a Lighthouse Point, Florida-based startup trade show producer and the creator of "DXWorldEXPO® - Digital Transformation Conference & Expo" has announced its executive management team. The team is headed by Levent Selamoglu, who has been named CEO. "Now is the time for a truly global DX event, to bring together the leading minds from the technology world in a conversation about Digital Transformation," he said in making the announcement.
In this strange new world where more and more power is drawn from business technology, companies are effectively straddling two paths on the road to innovation and transformation into digital enterprises. The first path is the heritage trail – with “legacy” technology forming the background. Here, extant technologies are transformed by core IT teams to provide more API-driven approaches. Legacy systems can restrict companies that are transitioning into digital enterprises. To truly become a lead...
Digital Transformation (DX) is not a "one-size-fits all" strategy. Each organization needs to develop its own unique, long-term DX plan. It must do so by realizing that we now live in a data-driven age, and that technologies such as Cloud Computing, Big Data, the IoT, Cognitive Computing, and Blockchain are only tools. In her general session at 21st Cloud Expo, Rebecca Wanta explained how the strategy must focus on DX and include a commitment from top management to create great IT jobs, monitor ...
"Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
The IoT Will Grow: In what might be the most obvious prediction of the decade, the IoT will continue to expand next year, with more and more devices coming online every single day. What isn’t so obvious about this prediction: where that growth will occur. The retail, healthcare, and industrial/supply chain industries will likely see the greatest growth. Forrester Research has predicted the IoT will become “the backbone” of customer value as it continues to grow. It is no surprise that retail is ...