|
1 | 1 | package org.java_websocket.drafts; |
2 | 2 |
|
| 3 | +import org.java_websocket.exceptions.InvalidHandshakeException; |
| 4 | +import org.java_websocket.handshake.ClientHandshake; |
| 5 | +import org.java_websocket.handshake.HandshakeBuilder; |
| 6 | +import org.java_websocket.handshake.ServerHandshakeBuilder; |
| 7 | + |
| 8 | +import java.text.SimpleDateFormat; |
| 9 | +import java.util.Calendar; |
| 10 | +import java.util.Locale; |
| 11 | +import java.util.TimeZone; |
| 12 | + |
3 | 13 | /** |
4 | 14 | * Implementation for the RFC 6455 websocket protocol |
5 | 15 | * This is the recommended class for your websocket connection |
6 | 16 | */ |
7 | 17 | public class Draft_6455 extends Draft_17 { |
8 | 18 |
|
| 19 | + @Override |
| 20 | + public HandshakeBuilder postProcessHandshakeResponseAsServer(ClientHandshake request, ServerHandshakeBuilder response) throws InvalidHandshakeException { |
| 21 | + super.postProcessHandshakeResponseAsServer(request, response); |
| 22 | + response.setHttpStatusMessage("Web Socket Protocol Handshake"); |
| 23 | + response.put("Server", "TooTallNate Java-WebSocket"); |
| 24 | + response.put("Date", getServerTime()); |
| 25 | + return response; |
| 26 | + } |
| 27 | + |
9 | 28 | @Override |
10 | 29 | public Draft copyInstance() { |
11 | 30 | return new Draft_6455(); |
12 | 31 | } |
| 32 | + |
| 33 | + private String getServerTime() { |
| 34 | + Calendar calendar = Calendar.getInstance(); |
| 35 | + SimpleDateFormat dateFormat = new SimpleDateFormat( |
| 36 | + "EEE, dd MMM yyyy HH:mm:ss z", Locale.US); |
| 37 | + dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); |
| 38 | + return dateFormat.format(calendar.getTime()); |
| 39 | + } |
13 | 40 | } |
0 commit comments