393473 - Add support for JSR-356 (javax.websocket) draft

+ Adding support for @WebSocketClient method scanning of
    @WebSocketOpen
    @WebSocketClose
    @WebSocketError
This commit is contained in:
Joakim Erdfelt 2013-02-15 12:26:35 -07:00
parent 820e20f042
commit 7d1f774c0e
18 changed files with 709 additions and 71 deletions

View File

@ -20,33 +20,19 @@ package org.eclipse.jetty.websocket.jsr356.endpoints;
import static org.hamcrest.Matchers.*;
import java.lang.annotation.Annotation;
import javax.websocket.CloseReason;
import javax.websocket.Session;
import javax.websocket.WebSocketOpen;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.common.events.annotated.CallableMethod;
import org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureException;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicOpenCloseSessionSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicOpenCloseSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicOpenSessionSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicOpenSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.InvalidOpenCloseReasonSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.InvalidOpenIntSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.InvalidOpenSessionIntSocket;
import org.junit.Assert;
import org.junit.Test;
public class JsrAnnotatedClientScannerTest
{
private static final Logger LOG = Log.getLogger(JsrAnnotatedClientScannerTest.class);
private void assertHasCallable(String msg, CallableMethod callable, Class<?>... expectedParameters)
{
Assert.assertThat(msg,notNullValue());
Assert.assertThat(msg,callable,notNullValue());
int len = expectedParameters.length;
for (int i = 0; i < len; i++)
{
@ -57,30 +43,6 @@ public class JsrAnnotatedClientScannerTest
}
}
private void assertInvalidAnnotationSignature(Class<?> pojo, Class<? extends Annotation> expectedAnnoClass)
{
JsrAnnotatedClientScanner scanner = new JsrAnnotatedClientScanner(pojo);
try
{
scanner.scan();
Assert.fail("Expected " + InvalidSignatureException.class + " with message that references " + expectedAnnoClass + " annotation");
}
catch (InvalidSignatureException e)
{
LOG.debug("{}:{}",e.getClass(),e.getMessage());
Assert.assertThat("Message",e.getMessage(),containsString(expectedAnnoClass.getSimpleName()));
}
}
@Test
public void testScan_BasicOpen()
{
JsrAnnotatedClientScanner scanner = new JsrAnnotatedClientScanner(BasicOpenSocket.class);
JsrAnnotatedMetadata metadata = scanner.scan();
Assert.assertThat("Metadata",metadata,notNullValue());
assertHasCallable("Metadata.onOpen",metadata.onOpen);
}
@Test
public void testScan_BasicOpenClose()
{
@ -93,15 +55,6 @@ public class JsrAnnotatedClientScannerTest
assertHasCallable("Metadata.onClose",metadata.onClose,CloseReason.class);
}
@Test
public void testScan_BasicOpenSession()
{
JsrAnnotatedClientScanner scanner = new JsrAnnotatedClientScanner(BasicOpenSessionSocket.class);
JsrAnnotatedMetadata metadata = scanner.scan();
Assert.assertThat("Metadata",metadata,notNullValue());
assertHasCallable("Metadata.onOpen",metadata.onOpen,Session.class);
}
@Test
public void testScan_BasicSessionOpenClose()
{
@ -113,22 +66,4 @@ public class JsrAnnotatedClientScannerTest
assertHasCallable("Metadata.onOpen",metadata.onOpen);
assertHasCallable("Metadata.onClose",metadata.onClose,CloseReason.class);
}
@Test
public void testScan_InvalidOpenCloseReason()
{
assertInvalidAnnotationSignature(InvalidOpenCloseReasonSocket.class,WebSocketOpen.class);
}
@Test
public void testScan_InvalidOpenInt()
{
assertInvalidAnnotationSignature(InvalidOpenIntSocket.class,WebSocketOpen.class);
}
@Test
public void testScan_InvalidOpenSessionInt()
{
assertInvalidAnnotationSignature(InvalidOpenSessionIntSocket.class,WebSocketOpen.class);
}
}

View File

