Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/aslakhellesoy/htmlunit

Fork of HTMLUnit with WebSocket support
https://github.com/aslakhellesoy/htmlunit

Last synced: about 1 month ago
JSON representation

Fork of HTMLUnit with WebSocket support

Awesome Lists containing this project

README

        

h1. HTMLUnit with WebSocket support

This is a (temporary) fork of HTMLUnit with the purpose of adding WebSocket support. The fork is an import of revision 6270 of https://htmlunit.svn.sourceforge.net/svnroot/htmlunit/trunk/htmlunit

I didn't use git-svn as I couldn't get it to work. This means this fork won't be kept in sync with the official HTMLUnit in Subversion. Instead, a complete patch will be sent to the HTMLUnit project when WebSocket support is good enough.

HTMLUnit's issue tracker has an "open ticket":https://sourceforge.net/tracker/?func=detail&atid=448269&aid=3026502&group_id=47038 for WebSocket support, but I'm not aware that anyone else has started working on it yet.

EDIT: I've been made aware of an unmerged "patch":http://gwt-code-reviews.appspot.com/699801/show by Marko Vuksanovic. It's certainly more elaborate than this fork. You may want to apply that patch instead...

If you have comments and suggestions, please use this project's issue tracker instead of sending me personal messages, so that other interested people can join the discussion.

h2. API

The status of the "API":http://dev.w3.org/html5/websockets/ implementation is:

h3. Constructors

* WebSocket(url): *Implemented*
* WebSocket(url, protocols): Not Implemented

h3. Event Handlers

* onopen: *Implemented*
* onmessage: *Implemented*
* onerror: Not Implemented
* onclose: Not Implemented

h3. Readonly Properties

* url: *Implemented*
* readyState: Not Implemented
* bufferedAmount: Not Implemented
* protocol: Not Implemented

h3. Functions

* send: *Implemented*
* close: *Implemented*

h2. Hacking

If you want to hack on this, the test you want to run is com.gargoylesoftware.htmlunit.javascript.host.WebSocketTest. This test uses "Webbit":https://github.com/joewalnes/webbit - a fast async Web Server. Until Webbit lands in a Maven repo, you can install it in your local Maven repo by cloning the Webbit repo and run:


make
mvn install:install-file -DgroupId=webbit -DartifactId=webbit -Dversion=0.0.1 -Dpackaging=jar -Dfile=build/webbit.jar

If you want to build htmlunit without running all of the tests (very slow):


mvn clean install -Dmaven.test.skip=true

When you have done this once, tack on -o to put maven offline and make it faster.

h2. Implementation

HTMLUnit uses "Apache HTTP Components":http://hc.apache.org/ elsewhere in the code, but since it doesn't implement the WebSocket protocol I couldn't use that. I also looked at "Ning Async Http Client":https://github.com/AsyncHttpClient/async-http-client, but it doesn't implement WebSocket either.

I therefore went with "Adam MacBeth's WebSocket Client":https://github.com/adamac/Java-WebSocket-client, which now lives in com.gargoylesoftware.htmlunit.javascript.host.WebSocketImpl. As Adam mentions in the "README":https://github.com/adamac/Java-WebSocket-client/blob/master/README his implementation is out of date with the current spec, but it's good enough for my purposes for now.

I may switch to https://github.com/TooTallNate/Java-WebSocket or any other library that implements the protocol more faithfully later.

h2. Todos

# Implement the entire Javascript API
# Find a way to close al websockets if the page doesn't do it itself.

Currently the WebSocket must be closed in Javascript, or your JUnit tests will hang. Comment out the ws.close(); in com.gargoylesoftware.htmlunit.javascript.host.WebSocketTest to see this.
I haven't found a way to work around this, so contributions are welcome.