Issue #207 - fixing EchoTest
This commit is contained in:
parent
4202a98ec5
commit
2c7964d9c9
|
@ -37,22 +37,13 @@ import org.eclipse.jetty.util.BufferUtil;
|
||||||
import org.eclipse.jetty.webapp.WebAppContext;
|
import org.eclipse.jetty.webapp.WebAppContext;
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.EchoCase.PartialBinary;
|
import org.eclipse.jetty.websocket.jsr356.server.EchoCase.PartialBinary;
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.EchoCase.PartialText;
|
import org.eclipse.jetty.websocket.jsr356.server.EchoCase.PartialText;
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.BasicCloseReasonSessionSocket;
|
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.BasicCloseReasonSocket;
|
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.BasicCloseSessionReasonSocket;
|
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.BasicCloseSocket;
|
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.BasicErrorSessionSocket;
|
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.BasicErrorSessionThrowableSocket;
|
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.BasicErrorSocket;
|
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.BasicErrorThrowableSessionSocket;
|
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.BasicErrorThrowableSocket;
|
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.BasicOpenSessionSocket;
|
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.BasicOpenSocket;
|
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.BasicPongMessageSocket;
|
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.BasicTextMessageStringSocket;
|
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.StatelessTextMessageStringSocket;
|
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.beans.DateTextSocket;
|
import org.eclipse.jetty.websocket.jsr356.server.samples.beans.DateTextSocket;
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.binary.ByteBufferSocket;
|
import org.eclipse.jetty.websocket.jsr356.server.samples.binary.ByteBufferSocket;
|
||||||
|
import org.eclipse.jetty.websocket.jsr356.server.samples.echo.EchoAsyncTextSocket;
|
||||||
|
import org.eclipse.jetty.websocket.jsr356.server.samples.echo.EchoBasicTextSocket;
|
||||||
|
import org.eclipse.jetty.websocket.jsr356.server.samples.echo.EchoReturnTextSocket;
|
||||||
|
import org.eclipse.jetty.websocket.jsr356.server.samples.echo.EchoStatelessAsyncTextSocket;
|
||||||
|
import org.eclipse.jetty.websocket.jsr356.server.samples.echo.EchoStatelessBasicTextSocket;
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.partial.PartialTextSessionSocket;
|
import org.eclipse.jetty.websocket.jsr356.server.samples.partial.PartialTextSessionSocket;
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.partial.PartialTextSocket;
|
import org.eclipse.jetty.websocket.jsr356.server.samples.partial.PartialTextSocket;
|
||||||
import org.eclipse.jetty.websocket.jsr356.server.samples.primitives.BooleanObjectTextSocket;
|
import org.eclipse.jetty.websocket.jsr356.server.samples.primitives.BooleanObjectTextSocket;
|
||||||
|
@ -200,8 +191,11 @@ public class EchoTest
|
||||||
EchoCase.add(TESTCASES,IntParamTextSocket.class).requestPath("/echo/primitives/integer/params/5678").addMessage(1234).expect("1234|5678");
|
EchoCase.add(TESTCASES,IntParamTextSocket.class).requestPath("/echo/primitives/integer/params/5678").addMessage(1234).expect("1234|5678");
|
||||||
|
|
||||||
// Text based
|
// Text based
|
||||||
EchoCase.add(TESTCASES,BasicTextMessageStringSocket.class).addMessage("Hello").expect("Hello");
|
EchoCase.add(TESTCASES,EchoBasicTextSocket.class).addMessage("Hello").expect("Hello");
|
||||||
EchoCase.add(TESTCASES,StatelessTextMessageStringSocket.class).addMessage("Hello").expect("Hello");
|
EchoCase.add(TESTCASES,EchoStatelessBasicTextSocket.class).addMessage("Hello").expect("Hello");
|
||||||
|
EchoCase.add(TESTCASES,EchoAsyncTextSocket.class).addMessage("Hello").expect("Hello");
|
||||||
|
EchoCase.add(TESTCASES,EchoStatelessAsyncTextSocket.class).addMessage("Hello").expect("Hello");
|
||||||
|
EchoCase.add(TESTCASES,EchoReturnTextSocket.class).addMessage("Hello").expect("Hello");
|
||||||
|
|
||||||
// ByteBuffer based
|
// ByteBuffer based
|
||||||
EchoCase.add(TESTCASES,ByteBufferSocket.class).addMessage(BufferUtil.toBuffer("Hello World")).expect("Hello World");
|
EchoCase.add(TESTCASES,ByteBufferSocket.class).addMessage(BufferUtil.toBuffer("Hello World")).expect("Hello World");
|
||||||
|
@ -224,27 +218,7 @@ public class EchoTest
|
||||||
.expect("('Built',false)(' for',false)(' the',false)(' future',true)");
|
.expect("('Built',false)(' for',false)(' the',false)(' future',true)");
|
||||||
|
|
||||||
// Beans
|
// Beans
|
||||||
EchoCase.add(TESTCASES, DateTextSocket.class).addMessage("Ooops").expect("");
|
EchoCase.add(TESTCASES, DateTextSocket.class).addMessage("1995.08.01").expect("[1995/08/01]");
|
||||||
|
|
||||||
// Pong
|
|
||||||
EchoCase.add(TESTCASES, BasicPongMessageSocket.class).addMessage("send-ping").expect("Pong[]");
|
|
||||||
|
|
||||||
// Open Events
|
|
||||||
EchoCase.add(TESTCASES, BasicOpenSocket.class).expect("Open[]");
|
|
||||||
EchoCase.add(TESTCASES, BasicOpenSessionSocket.class).expect("Open[Session]");
|
|
||||||
|
|
||||||
// Close Events
|
|
||||||
EchoCase.add(TESTCASES, BasicCloseSocket.class).expect("Close[]");
|
|
||||||
EchoCase.add(TESTCASES, BasicCloseReasonSocket.class).expect("Close[Reason]");
|
|
||||||
EchoCase.add(TESTCASES, BasicCloseReasonSessionSocket.class).expect("Close[Reason,Session]");
|
|
||||||
EchoCase.add(TESTCASES, BasicCloseSessionReasonSocket.class).expect("Close[Session,Reason]");
|
|
||||||
|
|
||||||
// Error Events
|
|
||||||
EchoCase.add(TESTCASES, BasicErrorSocket.class).expect("Error[]");
|
|
||||||
EchoCase.add(TESTCASES, BasicErrorSessionSocket.class).expect("Error[Session]");
|
|
||||||
EchoCase.add(TESTCASES, BasicErrorSessionThrowableSocket.class).expect("Error[Session,Throwable]");
|
|
||||||
EchoCase.add(TESTCASES, BasicErrorThrowableSocket.class).expect("Error[Throwable]");
|
|
||||||
EchoCase.add(TESTCASES, BasicErrorThrowableSessionSocket.class).expect("Error[Throwable,Session]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class DateEncoder implements Encoder.Text<Date>
|
||||||
@Override
|
@Override
|
||||||
public String encode(Date object) throws EncodeException
|
public String encode(Date object) throws EncodeException
|
||||||
{
|
{
|
||||||
return new SimpleDateFormat("yyyy.MM.dd").format(object);
|
return new SimpleDateFormat("[yyyy/MM/dd]").format(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
package org.eclipse.jetty.websocket.jsr356.server.samples.beans;
|
package org.eclipse.jetty.websocket.jsr356.server.samples.beans;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import javax.websocket.OnError;
|
import javax.websocket.OnError;
|
||||||
|
@ -55,9 +54,8 @@ public class DateTextSocket
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String msg = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT).format(d);
|
|
||||||
// The encoder declared in the @ServerEndpoint will be used
|
// The encoder declared in the @ServerEndpoint will be used
|
||||||
session.getAsyncRemote().sendText(msg);
|
session.getAsyncRemote().sendObject(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// Copyright (c) 1995-2016 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.server.samples.echo;
|
||||||
|
|
||||||
|
import javax.websocket.OnMessage;
|
||||||
|
import javax.websocket.OnOpen;
|
||||||
|
import javax.websocket.Session;
|
||||||
|
import javax.websocket.server.ServerEndpoint;
|
||||||
|
|
||||||
|
@ServerEndpoint("/echo/text/async")
|
||||||
|
public class EchoAsyncTextSocket
|
||||||
|
{
|
||||||
|
private Session session;
|
||||||
|
|
||||||
|
@OnOpen
|
||||||
|
public void onOpen(Session session)
|
||||||
|
{
|
||||||
|
this.session = session;
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnMessage
|
||||||
|
public void onText(String msg)
|
||||||
|
{
|
||||||
|
session.getAsyncRemote().sendText(msg);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// Copyright (c) 1995-2016 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.server.samples.echo;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.websocket.CloseReason;
|
||||||
|
import javax.websocket.OnMessage;
|
||||||
|
import javax.websocket.OnOpen;
|
||||||
|
import javax.websocket.Session;
|
||||||
|
import javax.websocket.server.ServerEndpoint;
|
||||||
|
|
||||||
|
@ServerEndpoint("/echo/text/basic")
|
||||||
|
public class EchoBasicTextSocket
|
||||||
|
{
|
||||||
|
private Session session;
|
||||||
|
|
||||||
|
@OnOpen
|
||||||
|
public void onOpen(Session session)
|
||||||
|
{
|
||||||
|
this.session = session;
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnMessage
|
||||||
|
public void onText(String msg)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
session.getBasicRemote().sendText(msg);
|
||||||
|
}
|
||||||
|
catch (IOException esend)
|
||||||
|
{
|
||||||
|
esend.printStackTrace(System.err);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
session.close(new CloseReason(CloseReason.CloseCodes.getCloseCode(4001), "Unable to echo msg"));
|
||||||
|
}
|
||||||
|
catch (IOException eclose)
|
||||||
|
{
|
||||||
|
eclose.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// Copyright (c) 1995-2016 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.server.samples.echo;
|
||||||
|
|
||||||
|
import javax.websocket.OnMessage;
|
||||||
|
import javax.websocket.server.ServerEndpoint;
|
||||||
|
|
||||||
|
@ServerEndpoint("/echo/text/return")
|
||||||
|
public class EchoReturnTextSocket
|
||||||
|
{
|
||||||
|
@OnMessage
|
||||||
|
public String onText(String msg)
|
||||||
|
{
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// Copyright (c) 1995-2016 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.server.samples.echo;
|
||||||
|
|
||||||
|
import javax.websocket.OnMessage;
|
||||||
|
import javax.websocket.Session;
|
||||||
|
import javax.websocket.server.ServerEndpoint;
|
||||||
|
|
||||||
|
@ServerEndpoint("/echo/text/async/stateless")
|
||||||
|
public class EchoStatelessAsyncTextSocket
|
||||||
|
{
|
||||||
|
@OnMessage
|
||||||
|
public void onText(Session session, String msg)
|
||||||
|
{
|
||||||
|
session.getAsyncRemote().sendText(msg);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// Copyright (c) 1995-2016 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.server.samples.echo;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.websocket.CloseReason;
|
||||||
|
import javax.websocket.OnMessage;
|
||||||
|
import javax.websocket.Session;
|
||||||
|
import javax.websocket.server.ServerEndpoint;
|
||||||
|
|
||||||
|
@ServerEndpoint("/echo/text/basic/stateless")
|
||||||
|
public class EchoStatelessBasicTextSocket
|
||||||
|
{
|
||||||
|
@OnMessage
|
||||||
|
public void onText(Session session, String msg)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
session.getBasicRemote().sendText(msg);
|
||||||
|
}
|
||||||
|
catch (IOException esend)
|
||||||
|
{
|
||||||
|
esend.printStackTrace(System.err);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
session.close(new CloseReason(CloseReason.CloseCodes.getCloseCode(4001), "Unable to echo msg"));
|
||||||
|
}
|
||||||
|
catch (IOException eclose)
|
||||||
|
{
|
||||||
|
eclose.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue