Skip to main content

Screencast #Web11: Travel Map - Another Real-life app using jMaki & Jersey

Posted by arungupta on January 1, 2008 at 3:52 PM PST

In
my role of Technology Evangelist, I get the opportunity to meet a lot of
community (folks like you :) all around the world. In the year 2007, I
represented GlassFish
(and related technologies - Metro,
jMaki and href="http://jersey.dev.java.net">Jersey)
at multiple
conferences
. This blog introduces a  new real-life
application that plots all the places I visited this year on a
jMaki-wrapped
Google Map widget. Clicking on the marker shows more information about
the event such as dates and the blog entry covering the event.

Play the video below to see how the application looks like.

Here is the architecture of this application:

alt="travel map architecture" title="Travel Map Architecture"
src="http://blogs.sun.com/arungupta/resource/images/travel-map-architecture.png">

It consists of a server-side and a client-side applications -
developed as NetBeans
projects.

  1. Server-side project - A RESTful Web service endpoint that
    provides resource represenations
    for all the events attended and associated meta information such as
    date and blog URLs. This endpoint is created using href="http://jersey.dev.java.net">Jersey.
  2. Client-side project - A href="http://ajax.dev.java.net">jMaki-enabled Web
    application that consumes the representations generated
    by the RESTful Web service and plots the information on a jMaki-wrapped
    Google Map widget.

Both the server-side and client-side are deployed on href="http://glassfish.dev.java.net">GlassFish.

This
is only a sample application so optimizations are certainly possible
and corner cases (such as no blog entry for a particular visit) are not
accounted for. But the application still demonstrates the concept. The
fully built application looks like as shown below:

title="Arun's Travel Map 2007" alt="Arun's Travel Map 2007"
src="http://blogs.sun.com/arungupta/resource/images/travel-map-2007.png">

My
first presentation in this role was Sun Tech Days Atlanta (highlighted
in the image). This application generates an interactive Google Map so
feel free to zoom in/out and click 

And one last thing before we build the application. Here is
the list of technologies and associated concepts used to build this
application:

  1. Jersey
    1. Shows an example of how RESTful Web services can be
      easily generated from JPA Entity Classes.
    2. Shows how all the resource representations (instead of
      reference to individual resources) can be returned by a Jersey endpoint.
  2. jMaki
    1. Shows how to consume XML data from an href="http://blogs.sun.com/arungupta/entry/jmaki_accessing_external_services">external
      service (RESTful Web service endpoint) in this case.
    2. Shows how the underlying data model of a widget (Google
      Map in this case) can be accessed and manipulated.
  3. GlassFish
    1. All
      the applications are deployed on GlassFish - implicit in the
      development/deplyment process through seamless integration with
      NetBeans.
  4. NetBeans 6
    1. Used for generation of RESTful Web services from JPA
      Entity Classes.
    2. Used for generating/deploying jMaki projects and
      drag-and-drop of jMaki-wrapped widgets.
  5. JavaScript Closures - to persist the state for asynchronous
    callback functions
  6. JavaScript DOM processing - to process the XML data
    received from Jersey endpoint.
  7. Google Maps API
    1. Generate meaningful markers on each location
    2. Populate Google Map from a RESTful Web service endpoint
  8. Java Persistence API - to retrieve data from the database.

