Problem establishing a https connection - Weblogic

This is a discussion on Problem establishing a https connection - Weblogic ; Hi, I have the following problem in establishing a connection to a secured webserver. I tried to establish a connection to a secured web server from a application running in weblogic. I used the weblogic specific APIs, created a weblogic.net.http.HttpsURLConnection. ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Problem establishing a https connection

  1. Problem establishing a https connection

    Hi,

    I have the following problem in establishing a connection to a secured webserver.

    I tried to establish a connection to a secured web server from a application running in weblogic. I used the weblogic specific APIs, created a weblogic.net.http.HttpsURLConnection. I set the connection properties like setSocketFactory and used NulledTrustManager and NulledHostNameVerifier.

    I then tried to get a DataOutputStream so tht i can write my xml string to tht connection, nothing really is happening. When i tried to print the headervariables it is not printing any..... I am doubtful if the connection is established....

    i will attach my code....plz tell me if i am missing something out....

    The same code works when i use Java APIs....they are included in the code as comments....

    Actually i have a jsp file in the secure server which takes this string and sends mail to the required recipients.....

    Plz help.....Thanks in Advance for all the helping minds...

    In the code, the trustallcerts and hostnameverifier are classes written similar to nulledtrustmanager and nulledhostnameverifier.... ie it certifies everything and trusts everything.

    [pre]

    /* Code Snippet */

    import java.io.*;
    import java.util.Properties;
    import java.net.*;
    import weblogic.security.SSL.*;
    import weblogic.net.http.HttpsURLConnection;

    public class EmailClientW
    {
    String XMLMessage;
    byte[] XMLMessageBytes;
    String strURL= "some https url";


    public EmailClientW(){}

    public EmailClientW( String str )
    {
    XMLMessage = str;
    XMLMessageBytes = XMLMessage.getBytes();
    }


    public void HttpsConnect()
    {

    try{
    // Create the socket connection and open it to the secure remote web server

    // Used in case of Java API
    //System.setProperty("javax.net.ssl.trustStore", "C://bea/jdk141_03//jre//lib//security//cacerts");

    weblogic.security.SSL.SSLContext sc = weblogic.security.SSL.SSLContext.getInstance("SSL");

    //Used in case of Java API
    //sc.init(null, trustAllCerts, new java.security.SecureRandom());


    TrustManagerJSSE tManager = new TrustAllcerts();

    sc.setTrustManagerJSSE(tManager);
    //sc.loadLocalIdentity(certs, privateKey);

    sc.setHostnameVerifierJSSE(new HostNameVerifier());

    //Used in case of Java API
    //javax.net.ssl.HttpsURLConnection.setDefaultSSLSock etFactory(sc.getSocketFactory());

    URL url = new URL(strURL);
    weblogic.net.http.HttpsURLConnection connection = new weblogic.net.http.HttpsURLConnection(url);


    connection.setSSLSocketFactory(sc.getSocketFactory JSSE());
    connection.setHostnameVerifierJSSE(new HostNameVerifier());
    System.out.println("CLASS " + connection.getClass().getName());


    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setRequestProperty("Connection", "Keep-Alive");
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-Type","text/html");
    connection.setInstanceFollowRedirects(false);
    connection.setAllowUserInteraction(false);

    connection.setHostnameVerifierJSSE(new HostNameVerifier());

    //This doesnt print anything.
    System.out.println("getOutputStream :"+connection.getHeaderFields());

    DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
    dos.write(XMLMessageBytes, 0, XMLMessageBytes.length);
    dos.flush();
    dos.close();

    }catch (java.net.MalformedURLException mue){
    System.err.println("\n" + "URL is not exist or protocol does not exist or there is a typo in the submitted URL" + "\n");
    }catch (java.net.UnknownHostException uhe){
    System.err.println("\n" + "Remote server does not exist in DNS." + "\n");
    }catch (java.io.IOException ioe){
    System.err.println("\n" + "I/O Exception in the connection try again or contact developer." + "\n");
    ioe.printStackTrace();
    }catch (Exception exp){
    System.err.println("\n" + "Exception in the connection try again or contact developer." + "\n");
    exp.printStackTrace();
    }
    }

    public static void main(String args[]) throws Exception
    {
    new EmailClientW().HttpsConnect();
    }


    }[/pre]

  2. Re: Problem establishing a https connection

    Change the line
    URL url = new URL(strURL);

    as

    URL url = new URL(null, strURL, new com.sun.net.ssl.internal.www.protocol.https.Handler());


    and remove the line


    connection.setRequestProperty("Content-Type","text/> html");

  3. Re: Problem establishing a https connection

    This code should work with weblogic url handler, assuming a valid url is used. Try running with ssl debug flags on: -Dssl.debug=true -Dweblogic.StdoutDebugEnabled=true
    This should provide more info about the handshake failure.

    Pavel.

+ Reply to Thread