com.cri.xcat.api
Class Connection

java.lang.Object
  extended by com.cri.xcat.api.Connection

public class Connection
extends java.lang.Object

This class contains the information needed to make a valid SSL socket connection to an xCAT daemon. By default, the hostname of the xCAT daemon is set to localhost and the port is set to 3001. Since the connection to xCAT requires security information to make the SSL connection, users can add certificate files to make a secure connection.

Author:
Scott Brown

Constructor Summary
Connection()
          Create a new connection to an xCAT daemon using hostname of "localhost" port of "3001", and the default xCAT certificate files: "ca.pem" & "client-cred.pem" located in the default xCAT directory.
Connection(java.lang.String hostname, int port)
          Create a new connection to an xCAT daemon with the hostname and port specified.
Connection(java.lang.String hostname, int port, java.io.File[] certificateFiles)
          Create a new connection to an xCAT daemon with the hostname and port specified, and adds the security information from the security files specified.
 
Method Summary
 void addCertificateFile(java.io.File certFile)
          Adds the certificate file security information to the SSL client.
 javax.net.ssl.SSLSocket createSocket()
          Creates a SSL socket from the SSLClient.
 java.lang.String getHostname()
          Gets the host name of the server running the xCAT daemon.
 int getPort()
          Gets the port number of which the xCAT daemon is listening for incoming requests.
 void setHostname(java.lang.String hostname)
          Sets the host name of the server running the xCAT daemon.
 void setPort(int port)
          Sets the port number of which the xCAT daemon is listening for incoming requests.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Connection

public Connection()
           throws java.security.GeneralSecurityException,
                  java.io.IOException
Create a new connection to an xCAT daemon using hostname of "localhost" port of "3001", and the default xCAT certificate files: "ca.pem" & "client-cred.pem" located in the default xCAT directory.

Throws:
java.io.IOException - If there was an error creating a SSLClient
java.security.GeneralSecurityException - If there was an error creating a SSLClient
See Also:
SSLClient

Connection

public Connection(java.lang.String hostname,
                  int port)
           throws java.security.GeneralSecurityException,
                  java.io.IOException
Create a new connection to an xCAT daemon with the hostname and port specified.

This connection will also attempt to locate the ca.pem and client-cred.pem certificate files from the default xCAT directory. If these files are not present, an exception will be thrown.

Parameters:
hostname - The host name of the xcatd instance.
port - The port that xcatd is listening on.
Throws:
java.io.IOException - If there was an error creating a SSLClient or the default certificate files were not found.
java.security.GeneralSecurityException - If there was an error creating a SSLClient
See Also:
SSLClient

Connection

public Connection(java.lang.String hostname,
                  int port,
                  java.io.File[] certificateFiles)
           throws java.security.GeneralSecurityException,
                  java.io.IOException
Create a new connection to an xCAT daemon with the hostname and port specified, and adds the security information from the security files specified.

Parameters:
hostname - The host name of the xcatd instance.
port - The port that xcatd is listening on.
certificateFiles - An array of files that contain the certificate security information needed to connect to the xCAT server.
Throws:
java.io.IOException - If there was an error creating a SSLClient or the default certificate files were not found.
java.security.GeneralSecurityException - If there was an error creating a SSLClient
See Also:
SSLClient
Method Detail

addCertificateFile

public void addCertificateFile(java.io.File certFile)
                        throws java.io.IOException,
                               java.security.GeneralSecurityException
Adds the certificate file security information to the SSL client. The xCAT server requires authentication to create an SSL connection. During the xCAT install, PEM certificate files containing security information are created to allow clients to connect to the xCAT server. By default these files were named client-cred.pem and ca.pem and were placed in the .xcat directory.

This method allows the user to specify the certificate files that are required to connect to the xCAT server.

Parameters:
certFile - The certificate file used to create a SSL connection to the xCAT server.
Throws:
java.io.IOException - Exception thrown if there was a problem with IO when accessing the file.
java.security.GeneralSecurityException
See Also:
SSLClient

getHostname

public java.lang.String getHostname()
Gets the host name of the server running the xCAT daemon.

Returns:
the host name of the server running the xCAT daemon

getPort

public int getPort()
Gets the port number of which the xCAT daemon is listening for incoming requests.

Returns:
the port number of which the xCAT daemon is listening for incoming requests.

setHostname

public void setHostname(java.lang.String hostname)
Sets the host name of the server running the xCAT daemon.

Parameters:
hostname - the host name of the server running the xCAT daemon

setPort

public void setPort(int port)
Sets the port number of which the xCAT daemon is listening for incoming requests.

Port range must be from 1 to 65535.

Parameters:
port - the port number of which the xCAT daemon is listening for incoming requests

createSocket

public javax.net.ssl.SSLSocket createSocket()
                                     throws java.io.IOException
Creates a SSL socket from the SSLClient.

Returns:
a SSL socket to the host using the set port.
Throws:
java.io.IOException
See Also:
SSLClient