hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Canbay, Özkan" <O.Can...@hzd.hessen.de>
Subject How to implement a bi-directional SSL sheme ?
Date Thu, 08 May 2003 15:11:32 GMT
Hi,
 
currently I  am implementing the "clients authenticate servers and servers
authenticate clients" scheme by using net and jsse library.
How can I implement the following by using httpclient ?
 
public String getData(String targetURLString, String cookiename, String
sessionid, String xmlData) {
            System.setProperty( "javax.net.ssl.trustStore", "abc.jks");
            System.setProperty( "javax.net.ssl.trustStorePassword",
"blabla");
            System.setProperty( "javax.net.ssl.keyStore", "abc.jks");
            System.setProperty( "javax.net.ssl.keyStorePassword", "blabla");
            URL target = new URL( targetURLString);
            HttpURLConnection conn = (HttpURLConnection)
target.openConnection();
            conn.setRequestMethod("POST");
            try {
com.sun.net.ssl.HttpsURLConnection secureConnection =
(com.sun.net.ssl.HttpsURLConnection) conn;
 
secureConnection.setHostnameVerifier(getHostnameVerifier());
            } catch (ClassCastException e) {
                    System.out.println( "Connection is not HTTPS or not
provided by sun, cannot set 
HostnameVerifier");
            }
            conn.setRequestProperty("Cookie", cookiename + "=" + sessionid);
            conn.setUseCaches(false); 
            conn.setDoOutput(true); 
            conn.connect();
            BufferedWriter writer = new BufferedWriter(new
OutputStreamWriter(conn.getOutputStream()));
            this.getRequestContent().writeContent(new PrintWriter(writer));
            writer.write( xmlData); 
writer.flush(); 
writer.close();
            BufferedReader reader = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
            resultContentString = new StringBuffer();
            while ((text = reader.readLine()) != null) {
                    resultContentString.append(text + "\n");
            }
            return resultContentString.toString();
    }
    ...
 
 
I started implementing by looking at the examples but I don't know what to
to if I recognize that the
connection is a secure(SSL) connection. 
 
  public String responseXMLDatagramm(String request) {
    String response = null;
    int status;
    try {
      URI uri = new URI(azrURI.toCharArray());
      String host = uri.getHost();
      int port = uri.getPort();
      Protocol protocol = Protocol.getProtocol(uri.getScheme());
      HttpConnection connection = new HttpConnection(host, port, protocol);
 
      if (connection.isSecure()) {
       --> // What to do here ?? <--
      }
 
      HttpState state = new HttpState();
      PostMethod post = new PostMethod(uri.toString());
      post.setRequestBody(request);
 
      status = post.execute(state, connection);
      response = post.getResponseBodyAsString();
 
 
 
Regards
 
Özkan

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message