Top Description Inners Fields Constructors Methods
org.glassfish.tyrus.client

public Class TyrusClientEngine

extends Object
implements ClientEngine
Class Inheritance
All Implemented Interfaces
org.glassfish.tyrus.spi.ClientEngine
Imports
java.io.IOException, java.net.URI, .URISyntaxException, java.nio.Buffer, .ByteBuffer, java.text.ParseException, java.util.ArrayList, .Collections, .Date, .HashMap, .HashSet, .List, .Map, .Set, java.util.logging.Level, .Logger, jakarta.websocket.ClientEndpointConfig, .CloseReason, .Extension, .Session, .WebSocketContainer, jakarta.websocket.server.HandshakeRequest, org.glassfish.tyrus.client.auth.AuthConfig, .AuthenticationException, .Authenticator, .Credentials, org.glassfish.tyrus.core.CloseReasons, .DebugContext, .Handshake, .HandshakeException, .MaskingKeyGenerator, .ProtocolHandler, .RequestContext, .TyrusEndpointWrapper, .TyrusExtension, .TyrusWebSocket, .Utils, .Version, .WebSocketException, org.glassfish.tyrus.core.extension.ExtendedExtension, org.glassfish.tyrus.core.frame.CloseFrame, .Frame, org.glassfish.tyrus.core.l10n.LocalizationMessages, org.glassfish.tyrus.spi.ClientContainer, .ClientEngine, .Connection, .ReadHandler, .TyrusClientEndpointConfigurator, .UpgradeRequest, .UpgradeResponse, .Writer

Tyrus ClientEngine implementation.
Author
Pavel Bucek

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
TyrusClientEngine.ClientHandshakeListener

Called when response is received from the server.

private static enum
TyrusClientEngine.TyrusClientEngineState

State controls flow in processResponse(UpgradeResponse, Writer, Connection.CloseListener) and depends on upgrade response status code and previous state.

private static class

Field Summary

Modifier and TypeField and Description
private static final int
private volatile TyrusClientEngine.TyrusClientEngineState
private volatile Handshake
private final URI
private final DebugContext
public static final int
DEFAULT_INCOMING_BUFFER_SIZE

Default incoming buffer size for client container.

private static final int
private static final Version
private final TyrusEndpointWrapper
private final TyrusClientEngine.ClientHandshakeListener
private static final Logger
private final boolean
private final Map<String, Object>
private final ProtocolHandler
private final Boolean
private volatile URI
private final int
private final Set<URI>
private volatile ClientEngine.TimeoutHandler
private static final ClientEngine.ClientUpgradeInfo
private static final ClientEngine.ClientUpgradeInfo

Constructor Summary

AccessConstructor and Description
pack-priv
TyrusClientEngine(TyrusEndpointWrapper
wrapped client endpoint.
endpointWrapper
,
TyrusClientEngine.ClientHandshakeListener
used for reporting back the outcome of handshake. ClientHandshakeListener#onSessionCreated(jakarta.websocket.Session) is invoked if handshake is completed and provided Session is open and ready to be returned from WebSocketContainer#connectToServer(Class, jakarta.websocket.ClientEndpointConfig, java.net.URI) (and alternatives) call.
listener
,
Map<String, Object>
passed container properties, see * .ClientManager#getProperties().
properties
,
URI
to which the client is connecting.
connectToServerUriParam
,
DebugContext
debug context.
debugContext
)

Create org.glassfish.tyrus.spi.WebSocketEngine instance based on passed WebSocketContainer and with configured maximal incoming buffer size.

Method Summary

Modifier and TypeMethod and Description
public UpgradeRequest
createUpgradeRequest(ClientEngine.TimeoutHandler
handshake timeout handler. TimeoutHandler#handleTimeout() is invoked if processResponse(UpgradeResponse, Writer, Connection.CloseListener) is not called within handshake timeout.
timeoutHandler
)

Implements org.glassfish.tyrus.spi.ClientEngine.createUpgradeRequest.

