Tuesday, May 10, 2011

Using JackRabbit as a WebDAV client for Android

I have been looking for a WebDAV client to work on Android. Some of the WebDAV clients that are available are Jakarata Slide (which is now retired), JackRabbit (Apache open source) and Sardine (from Google code). I zeroed in on JackRabbit2.2.5 as Sardine was not working and did not want to spend time on debugging. But then JackRabbit did not work as well on Android. My first mistake was to download the jackrabbit-standalone.jar from the net, and trying to make it work. This was a 30+ MB file and hence not suitable for Android platform. Then I tried debugging the jackrabbit-webdav code. It internally uses some of the packages which Android does not support. After making all the "Android-happy" changes in the code, I built the jackrabbit-webdav-2.2.5.jar again using their pom.xml(maven). The files size was around 288 KB. I believe this can be optimized further, even though I did not spend much time in doing so later. :)
Here is a code snippet to upload a file to the WebDAV server using the  jar:

 File file = new File(filePath);
/*PutMethod is a class in the jackrabbit-webdav for uploading files in the server*/
        PutMethod putMethod = new PutMethod(baseURI+ uploadPath+file.getName());
        
RequestEntity requestEntity = new InputStreamRequestEntity(new FileInputStream(file));
        
putMethod.setRequestEntity(requestEntity);
//HttpClient httpClient  
httpClient.executeMethod(putMethod);

Same way, the MoveMethod, CopyMethod, DeleteMethod, MkColMethod (create), PropFindMethod (list the directory contents) can be used.
You can download the jar file ! :).


Edited:
The above file do not contain the org.apache.commons.httpclient. You may want to dowload the same from the apache site and add to your project class path  OR .....


As one of the readers had requested to provide a jar file which includes the "org.apache.commons.httpclient", I have rebuilt my library to accommodate this change. This library is heavier than the previous one.


Previously the commons-httpclient version 3.0 was used in my jackrabbit jar. As one of the readers of this post has pointed out, FileRequestEntity (for content chunking) was not being supported, I rebuilt my jar to include the same. This includes commons-httpclient version 3.1.

So those of you who would like to use FileRequestEntity API for larger file upload, you can download the latest version of my jar. Here you go:  jackrabbit-webdav-2.2.6-jar-with-dependencies.jar (size:  919 KB)

The older version (without FileRequestEntity) i.e. 2.2.5-jar, support only InputStreamRequestEntity and not FileRequestEntity. So those of you who would upload file of smaller size around 2 KB, can use the older version of my library:  jackrabbit-webdav-2.2.5-jar-with-dependencies (size 892 KB).

I would appreciate your feedback or acknowledgement in the form of comments or a g+ rating if my library has helped you. Thanks. :)