@ -0,0 +1,134 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.jsr356.endpoints;
import static org.hamcrest.Matchers.*;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.websocket.CloseReason;
import javax.websocket.Session;
import org.eclipse.jetty.websocket.common.events.annotated.CallableMethod;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicCloseReasonSessionSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicCloseReasonSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicCloseSessionReasonSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicCloseSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicErrorSessionSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicErrorSessionThrowableSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicErrorSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicErrorThrowableSessionSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicErrorThrowableSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicOpenSessionSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicOpenSocket;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
/**
* Test {@link JsrAnnotatedClientScanner} against various valid, simple, 1 method annotated classes with valid signatures.
*/
@RunWith(Parameterized.class)
public class JsrAnnotatedClientScanner_BasicTest
{
public static class Case
{
public static void add(List<Case[]> data, Class<?> pojo, Field metadataField, Class<?>... expectedParams)
{
data.add(new Case[]
{ new Case(pojo,metadataField,expectedParams) });
}
// The websocket pojo to test against
Class<?> pojo;
// The JsrAnnotatedMetadata field that should be populated
Field metadataField;
// The expected parameters for the Callable found by the scanner
Class<?> expectedParameters[];
public Case(Class<?> pojo, Field metadataField, Class<?>... expectedParams)
{
this.pojo = pojo;
this.metadataField = metadataField;
this.expectedParameters = expectedParams;
}
}
@Parameters
public static Collection<Case[]> data() throws Exception
{
List<Case[]> data = new ArrayList<>();
Field fOpen = findFieldRef(JsrAnnotatedMetadata.class,"onOpen");
Field fClose = findFieldRef(JsrAnnotatedMetadata.class,"onClose");
Field fError = findFieldRef(JsrAnnotatedMetadata.class,"onError");
// @formatter:off
Case.add(data,BasicOpenSocket.class, fOpen);
Case.add(data,BasicOpenSessionSocket.class, fOpen, Session.class);
Case.add(data,BasicCloseSocket.class, fClose);
Case.add(data,BasicCloseReasonSocket.class, fClose, CloseReason.class);
Case.add(data,BasicCloseReasonSessionSocket.class, fClose, CloseReason.class, Session.class);
Case.add(data,BasicCloseSessionReasonSocket.class, fClose, Session.class, CloseReason.class);
Case.add(data,BasicErrorSocket.class, fError);
Case.add(data,BasicErrorSessionSocket.class, fError, Session.class);
Case.add(data,BasicErrorSessionThrowableSocket.class, fError, Session.class, Throwable.class);
Case.add(data,BasicErrorThrowableSocket.class, fError, Throwable.class);
Case.add(data,BasicErrorThrowableSessionSocket.class, fError, Throwable.class, Session.class);
// @formatter:on
return data;
}
private static Field findFieldRef(Class<?> clazz, String fldName) throws Exception
{
return clazz.getField(fldName);
}
private Case testcase;
public JsrAnnotatedClientScanner_BasicTest(Case testcase)
{
this.testcase = testcase;
}
@Test
public void testScan_Basic() throws Exception
{
JsrAnnotatedClientScanner scanner = new JsrAnnotatedClientScanner(testcase.pojo);
JsrAnnotatedMetadata metadata = scanner.scan();
Assert.assertThat("Metadata",metadata,notNullValue());
CallableMethod cm = (CallableMethod)testcase.metadataField.get(metadata);
Assert.assertThat(testcase.metadataField.toString(),cm,notNullValue());
int len = testcase.expectedParameters.length;
for (int i = 0; i < len; i++)
{
Class<?> expectedParam = testcase.expectedParameters[i];
Class<?> actualParam = cm.getParamTypes()[i];
Assert.assertTrue("Parameter[" + i + "] - expected:[" + expectedParam + "], actual:[" + actualParam + "]",actualParam.equals(expectedParam));
}
}
}

View File