And finally, lets build this application. Lets build the
RESTful Web service endpoint project first.

  1. Create and Populate the Database
    1. In the NetBeans IDE, go to Services tab, and connect to
      the database with URL "
      jdbc:derby://localhost:1527/sample
      [app on APP]
      " (right-click and select "Connect...").
    2. Right-click on this database and select "
      Execute
      Command...
      " and create a table by giving the following
      command:



      create table EVENTS (id int GENERATED ALWAYS AS
      IDENTITY,

       
                       
      event_name varchar(255),

                 
              dates varchar(20),

                         
      venue varchar(255),

                         
      blogs varchar(2056),

                 
              PRIMARY KEY (id))




      Notice,
      the "id" column is marked as IDENTITY that instructs the database to
      auto generate the values for this column and increment by 1 (default)
      for each row. This column is also marked as the primary key.
    3. Again right-click on the database and select "
      Execute
      Command...
      " to add data to the table by giving the
      following command:



      INSERT INTO EVENTS (event_name, dates, venue,
      blogs) VALUES('SunTech Days - Atlanta', 'Jan 16 - Jan 17',
      'Cobb Galleria Center, Two
      Galleria Parkway, Atlanta, Georgia, 30339',
      'http://blogs.sun.com/arungupta/entry/wsit_and_web_2_0');

      INSERT
      INTO EVENTS (event_name, dates, venue, blogs) VALUES('jMaki Day', '
      Feb 23', '4150
      Network Circle Santa Clara, CA 95054',
      'http://blogs.sun.com/arungupta/entry/sun_internal_jmaki_day_review');

      INSERT
      INTO EVENTS (event_name, dates, venue, blogs) VALUES('Ajax World - New
      York', 'Mar 19 - Mar 21', 'The
      Roosevelt Hotel, 45 E 45th St, New York, NY 10017',
      'http://blogs.sun.com/arungupta/entry/sun_ajax_world');

      INSERT
      INTO
      EVENTS (event_name, dates, venue, blogs) VALUES('The Server Side Java
      Symposium - Las Vegas', 'Mar 22', '3355 Las Vegas Blvd. South
      Las
      Vegas, NV 89109',
      'http://blogs.sun.com/arungupta/entry/sun_the_server_side_java,
      http://blogs.sun.com/arungupta/entry/tango_at_venetian_las_vegas');

      INSERT
      INTO EVENTS (event_name, dates, venue, blogs) VALUES('JavaOne - San
      Francisco', 'May 7 - May 11', 'Moscone
      Center, 747 Howard Street, San Francisco, CA 94103',
      'http://blogs.sun.com/arungupta/entry/slides_for_ts_4865,
      http://blogs.sun.com/arungupta/entry/javaone_2007_day_1_finished,
      http://blogs.sun.com/arungupta/entry/javaone_2007_day_1,
      http://blogs.sun.com/arungupta/entry/javascript_everywhere_javaone_2007_...,
      http://blogs.sun.com/arungupta/entry/excel_using_wsit_javaone_2007,
      http://blogs.sun.com/arungupta/entry/ts_4865_takes_two_to,
      http://blogs.sun.com/arungupta/entry/communityone_glassfish_day_report,
      http://blogs.sun.com/arungupta/entry/javaone_2007_backstage,
      http://blogs.sun.com/arungupta/entry/javaone_2007_is_almost_here,
      http://blogs.sun.com/arungupta/entry/my_javaone_2007_picks');

      INSERT
      INTO EVENTS (event_name, dates, venue, blogs) VALUES('Rails Conf -
      Portland', 'May 17 - May 20', '777 NE MLK, Jr. Blvd. Portland,
      OR
      97232',
      'http://blogs.sun.com/arungupta/entry/tim_bray_s_keynote_session,
      http://blogs.sun.com/arungupta/entry/sun_rails_conf_2007_keep,
      http://blogs.sun.com/arungupta/entry/getting_started_with_jruby_tutorial,
      http://blogs.sun.com/arungupta/entry/jmaki_netbeans_and_glassfish_in');

      INSERT
      INTO EVENTS (event_name, dates, venue, blogs) VALUES('Google Developer
      Day - San Jose', 'May 31', '150 W San Carlos St San Jose, CA 95113',
      'http://blogs.sun.com/arungupta/entry/google_developer_day_report');

      INSERT
      INTO EVENTS (event_name, dates, venue, blogs) VALUES('Mashup Camp -
      Mountain View', 'Jul 18 - Jul 19', 'Computer History Museum, 1401 N
      Shoreline Blvd., Mountain View, CA 94043',
      'http://blogs.sun.com/arungupta/entry/jmaki_at_mashup_camp_report,
      http://blogs.sun.com/arungupta/entry/jmaki_mashup_camp');

      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('OSCON -
      Portland',
      'Jul 23 - Jul 27', '777 NE MLK, Jr. Blvd. Portland, OR 97232',
      'http://blogs.sun.com/arungupta/entry/jmaki_oscon');

      INSERT
      INTO EVENTS (event_name, dates, venue, blogs) VALUES('JRuby Hack Day -
      San Francisco', 'Aug 8', '1201 8th St, San Francisco, CA 94107',
      'http://blogs.sun.com/arungupta/entry/jruby_on_rails_hackday_report,
      http://blogs.sun.com/arungupta/entry/learn_jruby_on_rails_free');

      INSERT
      INTO EVENTS (event_name, dates, venue, blogs) VALUES('Rich Web
      Experience - San Jose', 'Sep 6 - Sep 8', '170 S Market St, San
      Jose,
      CA 95113',
      'http://blogs.sun.com/arungupta/entry/the_rich_web_experience_2007,
      http://blogs.sun.com/arungupta/entry/jmaki_javafx_the_rich_web');

      INSERT
      INTO EVENTS (event_name, dates, venue, blogs) VALUES('Rails Conf Europe
      - Berlin', 'Sep 17 - Sep 19', 'Maritim Pro Arte,
      Friedrichstrasse 151,
      10117 Berlin',
      'http://blogs.sun.com/arungupta/entry/rails_conf_europe_2007_day2,
      http://blogs.sun.com/arungupta/entry/rails_conf_europe_2007_day1,
      http://blogs.sun.com/arungupta/entry/rails_conf_europe_2007_day,
      http://blogs.sun.com/arungupta/entry/jmaki_netbeans_and_glassfish_in1');

      INSERT
      INTO EVENTS (event_name, dates, venue, blogs) VALUES('Sun Tech Days -
      Rome', 'Sep 24 - Sep 25', 'Meli

      Related Topics >>