Sun GlassFish Enterprise Server 

Samples Main Page

The MessageBoard Application

This sample demonstrates the possibility to use no-interface EJB session beans as RESTful resource classes deployed as a servlet.

MessageBoard represents message boards you may know from aiports or train stations. It stores messages and every new added message is placed on top and gets an unique message id.

If configured properly, page http://localhost:8080/message-board-war will be opened after invoking the run target.

The mapping of the URI path space is presented in the following table:

URI path Resource class HTTP method Description
/message-board-war --- GET Simple html/ajax client
/message-board-war/app/messages MessageBoardResourceBean GET Returns first ten messsages
/message-board-war/app/messages/{id} MessageBoardResourceBean GET Returns message with uniqueId = {id} or returns HTTP 404 if message does not exist
/message-board-war/app/messages/{id} MessageBoardResourceBean DELETE Deletes message with uniqueId = {id} or returns HTTP 404 if message does not exist
/message-board-war/app/messages/
(with message as request entity)
MessageBoardResourceBean POST Creates new message and allocates unique id for it

Application Structure

The application is built and deployed as a WAR file.

Web Module

The web module consists of:

The starting point of the application is the main index.html page (javascript must be enabled). The application control is straightforward:
  1. Click the LIST ALL MESSAGES button to see all messages. This command is executed automaticaly when you hit the main page.
  2. Select message number and click the GET MESSAGE button to see one particular message.
  3. Select message number and click the DELETE MESSAGE button to delete one particular message.
  4. Fill in message input box and click the ADD MESSAGE button to add message. Message will be added as first.

Building, Deploying, and Running the Application

Perform the following steps to build, deploy, and run the application:

  1. Setup your build environment and configure the application server with which the build system has to work by following the common build instructions.
  2. app_dir is the sample application base directory: samples_install_dir/javaee6/rest/message-board-war.
  3. Change directory to app_dir.
  4. Build, deploy, and run the sample application using the all target.
  5. app_dir> ant all

    You can replace the ant all command with the following set of commands:

    app_dir> ant default compiles and packages the application

    app_dir> ant deploy deploys it to application server

  6. Use the target clean to undeploy the sample application and to remove the temporary directories like build and dist.

    app_dir> ant clean

Building, Deploying, and Running the Application in NetBeans IDE

Perform the following steps to build, deploy, and run the application using NetBeans IDE:

  1. Refer to the common build instructions for setting up NetBeans IDE and Sun GlassFish Enterprise Server.
  2. In the NetBeans IDE, choose File → Open Project (Ctrl-Shift-O) and select message-board-war.
  3. Right click message-board-war and select Run Project to build, deploy, and run the project. If configured properly, the IDE opens the browser with the following URL: http://localhost:8080/message-board-war.
    Sample output is as follows:
    NetBeans IDE output
    init:
    deps-module-jar:
    deps-ear-jar:
    deps-jar:
    library-inclusion-in-archive:
    library-inclusion-in-manifest:
    compile:
    compile-jsps:
    Starting GlassFish v3 Prelude
    GlassFish v3 Prelude is running.
    Incrementally deploying message-board-war
    Completed incremental distribution of message-board-war
    run-deploy:
    Browsing: http://localhost:8080/message-board-war/
    run-display-browser:
    run:
    BUILD SUCCESSFUL (total time: 11 seconds)
    Browser output

    MessageBoard sample

    Message id#:
    Message id#:
    Message:

    MessageBoard

    query:

    GET app/messages

    result

    CREATED: Thu Jan 01 01:00:02 CET 1970 ID: 2 MESSAGE: msg2 link
    CREATED: Thu Jan 01 01:00:01 CET 1970 ID: 1 MESSAGE: msg1 link
    CREATED: Thu Jan 01 01:00:00 CET 1970 ID: 0 MESSAGE: msg0 link

Troubleshooting

If you run into a problem, refer the troubleshooting document.

 

Copyright © 2009 Sun Microsystems, Inc. All rights reserved.