use of io.undertow.websockets.jsr.ServerWebSocketContainer in project undertow by undertow-io.
the class JsrWebSocketServer07Test method testBinaryWithByteArrayUsingStream.
@org.junit.Test
public void testBinaryWithByteArrayUsingStream() throws Exception {
final byte[] payload = "payload".getBytes();
final AtomicReference<Throwable> cause = new AtomicReference<>();
final AtomicBoolean connected = new AtomicBoolean(false);
final FutureResult<?> latch = new FutureResult<>();
class TestEndPoint extends Endpoint {
@Override
public void onOpen(final Session session, EndpointConfig config) {
connected.set(true);
session.addMessageHandler(new MessageHandler.Whole<byte[]>() {
@Override
public void onMessage(final byte[] message) {
DefaultServer.getWorker().execute(() -> {
try {
OutputStream out = session.getBasicRemote().getSendStream();
out.write(message);
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
cause.set(e);
latch.setException(e);
}
});
}
});
}
}
ServerWebSocketContainer builder = new ServerWebSocketContainer(TestClassIntrospector.INSTANCE, DefaultServer.getWorkerSupplier(), DefaultServer.getBufferPool(), Collections.emptyList(), false, false);
builder.addEndpoint(ServerEndpointConfig.Builder.create(TestEndPoint.class, "/").configurator(new InstanceConfigurator(new TestEndPoint())).build());
deployServlet(builder);
WebSocketTestClient client = new WebSocketTestClient(getVersion(), new URI("ws://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostPort("default") + "/"));
client.connect();
client.send(new BinaryWebSocketFrame(Unpooled.wrappedBuffer(payload)), new FrameChecker(BinaryWebSocketFrame.class, payload, latch));
// FIXME UNDERTOW-1862 assertEquals(DONE, latch.getIoFuture().await());
latch.getIoFuture().await();
assertNull(cause.get());
client.destroy();
}
use of io.undertow.websockets.jsr.ServerWebSocketContainer in project undertow by undertow-io.
the class JsrWebSocketServer07Test method testBinaryWithByteArray.
@org.junit.Test
public void testBinaryWithByteArray() throws Exception {
final byte[] payload = "payload".getBytes();
final AtomicReference<Throwable> cause = new AtomicReference<>();
final AtomicBoolean connected = new AtomicBoolean(false);
final FutureResult<?> latch = new FutureResult<>();
class TestEndPoint extends Endpoint {
@Override
public void onOpen(final Session session, EndpointConfig config) {
connected.set(true);
session.addMessageHandler(new MessageHandler.Whole<byte[]>() {
@Override
public void onMessage(byte[] message) {
session.getAsyncRemote().sendBinary(ByteBuffer.wrap(message.clone()));
}
});
}
}
ServerWebSocketContainer builder = new ServerWebSocketContainer(TestClassIntrospector.INSTANCE, DefaultServer.getWorkerSupplier(), DefaultServer.getBufferPool(), Collections.emptyList(), false, false);
builder.addEndpoint(ServerEndpointConfig.Builder.create(TestEndPoint.class, "/").configurator(new InstanceConfigurator(new TestEndPoint())).build());
deployServlet(builder);
WebSocketTestClient client = new WebSocketTestClient(getVersion(), new URI("ws://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostPort("default") + "/"));
client.connect();
client.send(new BinaryWebSocketFrame(Unpooled.wrappedBuffer(payload)), new FrameChecker(BinaryWebSocketFrame.class, payload, latch));
// FIXME UNDERTOW-1862 assertEquals(DONE, latch.getIoFuture().await());
latch.getIoFuture().await();
assertNull(cause.get());
client.destroy();
}
use of io.undertow.websockets.jsr.ServerWebSocketContainer in project undertow by undertow-io.
the class JsrWebSocketServer07Test method testTextAsync.
@org.junit.Test
public void testTextAsync() throws Exception {
final byte[] payload = "payload".getBytes();
final AtomicReference<Throwable> cause = new AtomicReference<>();
final AtomicBoolean connected = new AtomicBoolean(false);
final FutureResult<?> latch = new FutureResult<>();
class TestEndPoint extends Endpoint {
@Override
public void onOpen(final Session session, EndpointConfig config) {
connected.set(true);
session.addMessageHandler(new MessageHandler.Partial<String>() {
final StringBuilder sb = new StringBuilder();
@Override
public void onMessage(String message, boolean last) {
sb.append(message);
if (!last) {
return;
}
session.getAsyncRemote().sendText(sb.toString());
}
});
}
}
ServerWebSocketContainer builder = new ServerWebSocketContainer(TestClassIntrospector.INSTANCE, DefaultServer.getWorkerSupplier(), DefaultServer.getBufferPool(), Collections.emptyList(), false, false);
builder.addEndpoint(ServerEndpointConfig.Builder.create(TestEndPoint.class, "/").configurator(new InstanceConfigurator(new TestEndPoint())).build());
deployServlet(builder);
WebSocketTestClient client = new WebSocketTestClient(getVersion(), new URI("ws://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostPort("default") + "/"));
client.connect();
client.send(new TextWebSocketFrame(Unpooled.wrappedBuffer(payload)), new FrameChecker(TextWebSocketFrame.class, payload, latch));
// FIXME UNDERTOW-1862 assertEquals(DONE, latch.getIoFuture().await());
latch.getIoFuture().await();
assertNull(cause.get());
client.destroy();
}
use of io.undertow.websockets.jsr.ServerWebSocketContainer in project undertow by undertow-io.
the class JsrWebSocketServer07Test method testTextByFuture.
@org.junit.Test
public void testTextByFuture() throws Exception {
final byte[] payload = "payload".getBytes();
final AtomicReference<Future<Void>> sendResult = new AtomicReference<>();
final AtomicBoolean connected = new AtomicBoolean(false);
final FutureResult<?> latch = new FutureResult<>();
class TestEndPoint extends Endpoint {
@Override
public void onOpen(final Session session, EndpointConfig config) {
connected.set(true);
session.addMessageHandler(new MessageHandler.Whole<String>() {
@Override
public void onMessage(String message) {
sendResult.set(session.getAsyncRemote().sendText(message));
}
});
}
}
ServerWebSocketContainer builder = new ServerWebSocketContainer(TestClassIntrospector.INSTANCE, DefaultServer.getWorkerSupplier(), DefaultServer.getBufferPool(), Collections.emptyList(), false, false);
builder.addEndpoint(ServerEndpointConfig.Builder.create(TestEndPoint.class, "/").configurator(new InstanceConfigurator(new TestEndPoint())).build());
deployServlet(builder);
WebSocketTestClient client = new WebSocketTestClient(getVersion(), new URI("ws://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostPort("default") + "/"));
client.connect();
client.send(new TextWebSocketFrame(Unpooled.wrappedBuffer(payload)), new FrameChecker(TextWebSocketFrame.class, payload, latch));
// FIXME UNDERTOW-1862 assertEquals(DONE, latch.getIoFuture().await());
latch.getIoFuture().await();
sendResult.get();
/* FIXME .wait(4000);
assertTrue(sendResult.get().isDone());*/
client.destroy();
}
use of io.undertow.websockets.jsr.ServerWebSocketContainer in project undertow by undertow-io.
the class SuspendResumeTestCase method setup.
@BeforeClass
public static void setup() throws ServletException {
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(TestMessagesReceivedInOrder.class.getClassLoader()).setContextPath("/").setResourceManager(new TestResourceLoader(TestMessagesReceivedInOrder.class)).setClassIntrospecter(TestClassIntrospector.INSTANCE).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorker()).addListener(new WebSocketDeploymentInfo.ContainerReadyListener() {
@Override
public void ready(ServerWebSocketContainer c) {
serverContainer = c;
}
}).addEndpoint(SuspendResumeEndpoint.class)).setDeploymentName("servletContext.war");
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/", manager.start()));
}
Aggregations