@ -0,0 +1,100 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.jsr356.endpoints;
import static org.hamcrest.Matchers.*;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.websocket.WebSocketClose;
import javax.websocket.WebSocketError;
import javax.websocket.WebSocketOpen;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureException;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.InvalidCloseIntSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.InvalidErrorErrorSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.InvalidErrorExceptionSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.InvalidErrorIntSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.InvalidOpenCloseReasonSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.InvalidOpenIntSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.InvalidOpenSessionIntSocket;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
/**
* Test {@link JsrAnnotatedClientScanner} against various simple, single method annotated classes with invalid signatures.
*/
@RunWith(Parameterized.class)
public class JsrAnnotatedClientScanner_InvalidSignatureTest
{
private static final Logger LOG = Log.getLogger(JsrAnnotatedClientScanner_InvalidSignatureTest.class);
@Parameters
public static Collection<Class<?>[]> data()
{
List<Class<?>[]> data = new ArrayList<>();
// @formatter:off
data.add(new Class<?>[]{ InvalidCloseIntSocket.class, WebSocketClose.class });
data.add(new Class<?>[]{ InvalidErrorErrorSocket.class, WebSocketError.class });
data.add(new Class<?>[]{ InvalidErrorExceptionSocket.class, WebSocketError.class });
data.add(new Class<?>[]{ InvalidErrorIntSocket.class, WebSocketError.class });
data.add(new Class<?>[]{ InvalidOpenCloseReasonSocket.class, WebSocketOpen.class });
data.add(new Class<?>[]{ InvalidOpenIntSocket.class, WebSocketOpen.class });
data.add(new Class<?>[]{ InvalidOpenSessionIntSocket.class, WebSocketOpen.class });
// @formatter:on
return data;
}
// The pojo to test
private Class<?> pojo;
// The annotation class expected to be mentioned in the error message
private Class<? extends Annotation> expectedAnnoClass;
public JsrAnnotatedClientScanner_InvalidSignatureTest(Class<?> pojo, Class<? extends Annotation> expectedAnnotation)
{
this.pojo = pojo;
this.expectedAnnoClass = expectedAnnotation;
}
@Test
public void testScan_InvalidSignature()
{
JsrAnnotatedClientScanner scanner = new JsrAnnotatedClientScanner(pojo);
try
{
scanner.scan();
Assert.fail("Expected " + InvalidSignatureException.class + " with message that references " + expectedAnnoClass + " annotation");
}
catch (InvalidSignatureException e)
{
LOG.debug("{}:{}",e.getClass(),e.getMessage());
Assert.assertThat("Message",e.getMessage(),containsString(expectedAnnoClass.getSimpleName()));
}
}
}

View File

@ -0,0 +1,37 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.jsr356.endpoints.samples;
import javax.websocket.CloseReason;
import javax.websocket.Session;
import javax.websocket.WebSocketClient;
import javax.websocket.WebSocketClose;
import org.eclipse.jetty.websocket.jsr356.endpoints.TrackingSocket;
@WebSocketClient
public class BasicCloseReasonSessionSocket extends TrackingSocket
{
@WebSocketClose
public void onClose(CloseReason reason, Session session)
{
addEvent("onClose(%s,%s)",reason,session);
closeLatch.countDown();
}
}

View File

@ -0,0 +1,36 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.jsr356.endpoints.samples;
import javax.websocket.CloseReason;
import javax.websocket.WebSocketClient;
import javax.websocket.WebSocketClose;
import org.eclipse.jetty.websocket.jsr356.endpoints.TrackingSocket;
@WebSocketClient
public class BasicCloseReasonSocket extends TrackingSocket
{
@WebSocketClose
public void onClose(CloseReason reason)
{
addEvent("onClose(%s)", reason);
closeLatch.countDown();
}
}

View File

@ -0,0 +1,37 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.jsr356.endpoints.samples;
import javax.websocket.CloseReason;
import javax.websocket.Session;
import javax.websocket.WebSocketClient;
import javax.websocket.WebSocketClose;
import org.eclipse.jetty.websocket.jsr356.endpoints.TrackingSocket;
@WebSocketClient
public class BasicCloseSessionReasonSocket extends TrackingSocket
{
@WebSocketClose
public void onClose(Session session, CloseReason reason)
{
addEvent("onClose(%s,%s)",session,reason);
closeLatch.countDown();
}
}

View File

@ -0,0 +1,35 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.jsr356.endpoints.samples;
import javax.websocket.WebSocketClient;
import javax.websocket.WebSocketClose;
import org.eclipse.jetty.websocket.jsr356.endpoints.TrackingSocket;
@WebSocketClient
public class BasicCloseSocket extends TrackingSocket
{
@WebSocketClose
public void onClose()
{
addEvent("onClose()");
closeLatch.countDown();
}
}

View File

@ -0,0 +1,35 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.jsr356.endpoints.samples;
import javax.websocket.Session;
import javax.websocket.WebSocketClient;
import javax.websocket.WebSocketError;
import org.eclipse.jetty.websocket.jsr356.endpoints.TrackingSocket;
@WebSocketClient
public class BasicErrorSessionSocket extends TrackingSocket
{
@WebSocketError
public void onError(Session session)
{
addEvent("onError(%s)",session);
}
}

View File

@ -0,0 +1,36 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.jsr356.endpoints.samples;
import javax.websocket.Session;
import javax.websocket.WebSocketClient;
import javax.websocket.WebSocketError;
import org.eclipse.jetty.websocket.jsr356.endpoints.TrackingSocket;
@WebSocketClient
public class BasicErrorSessionThrowableSocket extends TrackingSocket
{
@WebSocketError
public void onError(Session session, Throwable t)
{
addEvent("onError(%s,%s)",session,t);
addError(t);
}
}

View File

