You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2015/03/26 01:25:41 UTC

[Bug 57761] New: WebSocket client won't connect to URLs that don't end in a slash (/)

https://bz.apache.org/bugzilla/show_bug.cgi?id=57761

            Bug ID: 57761
           Summary: WebSocket client won't connect to URLs that don't end
                    in a slash (/)
           Product: Tomcat 8
           Version: trunk
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: WebSocket
          Assignee: dev@tomcat.apache.org
          Reporter: palmercox@gmail.com

The following program won't work on Tomcat's WebSocket client jars, both 8.0.20
and Trunk:

public class App2 {
    @ClientEndpoint
    public static class Client {
        @OnOpen
        public void onOpen(Session s) throws Exception {
            System.out.println("Sending PING");
            s.getBasicRemote().sendText("PING");
        }

        @OnMessage
        public void onMessage(Session s, String msg) throws Exception {
            System.out.println("GOT: " + msg);
            Thread.sleep(1000);
            s.getBasicRemote().sendText("PING");
            System.out.println("Sending PING");
        }
    }

    public static void main(final String[] args) throws Exception {
        ContainerProvider.getWebSocketContainer().connectToServer(
                Client.class,
                URI.create("ws://echo.websocket.org"));
        Thread.sleep(Long.MAX_VALUE);
    }
}

It fails with:

Exception in thread "main" javax.websocket.DeploymentException: The
HTTP request to initiate the WebSocket connection failed
    at
org.apache.tomcat.websocket.WsWebSocketContainer.connectToServer(WsWebSocketContainer.java:357)
    at
org.apache.tomcat.websocket.WsWebSocketContainer.connectToServer(WsWebSocketContainer.java:164)
    at
org.apache.tomcat.websocket.WsWebSocketContainer.connectToServer(WsWebSocketContainer.java:181)
    at io.davinci.test_sync_gateway_websocket.App2.main(App2.java:31)
Caused by: java.io.EOFException
    at
org.apache.tomcat.websocket.WsWebSocketContainer.processResponse(WsWebSocketContainer.java:606)
    at
org.apache.tomcat.websocket.WsWebSocketContainer.connectToServer(WsWebSocketContainer.java:309)
    ... 3 more


If you add a slash to the end of the URL, however, it connects.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 57761] WebSocket client won't connect to URLs that don't end in a slash (/)

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57761

Remy Maucherat <re...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All

--- Comment #1 from Remy Maucherat <re...@apache.org> ---
Without the slash, it would do a redirect and that's likely the cause of the
problem. The ws client is not a real HTTP client, and I guess it cannot do many
things, including auth, or apparently redirects. I am not convinced using a
real HTTP client is mandatory, working only with a server that will do a
straight upgrade could be good enough given what the ws API looks like (a non
interactive direct connection).

I recommend considering the slash is mandatory.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 57761] WebSocket client won't connect to URLs that don't end in a slash (/)

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57761

--- Comment #4 from Remy Maucherat <re...@apache.org> ---
The empty path in the request line is fixed in r1669353 in trunk, but I also
verified that the websocket client cannot handle anything other than an upgrade
response, so the same test adapted to a webapp root will fail to process the
redirect response.

I don't think it is required that the websocket client is a competent HTTP
client, so maybe this bz can be transformed into a more generic enhancement.

I don't think the fix is very useful "standalone" without client enhancements
so no plan for porting it.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 57761] WebSocket client won't connect to URLs that don't end in a slash (/)

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57761

--- Comment #3 from Remy Maucherat <re...@apache.org> ---
Ah, that's another explanation and easier fix !

More generally, if it ran into a redirect (like requesting the root of a webapp
maybe) or anything besides the upgrade response really, I don't think anything
is supported. Did I miss something ? I don't think support is mandatory (should
connect directly to a websocket URL, and it is not required to be a full
client).

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 57761] WebSocket client won't connect to URLs that don't end in a slash (/)

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57761

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Mark Thomas <ma...@apache.org> ---
I haven't seen any demand (yet) for handling a redirect. Lets cross that bridge
if we come to it.

I've backported your fix to 8.0.x (for 8.0.22 onwards) and 7.0.x (for 7.0.61
onwards).

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 57761] WebSocket client won't connect to URLs that don't end in a slash (/)

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57761

--- Comment #2 from Mark Thomas <ma...@apache.org> ---
It isn't the redirec.  The Tomcat client has a bug. It requests "GET 
HTTP/1.1".

-- 
You are receiving this mail because:
You are the assignee for the bug.

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