use of io.undertow.websockets.jsr.UndertowSession in project undertow by undertow-io.
the class AnnotatedEndpoint method onOpen.
@Override
public void onOpen(final Session session, final EndpointConfig endpointConfiguration) {
this.released = false;
final UndertowSession s = (UndertowSession) session;
boolean partialText = textMessage == null || (textMessage.hasParameterType(boolean.class) && !textMessage.getMessageType().equals(boolean.class));
boolean partialBinary = binaryMessage == null || (binaryMessage.hasParameterType(boolean.class) && !binaryMessage.getMessageType().equals(boolean.class));
if (textMessage != null) {
if (partialText) {
addPartialHandler(s, textMessage);
} else {
if (textMessage.getMaxMessageSize() > 0) {
s.setMaxTextMessageBufferSize((int) textMessage.getMaxMessageSize());
}
addWholeHandler(s, textMessage);
}
}
if (binaryMessage != null) {
if (partialBinary) {
addPartialHandler(s, binaryMessage);
} else {
if (binaryMessage.getMaxMessageSize() > 0) {
s.setMaxBinaryMessageBufferSize((int) binaryMessage.getMaxMessageSize());
}
addWholeHandler(s, binaryMessage);
}
}
if (pongMessage != null) {
addWholeHandler(s, pongMessage);
}
if (webSocketOpen != null) {
final Map<Class<?>, Object> params = new HashMap<>();
params.put(Session.class, session);
params.put(EndpointConfig.class, endpointConfiguration);
params.put(Map.class, session.getPathParameters());
invokeMethod(params, webSocketOpen, s);
}
}
use of io.undertow.websockets.jsr.UndertowSession in project undertow by undertow-io.
the class AnnotatedEndpointTest method testGenericMessageHandling.
@Test
public void testGenericMessageHandling() throws Exception {
//make a sub class
AnnotatedGenericClientEndpoint c = new AnnotatedGenericClientEndpoint() {
};
Session session = deployment.connectToServer(c, new URI("ws://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostPort("default") + "/ws/error"));
Assert.assertEquals("hi", ErrorEndpoint.getMessage());
session.getAsyncRemote().sendText("app-error");
Assert.assertEquals("app-error", ErrorEndpoint.getMessage());
Assert.assertEquals("ERROR: java.lang.RuntimeException", ErrorEndpoint.getMessage());
Assert.assertTrue(c.isOpen());
session.getBasicRemote().sendText("io-error");
Assert.assertEquals("io-error", ErrorEndpoint.getMessage());
Assert.assertEquals("ERROR: java.io.IOException", ErrorEndpoint.getMessage());
Assert.assertTrue(c.isOpen());
((UndertowSession) session).forceClose();
Assert.assertEquals("CLOSED", ErrorEndpoint.getMessage());
}
use of io.undertow.websockets.jsr.UndertowSession in project undertow by undertow-io.
the class AnnotatedEndpointTest method testErrorHandling.
@Test
public void testErrorHandling() throws Exception {
//make a sub class
AnnotatedClientEndpoint c = new AnnotatedClientEndpoint() {
};
Session session = deployment.connectToServer(c, new URI("ws://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostPort("default") + "/ws/error"));
Assert.assertEquals("hi", ErrorEndpoint.getMessage());
session.getAsyncRemote().sendText("app-error");
Assert.assertEquals("app-error", ErrorEndpoint.getMessage());
Assert.assertEquals("ERROR: java.lang.RuntimeException", ErrorEndpoint.getMessage());
Assert.assertTrue(c.isOpen());
session.getBasicRemote().sendText("io-error");
Assert.assertEquals("io-error", ErrorEndpoint.getMessage());
Assert.assertEquals("ERROR: java.io.IOException", ErrorEndpoint.getMessage());
Assert.assertTrue(c.isOpen());
((UndertowSession) session).forceClose();
Assert.assertEquals("CLOSED", ErrorEndpoint.getMessage());
}
use of io.undertow.websockets.jsr.UndertowSession in project undertow by undertow-io.
the class JsrWebSocketServer07Test method testErrorHandling.
@Test
public void testErrorHandling() throws Exception {
ServerWebSocketContainer builder = new ServerWebSocketContainer(TestClassIntrospector.INSTANCE, DefaultServer.getWorker(), DefaultServer.getBufferPool(), Collections.EMPTY_LIST, false, false);
builder.addEndpoint(ServerEndpointConfig.Builder.create(ProgramaticErrorEndpoint.class, "/").configurator(new InstanceConfigurator(new ProgramaticErrorEndpoint())).build());
deployServlet(builder);
AnnotatedClientEndpoint c = new AnnotatedClientEndpoint();
Session session = ContainerProvider.getWebSocketContainer().connectToServer(c, new URI("ws://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostPort("default") + "/"));
Assert.assertEquals("hi", ProgramaticErrorEndpoint.getMessage());
session.getAsyncRemote().sendText("app-error");
Assert.assertEquals("app-error", ProgramaticErrorEndpoint.getMessage());
Assert.assertEquals("ERROR: java.lang.RuntimeException", ProgramaticErrorEndpoint.getMessage());
Assert.assertTrue(c.isOpen());
session.getBasicRemote().sendText("io-error");
Assert.assertEquals("io-error", ProgramaticErrorEndpoint.getMessage());
Assert.assertEquals("ERROR: java.lang.RuntimeException", ProgramaticErrorEndpoint.getMessage());
Assert.assertTrue(c.isOpen());
((UndertowSession) session).forceClose();
Assert.assertEquals("CLOSED", ProgramaticErrorEndpoint.getMessage());
}
Aggregations