com.ning.http.client.websocket
Class WebSocketUpgradeHandler

java.lang.Object
  extended by com.ning.http.client.websocket.WebSocketUpgradeHandler
All Implemented Interfaces:
AsyncHandler<WebSocket>, UpgradeHandler<WebSocket>

public class WebSocketUpgradeHandler
extends Object
implements UpgradeHandler<WebSocket>, AsyncHandler<WebSocket>

An AsyncHandler which is able to execute WebSocket upgrade. Use the Builder for configuring WebSocket options.


Nested Class Summary
static class WebSocketUpgradeHandler.Builder
          Build a WebSocketUpgradeHandler
 
Nested classes/interfaces inherited from interface com.ning.http.client.AsyncHandler
AsyncHandler.STATE
 
Method Summary
 AsyncHandler.STATE onBodyPartReceived(HttpResponseBodyPart bodyPart)
          Invoked as soon as some response body part are received.
 WebSocket onCompleted()
          Invoked once the HTTP response processing is finished.
 void onFailure(Throwable t)
          If the upgrade fail.
 AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers)
          Invoked as soon as the HTTP headers has been received.
 AsyncHandler.STATE onStatusReceived(HttpResponseStatus responseStatus)
          Invoked as soon as the HTTP status line has been received
 void onSuccess(WebSocket webSocket)
          If the HTTP Upgrade succeed (response's status code equals 101), the AsyncHttpProvider will invoke that method
 void onThrowable(Throwable t)
          Invoked when an unexpected exception occurs during the processing of the response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

onThrowable

public final void onThrowable(Throwable t)
Invoked when an unexpected exception occurs during the processing of the response. The exception may have been produced by implementation of onXXXReceived method invocation.

Specified by:
onThrowable in interface AsyncHandler<WebSocket>
Parameters:
t - a Throwable

onBodyPartReceived

public final AsyncHandler.STATE onBodyPartReceived(HttpResponseBodyPart bodyPart)
                                            throws Exception
Invoked as soon as some response body part are received. Could be invoked many times.

Specified by:
onBodyPartReceived in interface AsyncHandler<WebSocket>
Parameters:
bodyPart - response's body part.
Returns:
a AsyncHandler.STATE telling to CONTINUE or ABORT the current processing.
Throws:
Exception - if something wrong happens

onStatusReceived

public final AsyncHandler.STATE onStatusReceived(HttpResponseStatus responseStatus)
                                          throws Exception
Invoked as soon as the HTTP status line has been received

Specified by:
onStatusReceived in interface AsyncHandler<WebSocket>
Parameters:
responseStatus - the status code and test of the response
Returns:
a AsyncHandler.STATE telling to CONTINUE or ABORT the current processing.
Throws:
Exception - if something wrong happens

onHeadersReceived

public final AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers)
                                           throws Exception
Invoked as soon as the HTTP headers has been received. Can potentially be invoked more than once if a broken server sent trailing headers.

Specified by:
onHeadersReceived in interface AsyncHandler<WebSocket>
Parameters:
headers - the HTTP headers.
Returns:
a AsyncHandler.STATE telling to CONTINUE or ABORT the current processing.
Throws:
Exception - if something wrong happens

onCompleted

public final WebSocket onCompleted()
                            throws Exception
Invoked once the HTTP response processing is finished.

Gets always invoked as last callback method.

Specified by:
onCompleted in interface AsyncHandler<WebSocket>
Returns:
T Value that will be returned by the associated Future
Throws:
Exception - if something wrong happens

onSuccess

public final void onSuccess(WebSocket webSocket)
If the HTTP Upgrade succeed (response's status code equals 101), the AsyncHttpProvider will invoke that method

Specified by:
onSuccess in interface UpgradeHandler<WebSocket>
Parameters:
webSocket - an Upgradable entity

onFailure

public final void onFailure(Throwable t)
If the upgrade fail.

Specified by:
onFailure in interface UpgradeHandler<WebSocket>
Parameters:
t - a Throwable


Copyright © 2012. All Rights Reserved.