Miles to go …

September 15, 2009

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

Filed under: General — arungupta @ 6:08 am

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

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

September 14, 2009

TOTD #102: Java EE 6 (Servlet 3.0 and EJB 3.1) wizards in Eclipse

Filed under: General — arungupta @ 6:51 am

The Eclipse community‘s WTP release with Java EE 6 support has been delayed to Jun 2010. So how do you do Java EE 6 development in Eclipse until then ?

The GlassFish team is trying to bridge the gap by adding new Java EE 6 wizards that allows you to create Servlet 3.0- (JSR 315) and EJB 3.1- (JSR 318) compliant artifacts. So for the first time, in Eclipse, a Java EE 6 application can be created using the GlassFish plugin for Eclipse (ver 1.0.32)! GlassFish v3 is the Java EE 6 in making and so Eclipse and GlassFish v3 together provides you a good environment for your Java EE 6 development.

This Tip Of The Day (TOTD) explains how to use those wizards using Eclipse 3.4.2. If you have an earlier version of plugin already installed then update it as described in TOTD #66. Make sure to use ver 1.0.33 (recently released) if you are using Eclipse 3.5.x. If you have an earlier version of GlassFish plugin installed, then you may have to start Eclipse with "-clean" flag, basically as "eclipse -clean", after updating the plugin. This will allow the environment to detect the new plugins.

  1. Using Eclipse 3.4.2, install the latest GlassFish Eclipse plugin (ver 1.0.32 or higher) in "Eclipse IDE for Java EE developers" as explained in screencast #28. The correct version snapshot is shown below:

    Install latest GlassFish v3 promoted build (62 as of this writing):

    specify the location:

    and click on "Finish" to complete the install. Make sure to select "JVM 1.6.0" as the Java Runtime Environment as that is the minimum requirement for GlassFish v3.

  2. Create a new "Dynamic Web Project" named "ee6".
  3. Add Servlet 3.0 using wizard
    1. Right-click on the project, select "New", "Other …", expand the "GlassFish" section and select "Web Servlet (Java EE 6)" as shown below:

      and click on "Next >".

    2. Specify the package name as "server" and servlet name as "HelloServlet" as shown below:

      and click on "Finish".

    3. The generated code looks like as shown:

      Notice the usage of "javax.servlet.annotation.WebServlet" annotation to specify the servlet name and url pattern. Also note that no new entries are made in "WEB-INF/web.xml".

    4. Add a new method in the code as:
      protected void doProcess(HttpServletRequest request, HttpServletResponse response) throws IOException {
      ServletOutputStream out = response.getOutputStream();
      out.print("<html><body>");
      out.print("Request received at: " + request.getContextPath());
      out.print("</body></html>");
      }
      

      and invoke this method from both doGet(…) and doPost(…).

    5. Right-click the project, select "Run As", "Run on Server" and select the recently added GlassFish server as shown below:

      and click on "Finish". This shows the default page "http://localhost:8080/index.jsp". Change the URL to "http://localhost:8080/ee6/HelloServlet" to see the output as:

    6. The "web.xml" and "sun-web.xml" can be conveniently deleted from "WebContent", "WEB-INF" and the deployed page will continue to function as expected because all the information is captured in annotations instead of the deployment descriptors.
  4. Add an EJB 3.1-compliant session bean
    1. Select "New", "Other …", expand the "GlassFish" section and select "Session Bean (Java EE 6)" as shown below:

      The important difference to note is that using this new wizard an EJB can now be packaged in a Web project instead of creating a separate "EJB Project".

    2. Specify the package name as "server" and class name as "HelloBean" as shown below:

      The bean type can be chosen from "Stateless", "Stateful" or "Singleton" and appropriate annotations are added accordingly and click on "Finish".

    3. Add a simple method to the generated bean as:
      public String sayHello(String name) {
      return "Hello " + name;
      }
      
    4. Inject a client in the servlet as:
      @EJB HelloBean bean;
      

      and call the business method on EJB as:

      protected void doProcess(HttpServletRequest request, HttpServletResponse response) throws IOException {
      ServletOutputStream out = response.getOutputStream();
      out.print("<html><body>");
      out.print("Request received at: " + request.getContextPath());
      out.print("<br>" + bean.sayHello("Duke"));
      out.print("</body></html>");
      }
      

      and see the response as:

      This new EJB wizard is different from the one that already exists in Eclipse in the following ways:

      1. Singleton session bean can be created
      2. Local interface is off by default
      3. Allows a session bean in a Web project
      4. Simplified wizard flow

