Java EE 7 SDK

Samples Main Page

# The Auction WebSocket Sample Application

This sample application resembles an auction site that enables users to submit real-time bids.

## Description

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.

## Key Features

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.

## 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. `app_dir` is the sample application base directory: `samples_install_dir/javaee7/websocket/auction`.
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/websocket-auction`.
   (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-2013 Oracle and/or its affiliates. All rights reserved.