Lines 20-25
Link Here
|
20 |
import java.io.InputStream; |
20 |
import java.io.InputStream; |
21 |
import java.io.InputStreamReader; |
21 |
import java.io.InputStreamReader; |
22 |
import java.io.Reader; |
22 |
import java.io.Reader; |
|
|
23 |
import java.nio.ByteBuffer; |
23 |
import java.nio.charset.MalformedInputException; |
24 |
import java.nio.charset.MalformedInputException; |
24 |
import java.nio.charset.UnmappableCharacterException; |
25 |
import java.nio.charset.UnmappableCharacterException; |
25 |
|
26 |
|
Lines 113-119
Link Here
|
113 |
try { |
114 |
try { |
114 |
// TODO User defined extensions may define values for rsv |
115 |
// TODO User defined extensions may define values for rsv |
115 |
if (frame.getRsv() > 0) { |
116 |
if (frame.getRsv() > 0) { |
116 |
getWsOutbound().close( |
117 |
closeOutboundConnection( |
117 |
Constants.STATUS_PROTOCOL_ERROR, null); |
118 |
Constants.STATUS_PROTOCOL_ERROR, null); |
118 |
return SocketState.CLOSED; |
119 |
return SocketState.CLOSED; |
119 |
} |
120 |
} |
Lines 127-133
Link Here
|
127 |
new InputStreamReader(wsIs, new Utf8Decoder()); |
128 |
new InputStreamReader(wsIs, new Utf8Decoder()); |
128 |
onTextData(r); |
129 |
onTextData(r); |
129 |
} else if (opCode == Constants.OPCODE_CLOSE){ |
130 |
} else if (opCode == Constants.OPCODE_CLOSE){ |
130 |
getWsOutbound().close(frame); |
131 |
closeOutboundConnection(frame); |
131 |
return SocketState.CLOSED; |
132 |
return SocketState.CLOSED; |
132 |
} else if (opCode == Constants.OPCODE_PING) { |
133 |
} else if (opCode == Constants.OPCODE_PING) { |
133 |
getWsOutbound().pong(frame.getPayLoad()); |
134 |
getWsOutbound().pong(frame.getPayLoad()); |
Lines 135-161
Link Here
|
135 |
// NO-OP |
136 |
// NO-OP |
136 |
} else { |
137 |
} else { |
137 |
// Unknown OpCode |
138 |
// Unknown OpCode |
138 |
getWsOutbound().close( |
139 |
closeOutboundConnection( |
139 |
Constants.STATUS_PROTOCOL_ERROR, null); |
140 |
Constants.STATUS_PROTOCOL_ERROR, null); |
140 |
return SocketState.CLOSED; |
141 |
return SocketState.CLOSED; |
141 |
} |
142 |
} |
142 |
} catch (MalformedInputException mie) { |
143 |
} catch (MalformedInputException mie) { |
143 |
// Invalid UTF-8 |
144 |
// Invalid UTF-8 |
144 |
getWsOutbound().close(Constants.STATUS_BAD_DATA, null); |
145 |
closeOutboundConnection(Constants.STATUS_BAD_DATA, null); |
145 |
return SocketState.CLOSED; |
146 |
return SocketState.CLOSED; |
146 |
} catch (UnmappableCharacterException uce) { |
147 |
} catch (UnmappableCharacterException uce) { |
147 |
// Invalid UTF-8 |
148 |
// Invalid UTF-8 |
148 |
getWsOutbound().close(Constants.STATUS_BAD_DATA, null); |
149 |
closeOutboundConnection(Constants.STATUS_BAD_DATA, null); |
149 |
return SocketState.CLOSED; |
150 |
return SocketState.CLOSED; |
150 |
} catch (IOException ioe) { |
151 |
} catch (IOException ioe) { |
151 |
// Given something must have gone to reach this point, this |
152 |
// Given something must have gone to reach this point, this |
152 |
// might not work but try it anyway. |
153 |
// might not work but try it anyway. |
153 |
getWsOutbound().close(Constants.STATUS_PROTOCOL_ERROR, null); |
154 |
closeOutboundConnection(Constants.STATUS_PROTOCOL_ERROR, null); |
154 |
return SocketState.CLOSED; |
155 |
return SocketState.CLOSED; |
155 |
} |
156 |
} |
156 |
frame = wsIs.nextFrame(false); |
157 |
frame = wsIs.nextFrame(false); |
157 |
} |
158 |
} |
158 |
return SocketState.UPGRADED; |
159 |
return SocketState.UPGRADED; |
|
|
160 |
} |
161 |
|
162 |
private void closeOutboundConnection(int status, ByteBuffer data) throws IOException { |
163 |
try { |
164 |
getWsOutbound().close(status, data); |
165 |
} finally { |
166 |
onClose(status); |
167 |
} |
168 |
} |
169 |
|
170 |
private void closeOutboundConnection(WsFrame frame) throws IOException { |
171 |
try { |
172 |
getWsOutbound().close(frame); |
173 |
} finally { |
174 |
onClose(Constants.OPCODE_CLOSE); |
175 |
} |
176 |
} |
177 |
|
178 |
@Override |
179 |
public void onUpgradeComplete() { |
180 |
onOpen(outbound); |
181 |
} |
182 |
|
183 |
/** |
184 |
* Intended to be overridden by sub-classes that wish to be notified |
185 |
* when the outbound connection is established. |
186 |
* |
187 |
* @param outbound The outbound WebSocket connection. |
188 |
*/ |
189 |
protected void onOpen(WsOutbound outbound) { |
190 |
} |
191 |
|
192 |
/** |
193 |
* Intended to be overridden by sub-classes that wish to be notified |
194 |
* when the outbound connection is closed. |
195 |
* |
196 |
* @param status The status code of the close reason. |
197 |
*/ |
198 |
protected void onClose(int status) { |
159 |
} |
199 |
} |
160 |
|
200 |
|
161 |
|
201 |
|