So we built a Java EE 6 application using the newly added Servlet 3.0 and EJB 3.1 wizards in GlassFish Plugin for Eclipse.

Please send your feedback and questions to users@glassfishplugins.dev.java.net. Let us know what other Java EE 6 features you’d like to see in Eclipse.

A complete archive of all the tips is available here.

Technorati: totd glassfish v3 eclipse javaee servlet3 ejb

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

Cross training for Runners using Biking

Filed under: Running — arungupta @ 6:49 am

Biking is a great way to cross-train for runners, it helps endurance and builds strength. And it also gives much needed break to your legs and knees :)

Here is the route I covered this morning biking approx 18.5 miles in San Jose/Cupertino/Saratoga neighborhood:

Click on the map for more details.

And here is the elevation map:

And this had to end with a 3 mile run, on a treadmill though.

With a total of 329 miles covered this quarter, there is 60 more miles to go in the next couple of weeks to meet 400 miles goal.

How do you cross-train for running ?

Technorati: biking running crosstrain

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

September 11, 2009

Running Inspirational Quotes from “Ultra Marathon Man: Confessions of an all-night runner”

Filed under: Running — arungupta @ 2:13 pm
Just finished reading Ultramarathon Man: Confessions of an All-Night Runner. This book is authored by Dean Karnazes (popularly known as "Karno") – an ultra endurance runner. The book describes Karno’s journey of becoming an ultra endurance runner and is highly inspirational. I give a strong recommendation for any runner to read this book (buy @ Amazon). Here is a very brief list of his running accolades:
  • 50 marathons in 50 states in 50 days
  • 9 times solo finisher of The Relay (199+ miles)
  • 11 times silver buckles (sub-24 hour finish) Western State 100-mile Endurance Run
  • 7 times Badwater Ultramarathon (135 miles foot race in 120 degrees), won in 2004
  • South Pole Marathon 2002 Winner (only person to complete the event in running shoes)
  • and many many many more …

Here are some inspirational / motivational / training quotes from the book:

  1. Don’t run with your legs, run with your heart.
  2. If running feels good, you didn’t push hard enough. It’s supposed to hurt like hell.
  3. Go out harder and finish harder.
  4. Running is about finding your inner peace, and so is a life well lived.
  5. Pain and suffering are often the catalysts for life’s most profound lessons.
  6. If you had the courage, stamina, and persistence to cross the finish line, you are a champion.
  7. Long distance runners requires a certain discretion and reserve. It’s easy to let you ego get the better of you early on and run beyond your means. It’s a mistake that may haunt as the miles and the hours add up.
  8. When exhaustion sets in, the mind often rationalizes the irrational. For example, 38 miles = 1 marathon + 2 10 Ks.
  9. Pain is the body’s way of ridding itself of weakness.
  10. Most dreams die a slow death. They’re conceived in a moment of passion, with the prospect of endless possibility, but often languish and are not pursued with the same heartfelt intensity as when first born. Slowly, subtly, a dream becomes elusive and ephemeral.
  11. If you can’t run then walk. And if you can’t walk then crawl. Do what you have to do. Just keep moving forward and never, even give up.

    A shorter version of the above quote is:

    Run when you can
    Walk if you have to
    Crawl if you must
    Just never give up.

  12. Runners are real people. They don’t run for money or recognition, they do it out of passion. Most have day job that pay the bills, and running is a labor of love.
  13. Without discipline to rise before dawn and pound out the miles, you’ll never make it. If the fire in your heart isn’t strong, there’s no point trying.
  14. How to run an ultramarathon ? Puff out your chest, put one foot in front of the other, and don’t stop till you cross the finish line.
  15. When it gets right down to it, the levels of commitment and devotion required to excel as an ultra-endurance athlete are all-consuming.
  16. The human body is capable of amazing physical deeds. If we could just free ourselves from our perceived limitations and tap into our internal fire, the possibilities are endless.
  17. Pursuit of a passion matters more than the passion itself. Immerse yourself in something deeply and with heartfelt intensity – continually improve, never give up – this is fulfillment, this is success.
  18. Struggling and suffering are the essence of a life worth living. If you’re not pushing yourself beyond the comfort zone, if you’re not demanding more from yourself – expanding and learning as you go – you’re choosing a numb existence. You’re denying yourself an extraordinary trip.

