use of javax.websocket.Session in project jetty.project by eclipse.
the class MessageReceivingTest method testPartialTextMessage.
/**
* Method tests receiving of text messages by parts.
*
* @throws Exception on exception occur
*/
@Test
public void testPartialTextMessage() throws Exception {
final TestEndpoint echoer = new TestEndpoint(new PartialStringCaptureHandler());
Assert.assertThat(echoer, instanceOf(javax.websocket.Endpoint.class));
// Issue connect using instance of class that extends Endpoint
final Session session = container.connectToServer(echoer, serverUri);
if (LOG.isDebugEnabled())
LOG.debug("Client Connected: {}", session);
session.getBasicRemote().sendText("");
session.getBasicRemote().sendText("Echo");
if (LOG.isDebugEnabled())
LOG.debug("Client Message Sent");
echoer.handler.getMessageQueue().awaitMessages(2, 1000, TimeUnit.MILLISECONDS);
}
use of javax.websocket.Session in project jetty.project by eclipse.
the class ExampleClient method run.
private void run() throws DeploymentException, IOException, URISyntaxException, InterruptedException {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
System.out.printf("WebSocketContainer Impl: %s%n", container.getClass().getName());
ExampleSocket socket = new ExampleSocket();
URI uri = new URI("ws://echo.websocket.org/");
Session session = container.connectToServer(socket, uri);
RemoteEndpoint.Basic remote = session.getBasicRemote();
String msg = "Hello world";
System.out.printf("Sending: %s%n", Objects.toString(msg));
remote.sendText(msg);
// give remote 1 second to respond
socket.messageLatch.await(1, TimeUnit.SECONDS);
session.close();
// give remote 1 second to acknowledge response
socket.closeLatch.await(1, TimeUnit.SECONDS);
System.out.println("Socket is closed");
}
use of javax.websocket.Session in project jetty.project by eclipse.
the class EndpointEchoTest method testAbstractEchoClassref.
@Test
public void testAbstractEchoClassref() throws Exception {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
// Issue connect using class reference (class that extends abstract that extends Endpoint)
Session session = container.connectToServer(EchoStringEndpoint.class, serverUri);
if (LOG.isDebugEnabled())
LOG.debug("Client Connected: {}", session);
session.getBasicRemote().sendText("Echo");
if (LOG.isDebugEnabled())
LOG.debug("Client Message Sent");
// TODO: figure out echo verification.
// echoer.messageQueue.awaitMessages(1,1000,TimeUnit.MILLISECONDS);
}
use of javax.websocket.Session in project jetty.project by eclipse.
the class EndpointEchoTest method testBasicEchoInstance.
@Test
public void testBasicEchoInstance() throws Exception {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
EndpointEchoClient echoer = new EndpointEchoClient();
Assert.assertThat(echoer, instanceOf(javax.websocket.Endpoint.class));
// Issue connect using instance of class that extends Endpoint
Session session = container.connectToServer(echoer, serverUri);
if (LOG.isDebugEnabled())
LOG.debug("Client Connected: {}", session);
session.getBasicRemote().sendText("Echo");
if (LOG.isDebugEnabled())
LOG.debug("Client Message Sent");
echoer.textCapture.messageQueue.awaitMessages(1, 1000, TimeUnit.MILLISECONDS);
}
use of javax.websocket.Session in project javaee7-samples by javaee-samples.
the class MyEndpointTest method testEndpointInputStream.
/**
* The basic test method for the class {
*
* @MyEndpointInputStream }
*
* @throws DeploymentException
* @throws IOException
* @throws URISyntaxException
*/
@Test
public void testEndpointInputStream() throws DeploymentException, IOException, URISyntaxException, InterruptedException {
MyEndpointClient.latch = new CountDownLatch(1);
Session session = connectToServer("inputstream");
assertNotNull(session);
assertTrue(MyEndpointClient.latch.await(2, TimeUnit.SECONDS));
assertNotNull(MyEndpointClient.response);
assertArrayEquals(RESPONSE.getBytes(), MyEndpointClient.response);
}
Aggregations