WebSocket / cleaning up example

This commit is contained in:
Joakim Erdfelt 2013-09-12 12:23:53 -07:00
parent cda13d76d4
commit eecc17ee67
1 changed files with 3 additions and 2 deletions

View File

@ -32,8 +32,7 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.jsr356.server.StackUtil;
@ServerEndpoint(value = "/echo/beans/date", decoders =
{ DateDecoder.class })
@ServerEndpoint(value = "/echo/beans/date", decoders = { DateDecoder.class }, encoders = { DateEncoder.class })
public class DateTextSocket
{
private static final Logger LOG = Log.getLogger(DateTextSocket.class);
@ -46,6 +45,7 @@ public class DateTextSocket
this.session = session;
}
// The decoder declared in the @ServerEndpoint will be used
@OnMessage
public void onMessage(Date d) throws IOException
{
@ -56,6 +56,7 @@ public class DateTextSocket
else
{
String msg = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT).format(d);
// The encoder declared in the @ServerEndpoint will be used
session.getAsyncRemote().sendText(msg);
}
}