Search code examples
javawebsocketwebsphere-libertyjava-websocket

how does code determine to use WebSphereRequestUpgradeStrategy vs TomcatRequestUpgradeStrategy?


I'm trying to use websockets and my spring app runs on Websphere Liberty. My Websockets connection does not work, and upon debugging with class libraries, I figured out that my code goes to TomcatRequestUpgradeStrategy and this one does not work, versus the one that uses WebSphereRequestUpgradeStrategy works fine. Am not clear on how does the logic to determine this work? I have set spring-boot-starter-tomcat as provided in my pom. So am not clear how it is causing it to use TomcatRequestUpgradeStrategy. Can someone help me with this?

Working:

SRTServletRequest31.upgrade(Class<T>) line: 157 
WsocHandlerImpl.handleRequest(HttpServletRequest, HttpServletResponse, ServerEndpointConfig, Map<String,String>, boolean) line: 268 
ServerContainerExt.doUpgrade(HttpServletRequest, HttpServletResponse, ServerEndpointConfig, Map<String,String>) line: 288   
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]  
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 62  
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43  
Method.invoke(Object, Object...) line: 498  
WebSphereRequestUpgradeStrategy.upgradeInternal(ServerHttpRequest, ServerHttpResponse, String, List<Extension>, Endpoint) line: 87  
WebSphereRequestUpgradeStrategy(AbstractStandardUpgradeStrategy).upgrade(ServerHttpRequest, ServerHttpResponse, String, List<WebSocketExtension>, Principal, WebSocketHandler, Map<String,Object>) line: 119    
DefaultHandshakeHandler(AbstractHandshakeHandler).doHandshake(ServerHttpRequest, ServerHttpResponse, WebSocketHandler, Map<String,Object>) line: 281    
WebSocketHttpRequestHandler.handleRequest(HttpServletRequest, HttpServletResponse) line: 166

Not working:

SRTServletRequest31.upgrade(Class<T>) line: 157 
RequestWrapper(HttpServletRequestWrapper).upgrade(Class<T>) line: 399   
HttpSessionSecurityContextRepository$Servlet3SaveToSessionRequestWrapper(HttpServletRequestWrapper).upgrade(Class<T>) line: 399 
HttpServlet3RequestFactory$Servlet3SecurityContextHolderAwareRequestWrapper(HttpServletRequestWrapper).upgrade(Class<T>) line: 399  
UpgradeUtil.doUpgrade(WsServerContainer, HttpServletRequest, HttpServletResponse, ServerEndpointConfig, Map<String,String>) line: 234   
WsServerContainer.doUpgrade(HttpServletRequest, HttpServletResponse, ServerEndpointConfig, Map<String,String>) line: 265    
TomcatRequestUpgradeStrategy.upgradeInternal(ServerHttpRequest, ServerHttpResponse, String, List<Extension>, Endpoint) line: 72 
TomcatRequestUpgradeStrategy(AbstractStandardUpgradeStrategy).upgrade(ServerHttpRequest, ServerHttpResponse, String, List<WebSocketExtension>, Principal, WebSocketHandler, Map<String,Object>) line: 119   
DefaultHandshakeHandler(AbstractHandshakeHandler).doHandshake(ServerHttpRequest, ServerHttpResponse, WebSocketHandler, Map<String,Object>) line: 281    
WebSocketHttpRequestHandler.handleRequest(HttpServletRequest, HttpServletResponse) line: 166    

Pls let me know if you need more details. Appreciate any response.


Solution

  • I figured out the answer for my question. This could be helpful for someone else in the future.

    DefaultHandshakeHandler has a check to see if org.apache.tomcat.websocket.server.WsHttpUpgradeHandler is present in the class loader. Since there was tomcat-embed-websocket in the pom dependency, this class was present. So, even though I was running on Liberty, this was getting triggered. Removing the same from the pom, helped me fix the problem.