Miles to go …

July 31, 2008

Why GlassFish Metro over Axis ?

Filed under: webservices — arungupta @ 5:00 am

Metro (Web services stack from GlassFish) is kicking strong these days – here are two instances!

  1. ArcGIS SOAP stack gains 90% performance improvement using Metro

    An intern in the Web services team for performance enhancement of ArcGIS SOAP SDK reported:

    With Axis 1.x based tool kits XML parsing was identified as a bottleneck and therefore we wanted to make a switch to a tool kit that uses the Streaming API for XML Parsing (StAX). We identified that Metro (Glassfish’s SOAP Stack) was the way to go and i generated the new Metro based SDK for accessing Web-Services.

    And the conclusion is …

    The result of this project is an increased performance of the ArcGIS Server’s SOAP stack (by about 90%).

    Pretty cool – Metro (Web services stack baked in GlassFish) gave about 90% improvement over Axis! Read more details about the study here.

  2. Change of the guard: AXIS out, JAX-WS in

    Here are some relevant points:

    I have come to a conclusion: I no longer want to deal with the hassle that has become Apache AXIS.

    AXIS2 is current, but has become very large, the doc is poor, the support is invisible, the generated code smells, and the seams are everywhere.  Fifty nine jar files?  Really?   Do I need this hassle?  With JAX-WS, do I need AXIS any longer? I think not.

    But I honestly cannot believe customers will continue to put up with the furball that AXIS2 has become. And if I am in a position to make a recommendation, I will recommend JAX-WS. It works.

And you can also connect to Microsoft Exchange Server using JAX-WS.

And here are some other endorsements for Metro.

Technorati: webservices adoption glassfish metro axis

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

July 30, 2008

Grails on GlassFish v3 – Embedded or Stand-alone

Filed under: web2.0 — arungupta @ 5:00 am

Grails 1.0.3 was released a few weeks ago. This blog uses the instructions originally posted here and shows how to deploy a simple Grails application on GlassFish.

  1. Download Grails 1.0.3 and unzip.
  2. Download the latest *-overlay.zip from here and unzip on your Grails installation as shown:
    ~/tools/grails-1.0.3 >unzip ~/Downloads/grails-gfv3-1.1-overlay.zip
    Archive:  /Users/arungupta/Downloads/grails-gfv3-1.1-overlay.zip
       creating: lib/glassfish-v3/
      inflating: lib/glassfish-v3/gf-embedded-api-1.0-alpha-4.jar 
      inflating: lib/glassfish-v3/web-all-10.0-build-20080430.jar 
      inflating: lib/grails-gfv3-1.1.jar 
      inflating: scripts/RunAppGf.groovy
  3. Create a sample app as explained in Getting Started With Grails on GlassFish.
  4. Run the app using embedded GlassFish as:
    ~/tools/grails-1.0.3/samples/helloworld >grails run-app-gf

    Welcome to Grails 1.0.3 – http://grails.org/
    Licensed under Apache Standard License 2.0
    Grails home is set to: /Users/arungupta/tools/grails-1.0.3

    Base Directory: /Users/arungupta/tools/grails-1.0.3/samples/helloworld
    Note: No plugin scripts found
    Running script /Users/arungupta/tools/grails-1.0.3/scripts/RunAppGf.groovy
    Environment set to development
    Starting GlassFish embedded server…     [copy] Copying 1 file to /Users/arungupta/.grails/1.0.3/projects/helloworld
    Running Grails application..
    Application name : helloworld
    Web App Root :/Users/arungupta/tools/grails-1.0.3/samples/helloworld/web-app
    web.xml:/Users/arungupta/.grails/1.0.3/projects/helloworld/resources/web.xml
    Jul 28, 2008 2:25:38 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: HK2 initialized in 620 ms
    Jul 28, 2008 2:25:38 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: com.sun.enterprise.naming.impl.ServicesHookup@2aef3499 Init done in 646 ms
    Jul 28, 2008 2:25:38 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: com.sun.enterprise.v3.server.Globals@3710f32d Init done in 648 ms
    Jul 28, 2008 2:25:38 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: com.sun.enterprise.v3.server.SystemTasks@632dc291 Init done in 655 ms
    Jul 28, 2008 2:25:38 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: com.sun.enterprise.v3.services.impl.HouseKeeper@64c3d9c0 Init done in 658 ms
    Jul 28, 2008 2:25:38 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: com.sun.enterprise.v3.services.impl.CmdLineParamProcessor@3a151d3b Init done in 664 ms
    JMXMP connector server URL = service:jmx:jmxmp://localhost:8888
    Jul 28, 2008 2:25:39 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
    INFO: Listening on port 8080
    Jul 28, 2008 2:25:39 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: com.sun.enterprise.v3.services.impl.GrizzlyService@2ddd5c89 startup done in 1059 ms
    Jul 28, 2008 2:25:39 PM com.sun.enterprise.v3.services.impl.ApplicationLoaderService postConstruct
    INFO: loader service postConstruct started at 1217280339578
    Jul 28, 2008 2:25:39 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Application Loader startup done in 1353 ms
    Jul 28, 2008 2:25:39 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Glassfish v3 started in 1355 ms
    Jul 28, 2008 2:25:41 PM org.apache.catalina.loader.WebappLoader setClassPath
    INFO: Unknown loader org.glassfish.grails.MaskingClassLoader@5cbde5b4 class org.glassfish.grails.MaskingClassLoader
    Jul 28, 2008 2:25:41 PM com.sun.enterprise.web.WebModuleContextConfig authenticatorConfig
    SEVERE: webModuleContextConfig.missingRealm
    [0] spring.GrailsWebApplicationContext Refreshing org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@4c721585: display name [org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@4c721585]; startup date [Mon Jul 28 14:25:44 PDT 2008]; parent: org.springframework.web.context.support.XmlWebApplicationContext@631a8160
    [0] spring.GrailsWebApplicationContext Bean factory for application context [org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@4c721585]: org.springframework.beans.factory.support.DefaultListableBeanFactory@3e11bc1d
    Server running. Browse to http://localhost:8080/helloworld

    Browsing to “http://localhost:8080/helloworld” shows:


  5. Create a controller

    ~/tools/grails-1.0.3/samples/helloworld >grails create-controller home

    Welcome to Grails 1.0.3 – http://grails.org/
    Licensed under Apache Standard License 2.0
    Grails home is set to: /Users/arungupta/tools/grails-1.0.3

    Base Directory: /Users/arungupta/tools/grails-1.0.3/samples/helloworld
    Note: No plugin scripts found
    Running script /Users/arungupta/tools/grails-1.0.3/scripts/CreateController.groovy
    Environment set to development
         [copy] Copying 1 file to /Users/arungupta/tools/grails-1.0.3/samples/helloworld/grails-app/controllers
    Created Controller for Home
        [mkdir] Created dir: /Users/arungupta/tools/grails-1.0.3/samples/helloworld/grails-app/views/home
         [copy] Copying 1 file to /Users/arungupta/tools/grails-1.0.3/samples/helloworld/test/integration
    Created ControllerTests for Home

  6. Edit the generated controller in “grails-app/controllers/HomeController.groovy” such that it looks like:
    class HomeController {

        def index = {
            render “Grails using embedded GlassFish!”
        }
    }

  7. Refresh the web page in the browser and it looks like:

    and clicking on “HomeController” shows the output as:

