Sun GlassFish Enterprise Server |
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 |
The application is built and deployed as a WAR file.
The web module consists of:
index.html
page (javascript must be enabled). The application control is
straightforward:
LIST ALL MESSAGES
button to see all
messages. This command is executed automaticaly when you hit the main
page. GET MESSAGE
button to see one particular message. DELETE MESSAGE
button to delete one particular message. ADD MESSAGE
button to add message. Message will be added as first.
Perform the following steps to build, deploy, and run the
application:
app_dir
is the sample application base
directory: samples_install_dir/javaee6/rest/message-board-war
.
Change directory to app_dir.
all
target.
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
app_dir> ant
clean
Perform the following steps to build, deploy, and run the application using NetBeans IDE:
message-board-war
.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
.
init:Browser output
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)
If you run into a problem, refer the troubleshooting document.
Copyright © 2009 Sun Microsystems, Inc. All rights reserved.