[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
Conflict with java 7 tomcat WebSocket API  XML
Forum Index -> Terracotta for Web Sessions
Author Message
yoseph

neo

Joined: 04/29/2014 02:21:49
Messages: 3
Offline

I'm using org.terracotta.session.TerracottaTomcat70xSessionValve to handle tomcat session using Terracotta 3.7.7.

The problem is, if I enable the web session using terracotta, the websocket service is throwing an exception "Upgrade failed". After reading the code from org.apache.tomcat.websocket source, I found the following line which causing the error:

Code:
 package org.apache.tomcat.websocket.server;
 
 public class UpgradeUtil {
 .
 .
 .
     public static void doUpgrade(WsServerContainer sc, HttpServletRequest req,
             HttpServletResponse resp, ServerEndpointConfig sec,
             Map<String,String> pathParams)
             throws ServletException, IOException {
 .
 .
 .
 
         // Small hack until the Servlet API provides a way to do this.
         ServletRequest inner = req;
         // Unwrap the request
         while (inner instanceof ServletRequestWrapper) {
             inner = ((ServletRequestWrapper) inner).getRequest();
         }
         if (inner instanceof RequestFacade) {
             WsHttpUpgradeHandler wsHandler =
                     ((RequestFacade) inner).upgrade(WsHttpUpgradeHandler.class);
             wsHandler.preInit(ep, perSessionServerEndpointConfig, sc, wsRequest,
                     subProtocol, pathParams, req.isSecure());
         } else {
             throw new ServletException("Upgrade failed");
         }
 
     }
 
 }
 


It seems that the terracotta valve has modified the HTTPRequest object so it's not an instance of RequestFacade anymore.

Please somebody help me solving the problem.
teck

seraphim
[Avatar]
Joined: 05/24/2006 15:03:25
Messages: 1128
Offline

I could certainly believe the request wrapping done by the terracotta valve could interact poorly with the code referenced there.

Without fully understanding what's going on with the requests in this path it's hard to know what it would take to make everything "work" here.

About the best I can say is to file this as a bug/enhancement at https://jira.terracotta.org/jira/browse/CDV

What tomcat version is? Just curious


Tim Eck (terracotta engineer)
yoseph

neo

Joined: 04/29/2014 02:21:49
Messages: 3
Offline

I'm using Tomcat 7.0.53, Terracotta 3.7.7 and Java 1.7.0_55. Below the complete exception stacktrace, WsFilter class source, and UpgradeUtil class source which causing the Exception.

I'm hopping somebody can provide me a solution for this problem.

Thank you

Code:
 Apr 30, 2014 8:35:23 AM org.apache.catalina.core.StandardWrapperValve invoke
 SEVERE: Servlet.service() for servlet [default] in context with path [] threw exception [Upgrade failed] with root cause
 javax.servlet.ServletException: Upgrade failed
 	at org.apache.tomcat.websocket.server.UpgradeUtil.doUpgrade(UpgradeUtil.java:190)
 	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:77)
 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
 	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
 	at org.terracotta.modules.tomcat.tomcat_7_0.SessionValve70.tcInvoke(SessionValve70.java:97)
 	at org.terracotta.modules.tomcat.tomcat_7_0.SessionValve70.invoke(SessionValve70.java:82)
 	at org.terracotta.session.ModernTomcatSessionValve.invoke(ModernTomcatSessionValve.java:66)
 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
 	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
 	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
 	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
 	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
 	at java.lang.Thread.run(Thread.java:745)
 



Code:
 package org.apache.tomcat.websocket.server;
 .
 .
 .
 
 public class WsFilter implements Filter {
 .
 .
 .
 
       @Override
       public void doFilter(ServletRequest request, ServletResponse response,
             FilterChain chain) throws IOException, ServletException {
 .
 .
 .
 
         UpgradeUtil.doUpgrade(sc, req, resp, mappingResult.getConfig(),
                 mappingResult.getPathParams());
     }
 }
 
 


Code:
 package org.apache.tomcat.websocket.server;
 .
 .
 .
 
 public class UpgradeUtil {
 .
 .
 .
 
     public static void doUpgrade(WsServerContainer sc, HttpServletRequest req, HttpServletResponse resp, ServerEndpointConfig sec, Map<String,String> pathParams) throws ServletException, IOException {
 .
 .
 .
 
         // Small hack until the Servlet API provides a way to do this.
         ServletRequest inner = req;
         // Unwrap the request
         while (inner instanceof ServletRequestWrapper) {
             inner = ((ServletRequestWrapper) inner).getRequest();
         }
         if (inner instanceof RequestFacade) {
             WsHttpUpgradeHandler wsHandler =
                     ((RequestFacade) inner).upgrade(WsHttpUpgradeHandler.class);
             wsHandler.preInit(ep, perSessionServerEndpointConfig, sc, wsRequest,
                     subProtocol, pathParams, req.isSecure());
         } else {
             throw new ServletException("Upgrade failed");
         }
     }
 }
 
 
yoseph

neo

Joined: 04/29/2014 02:21:49
Messages: 3
Offline

I've submitted the issue in JIRA:
https://jira.terracotta.org/jira/browse/CDV-1664

Please help me vote for it. Thank you
burbidge

neo

Joined: 07/06/2016 16:24:06
Messages: 1
Offline

Any update on this. We're having the same problem.
 
Forum Index -> Terracotta for Web Sessions
Go to:   
Powered by JForum 2.1.7 © JForum Team