jsr340-experts@servlet-spec.java.net

[jsr340-experts] Re: Initial draft of Upgrade Proposal

From: Greg Wilkins <gregw_at_intalio.com>
Date: Mon, 17 Oct 2011 09:30:00 +1100

Shing Wai Chan,

I do not like this approach for Upgrade for several reasons:

* It does not allow containers to provide implementations of WebSockets (or
other protocols)

* Byte streams are not sufficient for full implementation/configuration of
protocols. You need access to the socket API for controlling such this as
half closes, linger setting and a wide range of other tuning parameters
available on that API.

* It does not support efficient NIO ByteBuffers

* It duplicates work that might be done for an async servlet IO API.



I think we need to consider upgrade support in several parts:

 0) An upgrade request is initially processed like any other request -
authenticated, authorised, filtered etc. A normal response may be served
including redirections and errors.

1) To handle the upgrade, the application needs to find a provider for the
protocol, which may be either provided either by the container or by the
application. Container implementations should have priority over
application implementations. Thus I believe we need an API where
applications can register protocol providers and from which we can request a
provider (either container or application provided).

    interface ProtocolConnection
    {
    }

    interface ProtocolProvider
    {
        ProtocolConnection init(ServletRequest,ServletResponse,Object
applicationHandler)
    }

    servletContext.registerProtocolProvider(String protocolName,
ProtocolProvider pp);
    servletContext.getProtocolProvider(String protocolName);


2) Once a protocol provider is available, the application will typically
need to initialise the connection by created a protocol handler object
(probably implementing some API of another JSR). Binding the application
object to the connection can be done with the ProtocolProvider.init
method. Within this init method, the provider might be container
provided and us arbitrary mechanisms to setup the IO; or it may be
application provided, in which case it can use the async IO api that we have
discussed to access input/output byte streams.

3) Only once we have the accepted request, the protocol provider and the
protocol handler do we actually accept the upgrade. This allows failures at
any stage to be well handled. So in short the process would look like:

    ProtocolProvider provider =
servletContext.getProtocolProvider(protocolName);
    ProtocolConnection connection =
provider.init(request,response,myApplicationHandler);
    response.upgrade(connection);



regards