Fix SSLProtocolSocketFactory with HttpClient 3.1

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@505 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2009-04-06 21:53:43 +00:00
parent a095d60835
commit de3790a86b
1 changed files with 19 additions and 8 deletions

View File

@ -1,29 +1,29 @@
package davmail.http;
import org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory;
import davmail.Settings;
import davmail.ui.tray.DavGatewayTray;
import org.apache.commons.httpclient.HttpsURL;
import org.apache.commons.httpclient.params.HttpConnectionParams;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.apache.commons.httpclient.HttpsURL;
import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import java.io.IOException;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
import java.net.MalformedURLException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import davmail.Settings;
import davmail.ui.tray.DavGatewayTray;
/**
* Manual Socket Factory.
* Let user choose to accept or reject certificate
*/
public class DavGatewaySSLProtocolSocketFactory extends SSLProtocolSocketFactory {
public class DavGatewaySSLProtocolSocketFactory implements SecureProtocolSocketFactory {
/**
* Register custom Socket Factory to let user accept or reject certificate
*/
@ -73,6 +73,18 @@ public class DavGatewaySSLProtocolSocketFactory extends SSLProtocolSocketFactory
}
}
public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort, HttpConnectionParams params) throws IOException {
try {
return getSSLContext().getSocketFactory().createSocket(host, port, clientHost, clientPort);
} catch (NoSuchAlgorithmException e) {
throw new IOException(e+" "+e.getMessage());
} catch (KeyManagementException e) {
throw new IOException(e+" "+e.getMessage());
} catch (KeyStoreException e) {
throw new IOException(e+" "+e.getMessage());
}
}
public Socket createSocket(String host, int port) throws IOException {
try {
@ -86,7 +98,6 @@ public class DavGatewaySSLProtocolSocketFactory extends SSLProtocolSocketFactory
}
}
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException {
try {
return getSSLContext().getSocketFactory().createSocket(socket, host, port, autoClose);