ASF Bugzilla – Attachment 28408 Details for
Bug 51181
Add support for Web Sockets
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Overrides for connection open and close
Overrides_for_connection_open_and_close_.patch (text/plain), 4.87 KB, created by
Johno Crawford
on 2012-03-01 19:13:34 UTC
(
hide
)
Description:
Overrides for connection open and close
Filename:
MIME Type:
Creator:
Johno Crawford
Created:
2012-03-01 19:13:34 UTC
Size:
4.87 KB
patch
obsolete
>Index: java/org/apache/catalina/websocket/StreamInbound.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- java/org/apache/catalina/websocket/StreamInbound.java (revision 1295334) >+++ java/org/apache/catalina/websocket/StreamInbound.java (revision ) >@@ -20,6 +20,7 @@ > import java.io.InputStream; > import java.io.InputStreamReader; > import java.io.Reader; >+import java.nio.ByteBuffer; > import java.nio.charset.MalformedInputException; > import java.nio.charset.UnmappableCharacterException; > >@@ -83,6 +84,7 @@ > public final void setUpgradeOutbound(UpgradeOutbound upgradeOutbound) { > outbound = new WsOutbound(upgradeOutbound, outboundByteBufferSize, > outboundCharBufferSize); >+ onOpen(outbound); > } > > >@@ -113,7 +115,7 @@ > try { > // TODO User defined extensions may define values for rsv > if (frame.getRsv() > 0) { >- getWsOutbound().close( >+ closeOutboundConnection( > Constants.STATUS_PROTOCOL_ERROR, null); > return SocketState.CLOSED; > } >@@ -127,7 +129,7 @@ > new InputStreamReader(wsIs, new Utf8Decoder()); > onTextData(r); > } else if (opCode == Constants.OPCODE_CLOSE){ >- getWsOutbound().close(frame); >+ closeOutboundConnection(frame); > return SocketState.CLOSED; > } else if (opCode == Constants.OPCODE_PING) { > getWsOutbound().pong(frame.getPayLoad()); >@@ -135,27 +137,61 @@ > // NO-OP > } else { > // Unknown OpCode >- getWsOutbound().close( >+ closeOutboundConnection( > Constants.STATUS_PROTOCOL_ERROR, null); > return SocketState.CLOSED; > } > } catch (MalformedInputException mie) { > // Invalid UTF-8 >- getWsOutbound().close(Constants.STATUS_BAD_DATA, null); >+ closeOutboundConnection(Constants.STATUS_BAD_DATA, null); > return SocketState.CLOSED; > } catch (UnmappableCharacterException uce) { > // Invalid UTF-8 >- getWsOutbound().close(Constants.STATUS_BAD_DATA, null); >+ closeOutboundConnection(Constants.STATUS_BAD_DATA, null); > return SocketState.CLOSED; > } catch (IOException ioe) { > // Given something must have gone to reach this point, this > // might not work but try it anyway. >- getWsOutbound().close(Constants.STATUS_PROTOCOL_ERROR, null); >+ closeOutboundConnection(Constants.STATUS_PROTOCOL_ERROR, null); > return SocketState.CLOSED; > } > frame = wsIs.nextFrame(false); > } > return SocketState.UPGRADED; >+ } >+ >+ private void closeOutboundConnection(int status, ByteBuffer data) throws IOException { >+ try { >+ getWsOutbound().close(status, data); >+ } finally { >+ onClose(status); >+ } >+ } >+ >+ private void closeOutboundConnection(WsFrame frame) throws IOException { >+ try { >+ getWsOutbound().close(frame); >+ } finally { >+ onClose(Constants.OPCODE_CLOSE); >+ } >+ } >+ >+ /** >+ * Intended to be overridden by sub-classes that wish to be notified >+ * when the outbound connection is established. >+ * >+ * @param outbound The outbound WebSocket connection. >+ */ >+ protected void onOpen(WsOutbound outbound) { >+ } >+ >+ /** >+ * Intended to be overridden by sub-classes that wish to be notified >+ * when the outbound connection is closed. >+ * >+ * @param status The status code of the close reason. >+ */ >+ protected void onClose(int status) { > } > > >Index: java/org/apache/catalina/websocket/WsOutbound.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- java/org/apache/catalina/websocket/WsOutbound.java (revision 1295334) >+++ java/org/apache/catalina/websocket/WsOutbound.java (revision ) >@@ -207,7 +207,7 @@ > * > * @throws IOException If an error occurs writing to the client > */ >- protected void close(WsFrame frame) throws IOException { >+ protected synchronized void close(WsFrame frame) throws IOException { > if (frame.getPayLoadLength() > 0) { > // Must be status (2 bytes) plus optional message > if (frame.getPayLoadLength() == 1) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 51181
:
28264
|
28342
|
28396
|
28407
|
28408
|
28410
|
28411
|
28415
|
28416
|
28420
|
28426
|
28457