Module org.htmlunit

Class JettyWebSocketAdapter

java.lang.Object
org.htmlunit.websocket.JettyWebSocketAdapter
All Implemented Interfaces:
WebSocketAdapter

public final class JettyWebSocketAdapter extends Object implements WebSocketAdapter
Jetty12 based impl of the WebSocketAdapter. To avoid conflicts with other jetty versions used by projects, we use our own shaded version of jetty12 (https://github.com/HtmlUnit/htmlunit-websocket-client).
Author:
Ronald Brill
  • Constructor Details

  • Method Details

    • start

      public void start() throws Exception
      Starts the client.
      Specified by:
      start in interface WebSocketAdapter
      Throws:
      Exception - in case of error
    • connect

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

      public 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).
      Specified by:
      connect in interface WebSocketAdapter
      Parameters:
      url - the target url
      protocols - the sub-protocols to offer, may be empty
      Throws:
      Exception - in case of error
    • getSelectedProtocol

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

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

      public void closeIncomingSession()
      Close the incoming session.
      Specified by:
      closeIncomingSession in interface WebSocketAdapter
    • closeOutgoingSession

      public void closeOutgoingSession()
      Close the outgoing session.
      Specified by:
      closeOutgoingSession in interface WebSocketAdapter
    • closeOutgoingSession

      public void closeOutgoingSession(int statusCode, String reason)
      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 WebSocketAdapter.closeOutgoingSession(), so existing implementations keep working.
      Specified by:
      closeOutgoingSession in interface WebSocketAdapter
      Parameters:
      statusCode - the status code of the close frame
      reason - the reason of the close frame, may be empty
    • closeClient

      public void closeClient() throws Exception
      Close the client.
      Specified by:
      closeClient in interface WebSocketAdapter
      Throws:
      Exception - in case of error