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
 
Constructor Summary
protected WebSocketUpgradeHandler(WebSocketUpgradeHandler.Builder b)
           
 
Method Summary
 AsyncHandler.STATE onBodyPartReceived(HttpResponseBodyPart bodyPart)
          Invoked as soon as some response body part are received.
 void onClose(WebSocket webSocket, int status, String reasonPhrase)
           
 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.
 void resetSuccess()
           
 boolean touchSuccess()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebSocketUpgradeHandler

protected WebSocketUpgradeHandler(WebSocketUpgradeHandler.Builder b)
Method Detail

onThrowable

public 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

touchSuccess

public boolean touchSuccess()

resetSuccess

public void resetSuccess()

onBodyPartReceived

public 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 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 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 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 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 void onFailure(Throwable t)
If the upgrade fail.

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

onClose

public void onClose(WebSocket webSocket,
                    int status,
                    String reasonPhrase)


Copyright © 2014. All Rights Reserved.