Skip to main content

Migrating WebLogic's JSP TagHandler example to GlassFish

Posted by sekhar on May 20, 2008 at 2:50 AM PDT

As I outlined in href="http://weblogs.java.net/blog/sekhar/archive/2008/02/migrate_to_glas.html">Migrate
to GlassFish acitivities , I am migrating samples from different
application servers to GlassFish to illustrate migration to
GlassFish. Here, I selected the WebLogic's "JSP TagHandler" sample to
migrate to GlassFish.

JSP Tag Handler Sample Application

The sample application that I migrated is the JSP Tag Handler
sample from WebLogic 9.2 distribution. The JSP Tag Handler application
is an Address Label Maker that uses JSP custom tags, tag handlers,
virtual directory mapping, split directory development.

The source for the WebLogic sample is in the directory
wls-install/weblogic92/samples/server/examples/src/webapp/jsp/tags/taghandler.

To try the migrated sample to GlassFish

  • Download and unzip href="http://migrate2glassfish.dev.java.net/blogs/wl92/gf_jspTagHandlerEar.zip">gf_jspTagHandlerEar.zip
    . The directory gf_jspTagHandlerEar contains files in an exploded EAR format.

  • asadmin deploydir gf_jspTagHandlerEar
  • Visit http://localhost:8080/jsp_tagHandler/TagHandler.jsp

Deployment: WLS Split Directory -> GF Exploded Directory

The JSP TagHandler example uses a split development directory
structure. In this approach, there are two directories - source and
build and supporting ant scripts and config files. The source and
build directory together contains the file for the J2EE/Java EE
application. GlassFish ,on the other hand, supports deployment of a
Java EE application from a directory that is an exploded format of a
deployable archive. Thus, to deploy on GlassFish, I first generated a
EAR file in exploded format using an ant build target in the build.xml
for the WebLogic sample as follows:


  • cd
    wls-install/weblogic92/samples/server/examples/src/webapp/jsp/tags/taghandler


  • ant build


  • ant package.exploded.ear

The above will build a jsfTagHandlerEar directory in exploded
format as shown below:

WebLogic: Exploded EAR 
jspTagHandlerEar
++++ META-INF
     .... application.xml
     .... weblogic-application.xml
++++ jspTagHandlerWar
     .... ExamplesFooter.jsp
     .... ExamplesHeader.jsp
     .... TagHandler.jsp
     .... wls_examples.css
     ++++ WEB-INF
          .... web.xml
          .... weblogic.xml
          ++++ lib
               .... jstl.jar
               .... standard.jar
          ++++ tags
               .... tagHandler.tag

Next, I repackaged the EAR file to replace WebLogic specific
artifacts with GF artificats by the making the following changes:

  • Removed jstl.jar. jstl.jar is the JavaServer Pages Standard
    Tag Library (JSTL) and is already included in
    gf-install/lib/javaee.jar.

  • Removed standards.jar. The tags are distributed in
    gf-install/lib/appserv-jstl.jar .

  • Removed WEB-INF/lib since neither jstl.jar nor standard.jar
    are required to be packaged.

  • Removed weblogic-application.xml. It was empty in this example.
  • Replaced weblogic.xml with sun-web.xml. The mapping is
    described below.

Thus, the exploded directory for deployment on GlassFish is as follows:

GlassFish: Exploded EAR 
gf_jspTagHandlerEar
++++ META-INF
     .... application.xml
++++ jspTagHandlerWar
     .... ExamplesFooter.jsp
     .... ExamplesHeader.jsp
     .... TagHandler.jsp
     .... wls_examples.css
     ++++ WEB-INF
          .... web.xml
          .... sun-web.xml
          ++++ tags
               .... tagHandler.tag

Then, I deployed the exploded directory gf_jspTagHandlerEar on
GlassFish:

  • asadmin deploydir gf_jspTagHandlerEar

weblogic.xml -> sun-web.xml Mapping

