Interface ConnectionStateHandler

All Known Implementing Classes:
DefaultConnectionStateHandler

public interface ConnectionStateHandler
Handles problems and other events which occur during communication with the server. The handler is responsible for handling any problem in XHR, heartbeat and push connections in a way it sees fit. The default implementation is DefaultConnectionStateHandler.
Since:
1.0
Author:
Vaadin Ltd
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    A string that, if found in a non-JSON response to a UIDL request, will cause the browser to refresh the page.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Called when some part of the reconnect dialog configuration has been changed.
    void
    heartbeatException(com.google.gwt.xhr.client.XMLHttpRequest request, Exception exception)
    Called when an exception occurs during a Heartbeat request.
    void
    heartbeatInvalidStatusCode(com.google.gwt.xhr.client.XMLHttpRequest xhr)
    Called when a heartbeat request returns a status code other than OK (200).
    void
    Called when a Heartbeat request succeeds.
    void
    pushClientTimeout(PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
    Called when a client side timeout occurs before a push connection to the server completes.
    void
    pushClosed(PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject responseObject)
    Called when the push connection to the server is closed.
    void
    pushError(PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
    Called when a fatal error fatal error occurs in the push connection.
    void
    pushInvalidContent(PushConnection pushConnection, String message)
    Called when invalid content (not JSON) was pushed from the server through the push connection.
    void
    pushNotConnected(elemental.json.JsonObject payload)
    Called when a message is to be sent to the server through the push channel but the push channel is not connected.
    void
    pushOk(PushConnection pushConnection)
    Called when the push connection to the server has been established.
    void
    Called when the push connection has lost the connection to the server and will proceed to try to re-establish the connection.
    void
    Called when the required push script could not be loaded.
    void
    xhrException(XhrConnectionError xhrConnectionError)
    Called when an exception occurs during an XmlHttpRequest request to the server.
    void
    Called when invalid content (not JSON) was returned from the server as the result of an XmlHttpRequest request.
    void
    Called when invalid status code (not 200) was returned by the server as the result of an XmlHttpRequest.
    void
    Called whenever a XmlHttpRequest to the server completes successfully.
  • Field Details

    • UIDL_REFRESH_TOKEN

      static final String UIDL_REFRESH_TOKEN
      A string that, if found in a non-JSON response to a UIDL request, will cause the browser to refresh the page. If followed by a colon, optional whitespace, and a URI, causes the browser to synchronously load the URI.

      This allows, for instance, a servlet filter to redirect the application to a custom login page when the session expires. For example:

       if (sessionExpired) {
           response.setHeader("Content-Type", "text/html");
           response.getWriter().write(myLoginPageHtml + "<!-- Vaadin-Refresh: "
                   + request.getContextPath() + " -->");
       }
       
      See Also:
  • Method Details

    • heartbeatException

      void heartbeatException(com.google.gwt.xhr.client.XMLHttpRequest request, Exception exception)
      Called when an exception occurs during a Heartbeat request.
      Parameters:
      request - The heartbeat request
      exception - The exception which occurred
    • heartbeatInvalidStatusCode

      void heartbeatInvalidStatusCode(com.google.gwt.xhr.client.XMLHttpRequest xhr)
      Called when a heartbeat request returns a status code other than OK (200).
      Parameters:
      xhr - the heartbeat request
    • heartbeatOk

      void heartbeatOk()
      Called when a Heartbeat request succeeds.
    • pushClosed

      void pushClosed(PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject responseObject)
      Called when the push connection to the server is closed. This might result in the push connection trying a fallback connection method, trying to reconnect to the server or might just be an indication that the connection was intentionally closed ("unsubscribe"),
      Parameters:
      pushConnection - The push connection which was closed
      responseObject - An object containing response data
    • pushClientTimeout

      void pushClientTimeout(PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
      Called when a client side timeout occurs before a push connection to the server completes. The client side timeout causes a disconnection of the push connection and no reconnect will be attempted after this method is called,
      Parameters:
      pushConnection - The push connection which timed out
      response - An object containing response data
    • pushError

      void pushError(PushConnection pushConnection, com.google.gwt.core.client.JavaScriptObject response)
      Called when a fatal error fatal error occurs in the push connection. The push connection will not try to recover from this situation itself and typically the problem handler should not try to do automatic recovery either. The cause can be e.g. maximum number of reconnection attempts have been reached, neither the selected transport nor the fallback transport can be used or similar.
      Parameters:
      pushConnection - The push connection where the error occurred
      response - An object containing response data
    • pushReconnectPending

      void pushReconnectPending(PushConnection pushConnection)
      Called when the push connection has lost the connection to the server and will proceed to try to re-establish the connection.
      Parameters:
      pushConnection - The push connection which will be reconnected
    • pushOk

      void pushOk(PushConnection pushConnection)
      Called when the push connection to the server has been established.
      Parameters:
      pushConnection - The push connection which was established
    • pushScriptLoadError

      void pushScriptLoadError(String resourceUrl)
      Called when the required push script could not be loaded.
      Parameters:
      resourceUrl - The URL which was used for loading the script
    • xhrException

      void xhrException(XhrConnectionError xhrConnectionError)
      Called when an exception occurs during an XmlHttpRequest request to the server.
      Parameters:
      xhrConnectionError - An event containing what was being sent to the server and what exception occurred
    • xhrInvalidContent

      void xhrInvalidContent(XhrConnectionError xhrConnectionError)
      Called when invalid content (not JSON) was returned from the server as the result of an XmlHttpRequest request.
      Parameters:
      xhrConnectionError - An event containing what was being sent to the server and what was returned
    • xhrInvalidStatusCode

      void xhrInvalidStatusCode(XhrConnectionError xhrConnectionError)
      Called when invalid status code (not 200) was returned by the server as the result of an XmlHttpRequest.
      Parameters:
      xhrConnectionError - An event containing what was being sent to the server and what was returned
    • xhrOk

      void xhrOk()
      Called whenever a XmlHttpRequest to the server completes successfully.
    • pushNotConnected

      void pushNotConnected(elemental.json.JsonObject payload)
      Called when a message is to be sent to the server through the push channel but the push channel is not connected.
      Parameters:
      payload - The payload to send to the server
    • pushInvalidContent

      void pushInvalidContent(PushConnection pushConnection, String message)
      Called when invalid content (not JSON) was pushed from the server through the push connection.
      Parameters:
      pushConnection - the push connection which was used
      message - the received message
    • configurationUpdated

      void configurationUpdated()
      Called when some part of the reconnect dialog configuration has been changed.