Java EE 7 SDK |
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. |
The sample application is built and deployed as a WAR file.
The web module consists of the following elements:
MessageBodyWriter
implementations for
Message
and ListMessage
, which are also stateless EJBs,
session, or singleton beans.
previous-response
and
this-response
.index.html
page (JavaScript must be enabled). The application control is the following:
LIST ALL MESSAGES
button to see all
messages. This command is executed automaticaly when you load the main
page.
GET MESSAGE
button to see a particular message.
DELETE MESSAGE
button to delete a particular message.
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.
response headers
that displays headers of
the response. The filters add the headers last-response
and this-response
.
This sample application demonstrates the following key features:
Filter
Interceptor
ExceptionMapper
MessageBodyWriter
@Path
@Singleton
@GET
@POST
@DELETE
@EJB
@Stateless
@Singleton
Perform the following steps to build, deploy, and run the application:
samples_install_dir
is the sample application base directory. Go to: samples_install_dir/javaee7/rest/message-board
.
run
outcome.
mvn clean verify cargo:run
http://localhost:8080/message-board
.clean
outcome to undeploy the sample application and to remove the temporary directories such as
build
and dist
.
mvn clean
If you have problems when running the application, refer to the troubleshooting document.
Copyright © 1997-2010 Oracle and/or its affiliates. All rights reserved.