More details about GlassFish embedding in Grails are available here.

This application can also be deployed on stand-alone GlassFish v3 Technology Preview 2 a
s explained here. This blog explains how to configure JNDI resources for a Grails application and I plan to explore that in upcoming days.

Once the Servlet engine in Grails is made configurable then GlassFish can be used as the target deployment platform from “run-app” script.

NetBeans 6.5 M1 provide extensive support on Grails application development – details are available here.

Technorati: grails glassfish v3 embedded netbeans

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

July 29, 2008

TOTD #39: Prototype/Script.aculo.us Autcomplete widget with MySQL, GlassFish, NetBeans

Filed under: web2.0 — arungupta @ 5:00 am

There are several JavaScript libraries that can be embedded in your webapplication to create a visually appealing interface. Script.aculo.us is one of the popular ones and is built on the Prototype JavaScript Framework. The library provides an easy-to-use, cross-browser user interface JavaScripts that allows you to create fancy effects commonly visible on web pages these days.

This blog entry gets you started by using Ajax.Autocompleter that allows for server-powered autocompleting of text fields. Basically, you type a character in a text field and suggestions for possible correct values starting with that character are shown . This is achieved by by sending an Ajax request to the data source on server, passing the typed character in the request and processing the response to display on the web page. This effect was first popularized by Google Suggest.

In this TOTD (Tip Of The Day) we will create a simple web application with a text field in a JSP page that will use Servlet as the data source. The Servlet retrieves the parameter from the RequestContext, uses Java Persistence API to query the database and return response in the expected format. We will use:

  • NetBeans IDE 6.1 for Web app creation/deployment
  • GlassFish v2 UR2 as deployment platform
  • MySQL database server bundled with Mac OSX 10.5.4