54 comments:

  1. Would you consider posting the .jar file you rebuilt?

    ReplyDelete
  2. Hi Kathie. I am updating the post with the link where I have shared the file. You can download the file from there.

    ReplyDelete
  3. Hello, could you publish a patch set?

    ReplyDelete
  4. Tried using your provided jar but i got an error which is preventing me from building an example. The compiler complains against a reference to org.apache.commons.httpclient.methods.EntityEnclosing in the jar.

    ReplyDelete
  5. Daniel,
    I had deliberately not included the dependencies for org.apache.commons. The idea was to create the library for webdav only and not include the http libraries. I think you should be able to include the apache-commons jar yourself in your android project. But since you have asked for it, I would provide the link for the jar file which has the apache commons library included. Pls. refer to my edited post to download the new jar. Happy coding. :)

    ReplyDelete
  6. Hello, I'm using your "jackrabbit-webdav-2.2.5-jar-with-dependencies.jar" for develop Webdav client app on Android 2.1, but it seem not worked.
    I follow instruction from this link "http://wiki.apache.org/jackrabbit/WebDAV" and use "http://demo.sabredav.org" for testing server and the result was was IOExcetion: "demo.sabredav.org". This sample is success on PC using "jackrabbit-standalone-2.2.7.jar". Please help me.

    ReplyDelete
  7. Hi Nguyen,

    Please try the other jar, i.e. jackrabbit-webdav-2.2.5.jar instead of the one without dependencies. You need to use the the appropriate httpclient with that. Unless I see the complete stack trace, it is difficult for me to point out the problem. Right now I am little busy and so unable to set up a project to test your url. We have been using the thin jar in our org without any issues so far. If time permits I will write a test code to test your url and share the code with you. Till then, pls. try to debug the issue.

    ReplyDelete
  8. Hi Nguygen,

    The jar works just fine. I have created a folder called "ashimita" in your site, from an android app. Checkout this link: http://demo.sabredav.org/public (I have used the userId and pwd that you had provided). My android app was able to download the file called test.txt that you have in your public folder. So things just work fine. :)
    I can mail you the sample code if you let me know your email id. Send me a personal email(with your email id) like you did earlier to let me know the username and pwd.
    Btw, I had used the jackrabbit-webdav-2.2.5-jar-with-dependencies.jar. Both the jars work fine. :)

    ReplyDelete
  9. Hi Ashimita,
    I'm very glad to read your comment, I had a busy week. Would you please send me the source code.
    My email address is: chusinguyen108@gmail.com
    Thanks again, you helped me a lot!

    ReplyDelete
  10. Yes, at last I can run your library successful.
    Everything is OK, except my silly mistake in manifest file.
    Thank you so much. You save my time a lot.
    Hope to have change to work with you.

    ReplyDelete
  11. Could you please provide diff or patches? Nobody can reproduce what to do and maintain if a new jackrabbit version is released. Thx

    ReplyDelete
  12. Thanks a lot for this jar it works perfect!!!!

    Best regards
    Christos

    ReplyDelete
  13. Hi Ashmitha,

    I have a built a simple java application which communicates to Webdav server and it is working fine. But, when I tried to port the same application in Android, I am facing the below issue

    ERROR/AndroidRuntime(244): java.lang.VerifyError: org.apache.jackrabbit.webdav.client.methods.XmlRequestEntity

    Can you please suggest me a solution for this? Will it work for all the versions of Android? I have verified it in 1.6 & 2.1 OS.

    Thanks in Advance
    Yadhu

    ReplyDelete
  14. No, it does not work for version lower than 8 and unfortunately I am not able to devote time to find a work around for the same. I will try to get a fix if possible.

    ReplyDelete
  15. Hi,

    how do you set up your HttpClient for SSL?
    In my case, PropFindMethod hangs if the Webdav server's url points to https://.

    PutMethod works, even with https.

    Thanks in advance,
    Bernd

    ReplyDelete
    Replies
    1. Hi Bernd,

      Unfortunately Propfind does not work with HTTPS and this is not related to the Jackrabbit as such. Any other client might work (not sure though) but they do not have support for android.
      You can refer to this link which talks about this issue:

      http://community.webfaction.com/questions/2414/webdav-method-not-allowed-for-propfind-with-https

      Delete
  16. Hi Ashimita,
    I forgot to thank you for jackrabbit-webdav-2.2.5-jar-with-dependencies.jar. It works now, except for PropFindMethod. I hope I'll find a workaround.

    Now I have another question: I need a simple way to read a remote WebDAV file. I could CopyMethod to get a temporary copy and read that copy. A simpler way would be to obtain an InputStream directly.
    Unfortunately, org.apache.jackrabbit.webdav.client.methods is not documented.
    Thanks in advance
    Bernd

    ReplyDelete
  17. Hi Ashimita,

    I found the solution for a "Webdav" get method by myself:
    As this is not a specific Webdav functionaliity, the solution is
    org.apache.commons.httpclient.methods.GetMethod.

    Regards,
    Bernd

    ReplyDelete
    Replies
    1. That's great, Bernd. Thanks for letting everybody know about your finding. Hope this will help many others. :)

      Delete
  18. Hi Ashimita,

    How to authenticate the server and executing a copy method , can u please provide the complete flow.

    regards
    Girish

    ReplyDelete
  19. Hi Ashimita,

    I'm looking for JackRabbit to build a android webdav project. But I have no idea about using jackrabbit-webdav-2.2.5-jar-with-dependencies.jar in my code. I have searched hard for android webdav code for a long time. Can you release a simple demo version to use or mail me the code.

    ReplyDelete
    Replies
    1. Hi Adam,

      Could you please let me know your email Id so that I can mail you a sample code for you to play around?

      Thanks,
      Ashimita

      Delete
    2. Hi Ashimita,

      I've been trying to get a simple example with your library that will give me a file listing from a server on an Android device, but have had no luck. Do you have any example code that might do something like that (or maybe just initialize everything correctly for me to work with)? my e-mail address is edgar.i.vasquez@gmail.com.

      Thanks for your help,
      Edgar

      Delete
    3. I have sent you a sample code to your email id. Hope it helps. :)

      Ashimita

      Delete
  20. Hi Ashimita,

    I'm looking for a way to implement a WebDav client into my android App. This seems to be the best (only ?) solution.
    Can you post some sample code ?
    (upload / download / reading file properties (file date) ).

    Thanks

    ReplyDelete
  21. Hi Ashimita,
    I'm very glad to read your comment. Would you please send me the source code.
    My email address is: androidworkman@gmail.com
    Thanks again, you really helped me a lot!

    ReplyDelete
  22. I'm also trying to get a webDav android project off the ground with little experience with Http clients. Could you possibly supply me with some sample code as well. My email is jdub1187@gmail.com.

    ReplyDelete
    Replies
    1. I have sent you a sample application for your reference. Happy coding. :)

      Delete
  23. Hi Ashimita,

    Please could you send me the jar and sample application as I am also looking to write a webdav app. My email is shane@complexit.co.za.

    ReplyDelete
  24. Dear Ashimita

    After a long week search, I found that you just had a good job on webdav over android. Unfortunately, the jar download link is broken. Could you also send the jar and a sample application for my reference ? And my email is accordit@hotmail.com. Thanks for your efforts.

    ReplyDelete
    Replies
    1. Thanks for your kind words. I have shared the code through your personal gmail id. Hope that helps.

      Delete
  25. Hi Ashimita!
    Thanks for your contribution on android.
    My problem:
    When I use InputStreamRequestEntity to upload small file(about 2MB) to server, it's ok. Failed for large file(6 MB), there is an exception of out of memory.

    I found some comments about FileRequestEntity, which could be used to resolve this exception of out of memory on android. So I wanna try it, but have no found it in jar.

    Is there an optional resolution for FileRequestEntity.

    Thanks!

    ReplyDelete
  26. Hi,

    Thanks for the heads up! :)

    Yes, my library did not support FileRequestEntity earlier since it used commons-httpclient 3.0. I was also aware of the out of memory issue for relatively larger file upload as the commons-httpclient did not support content chunking.

    Now that you have pointed out about FileRequestEntity, I have included the version 3.1 of httpclient in my build. Please refer to my updated post.

    You can also use my jar without the dependency and include commons-httpclient 3.1 manually in the classpath of your project. But most of the readers prefer to use the one with dependency, I guess.

    Thanks once again. :)

    ReplyDelete
    Replies
    1. Hi Ashimita!
      Thanks for your 2.2.6 version.
      I added the jar to my project, but the jar could not be parsed correctly in eclipse. Did you test it by yourself?
      Thanks!

      Delete
    2. Hi Yongl,

      When you say, the jar could not be parsed in eclipse, did you mean, you got compilation errors? As far eclipse is concerned, I did not see any problem with this jar.
      Can you give the stack trace of the error or let me know more details of what eclipse is showing as an error msg?
      Did you cross-check the application class path?

      Thanks,
      Ashimita

      Delete
    3. Thanks Yongl for the heads up!

      The jar got corrupted while uploading. I have re-uploaded the jar. Hope it helps. :)

      Delete
  27. Hi Ashimita,

    I am currently developing the webdave app, can you please send me the jar and sample application? My email is wendy_ttw@yahoo.com

    Thanks a lot...

    ReplyDelete
  28. Hi Ashmita,

    I am currently working on a webdav client to upload a file.
    Could you please send me the jar and sample application

    My email is roopa_pd@yahoo.com

    Thanks

    ReplyDelete
  29. Hi, great work! I was trying to download the jar you created but the download needs to be approved by you. So could you approve my request with t h e m u z z 2 3 6 at g m a i l dot c o m ?

    Thanks!

    ReplyDelete
  30. Hello! Thats realy cool, a got a big problem to lunch webdav on android, could you please approve my request pmascdna@gmail.com

    ReplyDelete
  31. hi please can you send me the jar / code to my email sudhasetty9@gmail.com I am stuck thankyou in advance

    ReplyDelete
  32. Hello! Could you please send me a sample code (or better yet, update your post with it, since you seems to have a lot of request like this one)? I'm getting a VerifyError due to one of the lib, so I'm probably no using the right sample code.

    ReplyDelete
    Replies
    1. Which version of Android are you using? The lib does not work for version older than Gingerbread and may result in Verify error.
      As regards, posting a sample code, I have not touched it for a long time now, and needs some tweaking to suit your needs. I haven't considered supporting it through public forum. Will share it if you need. Pls. share your gmail id.

      Delete
    2. It turned out I was adding the lib the wrong way (with Eclipse instead of putting it in a libs folder and letting Ant do it). It seems to work great now. Thanks for the message though !

      Delete
    3. Thanks for letting me know. Glad to know that worked for you. Happy coding. :)

      Delete
  33. Hi Ashimita,

    Please could you send me the jar and sample application as I am also looking to write a webdav app. My email is wubing111@yahoo.co.jp

    ReplyDelete
    Replies
    1. The jar is free to download and the link is given in my post. If you share your gmail id, I can share the sample code kept in my google docs.

      Delete
  34. Hi, Ashimita
    Thanks for ur library of Webdav, but I have a problem with HttpClient Authentication. I just have referenced this website http://wiki.apache.org/jackrabbit/WebDAV for implementing the connection between Android as client and Webdav server, but it was failed. The client has got no response!
    Could u give me some suggestions or give me a sample code to my gmail: bennychou7573@gmail.com? I appreciated a lot.

    ReplyDelete
  35. Hi~ Ashimita
    Have nice day~
    Can you send me the same code to implement my android APP.
    Thank you very much~
    My mail is sonnyshih@gmail.com

    sonny

    ReplyDelete
  36. Dear Ashimita
    I have searched the library to implement webdav client on Android for a few days. The library you supply seems to be the best solution.
    Could you please supply me some sample code to let me realize the operation process quickly.
    My e-mail is a77030124@gmail.com
    Thank you so much.

    ReplyDelete
  37. Hi Ashimita,
    I posted here before but I don't think it has been saved so I'm posting again.
    I'm trying to use jackrabbit in android but I'm having a lot of problems and I hope that your library can help me
    So please I need some sample code to see and implement in my app.
    My e-mail is miguelangeltjr @ gmail.com (without spaces of course)
    Thank you in advance.

    ReplyDelete
  38. Hello Ashimita.
    My name is Tanaka(Tokyo-Japan).

    I'm having problems.
    I decided to create a CardDAV in andriod
    A result of the investigation, it was thought to be created by remodeling the WebDAV (jackRabbit).
    But jackRabbit did not correspond to Android.
    ※ I've noticed in the build.

    If possible, would you provide a WebDAV(jackRabbit) code that created you?
    Email:thee.red555@gmail.com

    Thanks in advance.

    ReplyDelete