org.atmosphere.websocket.protocol
Class SimpleHttpProtocol

java.lang.Object
  extended by org.atmosphere.websocket.protocol.SimpleHttpProtocol
All Implemented Interfaces:
Serializable, AsyncProtocol, WebSocketProtocol

public class SimpleHttpProtocol
extends Object
implements WebSocketProtocol, Serializable

Like the AsynchronousProcessor class, this class is responsible for dispatching WebSocket messages to the proper WebSocket implementation by wrapping the Websocket message's bytes within an HttpServletRequest.

The content-type is defined using ApplicationConfig.WEBSOCKET_CONTENT_TYPE property The method is defined using ApplicationConfig.WEBSOCKET_METHOD property

Author:
Jeanfrancois Arcand
See Also:
Serialized Form

Constructor Summary
SimpleHttpProtocol()
           
 
Method Summary
 void configure(AtmosphereServlet.AtmosphereConfig config)
          Allow an implementation to query the AtmosphereConfig of init-param, etc.
 byte[] handleResponse(AtmosphereResponse<?> res, byte[] message, int offset, int length)
          Give a chance to a AsyncProtocol to modify the final response using a fake HttpServletResponse that was dispatched to a ServletContainer and it's framework or application running it.
 String handleResponse(AtmosphereResponse<?> res, String message)
          Give a chance to a AsyncProtocol to modify the final response using a fake HttpServletResponse that was dispatched to a ServletContainer and it's framework or application running it.
 boolean inspectResponse()
          Return true if this implementation will manipulate/change the WebSocket message;
 void onClose(WebSocket webSocket)
          Invoked when a WebSocket is closed
 void onError(WebSocket webSocket, WebSocketProcessor.WebSocketException t)
          Invoked when an error occurs.
 AtmosphereRequest onMessage(WebSocket webSocket, byte[] d, int offset, int length)
          Parse the WebSocket message, and delegate the processing to the AtmosphereServlet.cometSupport or to any existing technology.
 AtmosphereRequest onMessage(WebSocket webSocket, String d)
          Parse the WebSocket message, and delegate the processing to the AtmosphereServlet.cometSupport or to any existing technology.
 void onOpen(WebSocket webSocket)
          Invoked when a WebSocket is opened
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleHttpProtocol

public SimpleHttpProtocol()
Method Detail

configure

public void configure(AtmosphereServlet.AtmosphereConfig config)
Allow an implementation to query the AtmosphereConfig of init-param, etc.

Specified by:
configure in interface WebSocketProtocol
Parameters:
config - AtmosphereServlet.AtmosphereConfig

onMessage

public AtmosphereRequest onMessage(WebSocket webSocket,
                                   String d)
Parse the WebSocket message, and delegate the processing to the AtmosphereServlet.cometSupport or to any existing technology. Invoking AtmosphereServlet.cometSupport will delegate the request processing to the AtmosphereHandler implementation. Returning null means this implementation will handle itself the processing/dispatching of the WebSocket's request;
As an example, this is how Websocket messages are delegated to the Jersey runtime.

Specified by:
onMessage in interface WebSocketProtocol
Parameters:
webSocket - The WebSocket connection
d - The Websocket message

onMessage

public AtmosphereRequest onMessage(WebSocket webSocket,
                                   byte[] d,
                                   int offset,
                                   int length)
Parse the WebSocket message, and delegate the processing to the AtmosphereServlet.cometSupport or to any existing technology. Invoking AtmosphereServlet.cometSupport will delegate the request processing to the AtmosphereHandler implementation. Returning null means this implementation will handle itself the processing/dispatching of the WebSocket's request;
As an example, this is how Websocket messages are delegated to the Jersey runtime.

Specified by:
onMessage in interface WebSocketProtocol
Parameters:
webSocket - The WebSocket connection
offset - offset message index
length - length of the message.

onOpen

public void onOpen(WebSocket webSocket)
Invoked when a WebSocket is opened

Specified by:
onOpen in interface WebSocketProtocol
Parameters:
webSocket - WebSocket

onClose

public void onClose(WebSocket webSocket)
Invoked when a WebSocket is closed

Specified by:
onClose in interface WebSocketProtocol
Parameters:
webSocket - WebSocket

onError

public void onError(WebSocket webSocket,
                    WebSocketProcessor.WebSocketException t)
Invoked when an error occurs.

Specified by:
onError in interface WebSocketProtocol
Parameters:
webSocket - WebSocket
t - a WebSocketProcessor.WebSocketException

inspectResponse

public boolean inspectResponse()
Return true if this implementation will manipulate/change the WebSocket message;

Specified by:
inspectResponse in interface AsyncProtocol
Returns:
true if this implementation will manipulate/change the WebSocket message;

handleResponse

public String handleResponse(AtmosphereResponse<?> res,
                             String message)
Give a chance to a AsyncProtocol to modify the final response using a fake HttpServletResponse that was dispatched to a ServletContainer and it's framework or application running it. This method is only invoked when AtmosphereResponse is about to write some data.

Specified by:
handleResponse in interface AsyncProtocol
Parameters:
res - HttpServletResponse
message - the String message;
Returns:
a new response String

handleResponse

public byte[] handleResponse(AtmosphereResponse<?> res,
                             byte[] message,
                             int offset,
                             int length)
Description copied from interface: AsyncProtocol
Give a chance to a AsyncProtocol to modify the final response using a fake HttpServletResponse that was dispatched to a ServletContainer and it's framework or application running it. This method is only invoked when AtmosphereResponse is about to write some data.

Specified by:
handleResponse in interface AsyncProtocol
Parameters:
res - HttpServletResponse
message - the WebSocket message;
offset - offset of the message
length - the length of the message
Returns:
a new byte[] message.


Copyright © 2011. All Rights Reserved.