You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by di...@apache.org on 2001/11/18 19:28:33 UTC
cvs commit: jakarta-slide/src/webdav/client/src/org/apache/commons/httpclient HttpClient.java
dirkv 01/11/18 10:28:33
Modified: src/webdav/client/src/org/apache/commons/httpclient
HttpClient.java
Log:
https support using SSL sockets
Revision Changes Path
1.6 +43 -30 jakarta-slide/src/webdav/client/src/org/apache/commons/httpclient/HttpClient.java
Index: HttpClient.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/commons/httpclient/HttpClient.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HttpClient.java 2001/09/14 17:48:24 1.5
+++ HttpClient.java 2001/11/18 18:28:33 1.6
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/commons/httpclient/HttpClient.java,v 1.5 2001/09/14 17:48:24 juergen Exp $
- * $Revision: 1.5 $
- * $Date: 2001/09/14 17:48:24 $
+ * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/commons/httpclient/HttpClient.java,v 1.6 2001/11/18 18:28:33 dirkv Exp $
+ * $Revision: 1.6 $
+ * $Date: 2001/11/18 18:28:33 $
*
* ====================================================================
*
@@ -423,8 +423,7 @@
try {
openConnection();
methodProcessed = true;
-
- }
+ }
catch (java.net.ConnectException e) {
// System.out.println("##################11111 =" + retries);
// e.printStackTrace();
@@ -684,13 +683,7 @@
* to make usage more clear.
*/
public void startSession() {
-
- if (state == null)
- state = new State();
- this.sessionHost = "localhost";
- this.sessionPort = 80;
- this.https = false;
-
+ startSession("localhost",80,null,false);
}
@@ -698,7 +691,7 @@
* Start a session.
*/
public void startSession(String host, int port) {
- startSession(host,port,false);
+ startSession(host,port,null,false);
}
@@ -706,17 +699,7 @@
* Start a session.
*/
public void startSession(String host, int port, boolean https) {
- if (debug > 0)
- System.out.println("Start session : Host:" + host
- + " Port:" + port
- + " HTTPS:" + https);
-
- if (state == null)
- state = new State();
- this.sessionHost = host;
- this.sessionPort = port;
- this.https = https;
-
+ startSession(host,port,null,https);
}
@@ -744,7 +727,6 @@
this.sessionHost = host;
this.sessionPort = port;
this.https = https;
-
}
@@ -780,7 +762,7 @@
*/
public void startSession(URL url, Credentials creds) {
setCredentials(creds);
- startSession(url.getHost(), url.getPort() == -1 ? 80 : url.getPort());
+ startSession(url);
}
@@ -827,10 +809,21 @@
("Reopen connection : Host:"
+ sessionHost + " Port:" + sessionPort);
if(https) {
- socket = new Socket
- (this.sessionHost, this.sessionPort);
- //socket = SSLSocketFactory.getDefault().createSocket
- //(this.sessionHost, this.sessionPort);
+ // Use reflection to do:
+ // socket = SSLSocketFactory.getDefault().createSocket
+ // (this.sessionHost, this.sessionPort);
+ Class sslFactoryClass = Class.forName("javax.net.ssl.SSLSocketFactory");
+ Method getDefaultMethod = sslFactoryClass.getMethod("getDefault", new Class[0]) ;
+ Object sslSocketFactory = getDefaultMethod.invoke(null,null);
+ Class[] paramClass = new Class[2];
+ paramClass[0] = String.class;
+ paramClass[1] = int.class;
+ Method createSocketMethod = sslSocketFactory.getClass().getMethod("createSocket",paramClass);
+ Object[] param = new Object[2];
+ param[0] = this.sessionHost;
+ param[1] = new Integer(this.sessionPort);
+ Socket socket = (Socket) createSocketMethod.invoke(sslSocketFactory,param);
+
} else {
socket = new Socket
(this.sessionHost, this.sessionPort);
@@ -857,6 +850,21 @@
}
throw e;
+ } catch (Exception e) {
+ // no special handling for
+ // NoSuchAlgorithmException
+ // KeyManagementException
+ if (connectionInterceptor != null) {
+ connectionInterceptor.error(-1, e);
+ }
+
+ // Connection is probably half closed
+ // Closing the connection and trying again
+ if (socket != null) {
+ socket.close();
+ socket = null;
+ }
+ throw new IOException(e.getMessage());
}
if (connectionInterceptor != null) {
@@ -923,6 +931,11 @@
String hostName = sessionHost;
if (sessionPort != 80)
hostName = hostName + ":" + sessionPort;
+
+ if (this.https)
+ hostName = "https://" + hostName;
+ else
+ hostName = "http://" + hostName;
method.generateHeaders(hostName, state);
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>