Java EE 7 SDK 

Samples Main Page

The Message Board JAX-RS Sample Application

This sample demonstrates how to use no-interface EJB session beans as RESTful resource classes deployed as a web application.

MessageBoard resembles a message board like those in aiports and train stations. MessageBoard stores messages: every new message is placed at the top and gets an unique message id.

If configured properly, the page http://localhost:8080/message-board opens in a web browser after invoking the run Maven target.

The following table lists the mapping of the URI paths:

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

Application Structure

The sample application is built and deployed as a WAR file.

Web Module

The web module consists of the following elements:

The starting point of the application is the main index.html page (JavaScript must be enabled). The application control is the following:
  1. Click the LIST ALL MESSAGES button to see all messages. This command is executed automaticaly when you load the main page.
  2. Select the message number and click the GET MESSAGE button to see a particular message.
  3. Select the message number and click the DELETE MESSAGE button to delete a particular message.
  4. Fill in the message input box and click the ADD MESSAGE button to add a message. The message will be added as the first. Use any not valid characters (e.g. '/*+') to check that they are removed by the interceptor.
The page contains the section response headers that displays headers of the response. The filters add the headers last-response and this-response.

Key Features

This sample application demonstrates the following key features:

Building, Deploying, and Running the Application

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

  1. Set up your build environment and configure the application server with which the build system has to work by following the common build instructions.
  2. samples_install_dir is the sample application base directory. Go to: samples_install_dir/javaee7/rest/message-board.
  3. Build, deploy, and run the sample application using the run outcome.

    mvn clean verify cargo:run

  4. The front page of this sample is at http://localhost:8080/message-board.
    (The port number might vary.)
  5. Use the clean outcome to undeploy the sample application and to remove the temporary directories such as build and dist.

    mvn clean

Troubleshooting

If you have problems when running the application, refer to the troubleshooting document.


 

Copyright © 1997-2010 Oracle and/or its affiliates. All rights reserved.