Class TyrusServerContainer

    • Constructor Detail

      • TyrusServerContainer

        public TyrusServerContainer​(java.util.Set<java.lang.Class<?>> classes)
        Parameters:
        classes - classes to be included in this application instance. Can contain any combination of annotated endpoints (see ServerEndpoint) or Endpoint descendants.
    • Method Detail

      • start

        public void start​(java.lang.String rootPath,
                          int port)
                   throws java.io.IOException,
                          DeploymentException
        Start the container.
        Specified by:
        start in interface ServerContainer
        Parameters:
        rootPath - context path of the deployed websocket application.
        port - TCP port
        Throws:
        java.io.IOException - when any IO related issues emerge during ServerContainer.start(String, int).
        DeploymentException - when any deployment related error is found; should contain list of all found issues.
      • stop

        public void stop()
        Undeploy all endpoints and stop underlying ServerContainer.

        Release all created threadpools / executor services.

        Specified by:
        stop in interface ServerContainer
      • addEndpoint

        public void addEndpoint​(java.lang.Class<?> endpointClass)
                         throws DeploymentException
        Description copied from interface: ServerContainer
        Deploys the given annotated endpoint into this ServerContainer.
        Specified by:
        addEndpoint in interface ServerContainer
        Parameters:
        endpointClass - the class of the annotated endpoint
        Throws:
        DeploymentException - if the annotated endpoint was badly formed.
      • addEndpoint

        public void addEndpoint​(ServerEndpointConfig serverEndpointConfig)
                         throws DeploymentException
        Description copied from interface: ServerContainer
        Deploys the given endpoint described by the provided configuration into this ServerContainer.
        Specified by:
        addEndpoint in interface ServerContainer
        Parameters:
        serverEndpointConfig - the configuration instance representing the logical endpoint that will be registered.
        Throws:
        DeploymentException - if the endpoint was badly formed.
      • getPort

        public int getPort()
        Get port of the started container.
        Returns:
        the port of the started container or -1, when the container is not started or the container does not provide the port.
      • getClientManager

        protected ClientManager getClientManager()
        Can be overridden to provide own ClientManager implementation or instance.
        Returns:
        ClientManager associated with this server container.
      • connectToServer

        public Session connectToServer​(java.lang.Class annotatedEndpointClass,
                                       java.net.URI path)
                                throws DeploymentException,
                                       java.io.IOException
        Description copied from interface: WebSocketContainer
        Connect the supplied annotated endpoint to its server. The supplied object must be a class decorated with the class level ClientEndpoint annotation. This method blocks until the connection is established, or throws an error if either the connection could not be made or there was a problem with the supplied endpoint class.
        Specified by:
        connectToServer in interface WebSocketContainer
        Parameters:
        annotatedEndpointClass - the annotated websocket client endpoint.
        path - the complete path to the server endpoint.
        Returns:
        the Session created if the connection is successful.
        Throws:
        DeploymentException - if the class is not a valid annotated endpoint class.
        java.io.IOException - if there was a network or protocol problem that prevented the client endpoint being connected to its server.
      • connectToServer

        public Session connectToServer​(java.lang.Class<? extends Endpoint> endpointClass,
                                       ClientEndpointConfig cec,
                                       java.net.URI path)
                                throws DeploymentException,
                                       java.io.IOException
        Description copied from interface: WebSocketContainer
        Connect the supplied programmatic endpoint to its server with the given configuration. This method blocks until the connection is established, or throws an error if the connection could not be made.
        Specified by:
        connectToServer in interface WebSocketContainer
        Parameters:
        endpointClass - the programmatic client endpoint class Endpoint.
        cec - the configuration used to configure the programmatic endpoint.
        path - the complete path to the server endpoint.
        Returns:
        the Session created if the connection is successful.
        Throws:
        DeploymentException - if the configuration is not valid
        java.io.IOException - if there was a network or protocol problem that prevented the client endpoint being connected to its server
      • connectToServer

        public Session connectToServer​(java.lang.Object annotatedEndpointInstance,
                                       java.net.URI path)
                                throws DeploymentException,
                                       java.io.IOException
        Description copied from interface: WebSocketContainer
        Connect the supplied annotated endpoint instance to its server. The supplied object must be a class decorated with the class level ClientEndpoint annotation. This method blocks until the connection is established, or throws an error if either the connection could not be made or there was a problem with the supplied endpoint class. If the developer uses this method to deploy the client endpoint, services like dependency injection that are supported, for example, when the implementation is part of the Java EE platform may not be available. If the client endpoint uses dependency injection, use WebSocketContainer.connectToServer(java.lang.Class, java.net.URI) instead.
        Specified by:
        connectToServer in interface WebSocketContainer
        Parameters:
        annotatedEndpointInstance - the annotated websocket client endpoint instance.
        path - the complete path to the server endpoint.
        Returns:
        the Session created if the connection is successful.
        Throws:
        DeploymentException - if the annotated endpoint instance is not valid.
        java.io.IOException - if there was a network or protocol problem that prevented the client endpoint being connected to its server.
      • connectToServer

        public Session connectToServer​(Endpoint endpointInstance,
                                       ClientEndpointConfig cec,
                                       java.net.URI path)
                                throws DeploymentException,
                                       java.io.IOException
        Description copied from interface: WebSocketContainer
        Connect the supplied programmatic client endpoint instance to its server with the given configuration. This method blocks until the connection is established, or throws an error if the connection could not be made. If the developer uses this method to deploy the client endpoint, services like dependency injection that are supported, for example, when the implementation is part of the Java EE platform may not be available. If the client endpoint uses dependency injection, use WebSocketContainer.connectToServer(java.lang.Class, jakarta.websocket.ClientEndpointConfig, java.net.URI) instead.
        Specified by:
        connectToServer in interface WebSocketContainer
        Parameters:
        endpointInstance - the programmatic client endpoint instance Endpoint.
        cec - the configuration used to configure the programmatic endpoint.
        path - the complete path to the server endpoint.
        Returns:
        the Session created if the connection is successful.
        Throws:
        DeploymentException - if the configuration is not valid
        java.io.IOException - if there was a network or protocol problem that prevented the client endpoint being connected to its server
      • asyncConnectToServer

        public java.util.concurrent.Future<Session> asyncConnectToServer​(java.lang.Class<?> annotatedEndpointClass,
                                                                         java.net.URI path)
                                                                  throws DeploymentException
        Non-blocking version of WebSocketContainer.connectToServer(Class, java.net.URI).

        Only simple checks are performed in the main thread; client container is created in different thread, same applies to connecting etc.

        Parameters:
        annotatedEndpointClass - the annotated websocket client endpoint.
        path - the complete path to the server endpoint.
        Returns:
        Future for the Session created if the connection is successful.
        Throws:
        DeploymentException - if the class is not a valid annotated endpoint class.
      • setDefaultMaxBinaryMessageBufferSize

        public void setDefaultMaxBinaryMessageBufferSize​(int max)
        Description copied from interface: WebSocketContainer
        Sets the default maximum size of incoming binary message that this container will buffer.
        Specified by:
        setDefaultMaxBinaryMessageBufferSize in interface WebSocketContainer
        Parameters:
        max - the maximum size of binary message in number of bytes.
      • setDefaultMaxTextMessageBufferSize

        public void setDefaultMaxTextMessageBufferSize​(int max)
        Description copied from interface: WebSocketContainer
        Sets the maximum size of incoming text message that this container will buffer.
        Specified by:
        setDefaultMaxTextMessageBufferSize in interface WebSocketContainer
        Parameters:
        max - the maximum size of text message in number of bytes.
      • getDefaultAsyncSendTimeout

        public long getDefaultAsyncSendTimeout()
        Description copied from interface: WebSocketContainer
        Return the number of milliseconds the implementation will timeout attempting to send a websocket message for all RemoteEndpoints associated with this container. A zero or negative value indicates the implementation will not timeout attempting to send a websocket message asynchronously. Note this default may be overridden in each RemoteEndpoint.
        Specified by:
        getDefaultAsyncSendTimeout in interface WebSocketContainer
        Returns:
        the timeout time in milliseconds.
      • setAsyncSendTimeout

        public void setAsyncSendTimeout​(long timeoutmillis)
        Description copied from interface: WebSocketContainer
        Sets the number of milliseconds the implementation will timeout attempting to send a websocket message for all RemoteEndpoints associated with this container. A zero or negative value indicates the implementation will not timeout attempting to send a websocket message asynchronously. Note this default may be overridden in each RemoteEndpoint.
        Specified by:
        setAsyncSendTimeout in interface WebSocketContainer
        Parameters:
        timeoutmillis - the timeout in milliseconds; use zero or negative value for no timeout
      • getDefaultMaxSessionIdleTimeout

        public long getDefaultMaxSessionIdleTimeout()
        Description copied from interface: WebSocketContainer
        Return the default time in milliseconds after which any web socket sessions in this container will be closed if it has been inactive. A value that is zero or negative indicates the sessions will never timeout due to inactivity. The value may be overridden on a per session basis using Session.setMaxIdleTimeout(long)
        Specified by:
        getDefaultMaxSessionIdleTimeout in interface WebSocketContainer
        Returns:
        the default number of milliseconds after which an idle session in this container will be closed
      • setDefaultMaxSessionIdleTimeout

        public void setDefaultMaxSessionIdleTimeout​(long defaultMaxSessionIdleTimeout)
        Description copied from interface: WebSocketContainer
        Sets the default time in milliseconds after which any web socket sessions in this container will be closed if it has been inactive. A value that is zero or negative indicates the sessions will never timeout due to inactivity. The value may be overridden on a per session basis using Session.setMaxIdleTimeout(long)
        Specified by:
        setDefaultMaxSessionIdleTimeout in interface WebSocketContainer
        Parameters:
        defaultMaxSessionIdleTimeout - the maximum time in milliseconds; use zero or negative value for no timeout
      • upgradeHttpToWebSocket

        public void upgradeHttpToWebSocket​(java.lang.Object httpServletRequest,
                                           java.lang.Object httpServletResponse,
                                           ServerEndpointConfig sec,
                                           java.util.Map<java.lang.String,​java.lang.String> pathParameters)
                                    throws java.io.IOException,
                                           DeploymentException
        Description copied from interface: ServerContainer
        Upgrade the HTTP connection represented by the HttpServletRequest and HttpServletResponse to the WebSocket protocol and establish a WebSocket connection as per the provided ServerEndpointConfig.

        This method is primarily intended to be used by frameworks that implement the front-controller pattern. It does not deploy the provided endpoint.

        If the WebSocket implementation is not deployed as part of a Jakarta Servlet container, this method will throw an UnsupportedOperationException.

        Specified by:
        upgradeHttpToWebSocket in interface ServerContainer
        Parameters:
        httpServletRequest - The HttpServletRequest to be processed as a WebSocket handshake as per section 4.0 of RFC 6455.
        httpServletResponse - The HttpServletResponse to be used when processing the httpServletRequest as a WebSocket handshake as per section 4.0 of RFC 6455.
        sec - The server endpoint configuration to use to configure the WebSocket endpoint
        pathParameters - Provides a mapping of path parameter names and values, if any, to be used for the WebSocket connection established by the call to this method. If no such mapping is defined, an empty Map must be passed.
        Throws:
        java.io.IOException - if an I/O error occurs during the establishment of a WebSocket connection
        DeploymentException - if a configuration error prevents the establishment of a WebSocket connection