https://issues.apache.org/bugzilla/show_bug.cgi?id=56673
Bug ID: 56673 Summary: Tomcat Websocket 8.0.8 Java Standalone Client Session.getId() returns "0" Product: Tomcat 8 Version: 8.0.8 Hardware: PC Status: NEW Severity: major Priority: P2 Component: WebSocket Assignee: dev@tomcat.apache.org Reporter: tellercapi...@gmail.com I'm currently testing various Java websocket standalone client containers with a simple test application where the standalone Java client app makes a websocket connection to a Wildfly 8.0.0.Final app server running on the same machine. For the Tomcat client container, the client app uses the following Maven dependencies: <dependency> <groupId>javax.websocket</groupId> <artifactId>javax.websocket-api</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-websocket</artifactId> <version>8.0.8</version> </dependency> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-coyote</artifactId> <version>8.0.8</version> </dependency> Everything works fine: the client is able to successfully connect to the server, send messages and receive messages. The only problem that I've encountered is that on each of the callback methods on the client, the Session parameter doesn't contain the correct Session id, i.e. calling session.getId() returns "0". On the server side, the callback session params contain the session id, so I know that it being created correctly on the server, just not sent to the client. ****************************************************** CLIENT CODE: @ClientEndpoint() public class MyClientEndpoint { private static CountDownLatch latch; public void connect(URI endpointURI) { try { WebSocketContainer container = ContainerProvider.getWebSocketContainer(); System.out.println("container = " + container); container.connectToServer(MyClientEndpoint.class, endpointURI); } catch (Exception e) { System.out.println("Exception trying to connect"); latch.countDown(); throw new RuntimeException(e); } } @OnMessage public void onMessage(Session pSession, String message) { System.out.println("Received message: " + message + " from Session: " + pSession.getId()); if (message.equalsIgnoreCase("goodbye")) { try { pSession.close(); } catch (IOException e) { e.printStackTrace(); } } } @OnOpen public void onOpen(Session pSession) { System.out.println("Session Opened Successfully: " + pSession.getId()); System.out.println("Session class = " + pSession.getClass().getName()); try { pSession.getBasicRemote().sendText("Hello!"); } catch (IOException e) { e.printStackTrace(); } } @OnClose public void onClose(Session pSession) { System.out.println("Session Closed: " + pSession.getId()); latch.countDown(); } @OnError public void onError(Session pSession, Throwable pThrowable) { System.out.println("Received Error: "); try { pSession.close(); } catch (IOException e) { } latch.countDown(); pThrowable.printStackTrace(); } public static void main(String[] args) { latch = new CountDownLatch(1); String uriString = "ws://localhost/test"; try { URI uri = new URI(uriString); SampleClientEndpoint client = new SampleClientEndpoint(); client.connect(uri); latch.await(); } catch (URISyntaxException | InterruptedException e) { throw new RuntimeException(e); } } } ****************************************************** SERVER CODE: @ServerEndpoint("/test") public class MyServerEndpoint { @OnMessage public void onMessage(Session pSession, String message) { System.out.println("Received message: " + message + " from Session: " + pSession.getId()); } @OnOpen public void onOpen(Session pSession) { System.out.println("Session Opened Successfully: " + pSession.getId()); try { for (int i = 1; i < 5; i++) { pSession.getBasicRemote().sendText("hello" + i); } pSession.getBasicRemote().sendText("goodbye"); } catch (IOException e) { e.printStackTrace(); } } @OnClose public void onClose(Session pSession) { System.out.println("Session Closed: " + pSession.getId()); } @OnError public void onError(Session pSession, Throwable pThrowable) { System.out.println("Received Error For Session: " + pSession.getId()); pThrowable.printStackTrace(); } } -- You are receiving this mail because: You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org