I only wish to reach up to 10% of his level … that’s my first "baby step". And certainly a dream would be run/train along with him :)

Follow him at @DeanKarnazes or subscribe to his blog.

Technorati: running training ultramarathon motivation deankarnazes karno

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

September 10, 2009

Larry Ellison to Sun Customers – “We’re in it to win it”

Filed under: General — arungupta @ 5:52 am

Here is an advertisement from today’s (Sep 10, 2001) Wall Street Journal (also here)

Also find out why Oracle + Sun is faster than IBM on Oct 14.

Technorati: sun oracle ibm openworld

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

Getting Started with WordPress Customization

Filed under: General — arungupta @ 5:51 am

So you have a brand new WordPress installation and would like to start blogging. There are several tutorials available on that topic. However it’s important to customize your blog as it reflects your style / personality. WordPress official documentation is extensive, very nicely organized and provide great tips on how to customize your blogs. But it can take a while to go through the docs and customize look-and-feel of your blog.

This blog entry explains how this blog was customized from a fresh WordPress installation.

  • Pick a theme that you like and customize it. This blog started with "Classic" theme and added pages as relevant. This is totally a personal preference as I like the header + right navigation bar + body format.
  • Add your picture and edit the "About" page so that readers know you.
  • Customize sidebar
    • Prefer static toolbar by editing "sidebar.php" instead of dynamic toolbar created using the "Appearance" -> "Widgets".
    • Add "search" dialog box
    • Add Twitter widget (choose "Yes" for "Loop old results", explained here). May not be relevant if you don’t tweet, but seems like everybody is these days ;-)
    • Add a ClustrMap widget to monitor geographical spread of readership.
    • Total Page hits / page views on sidebar + on each post (How ?)
  • Installed the following WordPress plugins to begin with:
    • Google XML Sitemaps – Creates a Google Sitemaps compliant XML file and submits the blog content to Google, Bing and Ask.com. It took 1.64 seconds for the first creation and used 12.75 MB.
    • Sociable – Adds social media button to your posts
    • Google Analyticator plugin – Adds Google Analytics script to monitor traffic. Even though Google Analytics capture geographical distribution as well but I like the ClustrMap widget that can be displayed on the nav bar. Do Google Analytics provide that kind of widget ?
    • Search Plugin for Firefox and IE – Creates a Firefox and IE search plug-in. Install the plugin, go to "Settings", "Search Browser" to generate the code and insert in "header.php". Add a customized search page by copying "search.php" from the "default" theme. Show the summarized result with clickable links to the content.
    • Smart 404 plugin – Creates a clean and simple page with a friendly error message to a reader who might have somehow reached a broken link or mistyped the URL. Add/Edit a 404.php as explained here. It’s important to not loose your reader and instead gracefully guide them to the next steps.
    • YARPP – Shows a list of related entries based on a unique algorithm for display on your blog and RSS feeds. A templating feature allows customization of the display.
    • WP Greet Box – Show a different greeting message to your new visitors
      depending on their referrer URL.
  • Some more customizations
    • Add pre/code styles to "styles.css" for code formatting. Now simple <pre> and <code> will format the code nicely.
    • Create hierarchical categories so that readers can read the topic of their choice
    • Add Next and Previous links to each page (<?php posts_nav_link(); ?>) and each blog post (<?php previous_post(); ?> <?php next_post(); ?>) as described here.
    • Personalize the page using a favicon as described here.
    • Change the default permalink format from "http://example.com/?p=N" to "http://example.com/year/month/day/post-name" as described here. This makes your blog entry URLs search-engine friendly.
  • Editing
    • If you prefer editing online, disable the "Visual rich editor" as it strips all the paragraph formatting from a nicely-formatted HTML page. It’s primarily meant for newbies and I like better control over the HTML formatting so prefer editing it manually.
    • Choose a blog editor client. It seems WordPress adds line breaks (<br>) if the text in a line is not wrapped. Qumana was chosen as the blog editor after trying nvu, Kompozer, Ecto, MarsEdit, Smultron, and HTML Tidy. Loving it’s WYSIWYG capabilities, transition between WYSIWYG and source view is seamless, ease of cross-posting to multiple blogs and intuitive interface.
  • Join Technorati (if not already) and Claim your blog.

The beauty of WordPress is that a myriad of customizations is possible but the tips above provide a common set of configuration.

Any other obvious tips that are missing ?

Technorati: wordpress blog milestogo

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

September 4, 2009

TOTD #101: Applying Servlet 3.0/Java EE 6 “web-fragment.xml” to Lift – Deploy on GlassFish v3

Filed under: General — arungupta @ 9:07 am

TOTD #100 explained how to deploy Lift framework applications on GlassFish v3. As explained in TOTD #91, Java EE 6 defines how the framework configuration deployment descriptor can be defined in “META-INF/web-fragment.xml” in the JAR file of the framework instead of mixing it with "WEB-INF/web.xml" which is intended for application deployment descriptor aspects.

This Tip Of The Day (TOTD) explains how to leverage ”web-fragment.xml” to deploy a Lift application on a Java EE 6 compliant container. The original "lift-*.jar" files are untouched and instead a new JAR file is included that contains only the framework configuration deployment descriptor.

The generated "web.xml" from TOTD #100 looks like:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<filter>
<filter-name>LiftFilter</filter-name>
<display-name>Lift Filter</display-name>
<description>The Filter that intercepts lift calls</description>
<filter-class>net.liftweb.http.LiftFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LiftFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

The deployment descriptor defines a Servlet Filter (LiftFilter) that registers the Lift framework with the Web container. And then it defines a URL mapping to "/*". All of this information is required by the Lift framework for request dispatching. And so that makes this fragment suitable for "web-fragment.xml".

Here are simple steps to make this change:

  1. Remove “src/main/webapp/WEB-INF/web.xml” because no application specific deployment descriptors are required.
  2. Include “lift-web-fragment.jar” in the “WEB-INF/lib” of your application by adding the following fragment in your “pom.xml”:
    <dependencies>
    . . .
    <!– web-fragment –>
    <dependency>
    <groupId>org.glassfish.extras</groupId>
    <artifactId>lift-web-fragment</artifactId>
    <version>1.0</version>
    <scope>runtime</scope>
    </dependency>
    </dependencies>
    . . .
    <repositories>
    <repository>
    <id>maven2-repository.dev.java.net</id>
    <name>Java.net Repository for Maven</name>
    <url>http://download.java.net/maven/2/</url>
    </repository>
    </repositories>
    

    This file contains only “META-INF/web-fragment.xml” with the following content:

    <web-fragment>
    <filter>
    <filter-name>LiftFilter</filter-name>
    <display-name>Lift Filter</display-name>
    <description>The Filter that intercepts lift calls</description>
    <filter-class>net.liftweb.http.LiftFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>LiftFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    </web-fragment>
    
    
  3. Create the WAR file without “web.xml” by editing “pom.xml” and adding the following fragment:
    <build>
    . . .
    <plugins>
    . . .
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1-beta-1</version>
    <configuration>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
    </plugin>
    </plugins>
    </build>
    

That’s it, now now you can create a WAR file using “mvn package” and deploy this web application on GlassFish v3 latest promoted build (61 as of today) as explained in TOTD #100.

Technorati: totd glassfish v3 lift scala javaee6 servlet web-fragment

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

September 3, 2009

TOTD #100: Getting Started with Scala Lift on GlassFish v3

Filed under: General — arungupta @ 12:00 pm

Yaaay, 100th tip! Read earlier tips here.

