1

I'm having trouble sending https requests from eclipse.When I run this code it works fine.

public class HttpConnectionTest extends TestCase{

    @Test
    public void testConnection() throws HttpException, IOException {
        int statusCode = new HttpClient().executeMethod(new GetMethod("http://www.google.com"));
        assertTrue(statusCode == HttpStatus.SC_OK);
    }
}

But when i run the same code for "https://www.google.com", I get the exception below;

java.net.ConnectException: Connection timed out: connect
   at java.net.DualStackPlainSocketImpl.connect0(Native Method)
   at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
   at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
   at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
   at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
   at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
   at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
   at java.net.Socket.connect(Socket.java:579)
   at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:618)
   at sun.security.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:451)
   at sun.security.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:140)
   at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:81)
   at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:126)
   at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:706)
   at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:386)
   at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
   at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
   at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
   at adcWeb.HttpConnectionTest.testConnection(HttpConnectionTest.java:26)

I'm connecting to internet via proxy. My network setting are like this; I saw some people said to disable socks but eclipse doesn't allow me uncheck socks option (I'm using eclipse luna)

katatonia5
  • 13
  • 3

1 Answers1

1

I believe that the proxy you configure in the eclipse settings are for plugins and IDE related stuff..

You will have to setup the proxy in your code at runtime like so :

How do I make HttpURLConnection use a proxy?

Community
  • 1
  • 1
MajorT
  • 221
  • 1
  • 12
  • This is a valid approach but i dont want to do this by editing the code that actually sends the requests because there are third party jars who sends those requests. I need to this via eclipse settings. – katatonia5 Dec 31 '14 at 14:47
  • 1
    Then you will have to pass the proxy parameters to the JVM. Rightclick your project -> run as -> run configurations.. From there press the Arguments tab. Add these parameters: -Dhttp.proxyHost=10.10.10.10 -Dhttp.proxyPort=8080 as VM arguments. – MajorT Dec 31 '14 at 14:54