Need help in starting off

149 views
Skip to first unread message

Harsha Ramesh

unread,
Sep 29, 2011, 4:37:43 AM9/29/11
to cald...@googlegroups.com
I have pulled down the source and trying to connect to a couple of CalDAV servers. When I try and access Google, I am unable to get anywhere ... The example source is not very descriptive. Has anyone connected to Google successfully?

Thanks,
Harsha

Roberto Polli

unread,
Sep 29, 2011, 4:47:04 AM9/29/11
to cald...@googlegroups.com
2011/9/29 Harsha Ramesh <harsha...@gmail.com>:

> I have pulled down the source
Did you successfully build the sources?
Did you try to run junit tests in Eclipse?

> When I try and access Google, I am unable to get anywhere ...

How do you try to connect Google? Did you use the Junit tests?

> The
> example source is not very descriptive

The example/ tree is quite old, I should remove it.

Use the Junit tests to see how to connect to a caldav server.

Let me know + Peace,
R.

Message has been deleted

Harsha Ramesh

unread,
Sep 29, 2011, 1:48:16 PM9/29/11
to cald...@googlegroups.com
Hi Roberto,

The code compiled absolute fine. I am writing my own test case here. This is what I have:

HttpClient mClient = new HttpClient();
HostConfiguration mConfig = new HostConfiguration();
CalDAV4JMethodFactory mMethodFactory = new CalDAV4JMethodFactory();
Credentials credentials = new UsernamePasswordCredentials(USERNAME, PASSWORD);

mConfig.setHost("google.com", 443, "https");
mClient.getParams().setAuthenticationPreemptive(true);
mClient.getState().setCredentials(AuthScope.ANY, credentials);

GetMethod getMethod = mMethodFactory.createGetMethod();
getMethod.setPath("/calendar/dav/harsha.ramesh%40gmail.com/user");

        try {
            mClient.executeMethod(mConfig, getMethod);
            System.out.println(getMethod.getResponseBodyAsString());
        } catch (IOException e) {
            Assert.fail("Unable to list calendar", e);
        }


When I execute the same, I just get a HTML page with a lot of scripts on it.

When I hit the URL via a browser, I get a 405 unauthorized ... 

Honestly, I am quite confused about where I head from here.

Thanks,
Harsha

Harsha Ramesh

unread,
Oct 2, 2011, 7:58:35 AM10/2/11
to cald...@googlegroups.com
I understand that CalDAVCollection is the entry point in to the system ... but how does one go about finding out the location of, say the calendar for example.

After digging a little more, I created the following query:

        String COLLECTION_PATH = "/calendar/dav/harsha...@gmail.com/users/";
        CalDAVCollection collection =
                new CalDAVCollection(COLLECTION_PATH, mHostConfiguration,
                        mMethodFactory, "-//Google Inc//Google Calendar 70.9054//EN");
        try {

            Calendar calendar = collection.getCalendar(mHttpClient, "/");
            System.out.println(calendar.toString());
        } catch (Exception ex) {
            ex.printStackTrace();
        }

And this time around I am getting a 404 - Resource Not Found exception.

Honestly speaking, the JUnit tests don't quite explain a lot of what can be done with this library.

BTW, I am using version 0.7 from the svn repository.

Roberto Polli

unread,
Oct 2, 2011, 4:10:02 PM10/2/11
to cald...@googlegroups.com

Ok, you are trying to retrieve an entire collection, not a calendar.

Search for methods returning a List<Calendar> to do what you are trying to do.
The calendar query methods should fit.

I hope to find some time to improve docs and help you. May I ask you to arrange it and provide some  detailed documentation?

Peace, Rob

Harsha Ramesh

unread,
Oct 3, 2011, 1:56:27 PM10/3/11
to cald...@googlegroups.com
Hi Roberto,

In intend on creating a few articles which should help with getting started. I will definitely help out with the documentation :) .. Let me figure out the use cases.

Thanks,
Harsha

Harsha Ramesh

unread,
Oct 3, 2011, 2:13:37 PM10/3/11
to cald...@googlegroups.com
The following is still giving me 0 calendars .. Let me try snooping on the headers / messages sent from iCal .. And my search goes on .. 

Harsha Ramesh

unread,
Oct 3, 2011, 2:14:58 PM10/3/11
to cald...@googlegroups.com
Forgot adding the code snippet:

            Date start = ICalendarUtils.createDate(2011, 01, 01);
            Date end = ICalendarUtils.createDate(2011, 12, 31);
            GenerateQuery gq = new GenerateQuery();
            gq.setFilter("VEVENT");
            gq.setTimeRange(start, end);
            List<Calendar> list = collection.queryCalendars(mHttpClient, gq.generate());
            System.out.println(list.size());

