0
votes

I would like to get an ICS file from Google Agenda in a Java project, without using APIs (just getting the content of the ics). The calendar is set to "public", and I get the public ical address from the paramaters (https://www.google.com/calendar/ical/perrine.lbc62%40gmail.com/public/basic.ics). If I try this address in a browser, I can download the file (event if i'm not connected).

But if I try to get the content with curl command line for example, or with my Java code, it doesn't work : I can't connect to the URL.

Curl says : curl: (7) couldn't connect to host

Java code is the following :

private ICalendar getICalWithUrl(String url) throws Exception {
    ICalendar iCal = null; 
    // Create an instance of HttpClient.
    HttpClient client = new HttpClient();
    // Create a method instance.
    GetMethod method = new GetMethod(url);
    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
    try {
      // Execute the method.
      int statusCode = client.executeMethod(method);
      if (statusCode != HttpStatus.SC_OK) {
        throw new Exception("Unable to get content at the url "+url+". Method failed: " + method.getStatusLine());
      }
      // Read the response body.
      byte[] responseBody = method.getResponseBody();
      iCal=BiweeklyManager.parse(new String(responseBody));
    } finally {
      // Release the connection.
      method.releaseConnection();
    }
    return iCal;  
}

And the stacktrace is the following :

java.net.ConnectException: Connection refused
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:519)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:550)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:394)
        at com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:123)
        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)

Do you know why I can't access to the url in this cases, and what can I do to access it ?

Thanks a lot for your answers :)

1
That exact URL works for me in curl...Jon Skeet

1 Answers

0
votes

Are you in a corporate environment ? This sounds like a proxy setting issue, especially given that you you access it from your browser.

Try curl with the --proxy option (see for example Linux curl command with proxy)