Using the WebSocket transport

The intention for providing the WebSocket transport in CXF is to turn CXF endpoint services capable of reading or writing data over the socket that is connected to the client. For example, a JAXRS service using the WebSocket transport can continuously push or write data (e.g., status changes, events, etc) to the client once the client establishes a WebSocket connection to the service.

Current Status

Short summary

Usage Patterns

We have the following message exchange patterns to use this websocket transport for cxf service invocation.

  1. the client opens a websocket to some URL hosting a cxf service (e.g. ws://localhost:8080/cxf/myapp/books)
  2. the client can subsequently invoke an operation provided by this service (e.g., the book order operation at /myapp/books/order/123) by sending a request message that a simplified HTTP request message.

    Request = Request-Line CRLF
                 *(( header ) CRLF)
                 CRLF
                 [ body ]
    
    Request-Line  = Method SP Request-URI
    
    


    Method uses the HTTP methods.

    header may include any headers that are required by CXF to determine the operation and expected by the operation itself (e.g., Content-Type).



  3. the response message returned by the the service is sent back to the client as

    Response = [ Status-Line CRLF ]
               *(( header ) CRLF)
               CRLF
               [ body ]
    
    Status-Line = Status-Code
     


    Status-Code uses the HTTP status codes.



  4.  the service can subsequently push further data using jaxrs StreamingOuptut or writing to the injected servlet response's output stream. In this case, the message is simply returned to the client without Status-Line and may or may not include headers.

(Note: need for discussing the above binding syntax).


Further details

Open questions

TODOs of immediate interests


Currently, what is written over out.write(byte[] b, int offset, int length) will be written as a websocket message (e.g., triggering a single onMessage event to the client). We should allow sending back a sequence of fragments and terminates the transmission at the flushing step (i.e., out.flush() or of some sort).

Currently, strings are converted into utf-8 bytes and sent using the byte transfer mode of websocket. We could add the native string/text transfer as websocket supports it. However, this should be allowed only when the entity body is absent or of string/text.

we can update the logbrowser sample. There is a browser based demo in the samples collection (see above). This demo uses the current default binding which is not javascript friendly. To support browser based applications, we need different bindings.


TODOs of future interests

Examples