Scala is a strongly typed JVM language that provides benefits of functional programming and dynamic languages on the JVM. As a result you get flexibility of language such as Ruby and performance of Java. Lift is an MVC-based Web framework, based on Scala, that claims to pick the best of Rails (ease of development), Seaside (highly granular sessions and security), Django (access control), and Wicket (designer-friendly templating system).

Lift applications can run inside any Java application server. GlassFish v3 can run Rails and Django applications natively and can also run Wicket applications. This Tip Of The Day (TOTD) explains how to get started with Lift applications and run inside GlassFish v3.

  1. Create a new Lift project using Maven as shown:

    ~/samples/v3/lift >mvn archetype:generate -U -DarchetypeGroupId=net.liftweb
    -DarchetypeArtifactId=lift-archetype-blank -DarchetypeVersion=1.0
    -DremoteRepositories=http://scala-tools.org/repo-releases
    -DgroupId=demo.helloworld -DartifactId=helloworld
    -Dversion=1.0-SNAPSHOT
    [INFO] Scanning for projects...
    [INFO] Searching repository for plugin with prefix: 'archetype'.
    [INFO] org.apache.maven.plugins: checking for updates from central
    . . .
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESSFUL
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 14 seconds
    [INFO] Finished at: Tue Sep 01 16:11:34 PDT 2009
    [INFO] Final Memory: 12M/80M
    [INFO] ------------------------------------------------------------------------
    

    This creates a directory "helloworld" which looks like:

    ~/samples/v3/lift/helloworld >find .
    .
    ./pom.xml
    ./src
    ./src/main
    ./src/main/resources
    ./src/main/scala
    ./src/main/scala/bootstrap
    ./src/main/scala/bootstrap/liftweb
    ./src/main/scala/bootstrap/liftweb/Boot.scala
    ./src/main/scala/demo
    ./src/main/scala/demo/helloworld
    ./src/main/scala/demo/helloworld/comet
    ./src/main/scala/demo/helloworld/comet/.keep
    ./src/main/scala/demo/helloworld/model
    ./src/main/scala/demo/helloworld/model/.keep
    ./src/main/scala/demo/helloworld/snippet
    ./src/main/scala/demo/helloworld/snippet/.keep
    ./src/main/scala/demo/helloworld/snippet/HelloWorld.scala
    ./src/main/scala/demo/helloworld/view
    ./src/main/scala/demo/helloworld/view/.keep
    ./src/main/webapp
    ./src/main/webapp/index.html
    ./src/main/webapp/templates-hidden
    ./src/main/webapp/templates-hidden/default.html
    ./src/main/webapp/WEB-INF
    ./src/main/webapp/WEB-INF/web.xml
    ./src/test
    ./src/test/resources
    ./src/test/scala
    ./src/test/scala/demo
    ./src/test/scala/demo/helloworld
    ./src/test/scala/demo/helloworld/AppTest.scala
    ./src/test/scala/LiftConsole.scala
    ./src/test/scala/RunWebApp.scala
    

    In this directory, "src/main/scala" contains Scala source code, "src/main/webapp" contains the HTML and other related artifacts, and "src/test/scala" contains a simple test case to test the generated application. The "demo/helloworld/model" directory is used for models, "demo/helloworld/snippet" for controller, and "demo/helloworld/view" for views. The Lift Getting Started Guide provides a detailed explanation of how the different components work together to provide the end result.

  2. Create a WAR file of the application as:
    ~/samples/v3/lift/helloworld >mvn package [INFO] Scanning for projects...
    [INFO] ------------------------------------------------------------------------
    [INFO] Building helloworld
    [INFO] task-segment: [package]
    [INFO] ------------------------------------------------------------------------
    [INFO] artifact org.scala-tools:maven-scala-plugin: checking for updates from scala-tools.org
    [INFO] artifact org.scala-tools:maven-scala-plugin: checking for updates from central
    . . .
    [INFO] Building war: /Users/arungupta/samples/v3/lift/helloworld/target/helloworld-1.0-SNAPSHOT.war
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESSFUL
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 9 minutes 25 seconds
    [INFO] Finished at: Tue Sep 01 16:42:32 PDT 2009
    [INFO] Final Memory: 24M/80M
    [INFO] ------------------------------------------------------------------------
    

    This generates "target/helloworld-1.0-SNAPSHOT.war" file.

  3. The WAR file can be easily deployed to GlassFish v3. Download the latest GlassFish v3 promoted build (61 as of this writing) and unzip. Start the GlassFish server as:
    ~/tools/glassfish/v3/61/glassfishv3 >./bin/asadmin start-domain --verbose
    Sep 2, 2009 3:43:09 PM com.sun.enterprise.admin.launcher.GFLauncherLogger info
    INFO: JVM invocation command line:
    . . .
    Sep 2, 2009 3:46:01 PM OSGiModuleImpl start
    INFO: Started bundle org.glassfish.security [174]
    Sep 2, 2009 3:46:02 PM OSGiModuleImpl start
    INFO: Started bundle org.glassfish.deployment.javaee-full [51]
    

    and deploy the WAR file as:

    ~/samples/v3/lift/helloworld >~/tools/glassfish/v3/8-31/glassfishv3/bin/asadmin deploy target/helloworld-1.0-SNAPSHOT.war
    
    Command deploy executed successfully.
    

    The app is now accessible at "http://localhost:8080/helloworld-1.0-SNAPSHOT/" and the output looks like:

