JDK-6968163 : WebSocket protocol support
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.net
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86
  • Submitted: 2010-07-10
  • Updated: 2017-02-28
  • Resolved: 2017-02-28
Related Reports
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
It is not possible to create an URL which should use web sockets protocol.

new URL("ws://foo.bar/"); throws a malformed url exception even though this protocol should be legal.

WebSockets specifications can be found at
http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76

As it is stated in the spec "ws" is used for this protocol.

JUSTIFICATION :
Based on the fact that web sockets become more and more popular within web applications, and there are more and more web servers that use them as well as more and more applications that need to use it, it would be good if the protocol is marked legal in jdk.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
URL instance should be created.
ACTUAL -
MalformedURLException is thrown.

---------- BEGIN SOURCE ----------
new URL("ws://foo.bar");
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
I guess vanilla strings could be used.

Comments
I guess, we're not going to address this. A WebSocket URI can be created instead and fed to the jdk.incubator.http.HttpClient#newWebSocketBuilder (as of jdk 9 the WebSocket support is an incubating feature).
28-02-2017

EVALUATION "Exception in thread "main" java.net.MalformedURLException: unknown protocol: ws" is thrown because, by deafult, there is no websocket protocol handler. java.net.URL has constructors that allow the caller to specify a protocol handler. There is also a system property, java.protocol.handler.pkgs, that can be used to specify the location to search for handlers. Keeping this RFE open for now as more investigation needs to be done to look at the possibility of supporting WebSocket protocol.
21-10-2010