The following is how I mapped the weblogic.xml to
sun-web.xml. Additional details are after the mapping.

  <!-- weblogic.xml -->

  <?xml version="1.0" encoding="ISO-8859-1"?>
  <weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90">
  <jsp-descriptor>
    <page-check-seconds>1</page-check-seconds>
    <verbose>true</verbose>
  </jsp-descriptor>
    <!--
  Use the virtual-directory-mapping element to specify document roots other
  than the default document root of the Web application for certain kinds of
  requests, such as image requests. All images for a set of Web applications
  can be stored in a single location, and need not be copied to the document
  root of each Web application that uses them. For an incoming request, if a
  virtual directory has been specified servlet container will search for the
  requested resource first in the virtual directory and then in the
  Web application's original document root.
  -->
  <virtual-directory-mapping>
    <local-path>C:/bea/weblogic92/samples/server/</local-path>
    <url-pattern>/examples/*</url-pattern>
  </virtual-directory-mapping>
  <virtual-directory-mapping>
    <local-path>C:/bea/weblogic92/samples/server/examples/build</local-path>
    <url-pattern>images/*</url-pattern>
  </virtual-directory-mapping>


  <!-- sun-web.xml -->
  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
  <sun-web-app>
    <jsp-config>
      <property name="modificationTestInterval" value="1"/>
      <property name="verbose" value="true"/>
    </jsp-config>
   
    <property name="alternatedocroot_1" value="from=/examples/* dir=C:/bea/weblogic92/samples/server/"/>
    <property name="alternatedocroot_2" value="from=/images/* dir=C:/bea/weblogic92/samples/server/examples/build"/>
  </sun-web-app>

Virtual Directory Mapping

The example uses virtual directory mapping to locate the BEA logo
in the example. The GlassFish equivalent for WebLogic's
virtual-directory-mapping is the alternatedocroot property. I also had
to make two more changes to bring up the BEA logo. Of course, I could have replaced it with a
GlassFish logo once I was done :-) but I am trying to show migration
issues here.

URL Pattern

In alternatedocroot_2, I changed the URL pattern from
images/* to /images/*. Withtout the preceeding / , the following
WARNING is generated in the GlassFish server.log file
(i.e. gf-install/domain/domain1/logs/server.log )

    [#|2008-05-15T17:57:49.500-0400|WARNING|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=24;_ThreadName=httpWorkerThread-4848-1;images/*;_RequestID=1b29dda8-9133-4863-b0ef-9b7ec44c8576;|WEB0504: URL pattern images/* for alternate docbase is invalid|#]

Relative Path in URL

Another issue I ran into was related to use of a relative
path in ExamplesHeader.jsp. This file contains a reference to SRC
using a relative path as shown in the following fragment.

<!-- weblogic : ExamplesHeader.jsp fragment -->
...

<!-- TITLE -->
<table border=0 cellspacing="18" cellpadding="0">
  <tr>
    <td valign="top">
      <a HREF="http://www.bea.com"><IMG SRC="../../../../images/logo_tm_onwt.jpg" alt="BEA Logo" width="161" height="96" border="0"></a>
      <h3><%=request.getParameter("title")%></h3>
    </td>
  </tr>
</table>
...

The relative path used for SRC did not work (the BEA logo won't come up). I changed the SRC reference to images/* .

<!-- GlassFish : ExamplesHeader.jsp fragment -->
...

<table border=0 cellspacing="18" cellpadding="0">
  <tr>
    <td valign="top">
      <a HREF="http://www.bea.com"><IMG SRC="images/logo_tm_onwt.jpg" alt="BEA Logo" width="161" height="96" border="0"></a>
      <h3><%=request.getParameter("title")%></h3>
    </td>
  </tr>
</table>
...

Summary

The code changes were minimal. I plan to followup up and provide
more details on the migration issues outlined above.

As always, feedback is welcome. For questions and feedback, visit Migrate To GlassFish project and follow the "Discussion Forums" link .

Related Topics >>