-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TimeoutException when running example in doc #11009
Comments
|
Note that You are doing
The class used in this line should extend |
But regardless you should be getting better error messages instead of just a timeout exception so I will look into this soon and see if it can be improved. |
Here is a revision of your code which works. public static void main(String[] args) throws Exception {
Server server = new Server(8080);
ServletContextHandler handler = new ServletContextHandler("/ctx");
server.setHandler(handler);
JakartaWebSocketServletContainerInitializer.configure(handler, (servletContext, container) -> {
container.setDefaultMaxTextMessageBufferSize(128 * 1024);
container.addEndpoint(ServerEndpointConfig.Builder.create(Test.class, "/ws").build());
});
server.start();
WebSocketClient client = new WebSocketClient();
client.start();
Session session = client.connect(new Session.Listener.AutoDemanding() {
public void onWebSocketOpen(Session session) {
System.out.println("client open");
}
public void onWebSocketText(String message) {
System.out.println(message);
}
}, new URI("ws://127.0.0.1:8080/ctx/ws")).get(300, TimeUnit.SECONDS);
var callback = new Callback.Completable();
session.sendText("test", callback);
callback.get();
}
public static class Test extends Endpoint implements MessageHandler.Whole<String> {
@Override
public void onOpen(jakarta.websocket.Session session, EndpointConfig config)
{
try
{
session.addMessageHandler(this);
System.out.println("server open");
session.getBasicRemote().sendText("connected");
}
catch (Throwable t)
{
t.printStackTrace(System.err);
}
}
@Override
public void onMessage(String message)
{
System.out.println(message);
}
} |
Signed-off-by: Lachlan Roberts <[email protected]>
Signed-off-by: Lachlan Roberts <[email protected]>
…tConfig Signed-off-by: Lachlan Roberts <[email protected]>
Signed-off-by: Lachlan Roberts <[email protected]>
…ServerEndpointConfig (#11032) * Issue #11009 - add test for bad Jakarta endpoint * Issue #11009 - ensure endpoint deployable before adding ServerEndpointConfig * add same test and fix for ee9 Signed-off-by: Lachlan Roberts <[email protected]>
Jetty Version
jetth 12
Jetty Environment
ee10
Java Version
java 17
Question
dependency
code
The text was updated successfully, but these errors were encountered: