Example usage for javax.net.ssl SSLHandshakeException getStackTrace

List of usage examples for javax.net.ssl SSLHandshakeException getStackTrace

Introduction

In this page you can find the example usage for javax.net.ssl SSLHandshakeException getStackTrace.

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Usage

From source file:net.sf.taverna.t2.security.credentialmanager.impl.HTTPSConnectionAndTrustConfirmationIT.java

@Test
public void testTrustConfirmationProvidersTrustAlways() throws IOException, CMException {
    // Initially trust provider list is empty, we only verify by what is in 
    // Credential Manager's Truststore (and it does not contains the certificate for https://heater.cs.man.ac.uk:7443/)

    // Do not forget to initialise Taverna's/Credential Manager's SSLSocketFactory
    credentialManager.initializeSSL();//  w  w  w  . j a  va2  s .  c  om

    URL url = new URL("https://heater.cs.man.ac.uk:7443/");
    HttpsURLConnection conn;
    conn = (HttpsURLConnection) url.openConnection();
    try {
        // This should fail
        conn.connect();
        fail("Connection to https://heater.cs.man.ac.uk:7443/ should be untrusted at this point.");
    } catch (SSLHandshakeException sslex) {
        // expected to fail so all is good
        System.out.println(sslex.getStackTrace());
    } finally {
        conn.disconnect();
    }

    // Add the trust confirmation provider that trusts everyone
    List<TrustConfirmationProvider> trustProviders = new ArrayList<TrustConfirmationProvider>();
    trustProviders.add(new TrustAlwaysTrustConfirmationProvider());
    credentialManager.setTrustConfirmationProviders(trustProviders);

    HttpsURLConnection conn2 = (HttpsURLConnection) url.openConnection();
    // This should work now
    conn2.connect();
    System.out.println("Status header: " + conn2.getHeaderField(0));

    assertEquals("HTTP/1.1 200 OK", conn2.getHeaderField(0));
    conn2.disconnect();
}