@ -0,0 +1,34 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.jsr356.endpoints.samples;
import javax.websocket.WebSocketClient;
import javax.websocket.WebSocketError;
import org.eclipse.jetty.websocket.jsr356.endpoints.TrackingSocket;
@WebSocketClient
public class BasicErrorSocket extends TrackingSocket
{
@WebSocketError
public void onError()
{
addEvent("onError()");
}
}

View File

@ -0,0 +1,36 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.jsr356.endpoints.samples;
import javax.websocket.Session;
import javax.websocket.WebSocketClient;
import javax.websocket.WebSocketError;
import org.eclipse.jetty.websocket.jsr356.endpoints.TrackingSocket;
@WebSocketClient
public class BasicErrorThrowableSessionSocket extends TrackingSocket
{
@WebSocketError
public void onError(Throwable t, Session session)
{
addEvent("onError(%s,%s)",t,session);
addError(t);
}
}

View File

@ -0,0 +1,35 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.jsr356.endpoints.samples;
import javax.websocket.WebSocketClient;
import javax.websocket.WebSocketError;
import org.eclipse.jetty.websocket.jsr356.endpoints.TrackingSocket;
@WebSocketClient
public class BasicErrorThrowableSocket extends TrackingSocket
{
@WebSocketError
public void onError(Throwable t)
{
addEvent("onError(%s)",t);
addError(t);
}
}

View File

@ -0,0 +1,37 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.jsr356.endpoints.samples;
import javax.websocket.WebSocketClient;
import javax.websocket.WebSocketClose;
import org.eclipse.jetty.websocket.jsr356.endpoints.TrackingSocket;
@WebSocketClient
public class InvalidCloseIntSocket extends TrackingSocket
{
/**
* Invalid Close Method Declaration (parameter type int)
*/
@WebSocketClose
public void onClose(int statusCode)
{
closeLatch.countDown();
}
}

View File

@ -0,0 +1,37 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.jsr356.endpoints.samples;
import javax.websocket.WebSocketClient;
import javax.websocket.WebSocketError;
import org.eclipse.jetty.websocket.jsr356.endpoints.TrackingSocket;
@WebSocketClient
public class InvalidErrorErrorSocket extends TrackingSocket
{
/**
* Invalid Error Method Declaration (parameter type Error)
*/
@WebSocketError
public void onError(Error error)
{
/* no impl */
}
}

View File

@ -0,0 +1,37 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.jsr356.endpoints.samples;
import javax.websocket.WebSocketClient;
import javax.websocket.WebSocketError;
import org.eclipse.jetty.websocket.jsr356.endpoints.TrackingSocket;
@WebSocketClient
public class InvalidErrorExceptionSocket extends TrackingSocket
{
/**
* Invalid Error Method Declaration (parameter type Exception)
*/
@WebSocketError
public void onError(Exception e)
{
/* no impl */
}
}

View File

@ -0,0 +1,37 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.jsr356.endpoints.samples;
import javax.websocket.WebSocketClient;
import javax.websocket.WebSocketError;
import org.eclipse.jetty.websocket.jsr356.endpoints.TrackingSocket;
@WebSocketClient
public class InvalidErrorIntSocket extends TrackingSocket
{
/**
* Invalid Error Method Declaration (parameter type int)
*/
@WebSocketError
public void onError(int errorCount)
{
/* no impl */
}
}

View File

@ -18,6 +18,7 @@
package org.eclipse.jetty.websocket.jsr356.endpoints.samples;
import javax.websocket.CloseReason;
import javax.websocket.WebSocketClient;
import javax.websocket.WebSocketOpen;
@ -27,10 +28,10 @@ import org.eclipse.jetty.websocket.jsr356.endpoints.TrackingSocket;
public class InvalidOpenCloseReasonSocket extends TrackingSocket
{
/**
* Invalid Open Method Declaration (parameter type int)
* Invalid Open Method Declaration (parameter type CloseReason)
*/
@WebSocketOpen
public void onOpen(int count)
public void onOpen(CloseReason reason)
{
openLatch.countDown();
}

View File

@ -18,7 +18,6 @@
package org.eclipse.jetty.websocket.jsr356.endpoints.samples;
import javax.websocket.CloseReason;
import javax.websocket.WebSocketClient;
import javax.websocket.WebSocketOpen;
@ -28,10 +27,10 @@ import org.eclipse.jetty.websocket.jsr356.endpoints.TrackingSocket;
public class InvalidOpenIntSocket extends TrackingSocket
{
/**
* Invalid Open Method Declaration (parameter type CloseReason)
* Invalid Open Method Declaration (parameter type int)
*/
@WebSocketOpen
public void onOpen(CloseReason close)
public void onOpen(int value)
{
openLatch.countDown();
}