I tried using the following collection paths:

 "/calendar/dav/harsha.ramesh@gmail.com/";

Both return 0 results.

Harsha Ramesh

unread,
Oct 3, 2011, 3:13:23 PM10/3/11
to cald...@googlegroups.com
Quick update. Specifying the following URL in the browser downloads the ics file:

https://www.google.com/calendar/dav/ [ your Google Calendar ID ] /events


Ok .. some progress :) .. Now to see how to connect it in the code.

Roberto Polli

unread,
Oct 3, 2011, 3:48:47 PM10/3/11
to cald...@googlegroups.com
2011/10/3 Harsha Ramesh <harsha...@gmail.com>:

> Quick update. Specifying the following URL in the browser downloads the ics
> file:
> https://www.google.com/calendar/dav/ [ your Google Calendar ID ] /events
I didn't understood you were using google caldav: it doesn't support queries...

Anyway see:
Google Credential Pattern
http://code.google.com/p/caldav4j/source/browse/trunk/src/test/java/org/osaf/caldav4j/credential/GCaldavCredential.java

See here some failing tests (google has many issues with REPORT: use
OPTIONS to check supported methods)
http://code.google.com/p/caldav4j/source/browse/trunk/src/test/java/org/osaf/caldav4j/google/GCalDAVCalendarCollectionTest.java

Sorry for the little help but my 2nd child was born some days ago, and
I'm quite busy :D

Peace,
R.

Harsha Ramesh

unread,
Oct 3, 2011, 4:35:34 PM10/3/11
to cald...@googlegroups.com
Not a problem Roberto .. and congratulations on your new born :)

I made more progress ... Now I am stuck to parsing the DSTART time .. Looks like I will need to tweak the SimpleDateFormater a little bit.

DTSTART;TZID=GMT+05:30:20111201T210000
...
Caused by: java.text.ParseException: Unparseable date: "30:20120301T210000"
at java.text.DateFormat.parse(DateFormat.java:337)


Now to see how a timezone can be passed .. or how the existing one can be tweaked to support the various possibilities.

-Harsha

Roberto Polli

unread,
Oct 3, 2011, 4:51:13 PM10/3/11
to cald...@googlegroups.com
2011/10/3 Harsha Ramesh <harsha...@gmail.com>:

> Not a problem Roberto .. and congratulations on your new born :)
Thanks!

> I made more progress ... Now I am stuck to parsing the DSTART time .. Looks
> like I will need to tweak the SimpleDateFormater a little bit.
> DTSTART;TZID=GMT+05:30:20111201T210000

Watch out: that format is well defined in a standard way and shouldn't
accept malformed strings.
http://code.google.com/p/google-caldav-issues/issues/detail?id=57

Google Caldav doesn't care enough for standard... I started tweaking
caldav4j around google for more than one year, but they changed the
behavior various times, so I gave up and decided to do the minimum...

For the TZID stuff, write on the ICAL4J mailing list and propose a
patch or extension to the SimpleDateFormat Class (or extend it
yourself).

Peace,
R.

Harsha Ramesh

unread,
Oct 9, 2011, 8:09:49 AM10/9/11
to cald...@googlegroups.com
Hi Roberto,

The format is proper .. I noticed a bug in the iCal4J codebase

CalendarParserImpl.java : #325~

If the timezone is of the format GMT+05:30 or say UTC-08:00 ... then the parser skips after the first colon .. which is why the code was failing. I fixed it locally.

I also found a bug in the CalDAV (0.7) code base:

CalDAVCollection.java: #742

If for some reason the ETAG header is missing, then we get a NullPointerException .. I ran in to that one a while back.

So, now I am able to connect to the Google Calendar as well as my corporate calendar. Next I am going to write a few test cases of Create / Fetch / Update / Delete items. Once I have a little more hang of things, I shall put up a few documentation bits together.

Thanks,
Harsha

Harsha Ramesh

unread,
Oct 9, 2011, 8:58:17 AM10/9/11
to cald...@googlegroups.com
Hey Roberto,

I think the documentation on the CalDAVCollection needs to be streamlined, since I am again running around like a lost puppy ... I am not sure which method should I use from the CalDAVCollection to say, list all the Events and Todos in between a certain time period .. There is GenerateQuery and then there is CalendarQuery, when would I use each one?

Thanks,
Harsha

Harsha Ramesh

unread,
Oct 9, 2011, 10:54:58 AM10/9/11
to cald...@googlegroups.com
Another quick point .. Why are most of the methods in CalDAVCollection protected, like getCalDAVResources() ??? The library is forcing people to extend the collection or make use of deprecated methods ... I am not sure what the rationale behind that is ...

Roberto Polli

unread,
Oct 9, 2011, 11:43:22 AM10/9/11
to cald...@googlegroups.com
2011/10/9 Harsha Ramesh <harsha...@gmail.com>:

