1 package com.ericsson.research.transport.ws.spi;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 import java.io.IOException;
37 import java.io.OutputStream;
38
39 import com.ericsson.research.transport.ws.WSException;
40 import com.ericsson.research.transport.ws.WSSecurityContext;
41
42 public class WSPrefetcherHandshake extends WSAbstractHandshake implements WSConstants {
43
44 private final WSSecurityContext securityContext;
45
46 public WSPrefetcherHandshake(WSSecurityContext securityContext) {
47 super(null);
48 this.securityContext = securityContext;
49 }
50
51 public void preambleRead() throws WSException {}
52
53 public void headersRead() throws WSException {
54 if(getHeader(SEC_WEBSOCKET_VERSION_HEADER)!=null) {
55 if("13".equals(getHeader(SEC_WEBSOCKET_VERSION_HEADER)))
56 protocol = new WSRfc6455(securityContext);
57 else
58 if("8".equals(getHeader(SEC_WEBSOCKET_VERSION_HEADER)))
59 protocol = new WSHybi10(securityContext);
60 } else {
61 if(getHeader(SEC_WEBSOCKET_KEY1_HEADER) != null && getHeader(SEC_WEBSOCKET_KEY2_HEADER) != null)
62 protocol = new WSHixie76(securityContext);
63 else
64 if(getHeader(SEC_WEBSOCKET_KEY1_HEADER) == null && getHeader(SEC_WEBSOCKET_KEY2_HEADER) == null && getHeader(SEC_WEBSOCKET_KEY_HEADER) == null)
65 protocol = new WSHixie75(securityContext);
66 }
67 if(protocol == null)
68 throw new WSException("Could not determine WebSocket client version");
69 WSAbstractHandshake handshake = protocol.getHandshake();
70 expectedHandshakeBodyLength = handshake.expectedHandshakeBodyLength;
71 handshake.preamble = preamble;
72 handshake.headers = headers;
73 handshake.preambleRead();
74 handshake.headersRead();
75 }
76
77 public void bodyRead() throws WSException {
78 protocol.getHandshake().body = body;
79 protocol.getHandshake().bodyRead();
80 }
81
82 public void sendResponse() throws IOException {
83 protocol.getHandshake().sendResponse();
84 }
85
86 public void sendHandshake(OutputStream os) throws IOException {
87 protocol.getHandshake().sendHandshake(os);
88 }
89
90 }