jeudi 19 février 2015

Can't establish a websocket connection to a JavaEE Spring Server Application

i have a web application build up with spring mvc 4.1.3 on a Wildfly Server which has a websocket server implemented. About a few weeks ago everything worked as expected. Since then i didn't checked the websocket connection. Yesterday i wanted to check the features of the application and out of a sudden the websocket connection couldn't established. The Client, in my case chrome, reported the following error message



WebSocket connection to 'ws://127.0.0.1:8080/frontend/notificationws' failed: Error during WebSocket handshake: Unexpected response code: 200


Firefox reported the same error message, though the Server reported nothing. I tried to get any further information on the error message but had no luck yet. I observed the message exchange between the websocket server and client with wireshark but no luck either. Nothing suspicious found.


Websocket handling:



public class NotificationWs extends TextWebSocketHandler{
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) {
logger.info("Payload: " + message.getPayload());
}
}


Custom handshake:



public class NotificationHandshakeInterceptor extends HttpSessionHandshakeInterceptor {
@Override
public boolean beforeHandshake(ServerHttpRequest request,
ServerHttpResponse response, WebSocketHandler wsHandler,
Map<String, Object> attributes) throws Exception {
logger.info("Before Handshake");
return super.beforeHandshake(request, response, wsHandler, attributes);
}

@Override
public void afterHandshake(ServerHttpRequest request,
ServerHttpResponse response, WebSocketHandler wsHandler,
Exception ex) {
logger.info("After Handshake");
super.afterHandshake(request, response, wsHandler, ex);

}
}


Configuration in Servlet Context:



<bean id="notificationWs" class="com.supo.frontend.websocket.notification.NotificationWs" />
<websocket:handlers>
<websocket:mapping path="/notificationws" handler="notificationWs"/>
<websocket:handshake-interceptors>
<bean class="com.supo.frontend.websocket.notification.NotificationHandshakeInterceptor"/>
</websocket:handshake-interceptors>
</websocket:handlers>


javascript:



...
var uri = "ws://" + (document.location.hostname) + ":" + "8080" + "/frontend/notificationws";
websocket = new WebSocket(uri);
...


I hope thats enough info. I would appreciate any help.


Aucun commentaire:

Enregistrer un commentaire