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.net.InetSocketAddress;
38
39 import com.ericsson.research.transport.ws.WSException;
40 import com.ericsson.research.transport.ws.WSSecurityContext;
41 import com.ericsson.research.transport.ws.WSURI;
42
43 public class WSHixie75 extends WSAbstractProtocol implements WSConstants {
44
45 public WSHixie75(WSURI uri, WSSecurityContext securityContext) {
46 super(uri, securityContext);
47 }
48
49 protected WSAbstractHandshake getHandshake() {
50 if(this.handshake == null)
51 this.handshake = new WSHixie75Handshake(this);
52 return this.handshake;
53 }
54
55 public WSHixie75(WSSecurityContext securityContext) {
56 super(securityContext);
57 }
58
59 public void send(byte[] data) throws IOException {
60 if (this.state != OPEN)
61 throw new IOException(ILLEGAL_STATE+" "+this.getState());
62 new WSHixieFrame(WSAbstractFrame.BINARY_FRAME, data).serialize(this.getRawOutput());
63 }
64
65 public void send(String utf8String) throws IOException {
66 if (this.state != OPEN)
67 throw new IOException(ILLEGAL_STATE+" "+this.getState());
68 new WSHixieFrame(WSAbstractFrame.TEXT_FRAME, utf8String.getBytes(UTF_8)).serialize(this.getRawOutput());
69 }
70
71 protected WSAbstractFrame createEmptyFrame() {
72 return new WSHixieFrame();
73 }
74
75 protected void dispatchFrame(WSAbstractFrame frame) throws IOException, WSException {
76 switch (frame.getType()) {
77 case WSAbstractFrame.TEXT_FRAME:
78 this.wrapper.notifyMessage(new String(frame.getPayload(), UTF_8));
79 break;
80 case WSAbstractFrame.BINARY_FRAME:
81 this.wrapper.notifyMessage(frame.getPayload());
82 break;
83 default:
84 throw new WSException("Unknown frame type "+frame.getType());
85 }
86 }
87
88 public String toString() {
89 return "Hixie-75";
90 }
91
92 @Override
93 public InetSocketAddress getLocalSocketAddress()
94 {
95
96 return null;
97 }
98
99 @Override
100 public InetSocketAddress getRemoteSocketAddress()
101 {
102
103 return null;
104 }
105
106 }