permaculture playing cards*
The moose likes Sockets and Internet Protocols and the fly likes Connection timeout with HttpsURLConnection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Connection timeout with HttpsURLConnection" Watch "Connection timeout with HttpsURLConnection" New topic
Author

Connection timeout with HttpsURLConnection

Sankar Madhavan
Greenhorn

Joined: Nov 19, 2008
Posts: 3
In my project we need to connect to a site and get the response. We tried with org.apache.commons.httpclient.HttpClient and is working fine. But when we tried with javax.net.ssl.HttpsURLConnection I was getting Connection timed out, exception

we are using the following VM argument.

-Djavax.net.debug=ssl,handshake
-Djavax.net.ssl.keyStore=C:/test/client.keystore
-Djavax.net.ssl.trustStore=C:/test/telecom.ks
-Djavax.net.ssl.keyStorePassword=xxxxx
-Djavax.net.ssl.trustStorePassword=xxxxx


I appreciate if any one can help me to solve this.

CODE :


package com.test.efunds;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.*;
import java.net.*;
import javax.net.ssl.*;
import java.security.Security;
import java.util.Properties;

public class UseHttps {

public String sendMessage(String inputMessage) {

System.out.println("-->sendMessage()");
try {

String authenticationInWalletUrl ="https://mail.safeway.com";

URL url = null;
URLConnection connection = null;
HttpsURLConnection httpConn = null;
OutputStream out = null;
InputStreamReader isr = null;
BufferedReader in = null;
String inputLine = null;


Properties systemSettings = System.getProperties();
systemSettings.put( "proxySet", "true" );

systemSettings.put("http.proxyHost", "proxyvip.safeway.com");
systemSettings.put("http.proxyPort", "8080");
System.setProperties(systemSettings);


Authenticator authenticator = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return (new PasswordAuthentication("dkair00",
"Columbo!".toCharArray()));
}};
Authenticator.setDefault(authenticator);




// Create the connection to the Experian url
url = new URL(authenticationInWalletUrl);
connection = url.openConnection();
httpConn = (HttpsURLConnection) connection;



httpConn.setRequestProperty(
"Content-Type",
"text/xml; charset=utf-8");
httpConn.setRequestMethod("GET");

//To use the urlConnection for output
httpConn.setDoOutput(true);

//Retrieve InputStream for the Exparian url
isr = new InputStreamReader(httpConn.getInputStream());
in = new BufferedReader(isr);

StringBuffer sb = new StringBuffer();

//Reading the Experian response
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
sb.append(inputLine);
}

//Closing InputStream for the Exparian url
in.close();

System.out.println("<--sendMessage()");
return sb.toString();
} catch (IOException ioe) {
ioe.printStackTrace();
}
return null;

}

public static void main(String args[]) {
new UseHttps().sendMessage("");
}

}


Regards,
Sankar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connection timeout with HttpsURLConnection
 
Similar Threads
Problems connecting to LDAP from Weblogic Server: BAD_CERTIFICATE error!
java.net.ConnectException: Connection refused: connect
Need Help in Netowork Programming.
java.net.ConnectException: Connection refused: connect
Logging in to a site programmatically