org.glassfish.jersey.examples.sseitemstore
Class ItemStoreResource

java.lang.Object
  extended by org.glassfish.jersey.examples.sseitemstore.ItemStoreResource

@Path(value="items")
public class ItemStoreResource
extends Object

A resource for storing named items.

Author:
Marek Potociar (marek.potociar at oracle.com)

Constructor Summary
ItemStoreResource()
           
 
Method Summary
 void addItem(String name)
          Add new item to the item store.
 EventOutput itemEvents(int lastEventId)
          Connect or re-connect to SSE event stream.
 String listItems()
          List all stored items.
 String processCommand(String command)
          Receive & process commands sent by the test client that control the internal resource state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ItemStoreResource

public ItemStoreResource()
Method Detail

listItems

@GET
@Produces(value="text/plain")
public String listItems()
List all stored items.

Returns:
list of all stored items.

processCommand

@POST
@Path(value="commands")
public String processCommand(String command)
Receive & process commands sent by the test client that control the internal resource state. Following is the list of recognized commands:

Parameters:
command - command to be processed.
Returns:
message about processing result.
Throws:
javax.ws.rs.BadRequestException - in case the command is not recognized or not specified.

itemEvents

@GET
@Path(value="events")
@Produces(value="text/event-stream")
public EventOutput itemEvents(@HeaderParam(value="Last-Event-ID")@DefaultValue(value="-1")
                                                int lastEventId)
Connect or re-connect to SSE event stream.

Parameters:
lastEventId - Value of custom SSE HTTP header. Defaults to -1 if not set.
Returns:
new SSE event output stream representing the (re-)established SSE client connection.
Throws:
javax.ws.rs.InternalServerErrorException - in case replaying missed events to the reconnected output stream fails.
javax.ws.rs.ServiceUnavailableException - in case the reconnect delay is set to a positive value.

addItem

@POST
public void addItem(@FormParam(value="name")
                         String name)
Add new item to the item store. Invoking this method will fire 2 new SSE events - 1st about newly added item and 2nd about the new item store size.

Parameters:
name - item name.


Copyright © 2007-2013, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.