Wednesday Jan 20, 2010

TOTD #118: Managing OSGi bundles in GlassFish v3 - asadmin, filesystem, telnet console, web browser, REST, osgish

GlassFish v3 and OSGi integration is now known for almost two years. Several blogs have been published on this topic and googling on "glassfish osgi" shows 817,000 results. This blog has published four entries on the topic so far.

This Tip Of The Day (TOTD) will show the different ways you can manage OSGi bundles in GlassFish v3.

The first part is to create a trivial OSGi bundle as explained in TOTD #36.

  1. Create a simple Maven project using the command as shown below:
    ~/samples/v3/osgi >mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=org.glassfish.samples.osgi.helloworld -DartifactId=helloworld
    [INFO] Scanning for projects...
    [INFO] Searching repository for plugin with prefix: 'archetype'.
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Maven Default Project
    [INFO]    task-segment: [archetype:create] (aggregator-style)
    [INFO] ------------------------------------------------------------------------
    [INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
    [INFO] Setting property: velocimacro.messages.on => 'false'.
    [INFO] Setting property: resource.loader => 'classpath'.
    [INFO] Setting property: resource.manager.logwhenfound => 'false'.
    [INFO] [archetype:create]
    [WARNING] This goal is deprecated. Please use mvn archetype:generate instead
    [INFO] Defaulting package to group ID: org.glassfish.samples.osgi.helloworld
    [INFO] artifact org.apache.maven.archetypes:maven-archetype-quickstart: checking for updates from central
    [INFO] ----------------------------------------------------------------------------
    [INFO] Using following parameters for creating OldArchetype: maven-archetype-quickstart:RELEASE
    [INFO] ----------------------------------------------------------------------------
    [INFO] Parameter: groupId, Value: org.glassfish.samples.osgi.helloworld
    [INFO] Parameter: packageName, Value: org.glassfish.samples.osgi.helloworld
    [INFO] Parameter: package, Value: org.glassfish.samples.osgi.helloworld
    [INFO] Parameter: artifactId, Value: helloworld
    [INFO] Parameter: basedir, Value: /Users/arungupta/samples/v3/osgi
    [INFO] Parameter: version, Value: 1.0-SNAPSHOT
    [INFO] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* End of debug info from resources from generated POM \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
    [INFO] OldArchetype created in dir: /Users/arungupta/samples/v3/osgi/helloworld
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESSFUL
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 11 seconds
    [INFO] Finished at: Wed Jan 20 14:12:41 PST 2010
    [INFO] Final Memory: 12M/80M
    [INFO] ------------------------------------------------------------------------
    
  2. Change the generated App class in "src/main/java/org/glassfish/samples/osgi/helloworld" folder so that it looks like:
    package org.glassfish.samples.osgi.helloworld;
    
    import org.osgi.framework.BundleActivator;
    import org.osgi.framework.BundleContext;
    
    /\*\*
     \* Hello world!
     \*
     \*/
    public class App implements BundleActivator {
        public void start(BundleContext context) throws Exception {
            System.out.println("Hey!");
        }
        public void stop(BundleContext context) throws Exception {
            System.out.println("Bye!");
        }
    }
    
    
    This is a trivial Activator class but sitll shows the key methods. The changes are highlighted in bold.
  3. Update "pom.xml" with the following changes:
    1. Change <packaging> to "bundle" from the default value of "jar".
    2. Add <dependency> on "org.osgi.core".
    3. Add the <plugin> maven-bundle-plugin and provide <instructions> to generate the appropriate MANIFEST.MF.
      <project xmlns="http://maven.apache.org/POM/4.0.0" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
                        http://maven.apache.org/maven-v4_0_0.xsd">
       <modelVersion>4.0.0</modelVersion>
       <groupId>org.glassfish.samples.osgi.helloworld</groupId>
       <artifactId>helloworld</artifactId>
       <packaging>bundle</packaging>
       <version>1.0-SNAPSHOT</version>
       <name>helloworld</name>
       <url>http://maven.apache.org</url>
       <dependencies>
         <dependency>
           <groupId>junit</groupId>
           <artifactId>junit</artifactId>
           <version>3.8.1</version>
           <scope>test</scope>
         </dependency>
         <dependency>
           <groupId>org.apache.felix</groupId>
           <artifactId>org.osgi.core</artifactId>
           <version>1.0.0</version>
         </dependency>
       </dependencies>
       <build>
         <plugins>
           <plugin>
             <groupId>org.apache.felix</groupId>
             <artifactId>maven-bundle-plugin</artifactId>
             <extensions>true</extensions>
             <configuration>
               <instructions>
                 <Export-Package>${pom.groupId}</Export-Package>
                 <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
                 <Bundle-Activator>${pom.groupId}.App</Bundle-Activator>
               </instructions>
             </configuration>
           </plugin>
         </plugins>
       </build>
      </project>
      

  4. Generate the OSGi bundle as shown below:
    ~/samples/v3/osgi/helloworld >mvn install
    [INFO] Scanning for projects...
    [INFO] ------------------------------------------------------------------------
    [INFO] Building helloworld
    [INFO]    task-segment: [install]
    [INFO] ------------------------------------------------------------------------
    [INFO] [resources:resources]
    [INFO] Using default encoding to copy filtered resources.
    [INFO] [compiler:compile]
    [INFO] Compiling 1 source file to /Users/arungupta/samples/v3/osgi/helloworld/target/classes
    [INFO] [resources:testResources]
    [INFO] Using default encoding to copy filtered resources.
    [INFO] [compiler:testCompile]
    [INFO] Compiling 1 source file to /Users/arungupta/samples/v3/osgi/helloworld/target/test-classes
    [INFO] [surefire:test]
    [INFO] Surefire report directory: /Users/arungupta/samples/v3/osgi/helloworld/target/surefire-reports
    
    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running org.glassfish.samples.osgi.helloworld.AppTest
    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.06 sec
    
    Results :
    
    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
    
    [INFO] [bundle:bundle]
    [INFO] [install:install]
    [INFO] Installing /Users/arungupta/samples/v3/osgi/helloworld/target/helloworld-1.0-SNAPSHOT.jar to /Users/arungupta/.m2/repository/org/glassfish/samples/osgi/helloworld/helloworld/1.0-SNAPSHOT/helloworld-1.0-SNAPSHOT.jar
    [INFO] [bundle:install]
    [INFO] Parsing file:/Users/arungupta/.m2/repository/repository.xml
    [INFO] Installing org/glassfish/samples/osgi/helloworld/helloworld/1.0-SNAPSHOT/helloworld-1.0-SNAPSHOT.jar
    [INFO] Writing OBR metadata
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESSFUL
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 8 seconds
    [INFO] Finished at: Wed Jan 20 14:18:31 PST 2010
    [INFO] Final Memory: 20M/80M
    [INFO] ------------------------------------------------------------------------
    
    
    The generated "target/helloworld-1.0-SNAPSHOT.jar" has the following contents:

     META-INF/MANIFEST.MF
     META-INF/
     META-INF/maven/
     META-INF/maven/org.glassfish.samples.osgi.helloworld/
     META-INF/maven/org.glassfish.samples.osgi.helloworld/helloworld/
     META-INF/maven/org.glassfish.samples.osgi.helloworld/helloworld/pom.properties
     META-INF/maven/org.glassfish.samples.osgi.helloworld/helloworld/pom.xml
     org/
     org/glassfish/
     org/glassfish/samples/
     org/glassfish/samples/osgi/
     org/glassfish/samples/osgi/helloworld/
     org/glassfish/samples/osgi/helloworld/App.class
    

    And the generated "MANIFEST.MF" looks like:
    Manifest-Version: 1.0
    Export-Package: org.glassfish.samples.osgi.helloworld;uses:="org.osgi.
     framework"
    Built-By: arungupta
    Tool: Bnd-0.0.357
    Bundle-Name: helloworld
    Created-By: Apache Maven Bundle Plugin
    Bundle-Version: 1.0.0.SNAPSHOT
    Build-Jdk: 1.6.0_17
    Bnd-LastModified: 1264025910352
    Bundle-ManifestVersion: 2
    Bundle-Activator: org.glassfish.samples.osgi.helloworld.App
    Import-Package: org.glassfish.samples.osgi.helloworld,org.osgi.framewo
     rk;version="1.3"
    Bundle-SymbolicName: helloworld
    

Lets install this newly created OSGi bundle in GlassFish v3. First, fire up GlassFish as:

~/tools/glassfish/v3/74b/glassfishv3/glassfish >./bin/asadmin start-domain -v
Jan 20, 2010 2:30:39 PM com.sun.enterprise.admin.launcher.GFLauncherLogger info
INFO: JVM invocation command line:
/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin/java
-cp
/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/glassfish.jar
-XX:+UnlockDiagnosticVMOptions
-XX:MaxPermSize=192m
-XX:NewRatio=2
-XX:+LogVMOutput

. . .

Jan 20, 2010 2:30:40 PM com.sun.enterprise.admin.launcher.GFLauncherLogger info
INFO: Successfully launched in 52 msec.
Jan 20, 2010 2:30:40 PM com.sun.enterprise.glassfish.bootstrap.ASMain main
INFO: Launching GlassFish on Felix platform

Welcome to Felix
================

[#|2010-01-20T14:30:49.437-0800|INFO|glassfishv3.0|com.sun.grizzly.config.GrizzlyServiceListener|_ThreadID=11;_ThreadName=FelixStartLevel;|Perform lazy SSL initialization for the listener 'http-listener-2'|#]

[#|2010-01-20T14:30:49.527-0800|INFO|glassfishv3.0|com.sun.grizzly.config.GrizzlyServiceListener|_ThreadID=12;_ThreadName=Thread-11;|Starting Grizzly Framework 1.9.18-k - Wed Jan 20 14:30:49 PST 2010|#]

. . .

[#|2010-01-20T14:30:58.668-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=21;_ThreadName={felix.fileinstall.poll=5000, felix.fileinstall.bundles.new.start=true, felix.fileinstall.dir=/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/autostart/, felix.fileinstall.debug=1};|Started bundle: file:/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/autostart/org.apache.felix.scr.jar|#]

[#|2010-01-20T14:30:58.786-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=21;_ThreadName={felix.fileinstall.poll=5000, felix.fileinstall.bundles.new.start=true, felix.fileinstall.dir=/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/autostart/, felix.fileinstall.debug=1};|Started bundle: file:/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/autostart/osgi-web-container.jar|#]

[#|2010-01-20T14:31:00.436-0800|INFO|glassfishv3.0|null|_ThreadID=23;_ThreadName=ping;|Total number of available updates : 0|#]

There are several ways to manage the OSGi bundles in GlassFish v3:

  1. The "asadmin" command (explained here)
  2. Filesystem operations using the pre-installed Apache Felix File Install bundle (explained here)
  3. A Telnet shell using pre-installed Apache Felix Remote Shell (explained here and TOTD #103)
  4. A Web browser using the Apache Felix Web Console (needs to be installed separately and more details below)
  5. A RESTful client by installing the REST console (need to be installed separately and more details below)


Lets explore each option in detail now.

Option 1: Manage the OSGi bundle using the "asadmin" command

  1. Deploy the generated OSGi bundle using asadmin command:
    ~/samples/v3/osgi/helloworld/target >~/tools/glassfish/v3/74b/glassfishv3/glassfish/bin/asadmin deploy --type osgi helloworld-1.0-SNAPSHOT.jar 
    Application deployed successfully with name helloworld-1.0-SNAPSHOT.
    
    
    Command deploy executed successfully.
    
    The server log shows the following output:
    [#|2010-01-20T16:15:10.553-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=36;_ThreadName=http-thread-pool-4848-(2);
    |Hey!|#]
    
    
    Notice "Hey!" message in the server log as the bundle gets started.
  2. Verify the installed bundle as:
    ~/samples/v3/osgi/helloworld/target >~/tools/glassfish/v3/74b/glassfishv3/glassfish/bin/asadmin list-applications
    helloworld-1.0-SNAPSHOT 
    
    Command list-applications executed successfully.
    

    Or if there are multiple applications deployed then only the OSGi bundles can be queried as:

    ~/samples/v3/osgi/helloworld/target >~/tools/glassfish/v3/74b/glassfishv3/glassfish/bin/asadmin list-applications --type osgi
    helloworld-1.0-SNAPSHOT 
    
    Command list-applications executed successfully.
    
  3. The bundle can be undeployed as:

    ~/samples/v3/osgi/helloworld/target >~/tools/glassfish/v3/74b/glassfishv3/glassfish/bin/asadmin undeploy helloworld-1.0-SNAPSHOT 
    
    Command undeploy executed successfully.
    
    
    And then the following message is shown on the console:
    [#|2010-01-20T16:22:19.554-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=37;_ThreadName=http-thread-pool-4848-(1);
    |Bye!|#]
    
    
    Notice "Bye!" message in second line of the log output indicating the bundle is stopped.

Option 2: Manage the OSGi bundle using file system operations

  1. Copy the generated jar (target/helloworld-1.0-SNAPSHOT.jar) in "modules/autostart" directory as:
    ~/tools/glassfish/v3/74b/glassfishv3/glassfish >cp ~/samples/v3/osgi/helloworld/target/helloworld-1.0-SNAPSHOT.jar modules/autostart/
    
    
    and that shows the log output as:
    [#|2010-01-20T16:29:04.625-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=21;_ThreadName={felix.fileinstall.poll=5000, felix.fileinstall.bundles.new.start=true, felix.fileinstall.dir=/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish
    /modules/autostart/, felix.fileinstall.debug=1};|Installed /Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/autostart/
    helloworld-1.0-SNAPSHOT.jar|#]
    
    [#|2010-01-20T16:29:04.635-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=21;_ThreadName={felix.fileinstall.poll=5000, felix.fileinstall.bundles.new.start=true, felix.fileinstall.dir=/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish
    /modules/autostart/, felix.fileinstall.debug=1};|Hey!|#]
    
    [#|2010-01-20T16:29:04.636-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=21;_ThreadName={felix.fileinstall.poll=5000, felix.fileinstall.bundles.new.start=true, felix.fileinstall.dir=/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish
    /modules/autostart/, felix.fileinstall.debug=1};|Started bundle: file:/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/autostart
    /helloworld-1.0-SNAPSHOT.jar|#]
    
    
    Notice "Hey!" message in the second line of log output as the bundle gets started.
  2. The bundle can be undeployed by removing the JAR file from "modules/autostart" directory as:

    ~/tools/glassfish/v3/74b/glassfishv3/glassfish >rm modules/autostart/helloworld-1.0-SNAPSHOT.jar
    
    
    that shows the following output:
    ~/tools/glassfish/v3/74b/glassfishv3/glassfish >[#|2010-01-20T16:32:04.677-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=21;_ThreadName={felix.fileinstall.poll=5000, felix.fileinstall.bundles.new.start=true, felix.fileinstall.dir=/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish
    /modules/autostart/, felix.fileinstall.debug=1};|Uninstalling bundle 224 (helloworld)|#]
    
    [#|2010-01-20T16:32:04.679-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=21;_ThreadName={felix.fileinstall.poll=5000, felix.fileinstall.bundles.new.start=true, felix.fileinstall.dir=/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish
    /modules/autostart/, felix.fileinstall.debug=1};|Bye!|#]
    
    [#|2010-01-20T16:32:04.682-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=21;_ThreadName={felix.fileinstall.poll=5000, felix.fileinstall.bundles.new.start=true, felix.fileinstall.dir=/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish
    /modules/autostart/, felix.fileinstall.debug=1};|Uninstalled /Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/autostart
    /helloworld-1.0-SNAPSHOT.jar|#]
    
    
    Notice "Bye!" message in second line of the log output indicating the bundle is stopped.

Option 3: Manage the OSGi bundle using a remote Telnet Shell

  1. Connecting to the Felix Remote Shell as:
    ~/tools/glassfish/v3/74b/glassfishv3/glassfish >telnet localhost 6666
    Trying ::1...
    telnet: connect to address ::1: Connection refused
    Trying fe80::1...
    telnet: connect to address fe80::1: Connection refused
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '\^]'.
    
    Felix Remote Shell Console:
    ============================
    
    ->
    
  2. Install the bundle as:
    -> install file:///Users/arungupta/samples/v3/osgi/helloworld/target/helloworld-1.0-SNAPSHOT.jar
    Bundle ID: 225
    
    The command output shows "225" as the bundle id. This id is used to start / stop / uninstall the bundle.
  3. Check the bundle status as:
    -> find hello
    START LEVEL 1
       ID   State         Level  Name
    [ 225] [Installed  ] [    1] helloworld (1.0.0.SNAPSHOT)
    
    
    and then start, stop, and uninstall the bundle as:
    -> start 225
    -> stop 225
    -> uninstall 225
    -> find hello
    No matching bundles found
    
    
    which shows following output in the logs:
    [#|2010-01-20T16:43:45.399-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=38;_ThreadName=telnetconsole.shell remote=/127.0.0.1:4894;|Hey!|#]
    
    [#|2010-01-20T16:43:58.516-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=38;_ThreadName=telnetconsole.shell remote=/127.0.0.1:4894;|Bye!|#]
    

    Notice "Hey!" and "Bye!" messages in the log output as the bundle is started and stopped.


Option 4 - Manage the OSGi bundle using a Web browser

Lets see how the OSGi bundles in GlassFish can be managed using Apache Felix Web Console. This is originally explained in Sahoo's blog.

  1. Copy GlassFish OSGi HTTP Service bundle from here (latest) and save it in the "modules/autostart" directory.

  2. Copy Apache Felix Web Console bundle from here (latest) and save it in the "modules/autostart" directory.

  3. Ignore the "NoClassDefFoundError" in the server log. The key is to look for the following message in server log:

    Started bundle: file:/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/autostart/org.apache.felix.webconsole-2.0.4.jar|#]
    
  4. Open the URL "http://localhost:8080/osgi/system/console/bundles" in a browser and use "admin" as the username and "admin" as the password as shown below:



    I had to enter the credentials couple of times for the login to work but finally the following window showed up:



    It shows a complete summary of all the OSGi bundles available/installed/active etc in GlassFish v3. A new OSGi bundle can be installed by clicking on "Choose File" button. Several administration commands such as Start/Stop, Update, Uninstall, Refresh Import Packages can be issued for each bundle by clicking on associated buttons.

  5. Install the OSGi bundle by clicking on "Choose File" and selecting "helloworld-1.0.-SNAPSHOT.jar" and then click on "Install or Update" button. The following message is shown in the server log:

    [#|2010-01-20T17:04:46.654-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=39;_ThreadName=Background Install /var/folders/+E/+E6YtSvGGEKNwOA77I-9Fk+++TI/-Tmp-/install1657418488877506078.tmp;
    |Hey!|#]
    

    The bundle gets installed and started as identified by "Hey!" message.
    The recently installed "HelloWorld" bundle looks like:

    Clicking on "helloworld" shows the complete status about the bundle as shown below:

     

  6. The bundle can be stopped by clicking on the Stopped, Refreshed Package Imports, Updated, and Uninstalled by clicking on the respective buttons in the "Actions" column. Clicking on the Stop button shows the following message:

    [#|2010-01-20T17:10:56.359-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com
    .sun.enterprise.v3.services.impl|_ThreadID=25;_ThreadName=http-thread-pool-8080-(2);
    |Bye!|#]
    
    
    Notice "Bye!" message indicating the bundle has stopped.

Option 5: Manage the OSGi bundle using a REST console

  1. If not done already, copy GlassFish OSGi HTTP Service bundle from here (latest) and save it in the "modules/autostart" directory.
  2. Download the REST console bundle (latest) in "modules/autostart" directory.
  3. The complete list of bundles is available in Text or XML format by accessing the URL "http://localhost:8080/osgi/restconsole/bundles/.txt" or "http://localhost:8080/osgi/restconsole/bundles" respectively. Here is how the text output looks like:
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 16198    0 16198    0     0  1173k      0 --:--:-- --:--:-- --:--:-- 1173kbundles 
         bundle 
              id 
                   0 
              symbolic-name 
                   org.apache.felix.framework 
    
    . . .
    
              description 
                   Generated using Pax-Construct 
              vendor 
              version 
                   1.0.0.SNAPSHOT 
              location 
                   file:/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/autostart/
    com.knokode.osgi.restconsole.main-1.0-PREVIEW01.jar 
              state 
                   ACTIVE
    
  4. The OSGi bundle should be installed by issuing the following command:
    curl -X PUT file:///Users/arungupta/samples/v3/osgi/helloworld/target/helloworld-1.0-SNAPSHOT.jar http://localhost:8080/osgi/restconsole/bundles
    
    but it's giving a "Segmentation fault". Am following with @fdiotalevi.

    Anyway, the complete usage information of the REST console is described here.

So how do you manage OSGi bundles in GlassFish v3 - asadmin, file system operations, telnet console, web browser, or REST ?

UPDATE: Osgish is a command-line shell for OSGi and implemented in Perl. See the complete installation instructions and it can be used to manage OSGi runtime in GlassFish as well.

A complete archive of all the TOTDs is available here.

Technorati: totd glassfish v3 osgi apache felix bundles maven

Monday Sep 14, 2009

TOTD #103: GlassFish v3 with different OSGi runtimes – Felix, Equinox, and Knoplerfish

GlassFish v3 uses standard OSGi APIs to achieve modularity. It bundles Apache Felix 2.0 as the OSGi runtime and can run on any other OSGi R4.1 compliant runtimes as well. This blog will use previously described instructions and show how to run GlassFish v3 on Eclipse Equinox and Knoplerfish. The complete details about different OSGi runtimes is described here, this TOTD provide detailed steps and overrides the instructions defined here (and here and here).

This blog is using a CI build from last week but you should try the instructions on a promoted build.

GlassFish with Felix - Felix 2.0.0 is bundled with GlassFish v3 and requires no additional configurations.

  1. Start GlassFish as:
    ~/tools/glassfish/v3/2269/glassfishv3/glassfish >./bin/asadmin start-domain --verbose
    

    and see the following messages in the log:
    Sep 11, 2009 4:41:16 PM com.sun.enterprise.glassfish.bootstrap.ASMain main
    INFO: Launching GlassFish on Felix platform
    
    Welcome to Felix
    ================
    
    . . .
    
    Sep 11, 2009 4:41:30 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: GlassFish v3  startup time : Felix(9669ms) startup services(4453ms) total(14122ms)
    
    
  2. Optionally, connect to Felix runtime using Apache Felix Remote Shell (described here) as:

    ~/tools/glassfish/v3/2269/glassfishv3 >telnet localhost 6666
    Trying ::1...
    telnet: connect to address ::1: Connection refused
    Trying fe80::1...
    telnet: connect to address fe80::1: Connection refused
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '\^]'.
    
    Felix Remote Shell Console:
    ============================
    
    ->
    


    and type "help" to see the list of commands available as:

    -> help
    bundlelevel
    cd
    find
    headers
    help
    inspect
    install
    log
    ps
    refresh
    resolve
    shutdown
    start
    startlevel
    stop
    uninstall
    update
    version
    
    Use 'help ' for more information.
    
  3. See the list of OSGi modules installed as:
    -> ps
    START LEVEL 1
       ID   State         Level  Name
    [   0] [Active     ] [    0] System Bundle (2.0.0)
    [   1] [Active     ] [    1] HK2 OSGi Main Bundle (0.3.91)
    [   2] [Installed  ] [    1] EclipseLink Core (2.0.0.v20090821-r4934)
    [   3] [Resolved   ] [    1] Hibernate validator library and Validation API (JSR 303) repackaged as OSGi and HK2 bundle (3.0.0.JBoss-400Beta3)
    [   4] [Installed  ] [    1] Connector (gluecode) for GlassFish Java EE Connector Architecture Runtime (3.0.0.SNAPSHOT)
    [   5] [Active     ] [    1] GlassFish Flashlight Framework (3.0.0.SNAPSHOT)
    
    . . .
    
    [ 201] [Resolved   ] [    1] glassfish-corba-asm (3.0.0.b024)
    [ 202] [Resolved   ] [    1] MIME streaming extension (1.4)
    [ 203] [Installed  ] [    1] Admin Console Connectors Plugin (3.0.0.SNAPSHOT)
    [ 204] [Installed  ] [    1] Apache Felix Shell TUI (1.4.0)
    [ 205] [Resolved   ] [    1] org.glassfish.core.glassfish-extra-jre-packages
    
  4. Use "headers" command to display the bundle header properties for any bundle. "help <command>" shows more information about each command displayed in the output of "help". Finally type "exit" to quit the shell.

GlassFish on Equinox

  1. Download Equinox latest release from http://www.eclipse.org/equinox/ (3.5 as of this writing).
  2. Unzip the contents and copy the Equinox jar file to "osgi/equinox" directory of GlassFish as shown below:
    ~/tools/glassfish/v3/2269/glassfishv3/glassfish >unzip ~/Downloads/equinox-SDK-3.5.zip -d ~/tools/equinox-3.5
    ~/tools/glassfish/v3/2269/glassfishv3/glassfish >cp ~/tools/equinox-3.5/plugins/org.eclipse.osgi_3.5.0.v20090520.jar ./osgi/equinox
    
    
  3. Start GlassFish as:
    ~/tools/glassfish/v3/2269/glassfishv3 >GlassFish_Platform=Equinox ./bin/asadmin start-domain --verbose
    

    and see the following messages in the log:
    Sep 11, 2009 5:11:13 PM com.sun.enterprise.glassfish.bootstrap.ASMain main
    INFO: Launching GlassFish on Equinox platform
    Listening on port 6667 ...
    
    . . .
    
    Sep 11, 2009 5:11:19 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: GlassFish v3  startup time : Equinox(3649ms) startup services(1843ms) total(5492ms)
    


    Note, Equinox platform started on port 6667 for remote management.
  4. Optionally, connect to Equinox runtime as:

    ~/tools/glassfish/v3/2269/glassfishv3/glassfish >telnet localhost 6667
    Trying ::1...
    Connected to localhost.
    Escape character is '\^]'.
    
    osgi>
    
    

    Make sure to use the port number specified during the startup. Type "help" to see the list of commands available as:
    osgi> help
    ---Controlling the OSGi framework---
            launch - start the OSGi Framework
            shutdown - shutdown the OSGi Framework
            close - shutdown and exit
            exit - exit immediately (System.exit)
            init - uninstall all bundles
            setprop = - set the OSGi property
    ---Controlling Bundles---
    
    . . . 
    
    ---Controlling the Console---
            more - More prompt for console output
            disconnect - Disconnects from telnet session
    
  5. See the list of OSGi modules installed as:
    osgi> ss
    
    Framework is launched.
    
    id      State       Bundle
    0       ACTIVE      org.eclipse.osgi_3.5.0.v20090520
                        Fragments=62, 128, 205
    1       ACTIVE      com.sun.enterprise.osgi-main_0.3.91
    2       RESOLVED    org.eclipse.persistence.core_2.0.0.v20090821-r4934
                        Fragments=136
    
    . . . 
    
    203     RESOLVED    org.glassfish.admingui.console-jca-plugin_3.0.0.SNAPSHOT
    204     RESOLVED    org.apache.felix.shell.tui_1.4.0
    205     RESOLVED    org.glassfish.core.glassfish-extra-jre-packages_0.0.0
                        Master=0
    

    Typing "help" shows a comprehensive list of commands. Finally type "disconnect" to terminate the shell. Do not type "exit" as it terminates the Equinox shell and killing the GlassFish process as well.

GlassFish with Knoplerfish - As mentioned here, GlassFish v3 requires at least R4.1 APIs. All Knopflerfish releases prior to 3.0.0 are R4 compliant and so will not work with the GlassFish v3 latest builds. Knopflerfish 3.0.0 beta1 is the first build that is R4.2 compliant but it does not start on Mac OS X 10.5.8 as described in issue #2858798. So until then, you you can follow the instructions documented at  GlassFish v3 on OSGi KnopflerFish and Using KnopflerFish Desktop in GlassFish v3 to get them running on GlassFish v3 TP2 or Prelude.

Some additional details missing form the entries above

  1. Download Knoplerfish 2.3.3 and install.
  2. In "knopflerfish_osgi_2.3.3/knopflerfish.org/osgi", copy "props.xargs" to "gf.xargs" and add the lines mentioned here. Make sure to copy the Knopflerfish related files to the modules directory and change the location accordingly.
  3. Create "gfpackages.txt" by copying "felix/conf/config.properties" from the GlassFish directory. List each package specified in the "gf-packages" property on a single line. There should be no other character such as ";" or "," or "/" on a line, only the package name.
  4. Start GlassFish as:
    ~/tools/glassfish/v3/2269/glassfishv3/glassfish >KNOPFLERFISH_HOME=/Users/arungupta/tools/knopflerfish_osgi_2.3.3/knopflerfish.org/osgi GlassFish_Platform=Knopflerfish ./bin/asadmin start-domain --verbose
    
    
    and see the following messages in the log:
    Knopflerfish OSGi framework, version 4.1.10
    Copyright 2003-2009 Knopflerfish. All Rights Reserved.
    
    See http://www.knopflerfish.org for more information.
    Loading xargs url file:/Users/arungupta/tools/knopflerfish_osgi_2.3.3/knopflerfish.org/osgi/gf.xargs
    Removed existing fwdir /Users/arungupta/tools/knopflerfish_osgi_2.3.3/knopflerfish.org/osgi/fwdir
    Installed: file:/Users/arungupta/tools/glassfish/v3/glassfishv3-tp2/glassfish/modules/tiger-types-osgi-0.2.1.jar (id#1)
    Installed: file:/Users/arungupta/tools/glassfish/v3/glassfishv3-tp2/glassfish/modules/auto-depends-0.2.1.jar (id#2)
    Installed: file:/Users/arungupta/tools/glassfish/v3/glassfishv3-tp2/glassfish/modules/config-0.2.1.jar (id#3)
    
    . . .
    
    Started: file:/Users/arungupta/tools/glassfish/v3/glassfishv3-tp2/glassfish/modules/cm_all-2.0.1.jar (id#7)
    Started: file:/Users/arungupta/tools/glassfish/v3/glassfishv3-tp2/glassfish/modules/console_all-2.0.1.jar (id#8)
    Started: file:/Users/arungupta/tools/glassfish/v3/glassfishv3-tp2/glassfish/modules/desktop_all-2.3.11.jar (id#11)
    


    and finally see the Knopflerfish console as:



The instructions will be updated after a more stable release of Knopflerfish is available.

A complete archive of all the tips is available here.

Technorati: totd glassfish v3 osgi apache felix eclipse equinox knopflerfish

Tuesday Jun 16, 2009

TOTD #84: Using Apache + mod_proxy_balancer to load balance Ruby-on-Rails running on GlassFish


TOTD #81 explained how to install/configure nginx for load-balancing/front-ending a cluster of Rails application running on GlassFish Gem. Another popular approach in the Rails community is to use Apache HTTPDmod_proxy_balancer. A user asked the exact details of this setup on the GlassFish Gem Forum. This Tip Of The Day (TOTD) will clearly explain the steps.
  1. Create a simple Rails scaffold and run this application using GlassFish Gem on 3 separate ports as explained in TOTD #81.
  2. Setup and configure HTTPD and mod_proxy_balancer
    1. Setup and install Apache HTTPD as explained here. I believe mod_proxy_balancer and other related modules comes pre-bundled with HTTPD, at least that's what I observed with Mac OS X 10.5.7. Make sure that the "mod_proxy_balancer" module is enabled by verifying the following line is uncommented in "/etc/apache2/httpd.conf":

      LoadModule proxy_balancer_module libexec/apache2/mod_proxy_balancer.so

      Please note another similar file exists in "/etc/httpd/httpd.conf" but ignore that one.
    2. Setup a mod_proxy_balancer cluster by adding the following fragment in "httpd.conf" as:

      <Proxy balancer://glassfishgem>
      BalancerMember http://localhost:3000
      BalancerMember http://localhost:3001
      BalancerMember http://localhost:3002
      </Proxy>

      The port numbers must exactly match with those used in the first step.
    3. Specify the ProxyPass directives to map the cluster to a local path as:

      ProxyPass / balancer://glassfishgem/
      CustomLog /var/log/glassfishgem.log/apache_access_log combined

      The "/" at the end of "balancer://glassfishgem" is very important to ensure that all the files are resolved correctly.
    4. Optionally, the following directive can be added to view the access log:

      CustomLog /var/log/glassfishgem.log/apache_access_log combined

      Make sure to create the directory specified in "CustomLog" directive.
  3. Now the application is accessible at "http://localhost/runlogs". If a new GlassFish instance is started then update the <Proxy> directive and restart your HTTPD as "sudo httpd -k restart". Dynamic update of BalancerMembers can be configured as explained here.
TOTD #81 started the Rails application in root context. You can alternatively start the application in a non-root context as:

~/tools/jruby/rails/runner >../../bin/jruby -S glassfish -e production -c myapp
Starting GlassFish server at: 10.0.177.178:3000 in production environment...
Writing log messages to: /Users/arungupta/tools/jruby-1.3.0/rails/runner/log/production.log.
Press Ctrl+C to stop.
. . .
~/tools/jruby/rails/runner >../../bin/jruby -S glassfish -e production -c myapp -p 3001
Starting GlassFish server at: 10.0.177.178:3001 in production environment...
Writing log messages to: /Users/arungupta/tools/jruby-1.3.0/rails/runner/log/production.log.
Press Ctrl+C to stop.
. . .
~/tools/jruby/rails/runner >../../bin/jruby -S glassfish -e production -c myapp -p 3002
Starting GlassFish server at: 10.0.177.178:3002 in production environment...
Writing log messages to: /Users/arungupta/tools/jruby-1.3.0/rails/runner/log/production.log.
Press Ctrl+C to stop.

and then the ProxyPass directive will change to:

ProxyPass /myapp/ balancer://glassfishgem/myapp/

The changes are highlighted in bold. And the application is now accessible at "http://localhost/myapp/runlogs".

After discussing on Apache HTTP Server forum, the BalancerMember host/port can be printd in the log file using a custom log format. So add the following log format to "/etc/apache2/httpd.conf":

LogFormat "%h %l %u %t \\"%r\\" %>s %b \\"%{Referer}i\\" \\"%{User-agent}i\\" \\"%{BALANCER_WORKER_NAME}e\\"" custom

And change the format from the default "combined" to the newly defined "custom" format as:

CustomLog /var/log/glassfishgem.com/apache_access_log custom

Three subsequent invocations of "http://localhost/runlogs" then prints the following log entries:

::1 - - [17/Jun/2009:10:53:53 -0700] "GET /runlogs HTTP/1.1" 304 - "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.11) Gecko/2009060214 Firefox/3.0.11" "http://localhost:3002"
::1 - - [17/Jun/2009:10:54:04 -0700] "GET /runlogs HTTP/1.1" 200 621 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.11) Gecko/2009060214 Firefox/3.0.11" "http://localhost:3000"
::1 - - [17/Jun/2009:10:54:05 -0700] "GET /runlogs HTTP/1.1" 304 - "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.11) Gecko/2009060214 Firefox/3.0.11" "http://localhost:3001"

As evident from the last fragment of each log line, the load is distributed amongst three GlassFish Gem instances. More details on load balancer algorithm are available here.

Feel free to drop a comment on this blog if you are using GlassFish in production for your Rails applications. Several stories are already available at rubyonrails+glassfish+stories.

Technorati: glassfish rubyonrails apache httpd mod_proxy_balancer loadbalancing clustering

Thursday Jan 29, 2009

TOTD #67: How to front-end a GlassFish Cluster with Apache + mod_jk on Mac OSX Leopard ?

GlassFish provides support for High Availability by creating a cluster of server instances and session state replication. This enhances the scalability and availability of your application and is a critical piece of decision making critieria when selecting an Application Server. Clustering in GlassFish Version 2 provides comprehensive introduction to clustering, high availability and load balancing in GlassFish.

GlassFish provides out-of-the-box support for load-balancing HTTP(S), JMS, and RMI/IIOP traffic and front-ended by Sun Java System Web Server, Apache Web Server, and Microsoft IIS (more details here) using the Load Balancer plug-in. This plug-in however is not available for Mac OS X and a popular technique used on that platform for front-ending is to use Apache httpd + mod_jk. This is exactly what this TOTD (Tip Of The Day) is going to describe.

This TOTD is going to explain how to front-end a 3-instance GlassFish cluster with Apache httpd and mod_jk on Mac OS X.

This blog is using information from the following blogs:
And thanks to Vivek and Shreedhar for helping me understand the guts of GlassFish High Availability.

Without further ado, lets get started. The steps are slightly involving so strap your seatbelts!
  1. First, lets create a 3-instance cluster following the screencast at GlassFish Clustering in under 10 minutes. Use the cluster name as "cluster1" and instance names as "instance1", "instance2", "instance3". The admin console will look like:



    Deploy "clusterjsp" and make sure it works using port hopping as explained in the screencast. Click on each instance to identify their associated HTTP port.
  2. Define "jvmRoute" and "enableJK" properties on the newly created cluster as:

    ~/samples/v2/clustering/glassfish/bin >./asadmin create-jvm-options --target cluster1 "-DjvmRoute=\\${AJP_INSTANCE_NAME}"
    Command create-jvm-options executed successfully.
    ~/samples/v2/clustering/glassfish/bin >./asadmin create-jvm-options --target cluster1 "-Dcom.sun.enterprise.web.connector.enableJK=\\${AJP_PORT}"
    Command create-jvm-options executed successfully.

    These properties are required to enable "stickiness" for "mod_jk". More details about how these properties are used internally is explained here.
  3. Configure the above system properties for each instance in the cluster as shown:

    ~/samples/v2/clustering/glassfish/bin >./asadmin create-system-properties --target instance1 AJP_INSTANCE_NAME=instance1
    Command create-system-properties executed successfully.
    ~/samples/v2/clustering/glassfish/bin >./asadmin create-system-properties --target instance1 AJP_PORT=9090
    Command create-system-properties executed successfully.
    ~/samples/v2/clustering/glassfish/bin >./asadmin create-system-properties --target instance2 AJP_INSTANCE_NAME=instance2
    Command create-system-properties executed successfully.
    ~/samples/v2/clustering/glassfish/bin >./asadmin create-system-properties --target instance2 AJP_PORT=9091
    Command create-system-properties executed successfully.
    ~/samples/v2/clustering/glassfish/bin >./asadmin create-system-properties --target instance3 AJP_INSTANCE_NAME=instance3
    Command create-system-properties executed successfully.
    ~/samples/v2/clustering/glassfish/bin >./asadmin create-system-properties --target instance3 AJP_PORT=9092
    Command create-system-properties executed successfully.

    Note the value of "AJP_PORT" property for each instance, this will be used for configuring "mod_jk" later. You may have to restart the cluster in order for these properties to be synchronized for each instance. This can be easily done using the admin console as explained in the screencast above.
  4. Install httpd: Mac OS X Leopard 10.5.6 comes bundled with Apache httpd 2.2, so that's cool! Otherwise it can be downloaded from httpd.apache.org. However in the pre-installed version there are some intricacies with directory names that are explained below.
  5. Lets install and configure "mod_jk" in "httpd".
    1. The mod_jk binaries for Mac OSX are supposedly available at www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/macosx/. But installing the available module in httpd gives the following error:

      httpd: Syntax error on line 116 of /private/etc/apache2/httpd.conf: Cannot load /usr/libexec/apache2/mod_jk-1.2.25-httpd-2.2.4.so into server: dlopen(/usr/libexec/apache2/mod_jk-1.2.25-httpd-2.2.4.so, 10): no suitable image found.  Did find:\\n\\t/usr/libexec/apache2/mod_jk-1.2.25-httpd-2.2.4.so: mach-o, but wrong architecture
    2. The alternative is to build "mod_jk". Fortunately it turned out to be a straight forward process because of this blog.
      1. Download latest Connectors source code (version 1.2.27). The file "BUILD.txt" (included in the source bundle) provide clear instructions to build and described below as well.
      2. Configure the build environment as shown:

        ~/workspaces/tomcat-connectors-1.2.27-src/native >./configure --with-apxs=/usr/sbin/apxs

        It shows the output as:

        . . .
        checking for target platform... unix
        no apache given
        no netscape given
        configure: creating ./config.status
        config.status: creating Makefile
        config.status: creating apache-1.3/Makefile
        config.status: creating apache-1.3/Makefile.apxs
        config.status: creating apache-2.0/Makefile
        config.status: creating apache-2.0/Makefile.apxs
        config.status: creating common/Makefile
        config.status: creating common/list.mk
        config.status: creating common/jk_types.h
        config.status: creating jni/Makefile
        config.status: creating common/portable.h
        config.status: executing depfiles commands
      3. Edit Edit "native/apache-2.0/Makefile.apxs" and add "-arch x86_64" as described here. Please note that this string needs to be specified twice.
      4. Invoke "make" and "mod_jk.so" is generated in "native/apache-2.0" directory.
    3. Copy the generated "mod_jk.so" as:

      ~/workspaces/tomcat-connectors-1.2.27-src/native/apache-2.0 >sudo cp mod_jk.so /usr/libexec/apache2/
    4. Load the "mod_jk" module in httpd by editing "/etc/apache2/httpd.conf". Please note another similar file exists in "/etc/httpd/httpd.conf" but ignore that one. Add the following as the last "LoadModule" line:

      LoadModule jk_module     libexec/apache2/mod_jk-1.2.25-httpd-2.2.4.so
    5. Configure "mod_jk" by adding the following lines immediately below the previously "LoadModule" line:

      JkWorkersFile /etc/apache2/worker.properties
      # Where to put jk logs
      JkLogFile /var/log/httpd/mod_jk.log
      # Set the jk log level [debug/error/info]
      JkLogLevel debug
      # Select the log format
      JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
      # JkRequestLogFormat set the request format
      JkRequestLogFormat "%w %V %T"
      # Send all jsp requests to GlassFish
      JkMount /\*.jsp loadbalancer

      The key lines in this configuration are the first and the last one. The first line informs "mod_jk" about the location of "worker.properties" file (explained later). The last line instructs to redirect only JSP requests. This will allow the static content such as images, text files, and media to be served from "httpd" itself.

      Also create the log directory specified in the configuration as:

      sudo mkdir /var/log/httpd
    6. Create a new file "/etc/apache2/worker.properties". Again, this is not in "/etc/httpd" directory. Use the following contents:

      # Define 1 real worker using ajp13
      worker.list=loadbalancer
      # Set properties for instance1
      worker.instance1.type=ajp13
      worker.instance1.host=localhost
      worker.instance1.port=9090
      worker.instance1.lbfactor=50
      worker.instance1.cachesize=10
      worker.instance1.cache_timeout=600
      worker.instance1.socket_keepalive=1
      worker.instance1.socket_timeout=300
      # Set properties for instance2
      worker.instance2.type=ajp13
      worker.instance2.host=localhost
      worker.instance2.port=9091
      worker.instance2.lbfactor=50
      worker.instance2.cachesize=10
      worker.instance2.cache_timeout=600
      worker.instance2.socket_keepalive=1
      worker.instance2.socket_timeout=300
      # Set properties for instance3
      worker.instance3.type=ajp13
      worker.instance3.host=localhost
      worker.instance3.port=9092
      worker.instance3.lbfactor=50
      worker.instance3.cachesize=10
      worker.instance3.cache_timeout=600
      worker.instance3.socket_keepalive=1
      worker.instance3.socket_timeout=300

      worker.loadbalancer.type=lb
      worker.loadbalancer.balance_workers=instance1,instance2,instance3

      Read more about worker.properties format. Essentially this file is used to load-balance a 3-instance cluster and specify configuration values for each instance. Note that the value of "worker.instanceX.port" for instance X is exactly same as specified during instance configuration earlier.
  6. Copy "tomcat-ajp.jar" from the "lib" directory of the latest Tomcat 5.5.xcommons-logging.jar (version 1.1.1), and commons-modeler.jar (version 2.0.1) to GLASSFISH_HOME/lib. This is done as:

    ~/samples/v2/clustering/glassfish/lib >cp ~/tools/apache-tomcat-5.5.27/server/lib/tomcat-ajp.jar .
    ~/samples/v2/clustering/glassfish/lib >cp ~/Downloads/commons-logging-1.1.1/commons-logging-1.1.1.jar .
    ~/samples/v2/clustering/glassfish/lib >cp ~/tools/commons-modeler-2.0.1/commons-modeler-2.0.1.jar .

    You may have to restart cluster in order for these JARs to be loaded by each instance.
  7. An "httpd" instance is already running on port# 80 in my particular instance of Mac OS X. Instead of mangling with that, I decided to change the listening port for the new instance that will be spawn for out front-end. This can be easily done by editing "/etc/apache2/httpd.conf" and looking for lines similar to:

    #Listen 12.34.56.78:80
    Listen 80

    And change "Listen 80" to "Listen 81".
That completes the configuration, phew!

Lets start "httpd" as:

sudo httpd

The "httpd" logs are available in "/private/var/log/apache2". The following message indicates a successful start of the web server:

. . .
[Thu Jan 29 11:14:16 2009] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Thu Jan 29 11:14:16 2009] [warn] No JkShmFile defined in httpd.conf. Using default /usr/logs/jk-run
time-status
[Thu Jan 29 11:14:16 2009] [warn] No JkShmFile defined in httpd.conf. Using default /usr/logs/jk-run
time-status
[Thu Jan 29 11:14:16 2009] [notice] Digest: generating secret for digest authentication ...
[Thu Jan 29 11:14:16 2009] [notice] Digest: done
[Thu Jan 29 11:14:16 2009] [warn] pid file /private/var/run/httpd.pid overwritten -- Unclean shutdow
n of previous Apache run?
[Thu Jan 29 11:14:16 2009] [notice] Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.7l DAV/2 mod_jk/1.
2.27 configured -- resuming normal operations

OK, now show time!

If everything has been configured properly as described above then "http://localhost:81/clusterjsp/HaJsp.jsp" looks like:



Enter session attribute as "aaa" and value of the attribute as "111". After you click on "ADD SESSION DATA" button, the updated page looks like:



The highlighted part shows that the request is served from "instance1" and recently added session data. Lets stop "instance1" and see if the promise of high availability is fulfilled :)

Click on "Instances" tab, select "instance1" and click "Stop". The admin console looks like:



Notice "instance1" is shown as stopped. Clicking on "Reload Page" on "http://localhost:81/clusterjsp/HaJsp.jsp" shows:




Aha!

Even though "instance1" is not runing the session data is still available. And that is possible because of the seamless session failover from primary ("instance1") to the replica partner ("instance2"). The highlighted part indicates that the request is now indeed served by "instance2".

Here are some other useful links to consider:
Please leave suggestions on other TOTD (Tip Of The Day) that you'd like to see. A complete archive of all tips is available here.

Technorati: totd glassfish highavailability clustering loadbalancer mod_jk apache httpd mac leopard

Thursday Dec 11, 2008

TOTD # 59: Alternative JSF implementations on GlassFish - MyFaces and Tomahawk


GlassFish comes bundled with an industry grade implementation of Java Server Faces codenamed Mojarra. It is the most complete, up-to-date and well-tested JSF implementation and used pretty extensively. GlassFish v2 and v3 Prelude ships with JSF 1.2.x-compliant implementation that is defined as part of Java EE 5. GlassFish v3 trunk contains JSF 2.0-compliant implementation that is getting defined as part of Java EE 6. The latest version of Mojarra can be installed from the Update Center.

But GlassFish does not restrict you to Mojarra and instead it embraces other JSF implementations easily. This blog uses MyFaces, an alternate JavaServer Faces implementation from Apache, to demonstrate that. If you are interested in a brief summary of what it takes to use these alternate implementations on GlassFish then scroll to the end of this entry.

MyFaces also provides several component libraries such as Tomahawk, Trinidad, and Tobago for building web applications. This blog shows how MyFaces Tomahawk samples can be deployed on GlassFish v2 and v3. The basic integration hooks between GlassFish and other JSF implementations remain the same and are independent of the component library.

Lets get started and understand all the glory!

Download MyFaces Tomahawk samples from here. The download consists of 4 WAR files and they are unzipeed in the current directory. So create a new directory and then unzip the bundle if you want to organize it slightly better. The getting Started instructions require you to copy "simple.war" where as the actual WAR filename is "myfaces-example-simple-1.1.8.war". Anyway, we are going to deploy this sample on GlassFish v2, v3 Prelude, and v3 trunk and what needs to be done to use the MyFaces implementation bundled within the WAR.
  1. Deploy using Mojarra on GlassFish v2
    1. Deploying "myfaces-example-simple-1.1.8.war" on GlassFish v2 using "asadmin deploy myfaces-example-simple-1.1.8.war" and it shows the following message:

      [#|2008-12-05T11:00:43.710-0800|INFO|sun-appserver9.1|javax.enterprise.system.tools.deployment|_ThreadID=22;_ThreadName=Thread-43;|
      deployed with moduleid = myfaces-example-simple-1.1.8|#]

      [#|2008-12-05T11:00:44.296-0800|INFO|sun-appserver9.1|javax.enterprise.resource.webcontainer.jsf.config|_ThreadID=21;
      _ThreadName=httpWorkerThread-4848-1;/myfaces-example-simple-1.1.8;|Initializing Sun's JavaServer Faces implementation (1.2_04-b20-p03) for context '/myfaces-example-simple-1.1.8'|#]

      The bold text indicates that Mojarra 1.2 bundled with GlassFish v2 is used as the JSF runtime, the exact version is shown in the bold text. The deployed web application is accessible at "http://localhost:8080/myfaces-example-simple-1.1.8/home.jsf" and looks like:



      The following error message is shown as you click through the samples:

      [#|2008-12-03T16:27:43.935-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=24;_ThreadName=httpSSLWorkerThread-8080-1;|
      2008-12-03 16:27:43,935 [httpSSLWorkerThread-8080-1] INFO  org.apache.myfaces.shared_tomahawk.config.MyfacesConfig - Starting up Tomahawk on the MyFaces-JSF-Implementation
      |#]

      [#|2008-12-03T16:27:43.935-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=24;_ThreadName=httpSSLWorkerThread-8080-1;|
      2008-12-03 16:27:43,935 [httpSSLWorkerThread-8080-1] ERROR org.apache.myfaces.shared_tomahawk.config.MyfacesConfig - Both MyFaces and the RI are on your classpath. Please make sure to use only one of the two JSF-implementations.

      This error message is generated by MyFaces and may be ignored. I think the message should be a WARNING instead of an ERROR.
  2. Deploy using MyFaces on GlassFish v2
    1. Create a directory "simple" and unjar "myfaces-example-simple-1.1.8.war" in there.
    2. Add "WEB-INF/sun-web.xml" and specify the contents as:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 8.1 Servlet 2.4//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_4-1.dtd">
      <sun-web-app>
      <class-loader delegate="false"/>
      <property name="useMyFaces" value="true"/>
      </sun-web-app>

      The key point to notice is the property name "useMyFaces". The name is slightly mis-leading because the switch essentially tells GlassFish runtime to use the bundled Java Server Faces runtime and is not restricted to MyFaces only. This is fixed in GlassFish v3 and is discussed later.
    3. Create a WAR file in "simple" directory as "jar cvf myfaces-simple-v2.war \*".
    4. Deploy the generated WAR on GlassFish v2 as "asadmin deploy myfaces-simple-v2.war". It shows the following message:

      . . .

      [#|2008-12-05T11:11:25.615-0800|INFO|sun-appserver9.1|javax.enterprise.system.tools.deployment|_ThreadID=24;_ThreadName=Thread-257;|
      deployed with moduleid = myfaces-simple-v2|#]

      [#|2008-12-05T11:11:26.266-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|
      2008-12-05 11:11:26,266 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.config.FacesConfigurator - Reading standard config org/apache/myfaces/resource/standard-faces-config.xml
      |#]

      [#|2008-12-05T11:11:26.290-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|
      2008-12-05 11:11:26,290 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.config.FacesConfigurator - Reading config jar:file:/Users/arungupta/tools/glassfish/v2/ur2/glassfish/domains/domain1/applications/j2ee-modules/myfaces-simple-v2/WEB-INF/lib/tomahawk-1.1.8.jar!/
      META-INF/faces-config.xml
      |#]

      [#|2008-12-05T11:11:26.309-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:26,308 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.config.FacesConfigurator - Reading config /WEB-INF/examples-config.xml
      |#]

      [#|2008-12-05T11:11:26.337-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:26,337 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.config.FacesConfigurator - Reading config /WEB-INF/testSuite-config.xml
      |#]

      [#|2008-12-05T11:11:26.349-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:26,349 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.config.FacesConfigurator - Starting up MyFaces-package : myfaces-api in version : 1.1.6 from path : file:/Users/arungupta/tools/glassfish/v2/ur2/glassfish/domains/domain1/applications/j2ee-modules/myfaces-simple-v2/WEB-INF/lib/myfaces-api-1.1.6.jar
      |#]

      [#|2008-12-05T11:11:26.350-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:26,350 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.config.FacesConfigurator - Starting up MyFaces-package : myfaces-impl in version : 1.1.6 from path : file:/Users/arungupta/tools/glassfish/v2/ur2/glassfish/domains/domain1/applications/j2ee-modules/myfaces-simple-v2/WEB-INF/lib/myfaces-impl-1.1.6.jar
      |#]

      [#|2008-12-05T11:11:26.350-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:26,350 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.config.FacesConfigurator - MyFaces-package : tomahawk-sandbox not found.
      |#]

      [#|2008-12-05T11:11:26.350-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:26,350 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.config.FacesConfigurator - Starting up MyFaces-package : tomahawk in version : 1.1.8 from path : file:/Users/arungupta/tools/glassfish/v2/ur2/glassfish/domains/domain1/applications/j2ee-modules/myfaces-simple-v2/WEB-INF/lib/tomahawk-1.1.8.jar
      |#]

      . . .

      [#|2008-12-05T11:11:27.069-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:27,069 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.shared_impl.config.MyfacesConfig - Starting up Tomahawk on the RI-JSF-Implementation.
      |#]

      [#|2008-12-05T11:11:27.069-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:27,069 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.shared_impl.config.MyfacesConfig - Starting up Tomahawk on the MyFaces-JSF-Implementation
      |#]

      [#|2008-12-05T11:11:27.070-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:27,070 [httpWorkerThread-4848-1] ERROR org.apache.myfaces.shared_impl.config.MyfacesConfig - Both MyFaces and the RI are on your classpath. Please make sure to use only one of the two JSF-implementations.
      |#]

      [#|2008-12-05T11:11:27.070-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:27,070 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.webapp.StartupServletContextListener - ServletContext '/Users/arungupta/tools/glassfish/v2/ur2/glassfish/domains/domain1/applications/j2ee-modules/myfaces-simple-v2/' initialized.
      |#]

      The first thing to note is that the message "Initializing Sun's JavaServer Faces implementation (1.2_04-b20-p03)" is not shown. That indicates Mojarra is not used as the JSF runtime. Then you can see how MyFaces 1.1.6 API and Implementation are loaded, Tomahaw 1.1.8 is loaded and finally started using MyFaces JSF implementation.

      The main page from this deployed application at "http://localhost:8080/myfaces-simple-v2" is very similar as shown below:

  3. Deploy using Mojarra on GlassFish v3 Prelude - This is very similar experience as with GlassFish v2.
    1. Deploying "myfaces-example-simple-1.1.8.war" on GlassFish v3 shows the following message:

      Dec 5, 2008 11:27:17 AM com.sun.faces.config.ConfigureListener contextInitialized
      INFO: Initializing Mojarra (1.2_10-b01-FCS) for context '/myfaces-example-simple-1.1.8'
      Dec 5, 2008 11:27:18 AM com.sun.enterprise.web.WebApplication start
      INFO: Loading application myfaces-example-simple-1.1.8 at /myfaces-example-simple-1.1.8
      Dec 5, 2008 11:27:18 AM org.glassfish.deployment.admin.DeployCommand execute
      INFO: Deployment of myfaces-example-simple-1.1.8 done is 3470 ms

      The bold text clearly indicates that Mojarra 1.2 bundled, exact version shown in the bold text, with GlassFish v3 is used as the JSF runtime. The deployed web application is accessible at "http://localhost:8080/myfaces-example-simple-1.1.8/home.jsf". Viewing the sample in browser shows:

      Dec 5, 2008 11:54:54 AM  
      INFO: 2008-12-05 11:54:54,083 [httpWorkerThread-8080-0] INFO  org.apache.myfaces.shared_tomahawk.config.MyfacesConfig - Starting up Tomahawk on the RI-JSF-Implementation.

      Dec 5, 2008 11:54:54 AM  
      INFO: 2008-12-05 11:54:54,083 [httpWorkerThread-8080-0] INFO  org.apache.myfaces.shared_tomahawk.config.MyfacesConfig - Starting up Tomahawk on the MyFaces-JSF-Implementation

      Dec 5, 2008 11:54:54 AM  
      INFO: 2008-12-05 11:54:54,083 [httpWorkerThread-8080-0] ERROR org.apache.myfaces.shared_tomahawk.config.MyfacesConfig - Both MyFaces and the RI are on your classpath. Please make sure to use only one of the two JSF-implementations.

      and may be ignored. None of the messages that indicate classloading, as shown for GlassFish v2 above, are displayed. I suspect these are standard messages displayed by MyFaces without taking into consideration that an alternate JSF runtime can be used to run these samples.
  4. Deploy using MyFaces on GlassFish v3 Prelude - There is no way to override JSF implementation with GlassFish v3 Prelude. So even though deploying "myfaces-simple-v2.war" will work fine but viewing the web page at "http://localhost:8080/myfaces-simple-v2/" will show the following exception:



    Basically, a web application cannot use MyFaces implementation on GlassFish v3 Prelude. However Mojarra provides a fully-compliant and feature-rich JSF implementation and is already baked in GlassFish v3 Prelude.
  5. Deploy using Mojarra on GlassFish v3 Trunk
    1. Pick your GlassFish v3 Build Flavor, this blog uses the trunk.
    2. Deploy the original sample as "asadmin deploy myfaces-example-simple-1.1.8.war" and the following log messages are shown:

      Dec 5, 2008 12:35:17 PM com.sun.faces.config.ConfigureListener contextInitialized
      INFO: Initializing Mojarra 2.0.0 (SNAPSHOT b05) for context '/myfaces-example-simple-1.1.8'
      Dec 5, 2008 12:35:18 PM org.apache.catalina.core.ApplicationContext log
      SEVERE: WebModule[/myfaces-example-simple-1.1.8]PWC1275: Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener
      java.lang.NoClassDefFoundError: com/sun/facelets/tag/jsf/ComponentHandler
              at java.lang.ClassLoader.defineClass1(Native Method)
              at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
              at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
              at org.glassfish.web.loader.WebappClassLoader.findClass(WebappClassLoader.java:974)

      This happens because the application has dependencies on internal classes of Facelets 1.1.x. That makes the application non-compatible with Mojarra 2.x which comes bundled with Facelets 2.0.
    3. Lets instruct the application to disable the Facelets 2.0 baked in Mojarra by adding the following application wide context parameter in "web.xml":

      <context-param>
             <param-name>javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER</param-name>
             <param-value>true</param-value>
       </context-param>

      Now the Facelets 1.1.x classes bundled with the application are used. With this change, the application gets deployed correctly and shows the following log message:

      Dec 5, 2008 2:50:21 PM com.sun.faces.config.ConfigureListener contextInitialized
      INFO: Initializing Mojarra 2.0.0 (SNAPSHOT b05) for context '/myfaces-simple-v3'
      Dec 5, 2008 2:50:21 PM com.sun.enterprise.web.WebApplication start
      INFO: Loading application myfaces-simple-v3 at /myfaces-simple-v3
      Dec 5, 2008 2:50:21 PM org.glassfish.deployment.admin.DeployCommand execute
      INFO: Deployment of myfaces-simple-v3 done is 1513 ms

      The important thing to note here is that Mojarra 2.0.0 implementation (as indicated by the bold text) is used as JSF runtime. This is the newest and the greatest runtime that implements JSF 2.0 specification and baked in GlassFish v3 trunk. The main page from this deployed application at "http://localhost:8080/myfaces-simple-v3/" looks like:

  6. Deploy using MyFaces on GlassFish v3 Trunk
    1. Download the latest GlassFish v3 Nightly.
    2. Lets deploy the WAR file previously created as "asadmin deploy myfaces-simple-v2.war". The main page of the application is accessible at "http://localhost:8080/myfaces-simple-v2".
    3. The "useMyFaces" property, as specified in "sun-web.xml", is expected to work for any bundled JSF implementation. The recommended way to deploy such a web application in GlassFish v3 is to use the property "useBundledJsf". The updated "sun-web.xml" is shown below:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 8.1 Servlet 2.4//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_4-1.dtd">
      <sun-web-app>
      <class-loader delegate="false"/>
      <property name="useBundledJsf" value="true"/>
      </sun-web-app>
    4. Create a WAR file in "simple" directory as "jar cvf myfaces-simple-v3-usebundled.war \*".
    5. Deploy the generated WAR on GlassFish v3 as "asadmin deploy myfaces-simple-v3-usebundled.war". It shows the following message:

      . . .

      Dec 5, 2008 3:19:54 PM  
      INFO: 2008-12-05 15:19:54,786 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.config.FacesConfigurator - Reading config jar:file:/Users/arungupta/tools/glassfish/v3/snapshot/glassfish/domains/domain1/applications/myfaces-simple-v3-usebundled/WEB-INF/lib/tomahawk-1.1.8.jar!/
      META-INF/faces-config.xml

      Dec 5, 2008 3:19:54 PM  
      INFO: 2008-12-05 15:19:54,806 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.config.FacesConfigurator - Reading config /WEB-INF/examples-config.xml

      Dec 5, 2008 3:19:54 PM  
      INFO: 2008-12-05 15:19:54,828 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.config.FacesConfigurator - Reading config /WEB-INF/testSuite-config.xml

      Dec 5, 2008 3:19:54 PM  
      INFO: 2008-12-05 15:19:54,841 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.config.FacesConfigurator - Starting up MyFaces-package : myfaces-api in version : 1.1.6 from path : file:/Users/arungupta/tools/glassfish/v3/snapshot/glassfish/domains/domain1/applications/myfaces-simple-v3-usebundled/WEB-INF/lib/myfaces-api-1.1.6.jar

      Dec 5, 2008 3:19:54 PM  
      INFO: 2008-12-05 15:19:54,841 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.config.FacesConfigurator - Starting up MyFaces-package : myfaces-impl in version : 1.1.6 from path : file:/Users/arungupta/tools/glassfish/v3/snapshot/glassfish/domains/domain1/applications/myfaces-simple-v3-usebundled/WEB-INF/lib/myfaces-impl-1.1.6.jar

      Dec 5, 2008 3:19:54 PM  
      INFO: 2008-12-05 15:19:54,841 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.config.FacesConfigurator - MyFaces-package : tomahawk-sandbox not found.

      Dec 5, 2008 3:19:54 PM  
      INFO: 2008-12-05 15:19:54,841 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.config.FacesConfigurator - Starting up MyFaces-package : tomahawk in version : 1.1.8 from path : file:/Users/arungupta/tools/glassfish/v3/snapshot/glassfish/domains/domain1/applications/myfaces-simple-v3-usebundled/WEB-INF/lib/tomahawk-1.1.8.jar

      . . .

      Dec 5, 2008 3:19:55 PM  
      INFO: 2008-12-05 15:19:55,763 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.shared_impl.config.MyfacesConfig - Starting up Tomahawk on the RI-JSF-Implementation.

      Dec 5, 2008 3:19:55 PM  
      INFO: 2008-12-05 15:19:55,764 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.shared_impl.config.MyfacesConfig - Starting up Tomahawk on the MyFaces-JSF-Implementation

      Dec 5, 2008 3:19:55 PM  
      INFO: 2008-12-05 15:19:55,764 [httpWorkerThread-4848-1] ERROR org.apache.myfaces.shared_impl.config.MyfacesConfig - Both MyFaces and the RI are on your classpath. Please make sure to use only one of the two JSF-implementations.

      Dec 5, 2008 3:19:55 PM  
      INFO: 2008-12-05 15:19:55,764 [httpWorkerThread-4848-1] INFO  org.apache.myfaces.webapp.StartupServletContextListener - ServletContext '/Users/arungupta/tools/glassfish/v3/snapshot/glassfish/domains/domain1/applications/myfaces-simple-v3-usebundled/' initialized.

      Dec 5, 2008 3:19:55 PM com.sun.enterprise.web.WebApplication start
      INFO: Loading application myfaces-simple-v3-usebundled at /myfaces-simple-v3-usebundled
      Dec 5, 2008 3:19:55 PM org.glassfish.deployment.admin.DeployCommand execute
      INFO: Deployment of myfaces-simple-v3-usebundled done is 1994 ms

      The first thing to note is that the message "Initializing Sun's JavaServer Faces implementation (1.2_04-b20-p03)" is not shown. That indicates Mojarra is not used as the JSF runtime. Then you can see how MyFaces 1.1.6 API and Implementation are loaded, Tomahawk 1.1.8 is loaded and finally started using MyFaces JSF implementation.

      The main page from this deployed application at "http://localhost:8080/myfaces-simple-v3-usebundled" is very similar as shown below:



Here is a brief summary of how MyFaces/Tomahawk sample is deployed using Mojarra and MyFaces on GlassFish:

JSF Implementations
Mojarra MyFaces
GlassFish v2 Default "useMyFaces" property in "sun-web.xml"
GlassFish v3 Prelude Default Not supported
GlassFish v3 Trunk Disable Facelets 2.0 in "web.xml" "useMyFaces" OR "useBundledJsf" property in "sun-web.xml"
Disable Facelets 2.0 in "web.xml" (only for Facelets 1.1.x dependencies)

The steps described above for MyFaces can be used with alternate JSF implementations as well. Which JSF implementation do you use ?

Just like Tomahawk components, Trinidad and Tobago libraries should work with Mojarra as well. Have you tried them ?

Technorati: glassfish javaserverfaces mojarra apache myfaces tomahawk

Wednesday Oct 18, 2006

Web Services Stack Comparison

Dims asked me to update the Web Services Stack matrix. I've worked in the Web services team at Sun since very beginning and have seen it growing to #1 toolkit and now supported natively in GlassFish. I was therefore tempted by the invitation and updated the matrix with GlassFish entries. Here are the key points I'd like to highlight:

  1. Most of the functionality in this matrix (for example JAX-WS 2.0 and JAXB 2.0) is available as part of Java SE 6.
  2. If you download the latest GlassFish v2 build, all the WS-\* components, exception WS-Atomic Transaction and WS-Coordination (coming soon), are integrated. WSDL 1.1 has always been part of JAX-WS and WS-Addressing is now part of JAX-WS 2.1. All other supported WS-\* components are developed on WSIT and very well tested to interoperate with Microsoft's .NET 3.0 runtime.
  3. Read about JMS transport support at jms-ws-transport.dev.java.net and TCP support here.
  4. Spring framework is supported in GlassFish as pointed out by Jerome. But the "Spring support" feature here means exposing Spring objects as Web services in GlassFish. Let me know if you are aware of any such effort and I'll be happy to update the matrix.
Technorati: WSIT Apache J2EE
About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
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
   
       
Today