Create upgrade request and register TimeoutHandler.

public ClientEngine.TimeoutHandler

Returns:

timeout handler instance or null when not present.
getTimeoutHandler
()

Get TimeoutHandler associated with current ClientEngine instance.

private ClientEngine.ClientUpgradeInfo
handleAuth(UpgradeResponse upgradeResponse)

private ClientEngine.ClientUpgradeInfo
private ClientEngine.ClientUpgradeInfo
handleSwitchProtocol(UpgradeResponse upgradeResponse, Writer writer, Connection.CloseListener closeListener)

private void
public void
processError(Throwable
encountered error.
t
)

Implements org.glassfish.tyrus.spi.ClientEngine.processError.

Process error.

public ClientEngine.ClientUpgradeInfo
processResponse(final UpgradeResponse
response to be processed.
upgradeResponse
,
final Writer
used for sending dataframes from client endpoint.
writer
,
final Connection.CloseListener
will be called when connection is closed, will be set as listener of returned Connection.
closeListener
)

Implements org.glassfish.tyrus.spi.ClientEngine.processResponse.

Process handshake and return ClientUpgradeInfo with handshake status (ClientUpgradeStatus).

private ClientEngine.ClientUpgradeInfo

Returns:

client upgrade info with ClientUpgradeStatus#SUCCESS status.
processUpgradeResponse
(UpgradeResponse
upgrade response received from client container.
upgradeResponse
,
final Writer
writer instance to be used for sending websocket frames.
writer
,
final Connection.CloseListener
client container connection listener.
closeListener
)

Process upgrade response.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BUFFER_STEP_SIZEback to summary
private static final int BUFFER_STEP_SIZE
clientEngineStateback to summary
private volatile TyrusClientEngine.TyrusClientEngineState clientEngineState
clientHandShakeback to summary
private volatile Handshake clientHandShake
connectToServerUriParamback to summary
private final URI connectToServerUriParam
debugContextback to summary
private final DebugContext debugContext
DEFAULT_INCOMING_BUFFER_SIZEback to summary
public static final int DEFAULT_INCOMING_BUFFER_SIZE

Default incoming buffer size for client container.

DEFAULT_REDIRECT_THRESHOLDback to summary
private static final int DEFAULT_REDIRECT_THRESHOLD
DEFAULT_VERSIONback to summary
private static final Version DEFAULT_VERSION
endpointWrapperback to summary
private final TyrusEndpointWrapper endpointWrapper
listenerback to summary
private final TyrusClientEngine.ClientHandshakeListener listener
LOGGERback to summary
private static final Logger LOGGER
logUpgradeMessagesback to summary
private final boolean logUpgradeMessages
propertiesback to summary
private final Map<String, Object> properties
protocolHandlerback to summary
private final ProtocolHandler protocolHandler
redirectEnabledback to summary
private final Boolean redirectEnabled
redirectLocationback to summary
private volatile URI redirectLocation
redirectThresholdback to summary
private final int redirectThreshold
redirectUriHistoryback to summary
private final Set<URI> redirectUriHistory
timeoutHandlerback to summary
private volatile ClientEngine.TimeoutHandler timeoutHandler
UPGRADE_INFO_ANOTHER_REQUEST_REQUIREDback to summary
private static final ClientEngine.ClientUpgradeInfo UPGRADE_INFO_ANOTHER_REQUEST_REQUIRED
UPGRADE_INFO_FAILEDback to summary
private static final ClientEngine.ClientUpgradeInfo UPGRADE_INFO_FAILED

Constructor Detail

TyrusClientEngineback to summary
pack-priv TyrusClientEngine(TyrusEndpointWrapper endpointWrapper, TyrusClientEngine.ClientHandshakeListener listener, Map<String, Object> properties, URI connectToServerUriParam, DebugContext debugContext)

Create org.glassfish.tyrus.spi.WebSocketEngine instance based on passed WebSocketContainer and with configured maximal incoming buffer size.

Parameters
endpointWrapper:TyrusEndpointWrapper

wrapped client endpoint.

listener:TyrusClientEngine.ClientHandshakeListener

used for reporting back the outcome of handshake. ClientHandshakeListener#onSessionCreated(jakarta.websocket.Session) is invoked if handshake is completed and provided Session is open and ready to be returned from WebSocketContainer#connectToServer(Class, jakarta.websocket.ClientEndpointConfig, java.net.URI) (and alternatives) call.

properties:Map<String, Object>

passed container properties, see * .ClientManager#getProperties().

connectToServerUriParam:URI

to which the client is connecting.

debugContext:DebugContext

debug context.

Method Detail

createUpgradeRequestback to summary
public UpgradeRequest createUpgradeRequest(ClientEngine.TimeoutHandler timeoutHandler)

Implements org.glassfish.tyrus.spi.ClientEngine.createUpgradeRequest.

Doc from org.glassfish.tyrus.spi.ClientEngine.createUpgradeRequest.

Create upgrade request and register TimeoutHandler.

Parameters
timeoutHandler:ClientEngine.TimeoutHandler

handshake timeout handler. TimeoutHandler#handleTimeout() is invoked if processResponse(UpgradeResponse, Writer, Connection.CloseListener) is not called within handshake timeout.

Returns:UpgradeRequest

request to be send on the wire or null, when the request cannot be created. When null is returned, client should free all resources tied to current connection.

Annotations
@Override
getTimeoutHandlerback to summary
public ClientEngine.TimeoutHandler getTimeoutHandler()

Get TimeoutHandler associated with current ClientEngine instance.

Returns:ClientEngine.TimeoutHandler

timeout handler instance or null when not present.

handleAuthback to summary
private ClientEngine.ClientUpgradeInfo handleAuth(UpgradeResponse upgradeResponse)
handleRedirectback to summary
private ClientEngine.ClientUpgradeInfo handleRedirect(UpgradeResponse upgradeResponse)
handleSwitchProtocolback to summary
private ClientEngine.ClientUpgradeInfo handleSwitchProtocol(UpgradeResponse upgradeResponse, Writer writer, Connection.CloseListener closeListener)
logUpgradeRequestback to summary
private void logUpgradeRequest(UpgradeRequest upgradeRequest)
processErrorback to summary
public void processError(Throwable t)

Implements org.glassfish.tyrus.spi.ClientEngine.processError.

Doc from org.glassfish.tyrus.spi.ClientEngine.processError.

Process error.

This method can be called any time when client encounters an error which cannot be handled in the container before ClientUpgradeStatus#SUCCESS is returned from processResponse(UpgradeResponse, Writer, Connection.CloseListener).

Parameters
t:Throwable

encountered error.

Annotations
@Override
processResponseback to summary
public ClientEngine.ClientUpgradeInfo processResponse(final UpgradeResponse upgradeResponse, final Writer writer, final Connection.CloseListener closeListener)

Implements org.glassfish.tyrus.spi.ClientEngine.processResponse.

Doc from org.glassfish.tyrus.spi.ClientEngine.processResponse.

Process handshake and return ClientUpgradeInfo with handshake status (ClientUpgradeStatus).

Parameters
upgradeResponse:UpgradeResponse

response to be processed.

writer:Writer

used for sending dataframes from client endpoint.

closeListener:Connection.CloseListener

will be called when connection is closed, will be set as listener of returned Connection.

Returns:ClientEngine.ClientUpgradeInfo

info with upgrade status.

Annotations
@Override
processUpgradeResponseback to summary
private ClientEngine.ClientUpgradeInfo processUpgradeResponse(UpgradeResponse upgradeResponse, final Writer writer, final Connection.CloseListener closeListener) throws HandshakeException

Process upgrade response. This method should be called only when the response HTTP status code is 101.

Parameters
upgradeResponse:UpgradeResponse

