Fix closing handshake and run against Autobahn V0.4.3

This commit is contained in:
Veebs 2011-11-28 22:27:58 +11:00
parent 1bb3322268
commit 8efe131eb0
3 changed files with 24 additions and 15 deletions

View File

@ -32,20 +32,23 @@
* *
* <p>06. Go to AutoBahn directory: <tt>cd Autobahn</tt> * <p>06. Go to AutoBahn directory: <tt>cd Autobahn</tt>
* *
* <p>07. Checkout stable version: <tt>git checkout v0.4.2</tt> * <p>07. Checkout stable version: <tt>git checkout v0.4.3</tt>
* *
* <p>08. Go to test suite directory: <tt>cd testsuite/websockets</tt> * <p>08. Go to test suite directory: <tt>cd testsuite/websockets</tt>
* *
* <p>09. Edit <tt>fuzzing_clinet_spec.json</tt> and set the version to 10. * <p>09. Edit <tt>fuzzing_clinet_spec.json</tt> and set the version to 10 or 17.
* <code> * <code>
* { * {
* "servers": [{"agent": "Netty", "hostname": "localhost", "port": 9000, "version": 10}], * "options": {"failByDrop": false},
* "cases": ["*"] * "servers": [{"agent": "Netty", "url": "ws://localhost:9000", "options": {"version": 17}}],
* "cases": ["*"],
* "exclude-cases": [],
* "exclude-agent-cases": {"FoobarServer*": ["4.*", "1.1.3"]}
* } * }
* </code> * </code>
* *
* <p>10. Run the test <tt>python fuzzing_client.py</tt>. Note that the actual test case python code is * <p>10. Run the test <tt>python fuzzing_client.py</tt>. Note that the actual test case python code is
* located in <tt>/usr/local/lib/python2.6/dist-packages/autobahn-0.4.2-py2.6.egg/autobahn/cases</tt> * located in <tt>/usr/local/lib/python2.6/dist-packages/autobahn-0.4.3-py2.6.egg/autobahn/cases</tt>
* and not in the checked out git repository. * and not in the checked out git repository.
* *
* <p>11. See the results in <tt>reports/servers/index.html</tt> * <p>11. See the results in <tt>reports/servers/index.html</tt>

View File

@ -260,7 +260,17 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDe
unmask(framePayload); unmask(framePayload);
} }
// Processing for fragmented messages // Processing ping/pong/close frames because they cannot be fragmented
if (frameOpcode == OPCODE_PING) {
return new PingWebSocketFrame(frameFinalFlag, frameRsv, framePayload);
} else if (frameOpcode == OPCODE_PONG) {
return new PongWebSocketFrame(frameFinalFlag, frameRsv, framePayload);
} else if (frameOpcode == OPCODE_CLOSE) {
this.receivedClosingHandshake = true;
return new CloseWebSocketFrame(frameFinalFlag, frameRsv);
}
// Processing for possible fragmented messages for text and binary frames
String aggregatedText = null; String aggregatedText = null;
if (frameFinalFlag) { if (frameFinalFlag) {
// Final frame of the sequence. Apparently ping frames are // Final frame of the sequence. Apparently ping frames are
@ -305,15 +315,8 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDe
return new TextWebSocketFrame(frameFinalFlag, frameRsv, framePayload); return new TextWebSocketFrame(frameFinalFlag, frameRsv, framePayload);
} else if (frameOpcode == OPCODE_BINARY) { } else if (frameOpcode == OPCODE_BINARY) {
return new BinaryWebSocketFrame(frameFinalFlag, frameRsv, framePayload); return new BinaryWebSocketFrame(frameFinalFlag, frameRsv, framePayload);
} else if (frameOpcode == OPCODE_PING) {
return new PingWebSocketFrame(frameFinalFlag, frameRsv, framePayload);
} else if (frameOpcode == OPCODE_PONG) {
return new PongWebSocketFrame(frameFinalFlag, frameRsv, framePayload);
} else if (frameOpcode == OPCODE_CONT) { } else if (frameOpcode == OPCODE_CONT) {
return new ContinuationWebSocketFrame(frameFinalFlag, frameRsv, framePayload, aggregatedText); return new ContinuationWebSocketFrame(frameFinalFlag, frameRsv, framePayload, aggregatedText);
} else if (frameOpcode == OPCODE_CLOSE) {
this.receivedClosingHandshake = true;
return new CloseWebSocketFrame(frameFinalFlag, frameRsv);
} else { } else {
throw new UnsupportedOperationException("Cannot decode web socket frame with opcode: " + frameOpcode); throw new UnsupportedOperationException("Cannot decode web socket frame with opcode: " + frameOpcode);
} }

View File

@ -20,6 +20,8 @@ import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.handler.codec.http.DefaultHttpResponse; import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
@ -150,7 +152,7 @@ public class WebSocketServerHandshaker10 extends WebSocketServerHandshaker {
} }
/** /**
* Echo back the closing frame * Echo back the closing frame and close the connection
* *
* @param ctx * @param ctx
* Channel context * Channel context
@ -159,7 +161,8 @@ public class WebSocketServerHandshaker10 extends WebSocketServerHandshaker {
*/ */
@Override @Override
public void executeClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame) { public void executeClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame) {
ctx.getChannel().write(frame); ChannelFuture f = ctx.getChannel().write(frame);
f.addListener(ChannelFutureListener.CLOSE);
} }
} }