Example #1
0
  /**
   * Return the security information associated with this connection. If the connection is still in
   * <CODE>Setup</CODE> state then the connection is initiated to establish the secure connection to
   * the server. The method returns when the connection is established and the <CODE>Certificate
   * </CODE> supplied by the server has been validated. The <CODE>SecurityInfo</CODE> is only
   * returned if the connection has been successfully made to the server.
   *
   * @return the security information associated with this open connection.
   * @exception CertificateException if the <code>Certificate</code> supplied by the server cannot
   *     be validated. The <code>CertificateException</code> will contain the information about the
   *     error and indicate the certificate in the validation chain with the error.
   * @exception IOException if an arbitrary connection failure occurs
   */
  public SecurityInfo getSecurityInfo() throws IOException {
    ensureOpen();

    sendRequest();

    if (sslConnection == null) {
      /*
       * This is a persistent connection so the connect method did
       * not get called, so the stream connection of HTTP class
       * will be a SSL connection. Get the info from that.
       */
      StreamConnection sc = ((StreamConnectionElement) getStreamConnection()).getBaseConnection();

      return ((SSLStreamConnection) sc).getSecurityInfo();
    }

    return sslConnection.getSecurityInfo();
  }