1

I'm trying to download - or even just open a stream - to a calendar located at webcal://www.somewhere.com/foo?etc=bar.

The Java URL class is throwing a "unknown protocol: webcal" exception when I do:

URL url = new URL("webcal://...");

How can I tell the URL class that it should just use HTTP as trasport protocol even if the web resource is located somewhere behind a webcal:// protocol?

Or, in any case, how can I get my calendar downloaded?

Please, bear in mind that the web server I'm calling does not serve the calendar if I try to replace the "webcal://" with "http://".

MatteoSp
  • 2,940
  • 5
  • 28
  • 36
  • If you want to treat it as just http, why not just fix the URL? – Jon Skeet Apr 12 '13 at 09:53
  • @JonSkeet see the last sentence of the question – MatteoSp Apr 12 '13 at 09:58
  • Ah, misread that as "does". In that case, it sounds like it's probably *not* just a case of using HTTP as the transport protocol. You need something which really understands webcal. Are you sure it doesn't work if you just change the rest of the URL a little, e.g. adding a fixed filename at the end? I suggest you use something like Wireshark to see what happens with a working client. – Jon Skeet Apr 12 '13 at 10:00
  • No, as I suspected was just a matter of transport. I will post the answer shortly – MatteoSp Apr 12 '13 at 14:35
  • still waiting on that answer you promised? – Tyler Durden Jan 16 '15 at 13:32

2 Answers2

2

As far as I understand, Apple's use of "webcal" really is just a synonym for "http"; so it's supposed to work.

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98
1

The "webcal://" is an unofficial URI scheme, see Wikipedia article on it.

As such it might stand for one or another back end implementation - e.g. the web server you are calling might be using any of the mentioned protocol implementations, such as WebDAV, CalDAV or OpenDAV

However if all you want is to read the contents of the file, then any HTTP client should do the trick, because the above mentioned protocols are based on HTTP.

Here is an example on how to read a remote iCal using URL's own mechanism for opening HttpURLConnection :

    URL calendarURL = new URL("http://www.facebook.com/ical/b.php?uid=myUID&key=myKEY");
    URLConnection connection = calendarURL.openConnection();
    BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    while (reader.ready()) {
        System.out.println(reader.readLine());
    }

As you can see I have changed the original URL from

webcal://www.facebook.com/ical/b.php?uid=MYUID&key=MYKEY

to

http://www.facebook.com/ical/b.php?uid=MYUID&key=MYKEY

, because we use a java.net.URL and by default Java does not recognize this protocol. If indeed the web server you want to contact only serves the content over webcal:// then you might need to use the appropriate client (based on the exact protocol implementation the server uses). For example there are a multitude of frameworks that provide WebDAV client capabilities, such as JackRabbit, Sardine, etc.

If you provide more information on the type of server we can dig further.