Inside Scoop on J2EE : Tips and tricks on J2EE and Oracle Application Server by Debu Panda
Updated: 11/18/2004; 5:19:20 PM.

 

Subscribe to "Inside Scoop on J2EE" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Wednesday, September 01, 2004

The J2EE platform allows developers to build portable application using Java.  However achieving 100 percent portability with J2EE is a myth due to several vendor extensions and ambiguity in J2EE specifications. The Java Application Verification Kit for Enterprise is an attempt by Sun to help developers to ensure that the application developed by them adheres to the J2EE standard and is portable across J2EE application servers.

 

The Java AVK tools use the two methodologies to verify J2EE compatibility of an application:

 

Static verification determines any vendor specific API is being used in the code. Also verifies the deployment descriptors and modules to determine whether those adhere to the standard.

 

Runtime verification determines the proportion of enterprise bean component methods, Web services methods, and Web components that are invoked by running the application.

 

I spent couple of days exploring Java JVK for Enterprise Version 1.4 to help out a customer. In this article I will discuss the use the Java AVK for verifying the compatibility of J2EE applications using static verification approach.

 

Installation Problems

 

I ran into the installation nightmare while installing Java AVK. Installation of AVK needs a JRE and J2SE 1.4.2_04. I did not have a JRE on my desktops and the installation would not launch and the documented work around to launch installation using -is:javahome did not work for me. Also it requires the exact version 1.4.2_04 of J2SE, nothing more nothing less. I had to pay the price for acting smart and not reading to the installation requirement carefully.

 

Dependencies on Sun Application Server

 

The Java Verification Kit comes with a baggage of Sun Application Server. Even though I had Sun Application Server installed as a part of my J2EE 1.4 SDK I could not find an option to reuse an existing install of the Sun Application Server. Nor do I find a documentation how can you use the AVK with another J2EE compatible application server such as OC4J or Websphere.

 

Static Verification

 

You can use Static Verification in two ways. First you can use code the scan to find out any vendor specific APIs are used. Second you can use the static verifier to determine any incompatibility with J2EE packaging and deployment descriptors.

Source Code Scan

 

You can use this to find out whether your application uses any vendor specific API.

 

Identify the Vendor specific API

 

You have to first identify the vendor specific APIs in $JAVAKE_HOME/bin/lib/asmt-config.xml. For example, if you want to find out as follows:

 

<jboss>

     supported>

     </supported>

      <unsupported>

             <name>org.jboss</name>

      </unsupported>

</jboss>

 

 

This file now has entries for Weblogic 5.0, and 6.0, Websphere and JBoss. Looking at this file you would assume you can add a new entry for your application server of your choice such as Oracle or Borland as follows:

 

<oracle>

                 <supported>

                  </supported>

                  <unsupported>

                        <name>com.oracle</name>

                        <name>oracle.j2ee</name>

                  </unsupported>

</oracle>

 

However that is not the case. The list of application servers seems to be finite and is not dynamic.

 

So if you want to run static verification for your application code and you use some other application server, you have to select either of these option and package names for your vendor specific API. For example, if you want to use OC4J you can select JBoss as your target application server and have the entry for Oracle specific APIs as follows:

 

<jboss>

            <supported>

             </supported>

             <unsupported>

                  <name>com.oracle</name>

                  <name>oracle.j2ee</name>

                  <name>com.evermind.server.rmi</name>

                  <name>com.evermind.server</name>

            </unsupported>

</jboss>

 

Define Ant Tasks for Source Code Scan

You have to add the supplied ant tasks to your build files to perform the source code scan.

 

<property name="cpath"

value="${avk.home}/appserver/lib/sun-appserv-ant.jar:${avk.home}/lib/javke-ant.jar"/>

 

 

<taskdef name="SourceScan" classname="org.apache.tools.ant.taskdefs.optional.sun.verification.SourceScan" classpath="${cpath}"/>

 

You have to define a target for doing the source code scan and specify the location where the source code of your application resides.

 

<target name="code-scan" description="scan source code tests">

        <SourceScan srcDir="D:\howto\how-to-startup-class\src"

                srcServer="jboss" />

    </target>

 

 

Running Source Code Scan

You can run the SourceScan by using the asant utility supplied with the AVK as follows:

 

asant code-scan

 

The SourceScan will run and generate a summary (codeAnalysisSummary.html) with list of vendor specific APIs used in your java and jsp sources.  For example, I used com.evermind.server.OC4Jstartup in one of my Java class and it reported in the summary that I'm using a proprietary API.

 

Unfortunately the code scan does not catch usage of vendor specific InitialContextFactory that is more prevalently used by many developers (although not a good practice) in J2EE applications. For example, I used the following code snippet in one of my Java class  

env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory");

I expected this to be reported by the Java AVK but apparently it did not report this as non-portable code although I identified com.evermind.server.rmi as unsupported package.

Static Archive Test

 

You can use the static archive test to do the following:

·        Identify problems with the method signatures and other static inconsistencies for J2EE modules

·        Find any inconsistencies with the API and deployment descriptors

·        Validate the packaging and structure of different modules.

 

Define Ant Tasks for Static Archive Test

 

In order to run the static archive test you have to add the following Ant task in the build

scipt:

 

    <taskdef name="ArchiveTest" classname="org.apache.tools.ant.taskdefs.optional.sun.verification.StaticArchiveTest" classpath="${cpath}" />

 

You have to define a target for the running the ArchiveTest task. You have to specify the location of the archive and

reporting option.

 

<target name="static-archive-test" description="static archive tests for application containing enterprise beans and web components, reporting on all tests">

 

        <ArchiveTest appName="D:howtohow-to-quartzlibquartz-app.ear"

                reportingOpts="w" />

    </target>

 

 

 

Here are the different reporting options available:

           a - all results

            f - failures only

            w -  failures and warnings only (default)

 

 

Running Static Archive Test

 

You can run the StaticArchive by using the asant utility supplied with the AVK as follows:

 

asant static-archive-test
 
The results will be reported in the $JAVAKE_HOME/reporttool/static directory.
 

I was really impressed with the static archive test and this reported me a

whole bunch of warning  and failures as I expected.

 
For example, one of business method of my very old EJB throws RemoteException and 
the verifier detected this.
 

Conclusion

 
Beside the snags I run into during installation and the fact that the code is too 
tightly integrated with Sun Application Server 8, I  found the static verifier of AVK 
useful for J2EE application 
 

References and Further reading

Java AVK for the Enterprise - Testing J2EE Applications for Portability 

12:20:27 PM    comment []

© Copyright 2004 Debu Panda.

PS: These are my own thoughts and not of my employer ..



Click here to visit the Radio UserLand website.
 


September 2004
Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Aug   Oct