upgrade response received from client container.

writer:Writer

writer instance to be used for sending websocket frames.

closeListener:Connection.CloseListener

client container connection listener.

Returns:ClientEngine.ClientUpgradeInfo

client upgrade info with ClientUpgradeStatus#SUCCESS status.

Exceptions
HandshakeException:
when there is a problem with passed UpgradeResponse.
org.glassfish.tyrus.client back to summary

public Interface TyrusClientEngine.ClientHandshakeListener

Known Direct Subinterfaces
org.glassfish.tyrus.client.ClientManager.ClientManagerHandshakeListener

Called when response is received from the server.

Method Summary

Modifier and TypeMethod and Description
public void
onError(Throwable
error found during handshake response check.
exception
)

Called when an error is found in handshake response.

public void
onSessionCreated(Session
opened client session.
session
)

Invoked when handshake is completed and provided Session is open and ready to be returned from WebSocketContainer#connectToServer(Class, jakarta.websocket.ClientEndpointConfig, java.net.URI) (and alternatives) call.

Method Detail

onErrorback to summary
public void onError(Throwable exception)

Called when an error is found in handshake response.

Parameters
exception:Throwable

error found during handshake response check.

onSessionCreatedback to summary
public void onSessionCreated(Session session)

Invoked when handshake is completed and provided Session is open and ready to be returned from WebSocketContainer#connectToServer(Class, jakarta.websocket.ClientEndpointConfig, java.net.URI) (and alternatives) call.

Parameters
session:Session

opened client session.

org.glassfish.tyrus.client back to summary

private final Enum TyrusClientEngine.TyrusClientEngineState

extends Enum<TyrusClientEngine.TyrusClientEngineState>
Class Inheritance

State controls flow in processResponse(UpgradeResponse, Writer, Connection.CloseListener) and depends on upgrade response status code and previous state.

Field Summary

Modifier and TypeField and Description
public static final TyrusClientEngine.TyrusClientEngineState
AUTH_REQUIRED

Authentication required.

public static final TyrusClientEngine.TyrusClientEngineState
AUTH_UPGRADE_REQUEST_CREATED

Upgrade request with Authorization header has been created.

private volatile Authenticator
public static final TyrusClientEngine.TyrusClientEngineState
FAILED

Handshake failed (final state).

public static final TyrusClientEngine.TyrusClientEngineState
INIT

Initial state.

public static final TyrusClientEngine.TyrusClientEngineState
REDIRECT_REQUIRED

Upgrade request must be redirected.

public static final TyrusClientEngine.TyrusClientEngineState
SUCCESS

Handshake succeeded (final state).

public static final TyrusClientEngine.TyrusClientEngineState
UPGRADE_REQUEST_CREATED

Upgrade request has been created.

private volatile String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv Authenticator
pack-priv String
pack-priv void
pack-priv void
setWwwAuthenticateHeader(String wwwAuthenticateHeader)

