Subject: WebDAV enabled applet example

From: Jim Whitehead <[email-masked]>
Date: Mon, 14 Aug 2000 16:46:55 -0700

I am attempting to develop a Java Applet with simple Webdav functionality -
I currently have an Applet that reads an XML file from a web server and I
would like to adapt it so that it reads the file from a Webdav server and
can perform updates ie
a) locks the file
b) deletes/replaces the file
c) unlocks the file

As it is a fairly simple Applet I didn't want to use the IBM DAV4J
libraries.
I am testing against mydocsonline and having trouble getting the Applet
working-even with a PROPFIND command - not sure if it is a problem with the
way Webdav works with mydocsonline or whether it is a fundamental mistake
in the way I'm going about things.

The return code I get is error 401, even when I put in Basic authentication
command - I have tried hardcoding the username/password.

(As a second issue - when I access the webfolders HTML page referencing the
applet, IE  prompts for username and password - is there any way of picking
up the username and password values that have been entered in IE and passing
them through to my PROPFIND command ?)

Apologies if these are 'rookie' questions, but I'd appreciate any
assistance - as there are few simple examples of Java code and Webdav, I'd
be
happy to share source sample code once I have a working version.

See below for code explanation...

Regards,

JC Samson

I'm using the URL class i.e.

       URL url=new URL("http://webfolders.mydocsonline.com/rfc 2518.htm");
        int port=url.getPort
        if (port==-1)port=80;// if no port use the default
        String host=url.getHost
        Socket socket = new Socket(host,port);
        InputStream from_server=socket.getInputStream();
        PrintWriter to_server=
          new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));

The code to create the PROPFIND looks like this :

         String userpass="";

{ 
               userpass=base64EncodeString("username:password"); 
       
             } catch(UnsupportedEncodingEx
ception

          to_server.println("PROPFIND " + filename + " HTTP/1.0\r\n\r\n");
          to_server.println("Host:" +  host);
          to_server.println("Content-Type: text/xml");
          to_server.println("Authorization: Basic " + userpass + " ");
           query="<?xml version=\"1.0\" encoding=\"utf-8\"?>"+
            "<D:propfind xmlns:D=\"DAV:\">"+
            "<D:allprop/></D:propfind>";
          to_server.println("Content-Length: "+ query.length());
          to_server.println(query);
          to_server.flush();

---

From: Jim Whitehead <[email-masked]>
Date: Mon, 14 Aug 2000 16:56:36 -0700

Oops -- looks like this message was accidentally attributed to me when I
re-sent it to the list after it was caught by the spam filter.  It was
originally sent by JC Sampson <[email-masked]>. I've added this email
address to the accept2 list, so future emails will go through to the list.

>           to_server.println("PROPFIND " + filename + " HTTP/1.0\r\n\r\n");

This looks like it would send too many CRLF's -- I think you should omit the
\r\n\r\n at the end of the line, since the CRLF added by println should be
sufficient.  Also, you should be sending HTTP/1.1, not HTTP/1.0.

>           to_server.println(query);

Perhaps it also expects a User-Agent header as well.  Do you get the same
behavior interacting against Sharemation <http://www.sharemation.com/>?

- Jim