java.net.ConnectException: Connection refused: connect
843811Jul 5 2002 — edited Sep 5 2002Hi there! I'm developing a java client which will connect to a HTTPS server. I made MyX509TrustManager class just as you told in one of your replies. I also used the SSLContext stuff. In other words, here it is the code:
/********** MyX509TrustManager class **************/
import com.sun.net.ssl.X509TrustManager;
import com.sun.net.ssl.TrustManager;
import javax.security.cert.X509Certificate;
class MyX509TrustManager implements X509TrustManager
{
public boolean isClientTrusted(java.security.cert.X509Certificate[] chain)
{
return true;
}
public boolean isServerTrusted(java.security.cert.X509Certificate[] chain)
{
return true;
}
public java.security.cert.X509Certificate[] getAcceptedIssuers()
{
return null;
}
}
/******* Where I set the properties to use SSL ***************/
//System.setProperty("https.proxyHost",proxyHost);
//System.setProperty("https.proxyPort",proxyPort);
System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
java.security.Security.addProvider((java.security.Provider)new com.sun.net.ssl.internal.ssl.Provider());
try
{
MyX509TrustManager tm = new MyX509TrustManager();
KeyManager[] km = null;
TrustManager[] tma = {tm};
SSLContext sc = SSLContext.getInstance("SSLv3");
SSLSocketFactory sf1 = null;
java.security.SecureRandom sr = new java.security.SecureRandom();
sc.init(km,tma,sr);
sf1 = sc.getSocketFactory();
HttpsURLConnection.setDefaultSSLSocketFactory(sf1);
System.out.println("Inicia SSL");
}
/***************then I try to stablish the connection with:*********/
BASE64Encoder b64e = new BASE64Encoder();
String encodedUser = b64e.encode(LDAPUserPasswd.getBytes());
urlConn = (HttpsURLConnection)url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestMethod("POST");
urlConn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
urlConn.setRequestProperty("Authorization", "Basic " + encodedUser);
if (sessionCookie != null)
{
urlConn.setRequestProperty("Cookie",sessionCookie);
}
But when I tried to connect, I got the exception:
java.net.ConnectException: Connection refused: connect
Please, if any of you have any idea of how to solve this problem of why does it appear, I would be very very thankful, because I'm stuck in this stuff and I can't continue with my developing. Thanks!