Class ConnectionManager

java.lang.Object
de.espirit.firstspirit.access.ConnectionManager

public final class ConnectionManager extends Object
Factory for connections. Example usage:
Connection connection = ConnectionManager.getConnection("localhost", 8000, ConnectionManager.HTTP_MODE, "login", "password", );
Remember to connect to the server and close the connection afterwards:
 try { connection.connect(); ... } catch (IOException e) { context.logError(e.getMessage()); } catch (AuthenticationException e) { context.logError(e.getMessage()); } catch (MaximumNumberOfSessionsExceededException e) { context.logError(e.getMessage()); } finally { try { connection.close(); } catch (IOException e) { context.logError(e.getMessage()); } } 
Since:
2.3
  • Field Details

    • AUTH_DEFAULT

      public static final String AUTH_DEFAULT
      Authentication method using the default login as defined in the fs-jaas.conf.
      Since:
      4.0.17
      See Also:
    • AUTH_CLIENT

      public static final String AUTH_CLIENT
      Authentication method using the client login as defined in the fs-jaas.conf.
      Since:
      4.0.17
      See Also:
    • AUTH_ADMIN

      public static final String AUTH_ADMIN
      Authentication method using the default admin as defined in the fs-jaas.conf.
      Since:
      4.0.17
      See Also:
    • AUTH_SYSTEM

      public static final String AUTH_SYSTEM
      Authentication method using the system login as defined in the fs-jaas.conf.
      Since:
      4.0.17
      See Also:
    • AUTH_WEB_SSO

      public static final String AUTH_WEB_SSO
      Authentication method using the SSO-based web login as defined in the fs-jaas.conf.
      Since:
      4.0.17
      See Also:
    • AUTH_WEB_NONSSO

      public static final String AUTH_WEB_NONSSO
      Authentication method using the Non-SSO-based web login as defined in the fs-jaas.conf.
      Since:
      4.0.17
      See Also:
    • ENCRYPTION_NONE

      public static final byte ENCRYPTION_NONE
      Use this value to use communication without encryption.
      Since:
      4.1.10
      See Also:
    • ENCRYPTION_TLS

      public static final byte ENCRYPTION_TLS
      Use the TLS encryption type for communications.
      Since:
      4.1.10
      See Also:
    • ENCRYPTION_DH_ARC4

      public static final byte ENCRYPTION_DH_ARC4
      Use the Alleged RC4 encryption type for communications.
      Since:
      4.1.10
      See Also:
    • COMPRESSION_NONE

      public static final byte COMPRESSION_NONE
      Use this value to use communication without compression.
      Since:
      4.1.10
      See Also:
    • COMPRESSION_DEFLATE

      public static final byte COMPRESSION_DEFLATE
      Default compression level.
      Since:
      4.1.10
      See Also:
    • COMPRESSION_DEFLATE_SPEED

      public static final byte COMPRESSION_DEFLATE_SPEED
      Compression level for fastest compression.
      Since:
      4.1.10
      See Also:
    • COMPRESSION_DEFLATE_BEST

      public static final byte COMPRESSION_DEFLATE_BEST
      Compression level for best compression.
      Since:
      4.1.10
      See Also:
    • COMPRESSION_SNAPPY

      @Deprecated public static final byte COMPRESSION_SNAPPY
      Deprecated.
      since 5.2.12, use COMPRESSION_NONE, COMPRESSION_DEFLATE_SPEED, or any of the other compression flags instead.
      Snappy compression
      Since:
      5.0.100
      See Also:
    • REVISION

      public static final String REVISION
      Current package implementation revision.
      Since:
      4.0.19
    • HTTP_MODE

      public static final int HTTP_MODE
      User HTTP-mode for communication
      Since:
      2.3
      See Also:
    • SOCKET_MODE

      public static final int SOCKET_MODE
      Use Socket-Mode for communication
      Since:
      2.3
      See Also:
    • SOCKET_DEFAULT_COMPRESSION

      public static byte SOCKET_DEFAULT_COMPRESSION
      Default compression level for SOCKET-mode.
      Since:
      5.0.100
    • SOCKET_DEFAULT_ENCRYPTION

      public static byte SOCKET_DEFAULT_ENCRYPTION
      Default encryption level for SOCKET-mode.
      Since:
      5.0.100
    • HTTP_DEFAULT_COMPRESSION

      public static byte HTTP_DEFAULT_COMPRESSION
      Default compression level for HTTP-mode.
      Since:
      5.0.100
    • HTTP_DEFAULT_ENCRYPTION

      public static byte HTTP_DEFAULT_ENCRYPTION
      Default encryption level for HTTP-mode.
      Since:
      5.0.100
  • Method Details

    • getConnection

      public static Connection getConnection(String host, int port, int mode, @Nullable @Nullable String servletzone, String module, CallbackHandler cbHandler)
      Create a connection accessor to a FirstSpirit server. To create the "physical" connection, you have to invoke Connection.connect() at a later point.
      Parameters:
      host - The name of the server's host to set up a connection for.
      port - The port of the server to be used.
      mode - The connection mode, one of HTTP_MODE or SOCKET_MODE.
      servletzone - The servlet zone to be used.
      module - The login method to be used, as defined in the fs-jaas.conf.
      cbHandler - The callback handler.
      Since:
      4.0.17
    • getConnection

      public static Connection getConnection(String host, int port, int mode, String login, Map<?,?> loginParams)
      Create a connection to a FIRSTspirit server instance, the physical connection is not already established after this call. Therefore you must call Connection.connect().
      Parameters:
      host - hostname
      port - port
      mode - connection mode, one of HTTP_MODE, or SOCKET_MODE
      login - login method (AuthenticationModule).
      loginParams - login parameters.
      Returns:
      the connection, you have to call Connection.connect() to
      Since:
      4.0.17
    • getConnection

      public static Connection getConnection(String host, int port, int mode, String servletZone, String login, Map<?,?> loginParams)
      Create a connection to a FIRSTspirit server instance, the physical connection is not already established after this call. Therefore you must call Connection.connect().
      Parameters:
      host - hostname
      port - port
      mode - connection mode, one of HTTP_MODE, or SOCKET_MODE
      servletZone - servletzone, only used when mode is HTTP_MODE
      login - login method (AuthenticationModule).
      loginParams - login parameters.
      Returns:
      the connection, you have to call Connection.connect() before you can use the connection
      Since:
      4.0.17
    • getConnection

      public static Connection getConnection(String host, int port, int mode, String login, String password)
      Create a connection to a FIRSTspirit server instance, the physical connection is not already established after this call. Therefore you must call Connection.connect().
      Parameters:
      host - hostname
      port - port
      mode - connection mode, one of HTTP_MODE, or SOCKET_MODE
      login - unsername
      password - password
      Returns:
      the connection, you have to call Connection.connect() to
      Since:
      2.3
    • getConnection

      public static Connection getConnection(String host, int port, int mode, String servletZone, String login, String password)
      Create a connection to a FIRSTspirit server instance, the physical connection is not already established after this call. Therefore you must call Connection.connect().
      Parameters:
      host - hostname
      port - port
      mode - connection mode, one of HTTP_MODE, or SOCKET_MODE
      servletZone - servletzone, only used when mode is HTTP_MODE
      login - username
      password - password
      Returns:
      the connection, you have to call Connection.connect() before you can use the connection
      Since:
      2.3
    • getProxy

      public static Proxy getProxy()
      Get the proxy used for new connections.
      Returns:
      The proxy
      Since:
      4.0.17
    • setProxy

      public static void setProxy(Proxy proxy)
      Set the proxy used for creating new connections.
      Parameters:
      proxy - The proxy
      Since:
      4.0.17
    • getEncryption

      public static byte getEncryption(int mode)
      Get the used encryption for the specified connection mode.
      Parameters:
      mode - connection mode, one of HTTP_MODE, or SOCKET_MODE
      Returns:
      the used encryption, one of ENCRYPTION_NONE, ENCRYPTION_TLS, ENCRYPTION_DH_ARC4
      Since:
      4.0.17
    • setEncryption

      public static void setEncryption(byte encryption)
      Set the used encryption. This method overrides the default encryption for all connection modes.
      Parameters:
      encryption - the used encryption, one of ENCRYPTION_NONE, ENCRYPTION_TLS, ENCRYPTION_DH_ARC4
      Since:
      4.0.17
    • resetEncryption

      public static void resetEncryption()
      Reset the used encryption to default values.
      Since:
      4.0.17
    • setCompression

      public static void setCompression(byte compression)
      Set the used compression. This method overrides the default compression for all connection modes.
      Parameters:
      compression - the used compression, one of COMPRESSION_NONE, COMPRESSION_DEFLATE, COMPRESSION_DEFLATE_BEST, COMPRESSION_DEFLATE_SPEED
      Since:
      4.0.17
    • resetCompression

      public static void resetCompression()
      Reset the used compression to default values.
      Since:
      4.0.17
    • getUseHttps

      public static boolean getUseHttps()
      Should https protocol be used for servlet communication.
      Since:
      4.0.120
    • setUseHttps

      public static void setUseHttps(boolean useHttps)
      Set if https protocol should be used for servlet communication.
      Since:
      4.0.120
    • getCompression

      public static byte getCompression(int mode)
      Get the used compression for the specified connection mode.
      Parameters:
      mode - connection mode, one of HTTP_MODE, or SOCKET_MODE
      Returns:
      the used compression, one of COMPRESSION_NONE, COMPRESSION_DEFLATE, COMPRESSION_DEFLATE_BEST, COMPRESSION_DEFLATE_SPEED
      Since:
      4.0.17
    • testConnection

      public static void testConnection(String host, int port, int mode) throws IOException
      Test connection parameters
      Parameters:
      host - The host o connect to
      port - The server port
      mode - The connection mode
      Throws:
      VersionMismatchException - Throw if client has wrong version
      IOException - Thrown if there is a communication problem
      Since:
      4.0.17
    • testConnection

      public static void testConnection(String host, int port, int mode, String servletZone) throws IOException
      Test connection parameters
      Parameters:
      host - The host to connect to
      port - The server port
      mode - The connection mode
      servletZone - The servletzone
      Throws:
      VersionMismatchException - Throw if client has wrong version
      IOException - Thrown if there is a communication problem
      Since:
      4.0.17
    • downloadClientJar

      public static ConnectionManager.ClientJarInputStream downloadClientJar(String host, int port, int mode) throws IOException
      Download fs-client.jar from server
      Parameters:
      host - The server host name
      port - The server port
      mode - The connection mode
      Returns:
      A InputStream for reading the jar file data
      Throws:
      IOException - Thrown if there is a communication problem
      Since:
      4.0.17
    • downloadClientJar

      public static ConnectionManager.ClientJarInputStream downloadClientJar(String host, int port, int mode, String servletZone) throws IOException
      Download fs-client.jar from server
      Parameters:
      host - The server host name
      port - The server port
      mode - The connection mode
      servletZone - The servletzone
      Returns:
      A InputStream for reading the jar file data
      Throws:
      IOException - Thrown if there is a communication problem
      Since:
      4.0.17
    • createCaller

      @NotNull public static @NotNull de.espirit.firstspirit.client.io.ServerCaller createCaller(String host, int port, int mode, String servletZone)
      Creates a server caller based on the given information.
      Parameters:
      host - The server host name.
      port - The server port.
      mode - The connection mode, one of HTTP_MODE or SOCKET_MODE.
      servletZone - The servlet zone.
      Returns:
      A server caller.
      Since:
      4.0.17
    • getForceConnect

      public static boolean getForceConnect()
      Indicates, whether to force connections.
      Returns:
      true, if to force connections.
      Since:
      4.0.17
    • createLoginParams

      public static Map<String,String> createLoginParams(String user, String plainPassword)
      Creates a login parameter container based on the given user name and plain password.
      Parameters:
      user - The user's name.
      plainPassword - The plain given password.
      Returns:
      A container to be used for transporting login information.
      Since:
      4.0.17
    • getDefaultExceptionHandler

      public static ExceptionHandler getDefaultExceptionHandler()
      Returns current default ExceptionHandler
      Returns:
      current default ExceptionHandler.
      Since:
      4.0.17
    • setDefaultExceptionHandler

      public static void setDefaultExceptionHandler(ExceptionHandler handler)
      Sets the default ExceptionHandler for all connections without an own handler.
      Parameters:
      handler - new default handler.
      Since:
      4.0.17