javax.servlet.ServletException: Upgrade failed

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • Conflict with java 7 tomcat WebSocket API
    via by Unknown author,
  • I'm using org.terracotta.session.TerracottaTomcat70xSessionValve to handle tomcat session. This is my environment version: Java 1.7.0_55 Tomcat 7.0.53 Terracotta 3.7.7 The problem is, if I enable the web session using terracotta, the websocket is throwing an exception "Upgrade failed" when trying to upgrade the http connection into websocket connection (if I'm not using terracotta session valve, the websocket working just fine). I think it must be related with the terracotta Request wrapper done in session valve. Please fix the problem ASAP. Thank you Thx Exception Stacktrace: {noformat} 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) {noformat} org.apache.tomcat.websocket.server.WsFilter: {noformat} 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()); } } {noformat} org.apache.tomcat.websocket.server.UpgradeUtil: {noformat} 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"); } } } {noformat} WebsocketEndpoint class: {noformat} import javax.websocket.CloseReason; import javax.websocket.EndpointConfig; import javax.websocket.OnClose; import javax.websocket.OnError; import javax.websocket.OnMessage; import javax.websocket.OnOpen; import javax.websocket.Session; import javax.websocket.server.ServerEndpoint; import org.apache.log4j.Logger; @ServerEndpoint("/websocket") public class WebsocketEndpoint { private static final Logger log = Logger.getLogger(MessagingEndpoint.class); public MessagingEndpoint() { log.info("WebSocket Endpoint Initialized"); } @OnOpen public void open(Session session, EndpointConfig conf) { log.debug("WebSocket Opened at: " + session.getRequestURI().toString()); } @OnMessage public void onMessage(Session session, String msg) { log.debug("Message Received: " + msg); } @OnError public void error(Session session, Throwable error) { log.debug("WebSocket Error: " + session.getId() + " - " + error.getMessage()); } @OnClose public void close(Session session, CloseReason reason) { log.debug("WebSocket Closed: " + session.getId() + " - " + reason.getReasonPhrase()); } } {noformat}
    via by Yoseph Stephen,
  • I'm using org.terracotta.session.TerracottaTomcat70xSessionValve to handle tomcat session. This is my environment version: Java 1.7.0_55 Tomcat 7.0.53 Terracotta 3.7.7 The problem is, if I enable the web session using terracotta, the websocket is throwing an exception "Upgrade failed" when trying to upgrade the http connection into websocket connection (if I'm not using terracotta session valve, the websocket working just fine). I think it must be related with the terracotta Request wrapper done in session valve. Please fix the problem ASAP. Thank you Thx Exception Stacktrace: {noformat} 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) {noformat} org.apache.tomcat.websocket.server.WsFilter: {noformat} 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()); } } {noformat} org.apache.tomcat.websocket.server.UpgradeUtil: {noformat} 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"); } } } {noformat} WebsocketEndpoint class: {noformat} import javax.websocket.CloseReason; import javax.websocket.EndpointConfig; import javax.websocket.OnClose; import javax.websocket.OnError; import javax.websocket.OnMessage; import javax.websocket.OnOpen; import javax.websocket.Session; import javax.websocket.server.ServerEndpoint; import org.apache.log4j.Logger; @ServerEndpoint("/websocket") public class WebsocketEndpoint { private static final Logger log = Logger.getLogger(MessagingEndpoint.class); public MessagingEndpoint() { log.info("WebSocket Endpoint Initialized"); } @OnOpen public void open(Session session, EndpointConfig conf) { log.debug("WebSocket Opened at: " + session.getRequestURI().toString()); } @OnMessage public void onMessage(Session session, String msg) { log.debug("Message Received: " + msg); } @OnError public void error(Session session, Throwable error) { log.debug("WebSocket Error: " + session.getId() + " - " + error.getMessage()); } @OnClose public void close(Session session, CloseReason reason) { log.debug("WebSocket Closed: " + session.getId() + " - " + reason.getReasonPhrase()); } } {noformat}
    via by Yoseph Stephen,
    • 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)
    No Bugmate found.