Module org.htmlunit

Interface WebSocketAdapter

All Known Implementing Classes:
JettyWebSocketAdapter

public interface WebSocketAdapter
Helper to have no direct dependency to the WebSockt client implementation used by HtmlUnit.
Author:
Ronald Brill
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Close the client.
    void
    Close the incoming session.
    void
    Close the outgoing session.
    default void
    closeOutgoingSession(int statusCode, String reason)
    Close the outgoing session with the given status code and reason.
    void
    connect(URI url)
    Connects to the given URI.
    default void
    connect(URI url, List<String> protocols)
    Connects to the given URI and offers the given sub-protocols in the handshake.
    default String
    Returns the sub-protocol the server selected in the handshake.
    void
    send(Object content)
    Sends the provided content.
    void
    Starts the client.
  • Method Details

    • start

      void start() throws Exception
      Starts the client.
      Throws:
      Exception - in case of error
    • connect

      void connect(URI url) throws Exception
      Connects to the given URI.
      Parameters:
      url - the target url
      Throws:
      Exception - in case of error
    • connect

      default void connect(URI url, List<String> protocols) throws Exception
      Connects to the given URI and offers the given sub-protocols in the handshake. The default implementation ignores the sub-protocols, so adapters without support keep working (no sub-protocol is selected then).
      Parameters:
      url - the target url
      protocols - the sub-protocols to offer, may be empty
      Throws:
      Exception - in case of error
    • getSelectedProtocol

      default String getSelectedProtocol()
      Returns the sub-protocol the server selected in the handshake. Only meaningful once the connection is open.
      Returns:
      the selected sub-protocol, or an empty string if the server did not select one
    • send

      void send(Object content) throws IOException
      Sends the provided content.
      Parameters:
      content - the content to be sent
      Throws:
      IOException - in case of error
    • closeIncomingSession

      void closeIncomingSession() throws Exception
      Close the incoming session.
      Throws:
      Exception - in case of error
    • closeOutgoingSession

      void closeOutgoingSession() throws Exception
      Close the outgoing session.
      Throws:
      Exception - in case of error
    • closeOutgoingSession

      default void closeOutgoingSession(int statusCode, String reason) throws Exception
      Close the outgoing session with the given status code and reason. The status code 1005 means that no status code at all is sent (an empty close frame), the reason is only sent together with a status code. The default implementation ignores the arguments and does the same as closeOutgoingSession(), so existing implementations keep working.
      Parameters:
      statusCode - the status code of the close frame
      reason - the reason of the close frame, may be empty
      Throws:
      Exception - in case of error
    • closeClient

      void closeClient() throws Exception
      Close the client.
      Throws:
      Exception - in case of error