public static TyrusClientEngine.TyrusClientEngineState
public static TyrusClientEngine.TyrusClientEngineState[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

AUTH_REQUIREDback to summary
public static final TyrusClientEngine.TyrusClientEngineState AUTH_REQUIRED

Authentication required.

Set in processResponse(UpgradeResponse, Writer, Connection.CloseListener) when 401 HTTP status code is received and the last upgrade request does not contain Authorization header (the last state was not AUTH_UPGRADE_REQUEST_CREATED).

AUTH_UPGRADE_REQUEST_CREATEDback to summary
public static final TyrusClientEngine.TyrusClientEngineState AUTH_UPGRADE_REQUEST_CREATED

Upgrade request with Authorization header has been created.

Set in createUpgradeRequest(TimeoutHandler).

authenticatorback to summary
private volatile Authenticator authenticator
FAILEDback to summary
public static final TyrusClientEngine.TyrusClientEngineState FAILED

Handshake failed (final state).

INITback to summary
public static final TyrusClientEngine.TyrusClientEngineState INIT

Initial state.

REDIRECT_REQUIREDback to summary
public static final TyrusClientEngine.TyrusClientEngineState REDIRECT_REQUIRED

Upgrade request must be redirected.

Set in processResponse(UpgradeResponse, Writer, Connection.CloseListener) when 3xx HTTP status code is received.

SUCCESSback to summary
public static final TyrusClientEngine.TyrusClientEngineState SUCCESS

Handshake succeeded (final state).

UPGRADE_REQUEST_CREATEDback to summary
public static final TyrusClientEngine.TyrusClientEngineState UPGRADE_REQUEST_CREATED

Upgrade request has been created.

Set in createUpgradeRequest(TimeoutHandler).

wwwAuthenticateHeaderback to summary
private volatile String wwwAuthenticateHeader

Constructor Detail

TyrusClientEngineStateback to summary
private TyrusClientEngineState()

Method Detail

getAuthenticatorback to summary
pack-priv Authenticator getAuthenticator()
getWwwAuthenticateHeaderback to summary
pack-priv String getWwwAuthenticateHeader()
setAuthenticatorback to summary
pack-priv void setAuthenticator(Authenticator authenticator)
setWwwAuthenticateHeaderback to summary
pack-priv void setWwwAuthenticateHeader(String wwwAuthenticateHeader)
valueOfback to summary
public static TyrusClientEngine.TyrusClientEngineState valueOf(String name)
valuesback to summary
public static TyrusClientEngine.TyrusClientEngineState[] values()
org.glassfish.tyrus.client back to summary

private Class TyrusClientEngine.TyrusReadHandler

extends Object
implements ReadHandler
Class Inheritance
  • java.lang.Object
  • org.glassfish.tyrus.client.TyrusClientEngine.TyrusReadHandler
All Implemented Interfaces
org.glassfish.tyrus.spi.ReadHandler

Field Summary

Modifier and TypeField and Description
private ByteBuffer
private final ExtendedExtension.ExtensionContext
private final ProtocolHandler
private final int
private final List<Extension>
private final TyrusWebSocket

Constructor Summary

AccessConstructor and Description
pack-priv
TyrusReadHandler(final ProtocolHandler protocolHandler, final TyrusWebSocket socket, int incomingBufferSize, List<Extension> negotiatedExtensions, ExtendedExtension.ExtensionContext extensionContext)

Method Summary

Modifier and TypeMethod and Description
public void
handle(ByteBuffer
websocket data of a connection.
data
)

Implements org.glassfish.tyrus.spi.ReadHandler.handle.

A transport reads websocket data and invokes this method to handover websocket data for a connection to tyrus runtime.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferback to summary
private ByteBuffer buffer
extensionContextback to summary
private final ExtendedExtension.ExtensionContext extensionContext
handlerback to summary
private final ProtocolHandler handler
incomingBufferSizeback to summary
private final int incomingBufferSize
negotiatedExtensionsback to summary
private final List<Extension> negotiatedExtensions
socketback to summary
private final TyrusWebSocket socket

Constructor Detail

TyrusReadHandlerback to summary
pack-priv TyrusReadHandler(final ProtocolHandler protocolHandler, final TyrusWebSocket socket, int incomingBufferSize, List<Extension> negotiatedExtensions, ExtendedExtension.ExtensionContext extensionContext)

Method Detail

handleback to summary
public void handle(ByteBuffer data)

Implements org.glassfish.tyrus.spi.ReadHandler.handle.

Doc from org.glassfish.tyrus.spi.ReadHandler.handle.

A transport reads websocket data and invokes this method to handover websocket data for a connection to tyrus runtime. The runtime consumes as much data as possible from the byte buffer. If there is some remaining data in the buffer, transport needs pass those bytes in more call (along with more data) in the same byte buffer or in a newer byte buffer.

Parameters
data:ByteBuffer

websocket data of a connection.

Annotations
@Override