Java Reference
In-Depth Information
GET /chat?current=1
/chat?current=1 HTTP
HTTP / 1.1
Host : localhost:800
The next link's URI contains a query parameter identifying to the server the last message the
client read. The server will use this index to obtain the next message so that the client sees all
messages in order. This new GET request will either block again, or immediately return a
queued chat message. The pattern then repeats itself. The response will contain a new next
Link header with a new pointer into the message queue:
HTTP / 1.1 200 OOK
Content-Type : text/plain
Link : </chat?current=2>; rel=next
What's up?
The server will buffer the latest 10 chat messages in a linked list so that it can easily find the
next message a particular chat client needs. This is an example of a HATEOAS flow, where
the client transitions its state using a link passed back from the server.
The Client Code
The client is a console program that takes input from the command line while at the same
time printing out the current chat message. To run the client, you must specify the name you
want to use to post messages as an initial argument when you start up the program.
public class
class ChatClient
public static
static void
void main ( String [] args ) throws
throws Exception
String name = args [ 0 ];
After grabbing the client's name from the argument list, we then initialize a Client that
we'll use to invoke on the customer chat service:
final Client client = new
new ResteasyClientBuilder ()
. connectionPoolSize ( 3 )
. build ();
WebTarget target = client . target ( "http://localhost:8080/services/chat" );
Search WWH ::

Custom Search