Issue #207 - Support javax.websocket version 1.1

This commit is contained in:
Joakim Erdfelt 2016-08-03 12:37:02 -07:00
parent 94ea9f5b05
commit 1f196f5276
11 changed files with 81 additions and 42 deletions

View File

@ -246,7 +246,7 @@ public class ClientContainer extends ContainerLifeCycle implements WebSocketCont
// synchronized (endpointClientMetadataCache)
// {
// metadata = endpointClientMetadataCache.get(endpoint);
//
//
// if (metadata != null)
// {
@ -282,7 +282,7 @@ public class ClientContainer extends ContainerLifeCycle implements WebSocketCont
// endpointClientMetadataCache.put(endpoint,metadata);
// return metadata;
// }
return metadata;
return null;
}
public DecoderFactory getDecoderFactory()

View File

@ -18,14 +18,17 @@
package org.eclipse.jetty.websocket.jsr356.annotations;
import javax.websocket.OnClose;
/**
* Callable for {@link javax.websocket.OnClose} annotated methods
*/
@Deprecated
public class OnCloseCallable extends JsrCallable
{
@Override
public void setDecodingType(Class<?> decodingType)
{
}
/*private int idxCloseReason = -1;
public OnCloseCallable(Class<?> pojo, Method method)

View File

@ -26,6 +26,11 @@ import javax.websocket.OnError;
@Deprecated
public class OnErrorCallable extends JsrCallable
{
@Override
public void setDecodingType(Class<?> decodingType)
{
}
/* private int idxThrowable = -1;
public OnErrorCallable(Class<?> pojo, Method method)

View File

@ -21,6 +21,12 @@ package org.eclipse.jetty.websocket.jsr356.annotations;
@Deprecated
public class OnMessageCallable extends JsrCallable
{
@Override
public void setDecodingType(Class<?> decodingType)
{
}
/* protected final Class<?> returnType;
protected Encoder returnEncoder;
protected Class<?> decodingType;

View File

@ -18,14 +18,17 @@
package org.eclipse.jetty.websocket.jsr356.annotations;
import javax.websocket.OnOpen;
/**
* Callable for {@link javax.websocket.OnOpen} annotated methods
*/
@Deprecated
public class OnOpenCallable extends JsrCallable
{
@Override
public void setDecodingType(Class<?> decodingType)
{
}
/* private int idxEndpointConfig = -1;
public OnOpenCallable(Class<?> pojo, Method method)

View File

@ -35,10 +35,10 @@ import org.eclipse.jetty.websocket.common.util.ReflectUtils;
public class OnByteArrayFunction implements Function<byte[], Void>
{
private static final DynamicArgs.Builder ARGBUILDER;
private static final Arg ARG_SESSION = new Arg(1, Session.class);
private static final Arg ARG_BUFFER = new Arg(2, byte[].class).required();
private static final Arg ARG_OFFSET = new Arg(3, int.class);
private static final Arg ARG_LENGTH = new Arg(4, int.class);
private static final Arg ARG_SESSION = new Arg(Session.class);
private static final Arg ARG_BUFFER = new Arg(byte[].class).required();
private static final Arg ARG_OFFSET = new Arg(int.class);
private static final Arg ARG_LENGTH = new Arg(int.class);
static
{

View File

@ -49,7 +49,16 @@ public class Arg
this.index = idx;
this.type = type;
}
public Arg(Arg arg)
{
this.method = arg.method;
this.index = arg.index;
this.type = arg.type;
this.tag = arg.tag;
this.required = arg.required;
}
public <T extends Annotation> T getAnnotation(Class<T> annoClass)
{
if (method == null)

View File

@ -31,6 +31,26 @@ import org.eclipse.jetty.websocket.common.util.ReflectUtils;
class UnorderedSignature implements Signature, Predicate<Method>
{
private class SelectedArg extends Arg
{
private boolean selected = false;
public SelectedArg(Arg arg)
{
super(arg);
}
public boolean isSelected()
{
return selected;
}
public void selected()
{
this.selected = true;
}
}
private final static Logger LOG = Log.getLogger(UnorderedSignature.class);
private final Arg[] params;
@ -118,6 +138,13 @@ class UnorderedSignature implements Signature, Predicate<Method>
methodArgs[pi] = argId.apply(methodArgs[pi]);
}
// Selected Args
SelectedArg selectedArgs[] = new SelectedArg[callArgs.length];
for (int ci = 0; ci < selectedArgs.length; ci++)
{
selectedArgs[ci] = new SelectedArg(callArgs[ci]);
}
// Iterate through mappings, looking for a callArg that fits it
for (int ai = 0; ai < argMappingLength; ai++)
{
@ -126,8 +153,9 @@ class UnorderedSignature implements Signature, Predicate<Method>
// Find reference to argument in callArgs
for (int ci = 0; ci < callArgsLen; ci++)
{
if (methodArgs[ai].matches(callArgs[ci]))
if (!selectedArgs[ci].selected && methodArgs[ai].matches(selectedArgs[ci]))
{
selectedArgs[ci].selected();
ref = ci;
break;
}
@ -171,32 +199,20 @@ class UnorderedSignature implements Signature, Predicate<Method>
// Ensure that required arguments are present in the mapping
for (int ci = 0; ci < callArgsLen; ci++)
{
if (callArgs[ci].isRequired())
if (selectedArgs[ci].isRequired() && !selectedArgs[ci].isSelected())
{
boolean found = false;
for (int ai = 0; ai < argMappingLength; ai++)
StringBuilder err = new StringBuilder();
err.append("Unable to find required type [");
err.append(callArgs[ci].getType());
err.append("] in method ");
ReflectUtils.append(err, method);
if (throwOnFailure)
throw new DynamicArgsException(err.toString());
else
{
if (argMapping[ai] == ci)
{
found = true;
break;
}
}
if (!found)
{
StringBuilder err = new StringBuilder();
err.append("Unable to find required type [");
err.append(callArgs[ci].getType());
err.append("] in method ");
ReflectUtils.append(err, method);
if (throwOnFailure)
throw new DynamicArgsException(err.toString());
else
{
LOG.debug("{}", err.toString());
return null;
}
LOG.debug("{}", err.toString());
return null;
}
}
}

View File

@ -217,13 +217,9 @@ public class DynamicArgsTest
DynamicArgs.Builder dab = new DynamicArgs.Builder();
dab.addSignature(ARG_BYTEARRAY, ARG_OFFSET, ARG_LENGTH);
final Arg CALL_BYTEARRAY = new Arg(byte[].class);
final Arg CALL_OFFSET = new Arg(int.class).setTag("offset");
final Arg CALL_LENGTH = new Arg(int.class).setTag("length");
SampleSignatures ssigs = new SampleSignatures();
Method m = findMethodByName(ssigs, "sigByteArray");
DynamicArgs dynamicArgs = dab.build(m, CALL_BYTEARRAY, CALL_OFFSET, CALL_LENGTH);
DynamicArgs dynamicArgs = dab.build(m, ARG_BYTEARRAY, ARG_OFFSET, ARG_LENGTH);
assertThat("DynamicArgs", dynamicArgs, notNullValue());
// Test with potential args

View File

@ -32,6 +32,7 @@ import org.eclipse.jetty.websocket.common.test.Fuzzer;
import org.eclipse.jetty.websocket.common.test.Fuzzer.SendMode;
import org.junit.Test;
@SuppressWarnings("Duplicates")
public class TestABCase1 extends AbstractABCase
{
/**

View File

@ -2,7 +2,7 @@ org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
org.eclipse.jetty.LEVEL=WARN
# org.eclipse.jetty.io.WriteFlusher.LEVEL=DEBUG
# org.eclipse.jetty.websocket.LEVEL=DEBUG
org.eclipse.jetty.websocket.LEVEL=DEBUG
# org.eclipse.jetty.websocket.LEVEL=INFO
# org.eclipse.jetty.websocket.common.io.LEVEL=DEBUG
# org.eclipse.jetty.websocket.server.ab.LEVEL=DEBUG