You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2012/05/12 22:51:24 UTC

svn commit: r1337643 - /tomcat/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java

Author: markt
Date: Sat May 12 20:51:24 2012
New Revision: 1337643

URL: http://svn.apache.org/viewvc?rev=1337643&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53067
Make sure request is unwrapped before we cast it to the internal Tomcat implementation

Modified:
    tomcat/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java

Modified: tomcat/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java?rev=1337643&r1=1337642&r2=1337643&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java Sat May 12 20:51:24 2012
@@ -27,6 +27,8 @@ import java.util.Queue;
 import java.util.concurrent.ConcurrentLinkedQueue;
 
 import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletRequestWrapper;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -112,9 +114,19 @@ public abstract class WebSocketServlet e
             // TODO
         }
 
-        // Small hack until the Servlet API provides a way to do this.
         StreamInbound inbound = createWebSocketInbound(subProtocol);
-        ((RequestFacade) req).doUpgrade(inbound);
+
+        // 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) {
+            ((RequestFacade) req).doUpgrade(inbound);
+        } else {
+            resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+        }
     }
 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1337643 - /tomcat/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java

Posted by Mark Thomas <ma...@apache.org>.
On 12/05/2012 23:14, Konstantin Kolinko wrote:
> 2012/5/13  <ma...@apache.org>:
>> Author: markt
>> Date: Sat May 12 20:51:24 2012
>> New Revision: 1337643
>> +        if (inner instanceof RequestFacade) {
>> +            ((RequestFacade) req).doUpgrade(inbound);
> 
> inner.doUpgrade(), not req.

Doh.

> 
>> +        } else {
>> +            resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
> 
> It would be hard to find what is the cause of an issue if it is just a
> generic error 500.
> 
> Maybe just throw a ServletException and let the ErrorReportValve to
> handle the rest?
> Well, just blatantly casting to RequestFacade will do effectively the same.

I'll add a message.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1337643 - /tomcat/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java

Posted by Konstantin Kolinko <kn...@gmail.com>.
2012/5/13  <ma...@apache.org>:
> Author: markt
> Date: Sat May 12 20:51:24 2012
> New Revision: 1337643
>
> URL: http://svn.apache.org/viewvc?rev=1337643&view=rev
> Log:
> Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53067
> Make sure request is unwrapped before we cast it to the internal Tomcat implementation
>
> Modified:
>    tomcat/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java
>
> Modified: tomcat/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java
> URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java?rev=1337643&r1=1337642&r2=1337643&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java (original)
> +++ tomcat/trunk/java/org/apache/catalina/websocket/WebSocketServlet.java Sat May 12 20:51:24 2012
> @@ -27,6 +27,8 @@ import java.util.Queue;
>  import java.util.concurrent.ConcurrentLinkedQueue;
>
>  import javax.servlet.ServletException;
> +import javax.servlet.ServletRequest;
> +import javax.servlet.ServletRequestWrapper;
>  import javax.servlet.http.HttpServlet;
>  import javax.servlet.http.HttpServletRequest;
>  import javax.servlet.http.HttpServletResponse;
> @@ -112,9 +114,19 @@ public abstract class WebSocketServlet e
>             // TODO
>         }
>
> -        // Small hack until the Servlet API provides a way to do this.
>         StreamInbound inbound = createWebSocketInbound(subProtocol);
> -        ((RequestFacade) req).doUpgrade(inbound);
> +
> +        // 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) {
> +            ((RequestFacade) req).doUpgrade(inbound);

inner.doUpgrade(), not req.

> +        } else {
> +            resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

It would be hard to find what is the cause of an issue if it is just a
generic error 500.

Maybe just throw a ServletException and let the ErrorReportValve to
handle the rest?
Well, just blatantly casting to RequestFacade will do effectively the same.

> +        }
>     }
>

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org