javax.servlet.ServletException: Upgrade failed

Terracotta | yoseph | 3 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Conflict with java 7 tomcat WebSocket API

    terracotta.org | 1 year ago
    javax.servlet.ServletException: Upgrade failed
  2. 0

    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}

    Terracotta Project Issue Tracker | 3 years ago | Yoseph Stephen
    javax.servlet.ServletException: Upgrade failed
  3. 0

    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}

    Terracotta Project Issue Tracker | 3 years ago | Yoseph Stephen
    javax.servlet.ServletException: Upgrade failed
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Re:Conflict with java 7 tomcat WebSocket API

    Terracotta | 3 years ago | yoseph
    javax.servlet.ServletException: Upgrade failed

    Root Cause Analysis

    1. javax.servlet.ServletException

      Upgrade failed

      at org.apache.tomcat.websocket.server.UpgradeUtil.doUpgrade()
    2. Tomcat WS
      WsFilter.doFilter
      1. org.apache.tomcat.websocket.server.UpgradeUtil.doUpgrade(UpgradeUtil.java:190)
      2. org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:77)
      2 frames
    3. Glassfish Core
      AuthenticatorBase.invoke
      1. org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
      2. org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      3. org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
      4. org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
      5. org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
      5 frames
    4. org.terracotta.modules
      SessionValve70.invoke
      1. org.terracotta.modules.tomcat.tomcat_7_0.SessionValve70.tcInvoke(SessionValve70.java:97)
      2. org.terracotta.modules.tomcat.tomcat_7_0.SessionValve70.invoke(SessionValve70.java:82)
      2 frames
    5. org.terracotta.session
      ModernTomcatSessionValve.invoke
      1. org.terracotta.session.ModernTomcatSessionValve.invoke(ModernTomcatSessionValve.java:66)
      1 frame
    6. Glassfish Core
      CoyoteAdapter.service
      1. org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
      2. org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
      3. org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
      4. org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
      5. org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      5 frames
    7. Grizzly HTTP
      JIoEndpoint$SocketProcessor.run
      1. org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
      2. org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
      3. org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
      3 frames
    8. Java RT
      Thread.run
      1. java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      2. java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      3. java.lang.Thread.run(Thread.java:745)
      3 frames