> Hi Roberto,
> The format is proper .. I noticed a bug in the iCal4J codebase
> CalendarParserImpl.java : #325~
Ok, let me know if Ben will fix it.

> I also found a bug in the CalDAV (0.7) code base:

> If for some reason the ETAG header is missing, then we get a
> NullPointerException ..

> CalDAVCollection.java: #742
http://www.google.com/codesearch#lU8bMIL0vRc/trunk/src/main/java/org/osaf/caldav4j/CalDAVCollection.java&q=caldavcollection.java%20package:http://caldav4j%5C.googlecode%5C.com&l=742
Not here, maybe there?
http://www.google.com/codesearch#lU8bMIL0vRc/trunk/src/main/java/org/osaf/caldav4j/CalDAVCollection.java&q=caldavcollection.java%20package:http://caldav4j%5C.googlecode%5C.com&l=746

Can you provide a quick fix? Pls ensure sources are up to HEAD: I
remember to have fixed something like that somewhere in the code.

> ...I am going to write a few test cases of Create / Fetch /
> Update / Delete items.
remember to separate test classes between google and other servers.

Roberto Polli

unread,
Oct 9, 2011, 11:53:23 AM10/9/11
to cald...@googlegroups.com
2011/10/9 Harsha Ramesh <harsha...@gmail.com>:

> method should I use from the CalDAVCollection to say, list all the Events
> and Todos in between a certain time period ..
The method is always the query one.

You may not be able to query *both* VEVENT and VTODO. A workaround
could be to query for VCALENDAR only.


> There is GenerateQuery and
> then there is CalendarQuery, when would I use each one?

GenerateQuery is an helper to create calendar queries without knowing
the exact structure of the CalendarQuery. GenerateQuery creates a
CalendarQuery.

The CalendarQuery is quite complex. See the caldav specification to
learn howto build a calendar query.

In the GenerateQueryTest file I recreate the queries listed in the
Caldav RFC using GenerateQuery and modifying the result.
http://www.google.com/codesearch#lU8bMIL0vRc/trunk/src/test/java/org/osaf/caldav4j/util/GenerateQueryTest.java

It's the hardest part of caldav (except scheduling, of course).

Shortly:
0. use CalendarQuery if you've time to waste
1. use GenerateQuery to create simple query
2. use GenerateQuery to create a query stub, then modify the
resulting CalendarQuery to easily create complex queries.
3. ALWAYS test+print the query in xml to check if you really build
the desired query.

Peace,
R.

Roberto Polli

unread,
Oct 9, 2011, 12:10:18 PM10/9/11
to cald...@googlegroups.com
2011/10/9 Harsha Ramesh <harsha...@gmail.com>:

> Another quick point .. Why are most of the methods in CalDAVCollection
> protected, like getCalDAVResources() ?
I inherited it and I decided not to change it. CaldavResource is an
internal class. It may be changed (I wish, I don't like that class at
all) or deleted. If you need to play with cache - anyway - it's a
quite useful class.

As of now, if something at CaldavResource method doesn't work then:
- there's a problem in caldav4j or
- there's a problem in the server/communication

In the first case, you need to patch caldav4j. In the second you
should fix the problem.
If you modify the library at that level in an external program, you're
modifying the CalDAV implementation behavior. This means that you're
going to break something somewere.

Moreover caldav4j is switching from slide backend to jackrabbit. While
I'm working to preserve all the CaldavCollection functionalities, I
don't guarantee internal methods' behavior in the change.

Anywyay, caldav4j is opensource and open to ideas and contribution: if
you have a valid reason to expose CaldavResource take some time to
explain:
* what you're trying to achieve
* why that class should be public.

I think there are some good reason to do it, but we need to do it in
the right way (ex. embedding a CaldavClient in caldav4j)

PS: take a look at how I use caldav4j (not trunk) in a calendar-sync
project http://funambol-caldav.svn.sourceforge.net/viewvc/funambol-caldav/trunk/src/main/java/it/babel/funambol/CalDAV/engine/CaldavInterface.java?revision=113&view=markup

HTH+Peace,
R.

Harsha Ramesh

unread,
Oct 10, 2011, 3:42:26 PM10/10/11
to cald...@googlegroups.com
Hi Roberto,

I am basically trying out a small experiment ... There are a lot of open source libraries that people use for their work .. Most of these libraries have flexible licensing agreements, where you can change the codebase as desired, as long as the author is given his due credit ... Now with the rise of smart phones like android, which allows applications to be written in Java, the entry barrier for writing mobile applications has been reduced.

As it stands, most people ignore the memory & bandwidth constraints and bloat up their application code (which in turn could leverage a variety of open source libraries). I am trying to run through an exercise of building a mobile client -- which in this case is a caldav sync adapter for Android .. I know that there are quite a few apps on the market and the wiki page also talks about a prototype that was done. I am trying to set up a codebase where I am pulling in the sources of various projects and then coming up a methodology of remove "unwanted" code.

