Making .common pass all existing tests
This commit is contained in:
parent
b37bd2b665
commit
2e3447f6ef
|
@ -374,12 +374,11 @@ public class Parser
|
|||
}
|
||||
|
||||
// base framing flags
|
||||
frame = new WebSocketFrame();
|
||||
frame = new WebSocketFrame(opcode);
|
||||
frame.setFin(fin);
|
||||
frame.setRsv1(rsv1);
|
||||
frame.setRsv2(rsv2);
|
||||
frame.setRsv3(rsv3);
|
||||
frame.setOpCode(opcode);
|
||||
frame.setContinuation(isContinuation);
|
||||
|
||||
if (frame.isDataFrame())
|
||||
|
|
|
@ -91,7 +91,7 @@ public class WebSocketFrame implements Frame
|
|||
private boolean rsv1 = false;
|
||||
private boolean rsv2 = false;
|
||||
private boolean rsv3 = false;
|
||||
private byte opcode = -1;
|
||||
private byte opcode = OpCode.UNDEFINED;
|
||||
private boolean masked = false;
|
||||
private byte mask[];
|
||||
/**
|
||||
|
@ -130,7 +130,7 @@ public class WebSocketFrame implements Frame
|
|||
public WebSocketFrame(byte opcode)
|
||||
{
|
||||
reset();
|
||||
this.opcode = opcode;
|
||||
setOpCode(opcode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -497,7 +497,15 @@ public class WebSocketFrame implements Frame
|
|||
public WebSocketFrame setOpCode(byte op)
|
||||
{
|
||||
this.opcode = op;
|
||||
this.type = Frame.Type.from(op);
|
||||
|
||||
if (op == OpCode.UNDEFINED)
|
||||
{
|
||||
this.type = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.type = Frame.Type.from(op);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,26 +16,17 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.common.extensions.identity;
|
||||
package org.eclipse.jetty.websocket.common.extensions;
|
||||
|
||||
import javax.net.websocket.extensions.FrameHandler;
|
||||
|
||||
import org.eclipse.jetty.websocket.common.WebSocketFrame;
|
||||
import org.eclipse.jetty.websocket.common.extensions.AbstractJettyFrameHandler;
|
||||
|
||||
/**
|
||||
* FrameHandler that just passes frames through with no modification.
|
||||
*/
|
||||
public class IdentityFrameHandler extends AbstractJettyFrameHandler
|
||||
public class PassthruFrameHandler extends FrameHandler
|
||||
{
|
||||
public IdentityFrameHandler(FrameHandler nextHandler)
|
||||
public PassthruFrameHandler(FrameHandler nextHandler)
|
||||
{
|
||||
super(nextHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleJettyFrame(WebSocketFrame frame)
|
||||
{
|
||||
nextJettyHandler(frame);
|
||||
}
|
||||
}
|
|
@ -68,6 +68,7 @@ public class DecompressFrameHandler extends AbstractJettyFrameHandler
|
|||
{
|
||||
out.setFin(false);
|
||||
}
|
||||
out.setRsv1(false); // Unset RSV1 on decompressed frame
|
||||
nextJettyHandler(out);
|
||||
}
|
||||
|
||||
|
|
|
@ -67,6 +67,7 @@ public class DecompressMessageHandler extends AbstractJettyFrameHandler
|
|||
{
|
||||
out.setFin(false);
|
||||
}
|
||||
out.setRsv1(false); // Unset RSV1 on decompressed frame
|
||||
nextJettyHandler(out);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.common.extensions.fragment;
|
|||
|
||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||
import org.eclipse.jetty.websocket.common.extensions.AbstractExtension;
|
||||
import org.eclipse.jetty.websocket.common.extensions.PassthruFrameHandler;
|
||||
|
||||
/**
|
||||
* Fragment Extension
|
||||
|
@ -32,7 +33,8 @@ public class FragmentExtension extends AbstractExtension
|
|||
@Override
|
||||
public javax.net.websocket.extensions.FrameHandler createIncomingFrameHandler(javax.net.websocket.extensions.FrameHandler incoming)
|
||||
{
|
||||
return new FragmentHandler(incoming,maxLength);
|
||||
// pass through handler
|
||||
return new PassthruFrameHandler(incoming);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.common.extensions.identity;
|
|||
import org.eclipse.jetty.util.QuotedStringTokenizer;
|
||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||
import org.eclipse.jetty.websocket.common.extensions.AbstractExtension;
|
||||
import org.eclipse.jetty.websocket.common.extensions.PassthruFrameHandler;
|
||||
|
||||
public class IdentityExtension extends AbstractExtension
|
||||
{
|
||||
|
@ -29,13 +30,13 @@ public class IdentityExtension extends AbstractExtension
|
|||
@Override
|
||||
public javax.net.websocket.extensions.FrameHandler createIncomingFrameHandler(javax.net.websocket.extensions.FrameHandler incoming)
|
||||
{
|
||||
return new IdentityFrameHandler(incoming);
|
||||
return new PassthruFrameHandler(incoming);
|
||||
}
|
||||
|
||||
@Override
|
||||
public javax.net.websocket.extensions.FrameHandler createOutgoingFrameHandler(javax.net.websocket.extensions.FrameHandler outgoing)
|
||||
{
|
||||
return new IdentityFrameHandler(outgoing);
|
||||
return new PassthruFrameHandler(outgoing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.common;
|
||||
|
||||
import org.eclipse.jetty.util.log.StdErrLog;
|
||||
|
||||
public class LogShush
|
||||
{
|
||||
public static void disableStacks(Class<?> clazz)
|
||||
{
|
||||
StdErrLog log = StdErrLog.getLogger(clazz);
|
||||
log.setHideStacks(true);
|
||||
}
|
||||
|
||||
public static void enableStacks(Class<?> clazz)
|
||||
{
|
||||
StdErrLog log = StdErrLog.getLogger(clazz);
|
||||
log.setHideStacks(false);
|
||||
}
|
||||
}
|
|
@ -33,10 +33,6 @@ import org.eclipse.jetty.websocket.api.BadPayloadException;
|
|||
import org.eclipse.jetty.websocket.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.common.CloseInfo;
|
||||
import org.eclipse.jetty.websocket.common.OpCode;
|
||||
import org.eclipse.jetty.websocket.common.Parser;
|
||||
import org.eclipse.jetty.websocket.common.WebSocketFrame;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -44,6 +40,17 @@ public class ParserTest
|
|||
{
|
||||
private static final Logger LOG = Log.getLogger(ParserTest.class);
|
||||
|
||||
/** Parse, but be quiet about stack traces */
|
||||
private void parseQuietly(UnitParser parser, ByteBuffer buf)
|
||||
{
|
||||
LogShush.disableStacks(Parser.class);
|
||||
try {
|
||||
parser.parse(buf);
|
||||
} finally {
|
||||
LogShush.enableStacks(Parser.class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to the server side 5.15 testcase. A normal 2 fragment text text message, followed by another continuation.
|
||||
*/
|
||||
|
@ -61,7 +68,8 @@ public class ParserTest
|
|||
UnitParser parser = new UnitParser();
|
||||
IncomingFramesCapture capture = new IncomingFramesCapture();
|
||||
parser.setIncomingFramesHandler(capture);
|
||||
parser.parse(completeBuf);
|
||||
|
||||
parseQuietly(parser,completeBuf);
|
||||
|
||||
capture.assertErrorCount(1);
|
||||
capture.assertHasFrame(OpCode.TEXT,2);
|
||||
|
@ -82,7 +90,7 @@ public class ParserTest
|
|||
UnitParser parser = new UnitParser();
|
||||
IncomingFramesCapture capture = new IncomingFramesCapture();
|
||||
parser.setIncomingFramesHandler(capture);
|
||||
parser.parse(completeBuf);
|
||||
parseQuietly(parser,completeBuf);
|
||||
|
||||
capture.assertErrorCount(1);
|
||||
capture.assertHasFrame(OpCode.TEXT,1); // fragment 1
|
||||
|
@ -109,7 +117,7 @@ public class ParserTest
|
|||
UnitParser parser = new UnitParser();
|
||||
IncomingFramesCapture capture = new IncomingFramesCapture();
|
||||
parser.setIncomingFramesHandler(capture);
|
||||
parser.parse(completeBuf);
|
||||
parseQuietly(parser,completeBuf);
|
||||
|
||||
capture.assertErrorCount(0);
|
||||
capture.assertHasFrame(OpCode.TEXT,5);
|
||||
|
@ -217,9 +225,9 @@ public class ParserTest
|
|||
IncomingFramesCapture capture = new IncomingFramesCapture();
|
||||
parser.setIncomingFramesHandler(capture);
|
||||
|
||||
parser.parse(part1);
|
||||
parseQuietly(parser,part1);
|
||||
capture.assertErrorCount(0);
|
||||
parser.parse(part2);
|
||||
parseQuietly(parser,part2);
|
||||
capture.assertErrorCount(1);
|
||||
capture.assertHasErrors(BadPayloadException.class,1);
|
||||
}
|
||||
|
|
|
@ -20,11 +20,11 @@ package org.eclipse.jetty.websocket.common.ab;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.util.log.StdErrLog;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketException;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.common.IncomingFramesCapture;
|
||||
import org.eclipse.jetty.websocket.common.LogShush;
|
||||
import org.eclipse.jetty.websocket.common.Parser;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
|
@ -36,19 +36,13 @@ public class TestABCase4
|
|||
@BeforeClass
|
||||
public static void disableParserStacks()
|
||||
{
|
||||
enableStacks(Parser.class,false);
|
||||
LogShush.disableStacks(Parser.class);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void enableParserStacks()
|
||||
{
|
||||
enableStacks(Parser.class,true);
|
||||
}
|
||||
|
||||
private static void enableStacks(Class<?> clazz, boolean enabled)
|
||||
{
|
||||
StdErrLog log = StdErrLog.getLogger(clazz);
|
||||
log.setHideStacks(!enabled);
|
||||
LogShush.enableStacks(Parser.class);
|
||||
}
|
||||
|
||||
private WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
|
||||
org.eclipse.jetty.websocket.LEVEL=DEBUG
|
||||
org.eclipse.jetty.websocket.LEVEL=WARN
|
||||
# org.eclipse.jetty.websocket.protocol.Parser.LEVEL=DEBUG
|
||||
# org.eclipse.jetty.websocket.protocol.LEVEL=DEBUG
|
||||
# org.eclipse.jetty.websocket.io.payload.LEVEL=DEBUG
|
||||
|
|
Loading…
Reference in New Issue