Let’s get started!

  1. TOTD #38 explains how to create a MySQL Persistence Unit. Please follow the steps there to create a new Web application and Persistence Unit. Follow the steps listed below after the PU is created.
      1. In Project Explorer, expand “Source Packages”, “server” and open “States” class. Add the following NamedQuery:

        @NamedQuery(name = “States.findLikeName”, query = “SELECT s FROM States s WHERE LOWER(s.name) LIKE :searchString”),

        at the position shown below:

      2. In “StatesServlet” class, replace the commented code in “processRequest” with the following fragment:
                    String searchString = request.getParameter(“autocomplete_parameter”);

                    List<States> list = em.createNamedQuery(“States.findLikeName”).
                            setParameter(“searchString”, searchString.toLowerCase() + “%”).
                            getResultList();

                    out.println(“<ul>”);

                    for (int i = 0; i < list.size(); i++) {
                        States s = list.get(i);
                        out.println(“<li>” + s.getName() + “</li>”);
                    }
                    out.println(“</ul>”);

        and fix the imports by right-clicking in editor pane and selecting “Fix Imports”.

    1. Download & Use Script.aculo.us libraries
      1. Download latest Script.aculo.us libraries from here (version 1.8.1 as of this writing) and unzip them.
      2. In NetBeans, right-click on “Web Pages”, select “New”, “Folder” and specify the folder name as “javascripts”.
      3. From the unzipped Script.aculo.us bundle, copy all files from “src” and “lib” directory to the newly created “javascripts” folder.
      4. Expand “Web Pages” and open “index.jsp”. Add the following fragment in HTML <head>:
                <script src=”javascripts/prototype.js” type=”text/javascript”></script>
                <script src=”javascripts/scriptaculous.js?load=effects,controls” type=”text/javascript”></script>
                <script type=”text/javascript”>
                    window.onload = function() {
                        new Ajax.Autocompleter(“autocomplete”, “autocomplete_choices”, “/Autocomplete/StatesServlet”, {});
                    }
                </script>

        and the following in HTML <body>:

                <input type=”text” id=”autocomplete” name=”autocomplete_parameter”/>
                <div id=”autocomplete_choices” class=”autocomplete”></div>

        These fragments are part of the original tutorial.

      5. Optionally, specify a stylesheet to render the result nicely
        1. Create a “stylesheets” folder in “Web pages”.
        2. Right -click on the newly created folder, select “New”, “Other…”, “Other” category and “Cascading Style Sheet” file type. Give the name “autocompleter” and click on “Finish”.
        3. Replace the generated template with the following contents:
          .autocomplete {
              position:absolute;
              width:250px;
              background-color:white;
              margin:0px;
              padding:0px;
              overflow:hidden;
          }
          .autocomplete ul {
              list-style-type:none;
              margin:0px;
              padding:0px;
              overflow:auto;
          }
          .autocomplete ul li.selected { background-color: #ffb;}
          .autocomplete ul li {
              list-style-type:none;
              display:block;
              margin:0;
              padding:2px;
              height:32px;
              cursor:pointer;
          }
        4. Add the following fragment in “index.jsp” in <head>:
          <LINK href=”stylesheets/autocompleter.css” rel=”stylesheet” type=”text/css”>

    Now the show time … right-click the project and select “Run”. This deploys the project on GlassFish v2 and brings up “http://localhost:8080/Autocomplete/index.jsp” in the default browser window. The default page looks like:

    As you start typing characters in the text box, Ajax.Autocompleter sends a request to the Servlet (specified using the “/Autocomplete/StatesServlet”) by passing the typed characters as query parameters. The servlet returns an unordered HTML list. Typing “A” in the text box shows the following output:

    and Firebug output looks like:

    Typing “C” in the text box shows the following output:

    Typing “Mi” in the text box shows the following output:

    A request to the Servlet is made everytime a letter is typed. The minimum number of characters that must be entered in the field before a Servlet request is made can be altered by passing the arguments to Ajax.Autocompleter function as shown below (changes highligted in bold):

                window.onload = function() {
                    new Ajax.Autocompleter(“autocomplete”, “autocomplete_choices”, “/Autocomplete/StatesServlet”, { minChars: 2 });
                }

    Some potential fun ideas to make this entry more meaningful:

    • Servlet can access data from a RESTful endpoint and transform the data to an unordered list
    • Autocompleter data source return data in JSON format
    • Autocompleter used in a HTML <form> and “afterUpdateElement” is used to process the selected entry, may be filter the data shown

    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 web2.0 autocompleter scriptaculous prototype javascript glassfish mysql netbeans

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

    July 28, 2008

    Spotlight – GlassFish Resources for Education Community

    Filed under: General — arungupta @ 3:00 am

    Are you a student interested in demonstrating the diverse and powerful features of GlassFish ?
    Are you a professor who would like to teach GlassFish in your curriculum ?
    Do you train other people in enterprise technology ?
    Are you involved in education community in any manner ?

    If the answer to any of the above questions is Yes, then spotlight.dev.java.net is onestop that provides a list of GlassFish resources for you. It provides a comprehensive list of resources about video Tutorials, Blogs, Demos, Training courses and other information.

    Do you have your favorite slide deck to share ?
    Do you have a demo to share ?
    What additional demos/resources would you like from us ?

    Let us know by sending an email to and we’ll shine the spotlight on you!

    You can find more detailed information Sun’s offering for students @ Students Portal.

    Technorati: glassfish education students spotlight

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

    July 26, 2008

    Running Strong with Billy Mills

    Filed under: Running — arungupta @ 5:00 am

    July 2008 issue (page 96) of Hemisphere Magazine has an interview with Billy Mills – the only American to ever win a Gold medal in the 10,000 meter run at Olympics. He did that in 1964 Olympics @ Tokyo. It is quite an inspiring interview and I read it a few times during my travel this week. I could connect with it more closely now that my upcoming 1/2 marathon is a week away.

    I’d like to share some inspirational quotes from there:

    I tried all different sports. Running – even though I wasn’t fast in the beginning – brought me tranquility. It was almost spiritual.

    His dad was his inspiration who said:

    Look down deeper, where the dreams lie. Find your dream, son. Pursure your dream. It’s the pursuit of a dream that heals you.

    And another one ..

    It’s important to pursue a dream that heals you. With dreams come desire.. With desire comes self-motivation. With self-motivation comes work. With work comes success.

    Check out one of the biggest upsets in Olympics:

    A movie was created based upon Mills’s story in 1983 – Running Brave and it’s way at the top in my Netflix queue now! Here is an excerpt from the movie:


    Quite an inspiration! Team Hoyt and Dean Karnazes are my other inspirations for running. What motivates you ?

    I could not verify the “only American” claim @ Olympics official website because the searchable database allows to search for all sports except “Running”. Weird, isn’t it ? But check for your self:

    Wikipedia comes to help and prooves that Billy Mills has indeed been the only American to ever win a Gold medal in 10,000 meters. Billy has taken running to a different extent now where he is traveling 300 days in a year as motivational speaker and supports non profit group Running Strong.

    Technorati: running motivation billymills olympics

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

    July 25, 2008

    TOTD #38: Creating a MySQL Persistence Unit using NetBeans IDE

    Filed under: web2.0 — arungupta @ 5:00 am

    This TOTD (Tip Of The Day) shows how to create a Persistence Unit (PU) for a MySQL database using NetBeans IDE. This PU can then be used in any of Java EE artifacts (JSP, Servlet, EJB, …) for database interaction.

    1. In NetBeans IDE, create a new project
      1. Create a new NetBeans Web project and enter the values (“Autocomplete”) as shown:

        and click on “Next”.

      2. Choose GlassFish v2 as the deployment server and then click on “Finish”.
    2. Set up the database
      1. Start the database as:

        ~ >sudo mysqld_safe –user root
        Password:<YOUR PASSWORD>
        Starting mysqld daemon with databases from /usr/local/mysql/data

      2. Create a user, create the database and grant the privileges to newly created user as:
        mysql> CREATE USER duke IDENTIFIED by ‘duke’;
        Query OK, 0 rows affected (0.00 sec)

        mysql> create database states;
        Query OK, 1 row affected (0.00 sec)

        mysql> GRANT ALL on states.* TO duke;
        Query OK, 0 rows affected (0.00 sec)

      3. In NetBeans IDE, Services panel, right-click on Databases and click on “New Connection…” and enter the values as shown:

        and click on “OK” and again on “OK”.

      4. Right-click on the newly created database and select “Execute Command …” as shown:

      5. Create the database table as:
        CREATE TABLE STATES (
              id INT,
              abbrev VARCHAR(2),
              name VARCHAR(50),
              PRIMARY KEY (id)
        );

        and click on the green button to run the query as shown here:

      6. Following the same instructions, populate the table using the following SQL:
        INSERT INTO STATES VALUES (1, “AL”, “Alabama”);
        INSERT INTO STATES VALUES (2, “AK”, “Alaska”);
        INSERT INTO STATES VALUES (3, “AZ”, “Arizona”);
        INSERT INTO STATES VALUES (4, “AR”, “Arkansas”);
        INSERT INTO STATES VALUES (5, “CA”, “California”);
        INSERT INTO STATES VALUES (6, “CO”, “Colorado”);
        INSERT INTO STATES VALUES (7, “CT”, “Connecticut”);
        INSERT INTO STATES VALUES (8, “DE”, “Delaware”);
        INSERT INTO STATES VALUES (9, “GL”, “Florida”);
        INSERT INTO STATES VALUES (10, “GA”, “Georgia”);
        INSERT INTO STATES VALUES (11, “HI”, “Hawaii”);
        INSERT INTO STATES VALUES (12, “ID”, “Idaho”);
        INSERT INTO STATES VALUES (13, “IL”, “Illinois”);
        INSERT INTO STATES VALUES (14, “IN”, “Indiana”);
        INSERT INTO STATES VALUES (15, “IA”, “Iowa”);
        INSERT INTO STATES VALUES (16, “KS”, “Kansas”);
        INSERT INTO STATES VALUES (17, “KY”, “Kentucky”);
        INSERT INTO STATES VALUES (18, “LA”, “Louisiana”);
        INSERT INTO STATES VALUES (19, “ME”, “Maine”);
        INSERT INTO STATES VALUES (20, “MD”, “Maryland”);
        INSERT INTO STATES VALUES (21, “MA”, “Massachussetts”);
        INSERT INTO STATES VALUES (22, “MI”, “Michigan”);
        INSERT INTO STATES VALUES (23, “MN”, “Minnesota”);
        INSERT INTO STATES VALUES (24, “MS”, “Mississippi”);
        INSERT INTO STATES VALUES (25, “MO”, “Missouri”);
        INSERT INTO STATES VALUES (26, “MT”, “Montana”);
        INSERT INTO STATES VALUES (27, “NE”, “Nebraska”);
        INSERT INTO STATES VALUES (28, “NV”, “Nevada”);
        INSERT INTO STATES VALUES (29, “NH”, “New Hampshire”);
        INSERT INTO STATES VALUES (30, “NJ”, “New Jersey”);
        INSERT INTO STATES VALUES (31, “NM”, “New Mexico”);
        INSERT INTO STATES VALUES (32, “NY”, “New York”);
        INSERT INTO STATES VALUES (33, “NC”, “North Carolina”);
        INSERT INTO STATES VALUES (34, “ND”, “North Dakota”);
        INSERT INTO STATES VALUES (35, “OH”, “Ohio”);
        INSERT INTO STATES VALUES (36, “OK”, “Oklahoma”);
        INSERT INTO STATES VALUES (37, “OR”, “Orgeon”);
        INSERT INTO STATES VALUES (38, “PA”, “Pennsylvania”);
        INSERT INTO STATES VALUES (39, “RI”, “Rhode Island”);
        INSERT INTO STATES VALUES (40, “SC”, “South Carolina”);
        INSERT INTO STATES VALUES (41, “SD”, “South Dakota”);
        INSERT INTO STATES VALUES (42, “TN”, “Tennessee”);
        INSERT INTO STATES VALUES (43, “TX”, “Texas”);
        INSERT INTO STATES VALUES (44, “UT”, “Utah”);
        INSERT INTO STATES VALUES (45, “VT”, “Vermont”);
        INSERT INTO STATES VALUES (46, “VA”, “Virginia”);
        INSERT INTO STATES VALUES (47, “WA”, “Washington”);
        INSERT INTO STATES VALUES (48, “WV”, “West Virignia”);
        INSERT INTO STATES VALUES (49, “WI”, “Wisconsin”);
        INSERT INTO STATES VALUES (50, “WY”, “Wyoming”);
    3. Create and configure the persistence unit
      1. Right-click on the newly created project and select “New”, “Entity Classes from Database …” as shown:

      2. In DataSource, select “New Data Source…” and enter the JNDI name “jndi/states” as shown:

      3. Select “STATES” table in “Available Tables:” and click on “Add >” and then “Next >”.
      4. Click on “Create Persistence Unit …”, take all the defaults and click on “Create”.
      5. Enter the package name as “server” and click on “Finish”.
      6. Expand “Configuration File”, open “persistence.xml”. Unselect “Include All Entity Classes” check box, click on “Add Class…”, select “server.States” and click on OK. The updated view looks like:

      7. Select the XML view and replace <properties/> with
            <properties>
                <prop
        erty name=”toplink.jdbc.user” value=”duke”/>
                <property name=”toplink.jdbc.password” value=”duke”/>
            </properties>

        The username and password values must match the ones specified during database creation. The updated “persistence.xml” looks like:

        <?xml version=”1.0″ encoding=”UTF-8″?>
        <persistence version=”1.0″ xmlns=”http://java.sun.com/xml/ns/persistence” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd”>
          <persistence-unit name=”AutocompletePU” transaction-type=”JTA”>
            <jta-data-source>jndi/states</jta-data-source>
            <class>server.States</class>
            <exclude-unlisted-classes>true</exclude-unlisted-classes>
            <properties>
              <property name=”toplink.jdbc.user” value=”duke”/>
              <property name=”toplink.jdbc.password” value=”duke”/>
            </properties>
          </persistence-unit>
        </persistence>
    4. Create a Servlet to perform the database operations
      1. Right-click on the project, select “New”, “Servlet”.
      2. Enter the class name as “StatesServlet” and package as “server” and click on “Finish”.
      3. Add the following fragment in the beginning of the class:
            EntityManager em;

            @Override
            public void init() throws ServletException {
                EntityManagerFactory emf = Persistence.createEntityManagerFactory(“AutocompletePU”);
                em = emf.createEntityManager();
            }

        Alternatively, you can use resource injection to populate the EntityManager. Use the following fragment, instead of the above, to achieve that:

            @PersistenceContext(unitName=”AutocompletePU”)
            EntityManager em;
      4. Replace the commented code in “processRequest” with the following fragment:
                    String abbrev = request.getParameter(“abbrev”);

                    List<States> list = em.createNamedQuery(“States.findByAbbrev”).
                            setParameter(“abbrev”, abbrev).
                            getResultList();

                    if (list.size() > 0) {
                        States s = list.get(0);
                        out.println(“Found ” + s.getName() + ” with abbrev \”" + abbrev + “\”");
                    } else {
                        out.println(“No matching state found with \”" + abbrev + “\”");
                    }

        and fix the imports by right-clicking in editor pane and selecting “Fix Imports”.

      5. Right-click on the project and select “Undeploy and Deploy”.

    Now let’s try it!

    Invoking “curl http://localhost:8080/Autocomplete/StatesServlet?abbrev=CA” shows the following output on command prompt:

    Found California with abbrev “CA”

    Alternatively, you can enter this URL in browser as well to see the output as:

    Invoking “http://localhost:8080/Autocomplete/StatesServlet?abbrev=CB” shows the output:

    Even though MySQL is used as the database in this case, any other database can be easily used for creating this portable PU.

    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 mysql jpa persistenceunit netbeans glassfish
    Technorati: totd mysql jpa persistenceunit netbeans glassfish jquery autocomplete

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

    July 24, 2008

    Job Opportunity in GlassFish Web Container Team

    Filed under: web2.0 — arungupta @ 5:00 am

    What’s common between

    • Close to 5 million downloads per year
    • > 1000 emails/month by users
    • Continuously growing adoption and
    • Hiring

    You are right – GlassFish is the answer!

    If you are a fresh graduate, then apply for GlassFish Scripting team. However if you have

    • Experience in Developing Web container and related web-tier technologies such as JSP, Servlets, Java Server Faces and Java Standard Tag Libraries
    • Like to define the direction of Web container in Java EE platform and GlassFish Application Server
    • Worked in the Open Source & distributed teams
    • Like to play “follow the leader” where you are the leader :)

    Then GlassFish team needs you. Apply now!

    Technorati: glassfish webtier jsp servlets jstl javaserverfaces job

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

    July 23, 2008

    FREE Hosting for Facebook & OpenSocial Developers – Social App Program

    Filed under: web2.0 — arungupta @ 5:45 am

    Are you developing Facebook and/or OpenSocial applications ?

    Would you like to deploy them and monetize before spending any money on infrastructure ?

    Social App Program is a new collaborative offering from Sun Microsystems and Joyent that allows you to do exactly that! It allows you to leverage Scalability and Cost-effectiveness of Joyent’s cloud powered by OpenSolaris on Sun’s renowned reliable servers and storage for deploying critical applications. And all this completely FREE for 12 months.

    This program is also accompanied with FREE Sun-Joyent Social Developer Days planned for 8 cities (San Francisco, Los Angeles, Seattle, Vancouver, Chicago, Boston, New York and Austin/Dallas) in the US later this year to learn and get hands-on experience on writing applications which can scale to million of users. Learn how to architect, develop and deploy web-scale applications on Cloud infrastructure.

    All details are available here. Also read the official press release.

    FREE infrastructure with FREE training for YOU to write Facebook/OpenSocial apps – cool!

    Is yours a startup company and under-equipped on infrastructure ? Join Startup Essentials today for FREE and discounted enterprise-class software, discounted partner hosting & storage and much more – apply online and membership FREE! Very minimal eligibility requirements and you can join inside the US or outside the US.

    Technorati: sun joyent facebook opensocial social web2.0 cloud opensolaris startup startupessentials

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

    July 21, 2008

    JRuby 1.1.3 released – Getting Started with GlassFish

    Filed under: web2.0 — arungupta @ 11:08 am

    JRuby 1.1.3 was released last week – download here. The highlights are:

    • 82 issues resolved since JRUby 1.1.2
    • RubyGem 1.2 (phew, finally Gem installation is much faster again :)
    • Bunch of Compatibility and Performance problems

    Going forward, JRuby point releases will be on a 3-4 week frequency. And you can always checkout the trunk and build yourself.

    Here are few simple steps to get you started:

    1. Download and unzip the distribution.
    2. Install Rails and GlassFish gem:
      ~/testbed/jruby-1.1.3 >./bin/jruby -S gem install rails glassfish –no-ri –no-rdoc
      JRuby limited openssl loaded. gem install jruby-openssl for full support.
      http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
      Successfully installed activesupport-2.1.0
      Successfully installed activerecord-2.1.0
      Successfully installed actionpack-2.1.0
      Successfully installed actionmailer-2.1.0
      Successfully installed activeresource-2.1.0
      Successfully installed rails-2.1.0
      Successfully installed glassfish-0.3.1-universal-java
      7 gems installed
    3. Create a new Rails app as:
      ~/testbed/jruby-1.1.3/samples/rails >../../bin/jruby -S rails helloworld -d mysql 
            create 
            create  app/controllers
            create  app/helpers
            create  app/models
            create  app/views/layouts
            create  config/environments
            create  config/initializers
            create  db
            create  doc
      . . .
            create  log/server.log
            create  log/production.log
            create  log/development.log
            create  log/test.log
    4. Run Rails application on GlassFish gem as:
      ~/testbed/jruby-1.1.3/samples/rails >../../bin/jruby -S glassfish_rails helloworld
      Jul 21, 2008 8:32:03 AM com.sun.enterprise.glassfish.bootstrap.ASMain main
      INFO: Launching GlassFish on HK2 platform
      Jul 21, 2008 8:32:03 AM com.sun.enterprise.glassfish.bootstrap.ASMainHK2 findDerbyClient
      INFO: Cannot find javadb client jar file, jdbc driver not available
      Jul 21, 2008 8:32:04 AM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
      INFO: Listening on port 3000
      Jul 21, 2008 8:32:04 AM com.sun.enterprise.v3.services.impl.GrizzlyEmbeddedHttpConfigurator configureSSL
      WARNING: pewebcontainer.all_ssl_protocols_disabled
      Jul 21, 2008 8:32:04 AM com.sun.enterprise.v3.services.impl.GrizzlyEmbeddedHttpConfigurator configureSSL
      WARNING: pewebcontainer.all_ssl_ciphers_disabled
      Jul 21, 2008 8:32:04 AM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
      INFO: Listening on port 3131
      Jul 21, 2008 8:32:04 AM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
      INFO: Listening on port 3838
      Jul 21, 2008 8:32:04 AM com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter setContextRoot
      INFO: Admin Console Adapter: context root: /admin
      Jul 21, 2008 8:32:05 AM com.sun.grizzly.jruby.RailsAdapter startRubyRuntimePool
      INFO: Starting Rails instances
      Jul 21, 2008 8:32:09 AM 
      SEVERE: JRuby limited openssl loaded. gem install jruby-openssl for full support.
      http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
      Jul 21, 2008 8:32:10 AM com.sun.grizzly.jruby.RubyObjectPool$1 run
      INFO: JRuby and Rails instance instantiation took : 5623ms
      Jul 21, 2008 8:32:10 AM org.glassfish.scripting.rails.RailsDeployer load
      INFO: Loading application helloworld at /
      Jul 21, 2008 8:32:10 AM com.sun.enterprise.v3.server.AppServerStartup run
      INFO: Glassfish v3 started in 7046 ms
    5. Create a scaffold as:


      ~/testbed/jruby-1.1.3/samples/rails/helloworld >../../../bin/jruby script/generate scaffold runner distance:float minutes:integer
      JRuby limited openssl loaded. gem install jruby-openssl for full support.
      http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
            exists  app/models/
            exists  app/controllers/
            exists  app/helpers/
            create  app/views/runners
            exists  app/views/layouts/
            exists  test/functional/
            exists  test/unit/
            exists  public/stylesheets/
            create  app/views/runners/index.html.erb
            create  app/views/runners/show.html.erb
            create  app/views/runners/new.html.erb
            create  app/views/runners/edit.html.erb
            create  app/views/layouts/runners.html.erb
            create  public/stylesheets/scaffold.css
            create  app/controllers/runners_controller.rb
            create  test/functional/runners_controller_test.rb
            create  app/helpers/runners_helper.rb
             route  map.resources :runners
        dependency  model
            exists    app/models/
            exists    test/unit/
            exists    test/fixtures/
            create    app/models/runner.rb
            create    test/unit/runner_test.rb
            create    test/fixtures/runners.yml
            create    db/migrate
            create    db/migrate/20080721153737_create_runners.rb
    6. Start MySQL database, create and migrate the database:
      ~/testbed/jruby-1.1.3/samples/rails/helloworld >../../../bin/jruby -S rake db:create
      (in /Users/arungupta/testbed/jruby-1.1.3/samples/rails/helloworld)
      ~
      /testbed/jruby-1.1.3/samples/rails/helloworld >../../../bin/jruby -S rake db:migrate
      (in /Users/arungupta/testbed/jruby-1.1.3/samples/rails/helloworld)
      == 20080721154435 CreateRunners: migrating ====================================
      — create_table(:runners)
         -> 0.0097s
      == 20080721154435 CreateRunners: migrated (0.0104s) ===========================

      Now “http://localhost:3000/runners” page is shown as:

      After adding couple of entries, the page looks like:

      Now, let’s try to run the same application on GlassFish v3 stand-alone build.

      TOTD #33 explains how to build GlassFish v3 workspace. Alternatively nightly or promoted builds can be downloaded as well.

    7. Start the v3 server as:
      ~/testbed/glassfish/v3/snapshot/glassfish >java -DJRUBY_HOME=/Users/arungupta/testbed/jruby-1.1.3 -jar modules/glassfish-10.0-SNAPSHOT.jar
      Jul 21, 2008 9:40:41 AM com.sun.enterprise.glassfish.bootstrap.ASMain main
      INFO: Launching GlassFish on Apache Felix OSGi platform
      Jul 21, 2008 9:40:41 AM com.sun.enterprise.glassfish.bootstrap.ASMainOSGi getSharedRepos
      INFO: /Users/arungupta/testbed/glassfish/v3/snapshot/glassfish/domains/domain1/lib does not exist

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

      . . .

      INFO: Started bundle org.glassfish.common.container-common [91]
      Jul 21, 2008 9:47:13 AM com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter setContextRoot
      INFO: Admin Console Adapter: context root: /admin
      Jul 21, 2008 9:47:13 AM OSGiModuleImpl loadClass
      INFO: Started bundle org.glassfish.deployment.deployment-common [71]
      Jul 21, 2008 9:47:13 AM com.sun.enterprise.v3.server.AppServerStartup run
      INFO: Glassfish v3 started in 1507 ms

    8. Deploy the application as:
      ~/testbed/jruby-1.1.3/samples/rails >~/testbed/glassfish/v3/snapshot/glassfish/bin/asadmin deploy helloworld

      Command deploy executed successfully.

      and the GlassFish console shows the following output:

      Jul 21, 2008 9:47:49 AM OSGiModuleImpl loadClass
      INFO: Started bundle org.glassfish.web.war-util [65]
      Jul 21, 2008 9:47:49 AM OSGiModuleImpl loadClass
      INFO: Started bundle org.glassfish.persistence.jpa-connector [25]
      Jul 21, 2008 9:47:49 AM OSGiModuleImpl loadClass
      INFO: Started bundle org.glassfish.scripting.gf-jruby-connector [13]
      Jul 21, 2008 9:47:49 AM OSGiModuleImpl loadClass
      INFO: Started bundle org.glassfish.core.security [22]
      Jul 21, 2008 9:47:49 AM OSGiModuleImpl loadClass
      INFO: Started bundle org.glassfish.web.gf-web-connector [86]
      Jul 21, 2008 9:47:49 AM OSGiModuleImpl loadClass
      INFO: Started bundle org.glassfish.connectors.gf-connectors-connector [53]
      Jul 21, 2008 9:47:49 AM com.sun.grizzly.jruby.RailsAdapter startRubyRuntimePool
      INFO: Starting Rails instances
      Jul 21, 2008 9:48:01 AM 
      SEVERE: JRuby limited openssl loaded. gem install jruby-openssl for full support.
      http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
      Jul 21, 2008 9:48:02 AM com.sun.grizzly.jruby.RubyObjectPool$1 run
      INFO: JRuby and Rails instance instantiation took : 12852ms
      Jul 21, 2008 9:48:02 AM org.glassfish.scripting.rails.RailsDeployer load
      INFO: Loading application helloworld at /helloworld
      Jul 21, 2008 9:48:02 AM com.sun.enterprise.v3.deployment.DeployCommand execute
      INFO: Deployment of helloworld done is 13326 ms

      The deployed application at “http://localhost:8080/helloworld/runners” looks like:

    Rails powered by the GlassFish Application Server explain in detail about the several benefits of using GlassFish for Rails development and deployment. Rails/GlassFish Deployment Stories gives a good idea of how to structure your own application.

    Are you using GlassFish for development or deployment of Rails ? Drop a comment on this blog.

    Technorati: rubyonrails jruby ruby glassfish v3 gem

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

    July 19, 2008

    600 StarBucks closing down – list available

    Filed under: General — arungupta @ 5:00 am
    StarBucks announced few days ago that they’ll close 600 stores in the US. It’s more real now as they announced the complete list. Luckily none of my stores are affected – at least this round :)

    Technorati: starbucks economy

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

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