java.lang.Object
org.htmlunit.websocket.JettyWebSocketAdapter
- All Implemented Interfaces:
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classclassJetty12 based implementation of the WebSocket listener. -
Constructor Summary
ConstructorsConstructorDescriptionJettyWebSocketAdapter(WebClient webClient, WebSocketListener listener) Ctor. -
Method Summary
Modifier and TypeMethodDescriptionvoidClose the client.voidClose the incoming session.voidClose the outgoing session.voidcloseOutgoingSession(int statusCode, String reason) Close the outgoing session with the given status code and reason.voidConnects to the givenURI.voidConnects to the givenURIand offers the given sub-protocols in the handshake.Returns the sub-protocol the server selected in the handshake.voidSends the provided content.voidstart()Starts the client.
-
Constructor Details
-
JettyWebSocketAdapter
Ctor.- Parameters:
webClient- theWebClientlistener- theWebSocketListener
-
-
Method Details
-
start
Starts the client.- Specified by:
startin interfaceWebSocketAdapter- Throws:
Exception- in case of error
-
connect
Connects to the givenURI.- Specified by:
connectin interfaceWebSocketAdapter- Parameters:
url- the target url- Throws:
Exception- in case of error
-
connect
Connects to the givenURIand 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:
connectin interfaceWebSocketAdapter- Parameters:
url- the target urlprotocols- the sub-protocols to offer, may be empty- Throws:
Exception- in case of error
-
getSelectedProtocol
Returns the sub-protocol the server selected in the handshake. Only meaningful once the connection is open.- Specified by:
getSelectedProtocolin interfaceWebSocketAdapter- Returns:
- the selected sub-protocol, or an empty string if the server did not select one
-
send
Sends the provided content.- Specified by:
sendin interfaceWebSocketAdapter- Parameters:
content- the content to be sent- Throws:
IOException- in case of error
-
closeIncomingSession
public void closeIncomingSession()Close the incoming session.- Specified by:
closeIncomingSessionin interfaceWebSocketAdapter
-
closeOutgoingSession
public void closeOutgoingSession()Close the outgoing session.- Specified by:
closeOutgoingSessionin interfaceWebSocketAdapter
-
closeOutgoingSession
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 asWebSocketAdapter.closeOutgoingSession(), so existing implementations keep working.- Specified by:
closeOutgoingSessionin interfaceWebSocketAdapter- Parameters:
statusCode- the status code of the close framereason- the reason of the close frame, may be empty
-
closeClient
Close the client.- Specified by:
closeClientin interfaceWebSocketAdapter- Throws:
Exception- in case of error
-