Java EE 7 SDK |
This sample application resembles an auction site that enables users to submit real-time bids.
This sample uses the Java API for WebSocket (JSR 356) to demonstrate how to use encoders and decoders for WebSocket messages. Refer to the WebSocket Echo sample or the WebSocket Draw sample on the samples main page for how to use the basic functionality in the Java API for WebSocket.
Encoders transform Java objects into WebSocket messages; decoders read incoming WebSocket messages into Java objects. Encoders and decoders enable application developers to use any custom Java type as an argument of annotated methods in a WebSocket endpoint.
The front page of this sample shows a log-in form that leads to an auction selection list. After choosing an auction, the application takes you to the Auction Detail page, where you can wait for that particular auction to start or bid if the auction is already in progress. Multiple users can bid on the same auction, and the application provides all connected users with details about the new bids and the current price.
This sample application demonstrates the following key features:
Creating a WebSocket server endpoint and registering methods that handle events using the following annotations from the Java API for WebSocket:
@ServerEndpoint
@OnMessage
@OnOpen
@OnClose
Using encoders and decoders for WebSocket messages.
Perform the following steps to build, deploy, and run the application:
app_dir
is the sample application base directory:
samples_install_dir/javaee7/websocket/auction
.run
outcome.
mvn clean verify cargo:run
http://localhost:8080/websocket-auction
. 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-2013 Oracle and/or its affiliates. All rights reserved.