What application server are you using to deploy your Lift applications ?

Please leave suggestions on other TOTD that you’d like to see. A complete archive of all the tips is available here.

Technorati: totd scala lift glassfish v3

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

Bollywood Dandia in Fremont on Sep 26, 2009 – Sharvari Dixit and Troupe

Filed under: General — arungupta @ 5:45 am

Content available at: http://blog.arungupta.me/2009/09/bollywood-dandia-in-fremont-on-sep-26-2009-sharvari-dixit-and-troupe/.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

September 2, 2009

Track your running miles using Apache Wicket, GlassFish, NetBeans, MySQL, and YUI Charts

Filed under: General — arungupta @ 2:00 pm

Track your running miles using Apache Wicket, GlassFish, NetBeans, MySQL, and YUI Charts

An earlier blog introduced an application that provides basic tracking of your running distance and generate charts to monitor progress. The idea is to build the same application using different Web frameworks and deploy on GlassFish and then evaluate each framework based upon a pre-defined critieria. The first version was built using JRuby and Ruby-on-Rails. This blog announces the completion of the Apache Wicket version of the application.

All efforts have been applied to ensure a consistent look-and-feel with the original application but there are minor inconsistencies to leverage the default behavior of the framework.

First here are some snapshots of the application deployed on GlassFish b3 build 61.

The home page looks like:

Here is a summary of all the runlogs:

All the records can be easily paginated through. There are a few validations while adding a new run:

The "datepicker" widget is used for selecting custom dates as shown in the following page:

Here is a line chart of last 30 days of running:

Notice, it also shows the complete summary as well. And finally a barchart for the entire year so far:

The complete instructions to check out and run the Wicket version of this application are available here.

Now comes the time to provide feedback on the Wicket framework based upon my experience of developing this application. The evaluation criteria is explained in detail here.