For, e.g., the projects depend upon commons-logging .. In the target environment, I do not wish to create multiple loggers, neither do I wish to use a separate logging framework .. So instead of changing code all over the place, I have put in a modified implementation of commons-logging which internally just creates a single JDK logger and uses that for logging. Similarly, there might be only one class needed from commons-lang .. then why would you want to import the whole library?

This exercise is good for closed-loop environments, where my final product is not a library for consumption by others. By removing unwanted code, we ensure that the final archive is
  • of the smallest possible size - better bandwidth & memory utilization
  • does exactly what it has been tested for - completely Test Driven Development
If the methodology can be made generic-enough, then we could develop a series of processes / tools (build scripts, source level annotation processing, etc) which can be applied to a large set of existing projects, thereby enabling them to function in multiple target environments at the highly optimized levels.

This is definitely not a new concept, but I definitely believe that development is overly complicated. We need to spend less time coding and more time having fun!!

So, that in a gist is what I have in mind =)


Coming back to the earlier discussions,

  1. I shall drop a message on the ical4j forum and let ben know about the issue in the code
  2. I shall generate the patch for the caldav4j trunk and put it up for review

Thanks for the pointer to the funambol client adapter .. That is pretty much what I will need to get started :)

Cheers,
Harsha

Roberto Polli

unread,
Oct 10, 2011, 4:37:23 PM10/10/11
to cald...@googlegroups.com

Hi Harsha,

if I get the point:
- you want to build a caldav sync plug in for android calendar
- you want your sw to be small, including only used classes
- you are willing to patch and rebuild dependencies to achieve this target

The caldav android plug in goes that way: patches and rebuilds some libs, even I do not know if those libs are "stripped".
did  you give it a try?

Let me know, I could enable you wiki or svn account for your contribution.

Peace, Rob

--
You received this message because you are subscribed to the Google Groups "caldav4j" group.
To view this discussion on the web visit https://groups.google.com/d/msg/caldav4j/-/Q8GpEnuNj6UJ.
To post to this group, send email to cald...@googlegroups.com.
To unsubscribe from this group, send email to caldav4j+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caldav4j?hl=en.

Harsha Ramesh

unread,
Oct 11, 2011, 11:55:44 AM10/11/11
to cald...@googlegroups.com
Hi Roberto,


if I get the point:
- you want to build a caldav sync plug in for android calendar

Yes.
 

- you want your sw to be small, including only used classes

Yes.
 

- you are willing to patch and rebuild dependencies to achieve this target

Yes :)
 

The caldav android plug in goes that way: patches and rebuilds some libs, even I do not know if those libs are "stripped".
did  you give it a try?

I wasn't aware of it. I did not see any mention of the module SVN details on the base project page ..
 

Let me know, I could enable you wiki or svn account for your contribution.

Once I am done ironing out the use cases here, I shall set up a proper diff between what is present and what I have done and get back to you for the SVN commit access.

Cheers,
Harsha

Santosh Guptha

unread,
Oct 28, 2013, 5:04:24 AM10/28/13
to cald...@googlegroups.com
Hi Ramesh,
I am also working on developing a caldav client for android, 
I have successfully connected and able to retireve events from Yahoo server, but few issues are still there.
The TimeRange filtering is not working, it is returning all the events outside the time range. 
And I am facing issues in syncing part also. 
The problems I am facing are:
1. Not able to instantiate cache object by calling enableSimpleCache()
Could you tell me how you handled this part ?? Can we use ehcache.jar in android ??
2. Handling inserted and deleted events in the server, 
It is easy to identify updated events by comparing etags values in the cache, But how about newly inserted and deleted events in the server.
I got one idea, Doing Set minus operations (A-B and B-A) where A is cache href values and B is server href values.
Do you have any better alternative for this. Because I have to use separate caches for each collection with my idea. and I have update my caches whenever modifications are done for collections in server.
 
It seems like google authentication procedure is different when compared to other servers. It seems like google is supporting all the reports of RFC4791.
Could you tell me if you are able run gmail account successfully ??


Thanks in advance.
Regards 
Santosh Guptha Pulluri

n.deepak prasath

unread,
Apr 8, 2015, 3:22:18 AM4/8/15
to cald...@googlegroups.com

Hi Santosh,

Is your code working ? If yes, Can you share your code base ? Because I am trying to retrieve, create calendar events from my Yahoo mail. When googled about which API would come handy, I found this API. I am not able to retrieve the calendar information from the yahoo server using this API.

Thanks and Regards,
N Deepak Prasath
Reply all
Reply to author
Forward
0 new messages