protected HttpsURLConnection getSSLConnection(URL url) throws IOException, IllegalStateException {

    if (sslSocketFactory == null) {
      synchronized (this) {
        if (sslSocketFactory == null) {

          if (trustStorePath == null || trustStorePassword == null) {
            String msg =
                    String.format("Can't get secure connection to %s.  Truststore path or password is not set.",
                            URLCredentialsHider.hideCredentials(url.toString()));

            LOG.error(msg);
            throw new IllegalStateException(msg);
          }
          FileInputStream in = null;
          try {
            in = new FileInputStream(new File(trustStorePath));
            KeyStore store = KeyStore.getInstance(trustStoreType == null ?
                KeyStore.getDefaultType() : trustStoreType);
            store.load(in, trustStorePassword.toCharArray());
            TrustManagerFactory tmf = TrustManagerFactory
                .getInstance(TrustManagerFactory.getDefaultAlgorithm());
            tmf.init(store);
            SSLContext context = SSLContext.getInstance("TLS");
            context.init(null, tmf.getTrustManagers(), null);
            sslSocketFactory = context.getSocketFactory();
          } catch (Exception e) {
            throw new IOException("Can't get connection.", e);
          } finally {
            if (in != null) {
              in.close();
            }
          }
        }
      }
    }
    HttpsURLConnection connection = (HttpsURLConnection) (url
        .openConnection());

    connection.setSSLSocketFactory(sslSocketFactory);

    return connection;
  }
Utility method to append a new cookie value to an existing list of cookies.

@param cookies    the semicolon separated list of cookie values
@param newCookie  a new cookie value to be appended.

@return the new list of cookie values
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.java