The feedback may be attributed to my ignorance of the Wicket framework. If so, please feel free to post a comment and I’ll be happy to fix.

  1. MVC separation: Wicket promotes MVC architecture by providing abstract wrappers over model but the actual implementation still needs to be plugged. For example, the controllers need to written from scratch anyway. There is no recommended directory structure that makes MVC inherent. This is related to the fact that Wicket is not a full-stack framework (more on this below).

    The framework provides a clean separation between views in HTML/CSS and business logic using POJO. However a lot (quite a lot) of glue code needs to be written to stitch them together. And it gets verbose really fast because of the multiple inner classes that keeps popping everywhere in the Java code. Also by default POJO and HTML are packaged together and mixing views/models in the same directory is very confusing.

  2. DRY and CoC principles: The framework neither explicitly promote or prohibit DRY or CoC. The standard HTML/CSS/Java techniques can be used to achieve DRY. And because there is no generated code, there is no concept of CoC.
  3. Limited Ajax: The framework provides buttons/links that can make an Ajax request to the back end. But there is no explicit abstraction of XmlHTTPRequest in the framework. And so an external JavaScript library needs to pulled (Prototype in this case) for any direct Ajax invocations.

    The documentation on wicketstuff-prototype is kinda unclear on how the integration works.

  4. ORM: Apache Wicket is a framework for creating UI applications and that’s exactly what it is, nothing beyond. It is not comparable with full stack frameworks like Java EE, Rails or Grails which provides a persistence mechanism, database connectivity, full MVC support, security and other similar features. As a result, this application could not be built using only Wicket. For example, Java Persistence API (JPA) was used for database access and Prototype was used for Ajax functionality. JPA and Prototype are just the chosen ones among other multiple options available.
    1. CRUD generation: Creating a basic CRUD applications required putting together a bunch of POJOs, corresponding HTML pages, JPA controllers and stitching them together.
    2. Table creation: Defined by the chosen persistence library.
    3. Loading data in the table: Defined by the chosen persistence library.
    4. Customizing queries: Defined by the chosen persistence library.
  5. Customization
    1. CSS & JavaScript: Standard HTML, CSS, and JavaScript techniques for packaging are used.
    2. Form Validation & Default Error Handling: There are validators available to enable basic checking like required, number / pattern / range / date validator. Anything above that needs to be custom built and adds to the verbose nature of the framework. For example a "FormValidator" was built to support the validation for each elements of the form. Custom messages for each validation message can be displayed as explained here. More user-friendly messages can be displayed as explained here.
    3. Templates: The template mechanism is really flexible and allows the repetitive code to be easily captured using "markup inheritance".
  6. 3rd Party Libraries: Adding 3rd-party libraries is quite a breeze because standard HTML/CSS/JavaScript integration techniques are used.
    1. Plugins: Wicket-extensions has some components in addition to the core framework. Wicket-stuff provides components that complement the core framework. The core functionality can be extended using wicket-stuff.
    2. Date picker: There are corresponding packages available for YUI, e.g. "org.apache.wicket.extensions.yui.calendar" for adding DatePicker widget.
    3. Pagination was quite simple to implement.
  7. IDEs: NetBeans provides the most advanced support for Wicket development. But the recommended way is to start wit
    h a Maven project and NetBeans provide good support for that as well. More on IDE support here. The Edit/Save/Deploy/Refresh cycle required by the Jetty is time consuming though.
  8. Browser Compatibility: The app was tested on Firefox 3.5.2 (on Mac), Safari 4.0.3 (on Mac) and IE 7.0.600.118000 (on Windows Vista) and no issues were encountered.
  9. Production Deployment: Generating a production deployment on GlassFish is very straight forward because of Maven, just create a WAR file using "mvn package" and deploy directly.
  10. Maintainability: The framework requires a good grasp of Object Oriented concepts like inheritance, encapsulation and inner classes. Even though these concepts are very powerful but they can be a maintenance nightmare. Also, the verbose nature of framework will likely make it cumbersome as a maintenance effort. However there is no real experience or feedback in this area.
  11. Any outstanding feature ? – The response time on the Wicket user list is truly outstanding. Most of my issues encountered during the development phase were resolved by asking questions there.
  12. Any pain point ? – As with any new framework, there is always a learning curve. The framework has a large set of APIs and so it takes a while to figure how the pieces fit together and can be assembled together to create a solution. If you are developing with Wicket, then the official documentation is pretty minimal and not much helpful. The very first link in the documentation actually points to Books on Wicket which is indeed a key resource. I borrowed "Wicket in Action" book from a colleague and it turned out to be helpful. But unfortunately the API has evolved since the book was released and so some of the recommendations from the book are already deprecated. The Wicket user list is definitely a very responsive resource and help me build a better understanding of the framework. Wicket Stuff provides a good set of examples as well with complete source code. But even here some of the samples are using deprecated APIs. Another pain point is that "search engine-driven development" paradigm cannot be applied easily because the search results are a mix from the pre- and post-Apache versions of blogs/docs/etc.

The latest version of this evaluation is available here.

TOTD #86 explains how to get started with using Apache Wicket and GlassFish. All other Wicket related entries on this blog are here.

Technorati: wicket glassfish netbeans mysql yahoo yui chart running miles framework

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
« Newer PostsOlder Posts »

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.
Powered by WordPress