TheProjecter / sardine

Automatically exported from code.google.com/p/sardine
0 stars 0 forks source link

createDirectory and getResources HTTP/1.1 415 Unsupported Media Type #37

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.sardine.createDirectory
("http://www.Verasonics.com/VerasonicsWebDav/TestFolder/");
2.sardine.getResources("http://www.Verasonics.com/VerasonicsWebDav/");

What is the expected output? What do you see instead?
Expect the directory to be created.  Instead get an exception.
Expect a directory listing to be returned.  Instead get an exception.

What version of the product are you using? On what operating system?
97, Windows XP SP 3, 32-bit, JRE 1.5 32-bit.

Please provide any additional information below.

Output with exception is listed below.  Looking around a bit in the Java 
debugger, I saw the "415" HTTP error message.

The server is Microsoft IIS.

Other Sardine commands work:
        // X getResources, HTTP/1.1 415 Unsupported Media Type
        // V getInputStream
        // V put, V put
        // V delete
        // X createDirectory, HTTP/1.1 415 Unsupported Media Type
        // X move fails to delete original
        // V copy
        // V exists

SoftwareReleaseTools version 1.3.119
Please provide logon creditials 
for "http://www.Verasonics.com/VerasonicsWebDav/".
Destination: "http://www.Verasonics.com/VerasonicsWebDav/TestFolder/"
Encoded: "http://www.Verasonics.com/VerasonicsWebDav/TestFolder/"
ERROR!  Exception when accessing WebDAV.  Details:  
com.googlecode.sardine.util.SardineException: The server has returned an 
HTTP error
com.googlecode.sardine.util.SardineException: The server has returned an 
HTTP error
    at com.googlecode.sardine.SardineImpl.createDirectory
(SardineImpl.java:334)
    at 
com.verasonics.softwarereleasetools.SoftwareReleaseTools.copyMexToWebDav
(SoftwareReleaseTools.java:1256)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at com.verasonics.softwarereleasetools.SoftwareReleaseTools.main
(SoftwareReleaseTools.java:165)

Original issue reported on code.google.com by BoydEdmo...@NebulaSoftware.com on 21 Mar 2010 at 9:43

GoogleCodeExporter commented 9 years ago
This bug is preventing me for being able to use Sardine.  Sardine is exactly 
what I 
need, so I am hoping this issue can be resolved quickly.  Thank you!

Original comment by BoydEdmo...@NebulaSoftware.com on 21 Mar 2010 at 9:44

GoogleCodeExporter commented 9 years ago
What server are you hitting? Is there any logs on the server end?

Original comment by latch...@gmail.com on 21 Mar 2010 at 11:17

GoogleCodeExporter commented 9 years ago
Microsoft IIS 6.0 on Windows Server 2003.  Logging is not enabled.

Original comment by BoydEdmo...@NebulaSoftware.com on 22 Mar 2010 at 12:04

GoogleCodeExporter commented 9 years ago
Well, I don't have that environment to test with so you are going to have to 
figure this one out for me. These 
things work fine with Apache httpd mod_dav. I suggest enabling logging. =)

Original comment by latch...@gmail.com on 22 Mar 2010 at 1:26

GoogleCodeExporter commented 9 years ago
Can you recommend how to debug it?  Does the following help?

The exception is thrown in this Sardine function:
    /*
     * (non-Javadoc)
     * @see com.googlecode.sardine.Sardine#createDirectory(java.lang.String)
     */
    public void createDirectory(String url) throws SardineException
    {
        HttpMkCol mkcol = new HttpMkCol(url);
        mkcol.setEntity(SardineUtil.createDirectoryEntity());

        HttpResponse response = this.executeWrapper(mkcol);

        StatusLine statusLine = response.getStatusLine();
        if (!SardineUtil.isGoodResponse(statusLine.getStatusCode()))
            throw new SardineException(url, statusLine.getStatusCode(), 
statusLine.getReasonPhrase());
    }

Here is the log file from my server with some good accesses for testing if the 
directory exists, then I deleted the directory (manually) and ran my program 
again 
to get the error when it tries to create the non-existing directory.

192.168.0.10, boydedmondson, 3/22/2010, 6:26:52, W3SVC437330871, 
NEBULASOFTWARE1, 
72.86.25.106, 93, 161, 188, 200, 0, HEAD, /VerasonicsWebDav/, -,
192.168.0.10, boydedmondson, 3/22/2010, 6:26:52, W3SVC437330871, 
NEBULASOFTWARE1, 
72.86.25.106, 187, 245, 187, 200, 0, 
HEAD, /VerasonicsWebDav/Developer/Software/Releases/External/Verasonics System 
Software/Release 4.3.0/, -,
192.168.0.10, boydedmondson, 3/22/2010, 6:27:46, W3SVC437330871, 
NEBULASOFTWARE1, 
72.86.25.106, 93, 161, 188, 200, 0, HEAD, /VerasonicsWebDav/, -,
192.168.0.10, boydedmondson, 3/22/2010, 6:27:46, W3SVC437330871, 
NEBULASOFTWARE1, 
72.86.25.106, 156, 245, 187, 200, 0, 
HEAD, /VerasonicsWebDav/Developer/Software/Releases/External/Verasonics System 
Software/Release 4.3.0/, -,
192.168.0.10, boydedmondson, 3/22/2010, 6:28:00, W3SVC437330871, 
NEBULASOFTWARE1, 
72.86.25.106, 31, 161, 188, 200, 0, HEAD, /VerasonicsWebDav/, -,
192.168.0.10, boydedmondson, 3/22/2010, 6:28:00, W3SVC437330871, 
NEBULASOFTWARE1, 
72.86.25.106, 62, 245, 0, 200, 64, 
HEAD, /VerasonicsWebDav/Developer/Software/Releases/External/Verasonics System 
Software/Release 4.3.0/, -,
192.168.0.10, -, 3/22/2010, 6:28:24, W3SVC437330871, NEBULASOFTWARE1, 
72.86.25.106, 
0, 891, 1902, 401, 2148074254, PROPFIND, /VerasonicsWebDav, -,
192.168.0.10, BoydEdmondson@NebulaSoftware.com, 3/22/2010, 6:28:26, 
W3SVC437330871, 
NEBULASOFTWARE1, 72.86.25.106, 328, 970, 19248, 207, 0, 
PROPFIND, /VerasonicsWebDav, -,
192.168.0.10, BoydEdmondson@NebulaSoftware.com, 3/22/2010, 6:28:27, 
W3SVC437330871, 
NEBULASOFTWARE1, 72.86.25.106, 0, 980, 4851, 207, 0, 
PROPFIND, /VerasonicsWebDav/Developer, -,
192.168.0.10, BoydEdmondson@NebulaSoftware.com, 3/22/2010, 6:28:27, 
W3SVC437330871, 
NEBULASOFTWARE1, 72.86.25.106, 0, 980, 4851, 207, 0, 
PROPFIND, /VerasonicsWebDav/Developer, -,
192.168.0.10, BoydEdmondson@NebulaSoftware.com, 3/22/2010, 6:28:27, 
W3SVC437330871, 
NEBULASOFTWARE1, 72.86.25.106, 0, 989, 6725, 207, 0, 
PROPFIND, /VerasonicsWebDav/Developer/Software, -,
192.168.0.10, BoydEdmondson@NebulaSoftware.com, 3/22/2010, 6:28:29, 
W3SVC437330871, 
NEBULASOFTWARE1, 72.86.25.106, 15, 998, 19850, 207, 0, 
PROPFIND, /VerasonicsWebDav/Developer/Software/Releases, -,
192.168.0.10, BoydEdmondson@NebulaSoftware.com, 3/22/2010, 6:28:31, 
W3SVC437330871, 
NEBULASOFTWARE1, 72.86.25.106, 0, 1007, 23651, 207, 0, 
PROPFIND, /VerasonicsWebDav/Developer/Software/Releases/External, -,
192.168.0.10, BoydEdmondson@NebulaSoftware.com, 3/22/2010, 6:28:33, 
W3SVC437330871, 
NEBULASOFTWARE1, 72.86.25.106, 78, 1038, 28495, 207, 0, 
PROPFIND, /VerasonicsWebDav/Developer/Software/Releases/External/Verasonics 
System 
Software, -,
192.168.0.10, BoydEdmondson@NebulaSoftware.com, 3/22/2010, 6:28:36, 
W3SVC437330871, 
NEBULASOFTWARE1, 72.86.25.106, 0, 1054, 3368, 207, 0, 
PROPFIND, /VerasonicsWebDav/Developer/Software/Releases/External/Verasonics 
System 
Software/Release 4.3.0, -,
192.168.0.10, BoydEdmondson@NebulaSoftware.com, 3/22/2010, 6:28:48, 
W3SVC437330871, 
NEBULASOFTWARE1, 72.86.25.106, 218, 548, 331, 200, 0, 
DELETE, /VerasonicsWebDav/Developer/Software/Releases/External/Verasonics 
System 
Software/Release 4.3.0, -,
192.168.0.10, boydedmondson, 3/22/2010, 6:29:01, W3SVC437330871, 
NEBULASOFTWARE1, 
72.86.25.106, 31, 161, 188, 200, 0, HEAD, /VerasonicsWebDav/, -,
192.168.0.10, boydedmondson, 3/22/2010, 6:29:01, W3SVC437330871, 
NEBULASOFTWARE1, 
72.86.25.106, 46, 245, 0, 404, 64, 
HEAD, /VerasonicsWebDav/Developer/Software/Releases/External/Verasonics System 
Software/Release 4.3.0/, -,
192.168.0.10, boydedmondson, 3/22/2010, 6:30:28, W3SVC437330871, 
NEBULASOFTWARE1, 
72.86.25.106, 31, 161, 188, 200, 0, HEAD, /VerasonicsWebDav/, -,
192.168.0.10, boydedmondson, 3/22/2010, 6:30:28, W3SVC437330871, 
NEBULASOFTWARE1, 
72.86.25.106, 31, 245, 195, 404, 2, 
HEAD, /VerasonicsWebDav/Developer/Software/Releases/External/Verasonics System 
Software/Release 4.3.0/, -,
192.168.0.10, boydedmondson, 3/22/2010, 6:30:28, W3SVC437330871, 
NEBULASOFTWARE1, 
72.86.25.106, 0, 484, 1611, 415, 0, 
MKCOL, /VerasonicsWebDav/Developer/Software/Releases/External/Verasonics System 
Software/Release 4.3.0/, -,

Original comment by BoydEdmo...@NebulaSoftware.com on 22 Mar 2010 at 1:35

GoogleCodeExporter commented 9 years ago
Well, that certainly isn't the same directory structure you gave me in the 
original report.

MKCOL, /VerasonicsWebDav/Developer/Software/Releases/External/Verasonics System 
Software/Release 4.3.0/, -,

I'm not sure if the log file url decodes the url, but are you passing in a 
properly encoded url? I'd expect to see 
something like this in the logs:

MKCOL, 
/VerasonicsWebDav/Developer/Software/Releases/External/Verasonics%20System 
Software/Release%204.3.0/, -,

Also, I need to see the server logs. You gave the access logs.

Original comment by latch...@gmail.com on 22 Mar 2010 at 3:20

GoogleCodeExporter commented 9 years ago
Different directory because it is a different test.

"http://www.Verasonics.com/VerasonicsWebDav/Developer/Software/Releases/External
/Vera
sonics%20System%20Software/Release%204.3.0/" is the String that is being passed 
to 
Sardine.createDirectory().

As soon as I can figure out how to get the "server logs" instead of the "access 
logs", I will post the results.

Original comment by BoydEdmo...@NebulaSoftware.com on 22 Mar 2010 at 3:28

GoogleCodeExporter commented 9 years ago
I think the IIS logs are both "server and access" logs.  I configured IIS to 
use "W3C Extended Log Format" instead and enabled as much logging output as was 
available.  Here is the log:

#Software: Microsoft Internet Information Services 6.0
#Version: 1.0
#Date: 2010-03-22 15:36:42
#Fields: date time s-sitename s-computername s-ip cs-method cs-uri-stem 
cs-uri-query 
s-port cs-username c-ip cs-version cs(User-Agent) cs(Cookie) cs(Referer) 
cs-host sc-
status sc-substatus sc-win32-status sc-bytes cs-bytes time-taken 
2010-03-22 15:36:42 W3SVC437330871 NEBULASOFTWARE1 72.86.25.106 
HEAD /VerasonicsWebDav/ - 80 boydedmondson 192.168.0.10 HTTP/1.1 Sardine/97 - - 
www.Verasonics.com 200 0 0 188 161 62
2010-03-22 15:36:42 W3SVC437330871 NEBULASOFTWARE1 72.86.25.106 
HEAD 
/VerasonicsWebDav/Developer/Software/Releases/External/Verasonics+System+Softwar
e/Release+4.3.0/ - 80 boydedmondson 192.168.0.10 HTTP/1.1 Sardine/97 - - 
www.Verasonics.com 404 0 2 195 245 15
2010-03-22 15:36:42 W3SVC437330871 NEBULASOFTWARE1 72.86.25.106 
MKCOL 
/VerasonicsWebDav/Developer/Software/Releases/External/Verasonics+System+Softwa
re/Release+4.3.0/ - 80 boydedmondson 192.168.0.10 HTTP/1.1 Sardine/97 - - 
www.Verasonics.com 415 0 0 1611 484 0

The first "HEAD" is in my "get access to the webdav and test that it is good" 
method, which seems to have succeeded.  The second "HEAD" is from the 
Sardine.getResources() call, which seems to have succeeded too.  It is the 
"MKCOL" 
from Sardine.getResources() that then fails.

My hunch is that Sardine.getResources() requests a MIME type that is not 
supported 
by the server.  If that makes sense, then perhaps you can tell me what MIME 
request 
Sardine.getResources() is using and I can add that to my IIS server.  Here are 
the 
current entries in my IIS server.

MIME Types:
Extention    Type
=================
.*           application/octect-stream
.htm         text/html
.html        text/html
.txt         text/plain

Original comment by BoydEdmo...@NebulaSoftware.com on 22 Mar 2010 at 3:45

GoogleCodeExporter commented 9 years ago
Sardine.getResources() should never be making a HEAD request. So, I have no 
idea what you are talking about 
with regards to your "second" HEAD request. Sardine.getResources() also doesn't 
do a MKCOL request.

Ok, I just did some googling around and found this page which implies that a 
content-type header needs to be 
set...

http://msdn.microsoft.com/en-us/library/aa142923(EXCHG.65).aspx

Try changing SardineUtil.HttpMkCol to look like this:

    public static class HttpMkCol extends HttpEntityEnclosingRequestBase
    {
        public HttpMkCol(String url)
        {
            super();
            this.setURI(URI.create(url));
            this.setHeader("Content-Type", "text/xml");
        }

        @Override
        public String getMethod()
        {
            return "MKCOL";
        }
    }

Original comment by latch...@gmail.com on 22 Mar 2010 at 4:00

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r99.

Original comment by latch...@gmail.com on 22 Mar 2010 at 4:05

GoogleCodeExporter commented 9 years ago
I rebuilt Sardine with the code alteration above, but my program still fails to 
create the directory.

I also tried adding ".xml  text/xml" to the supported MIME types for my IIS 
server.

I will now do some Google searching to see if I can find some IIS server side 
setting to allow the MKCOL request to succeed.

I have attached a screen snapshot that shows the debugger on the failure, in 
case it 
helps.

Original comment by BoydEdmo...@NebulaSoftware.com on 22 Mar 2010 at 4:53

Attachments:

GoogleCodeExporter commented 9 years ago
can you open up headercol to ensure that the content type is being set 
correctly?

Original comment by latch...@gmail.com on 22 Mar 2010 at 5:15

GoogleCodeExporter commented 9 years ago
Looks good to me ...

Original comment by BoydEdmo...@NebulaSoftware.com on 22 Mar 2010 at 5:22

Attachments:

GoogleCodeExporter commented 9 years ago
yea, then it must be some sort of configuration issue on your end, i'm not sure 
what else to change in sardine.

Original comment by latch...@gmail.com on 22 Mar 2010 at 5:33

GoogleCodeExporter commented 9 years ago
https://mozillalabs.com/forum/comments.php?DiscussionID=884 

The above link shows someone who had a similar problem with IIS and was able to 
correct it by removing "Content-Type: text/plain" from the request header.

I am trying to test this now, but I haven't been able to figure out yet where 
to 
make the change to do that.

Original comment by BoydEdmo...@NebulaSoftware.com on 22 Mar 2010 at 6:32

GoogleCodeExporter commented 9 years ago
Sardine Release 99 still fails.  Can you suggest how I might debug this problem?

Original comment by BoydEdmo...@NebulaSoftware.com on 23 Mar 2010 at 7:04

GoogleCodeExporter commented 9 years ago
the slide or jackrabbit webdav client. if those work then look at what is being 
sent over the wire and see how that 
is different from sardine.

the webdav protocol is pretty simple... the issue is that each server 
implements things a bit differently.

Original comment by latch...@gmail.com on 23 Mar 2010 at 7:12

GoogleCodeExporter commented 9 years ago
I find this issue should be reopened.
I have the same problem: Using WinXP to create the directory succeeds on the 
Alfresco
(Tomcat-based) WebDAV server, but with Sardine it fails (415 in Alfresco logs).

So Sardine should do some "magic" to make it work behind the scenes I guess. :-)
Sad I now have to look for another WebDAV client :-(

Original comment by and.diet...@gmail.com on 24 Mar 2010 at 3:21

GoogleCodeExporter commented 9 years ago
I am sorry that it is failing and that you have to look into a solution and 
possibly 
a new WebDAV client.

I am happy that I am no longer having to look at it on my own though.  =)

I will be in meetings most of today, but I hope to look at this failure again 
soon 
thereafter.

Original comment by BoydEdmo...@NebulaSoftware.com on 24 Mar 2010 at 3:24

GoogleCodeExporter commented 9 years ago
@and.dietrich: what version of sardine are you using? have you tried the trunk 
version? is there anything in the 
alfresco error logs?

I'd like to get this figured out, but you guys aren't doing much to help. I'm 
sorry Boyd, I don't have access to 
windows.

Original comment by latch...@gmail.com on 24 Mar 2010 at 3:31

GoogleCodeExporter commented 9 years ago
I am trying to help, but I am not an expert at WebDAV or the HTTP server 
protocols 
or the debug tools, so I am having to learn a lot as I go.

For example, I am not sure how "look at what is being sent over the wire" as 
you 
suggest in comment 17.

Original comment by BoydEdmo...@NebulaSoftware.com on 24 Mar 2010 at 3:37

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
ok, but I guess it won't help much since the logs are not detailled enough...

here are the Alfresco logs for the Sardine createDirectory() call:

15:48:05,824 DEBUG [org.alfresco.webdav.protocol] WebDAV request MKCOL on path
/alfresco/webdav/Sites/dba/documentLibrary/RDBA/mkdir-sardine
15:48:05,831 DEBUG [org.alfresco.webdav.protocol] MKCOL is returning status 
code: 415

and here is the Alfresco output doing it from WinXP (creating "mkdir-win" dir):

15:52:25,807 DEBUG [org.alfresco.webdav.protocol] WebDAV request MKCOL on path
/alfresco/webdav/Sites/dba/documentLibrary/RDBA/Neuer%20Ordner
15:52:25,907 DEBUG [org.alfresco.webdav.protocol] MKCOL took 100ms to execute
15:52:25,928 DEBUG [org.alfresco.webdav.protocol] WebDAV request PROPFIND on 
path
/alfresco/webdav/Sites/dba/documentLibrary/RDBA/Neuer%20Ordner
15:52:25,938 DEBUG [org.alfresco.webdav.protocol] PROPFIND took 10ms to execute
15:52:38,066 DEBUG [org.alfresco.webdav.protocol] WebDAV request PROPFIND on 
path
/alfresco/webdav/Sites/dba/documentLibrary/RDBA
15:52:38,075 DEBUG [org.alfresco.webdav.protocol] PROPFIND took 9ms to execute
15:52:38,089 DEBUG [org.alfresco.webdav.protocol] WebDAV request MOVE on path
/alfresco/webdav/Sites/dba/documentLibrary/RDBA/Neuer%20Ordner
15:52:38,090 DEBUG [org.alfresco.webdav.protocol] Parsing Destination header:
http://<server>:8080/alfresco/webdav/Sites/dba/documentLibrary/RDBA/mkdir-win
15:52:38,092 DEBUG [org.alfresco.webdav.protocol] Copy from
/Sites/dba/documentLibrary/RDBA/Neuer Ordner to 
/Sites/dba/documentLibrary/RDBA/mkdir-win
15:52:38,235 DEBUG [org.alfresco.webdav.protocol] MOVE took 146ms to execute

Original comment by and.diet...@gmail.com on 24 Mar 2010 at 4:06

GoogleCodeExporter commented 9 years ago
btw: I get the same 415 error using Jakarta Slide :-(

Original comment by and.diet...@gmail.com on 24 Mar 2010 at 4:49

GoogleCodeExporter commented 9 years ago
@and: please answer my question above (have you tried trunk). also, you say you 
get the same error using 
slide... could you please be a bit more clear? is that the slide client or the 
slide server?

@Boyd: unless you tell me that you don't understand something, then there isn't 
much i can do to help you. what 
i mean by "over the wire" is to use a tool to let you see the http level 
communication between the client and the 
server. google for "http sniffer"

Original comment by latch...@gmail.com on 24 Mar 2010 at 9:24

GoogleCodeExporter commented 9 years ago
I used the latest Slide client v2.1 (jakarta-slide-webdavlib-2.1.jar;
commons-httpclient-3.1.jar; jdom-1.0.jar)

Using the latest Sardine trunk rev102 resulted in the same error :-(
I don't have (or get - depending on how you want to see it :-) ) the time right 
now
to capture more infos (http traffic, log details...).

Original comment by and.diet...@gmail.com on 25 Mar 2010 at 9:26

GoogleCodeExporter commented 9 years ago
... and we have Alfresco 3.2 running under Linux (RedHat 5)

Original comment by and.diet...@gmail.com on 25 Mar 2010 at 9:53

GoogleCodeExporter commented 9 years ago
... as well as the Sardine-using app running on a WebLogic 10.3.2 under Linux 
(RedHat 5)

Original comment by and.diet...@gmail.com on 25 Mar 2010 at 9:54

GoogleCodeExporter commented 9 years ago
Well, if both sardine and the slide client have the same error, then it 
probably isn't a client issue.

Original comment by latch...@gmail.com on 25 Mar 2010 at 2:45

GoogleCodeExporter commented 9 years ago
Strange logic ... WinXP succeeds => so it must be a client (or 
environment/dependent
libs) issue in both Sardine and Slide.

Original comment by and.diet...@gmail.com on 25 Mar 2010 at 2:50

GoogleCodeExporter commented 9 years ago
well, capture the http traffic that winxp sends and compare it with the traffic 
that sardine sends and it will be 
clear really quick what the issue is. one question, do you have authentication 
on? what form of auth are you 
using? if you are using digest auth, then try with only basic auth.

Original comment by latch...@gmail.com on 25 Mar 2010 at 2:56

GoogleCodeExporter commented 9 years ago
Same problem here. See issue 35
(http://code.google.com/p/sardine/issues/detail?id=35&can=1).  Server is 
"catacomb".
(http://webdav.org/catacomb/)

Directory creation works perfect with webdavclient4j, but fails with SARDINE. 
So its
surely a client issue. 

Original comment by mail1....@online.de on 25 Mar 2010 at 3:21

GoogleCodeExporter commented 9 years ago
I don't know how to scream this any louder... YOU GUYS NEED TO WATCH WHAT IS 
GOING OVER THE WIRE AND 
TELL ME WHAT IS GOING ON.

Original comment by latch...@gmail.com on 25 Mar 2010 at 3:32

GoogleCodeExporter commented 9 years ago
I will definitely do that, latchkey, as soon as I can.  (I have a few high 
priority 
items for customers that I must do first.)

Original comment by BoydEdmo...@NebulaSoftware.com on 25 Mar 2010 at 3:40

GoogleCodeExporter commented 9 years ago
ok, i just tested put and fixed and tested an issue with mkcol 
(createDirectory)... whomever gave me that code 
didn't know what they are doing. grrr..

Original comment by latch...@gmail.com on 25 Mar 2010 at 4:01

GoogleCodeExporter commented 9 years ago
Confirmed that sardine.createDirectory() and sardine.getResources() now work 
for me 
with the 103 Sardine source release.  (Thank you!)

I do see an issue with the results from sardine.getResources(), but I will open 
that 
as a new issue.

Original comment by BoydEdmo...@NebulaSoftware.com on 25 Mar 2010 at 4:37

GoogleCodeExporter commented 9 years ago
103 works for me with Alfresco as well! great job guys!

Original comment by and.diet...@gmail.com on 26 Mar 2010 at 8:47

GoogleCodeExporter commented 9 years ago

Original comment by latch...@gmail.com on 6 Apr 2010 at 10:37

GoogleCodeExporter commented 9 years ago
I used Wireshark to figure out that IIS6 does not like headers. I only needed 
to create directories and put a file, so I created this wrapper.

import com.googlecode.sardine.DavResource;
import com.googlecode.sardine.Sardine;
import com.googlecode.sardine.impl.SardineImpl;
import com.googlecode.sardine.impl.handler.VoidResponseHandler;
import com.googlecode.sardine.impl.methods.HttpMkCol;
import org.apache.http.HttpStatus;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.HttpResponseException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.params.AuthPolicy;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.AbstractHttpClient;
import org.apache.http.impl.client.DefaultRedirectStrategy;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;

import javax.xml.namespace.QName;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.List;
import java.util.Map;

public class SardineIIS6Wrapper implements Sardine {
    final SardineImpl sardine;
    /**
     * Local context with authentication cache. Make sure the same context is used to execute
     * logically related requests.
     */
    final private HttpContext context = new BasicHttpContext();

    final AbstractHttpClient client;

    SardineIIS6Wrapper(final AbstractHttpClient client, final String username, final String password) {
        client.getCredentialsProvider().setCredentials(
                new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthPolicy.BASIC),
                new UsernamePasswordCredentials(username, password));

        sardine = new SardineImpl(client, null, null);
        this.client = client;
    }

    @Override
    public void setCredentials(final String username, final String password) {
        sardine.setCredentials(username, password);
    }

    @Override
    public void setCredentials(final String username, final String password, final String domain, final String workstation) {
        sardine.setCredentials(username, password, domain, workstation);
    }

    @Override
    public List<DavResource> getResources(final String url) throws IOException {
        return sardine.getResources(url);
    }

    @Override
    public List<DavResource> list(final String url) throws IOException {
        return sardine.list(url);
    }

    @Override
    public List<DavResource> list(final String url, final int depth) throws IOException {
        return sardine.list(url, depth);
    }

    @Override
    public void setCustomProps(final String url, final Map<String, String> addProps, final List<String> removeProps) throws IOException {
        sardine.setCustomProps(url, addProps, removeProps);
    }

    @Override
    public List<DavResource> patch(final String url, final Map<QName, String> addProps) throws IOException {
        return sardine.patch(url, addProps);
    }

    @Override
    public List<DavResource> patch(final String url, final Map<QName, String> addProps, final List<QName> removeProps) throws IOException {
        return sardine.patch(url, addProps, removeProps);
    }

    @Override
    public InputStream get(final String url) throws IOException {
        return sardine.get(url);
    }

    @Override
    public InputStream get(final String url, final Map<String, String> headers) throws IOException {
        return sardine.get(url, headers);
    }

    @Override
    public void put(final String url, final byte[] data) throws IOException {
        sardine.put(url, data);
    }

    /**
     * put without headers. IIS6 does not like them
     * @param url
     * @param dataStream
     * @throws IOException
     */
    @Override
    public void put(final String url, final InputStream dataStream) throws IOException {
        // A length of -1 means "go until end of stream"
        final InputStreamEntity entity = new InputStreamEntity(dataStream, -1);
        final HttpPut put = new HttpPut(url);
        put.setEntity(entity);
        try {
            this.execute(put, new VoidResponseHandler());
        }
        catch (HttpResponseException e) {
            if (e.getStatusCode() == HttpStatus.SC_EXPECTATION_FAILED) {
                // Retry with the Expect header removed
                put.removeHeaders(HTTP.EXPECT_DIRECTIVE);
                if (entity.isRepeatable()) {
                    this.execute(put, new VoidResponseHandler());
                    return;
                }
            }
            throw e;
        }
    }

    @Override
    public void put(final String url, final byte[] data, final String contentType) throws IOException {
        sardine.put(url, data, contentType);
    }

    @Override
    public void put(final String url, final InputStream dataStream, final String contentType) throws IOException {
        sardine.put(url, dataStream, contentType);
    }

    @Override
    public void put(final String url, final InputStream dataStream, final String contentType, final boolean expectContinue) throws IOException {
        sardine.put(url, dataStream, contentType, expectContinue);
    }

    @Override
    public void put(final String url, final InputStream dataStream, final Map<String, String> headers) throws IOException {
        sardine.put(url, dataStream, headers);
    }

    @Override
    public void delete(final String url) throws IOException {
        sardine.delete(url);
    }

    @Override
    public void createDirectory(final String url) throws IOException {
        final HttpMkColNoHeader mkcol = new HttpMkColNoHeader(url);
        execute(mkcol, new VoidResponseHandler());
    }

    protected <T> T execute(HttpRequestBase request, ResponseHandler<T> responseHandler)
            throws IOException {
        try {
            // Clear circular redirect cache
            this.context.removeAttribute(DefaultRedirectStrategy.REDIRECT_LOCATIONS);
            // Execute with response handler
            return this.client.execute(request, responseHandler, this.context);
        }
        catch (IOException e) {
            request.abort();
            throw e;
        }
    }

    @Override
    public void move(final String sourceUrl, final String destinationUrl) throws IOException {
        sardine.move(sourceUrl, destinationUrl);
    }

    @Override
    public void copy(final String sourceUrl, final String destinationUrl) throws IOException {
        sardine.copy(sourceUrl, destinationUrl);
    }

    @Override
    public boolean exists(final String url) throws IOException {
        return sardine.exists(url);
    }

    @Override
    public String lock(final String url) throws IOException {
        return sardine.lock(url);
    }

    @Override
    public void unlock(final String url, final String token) throws IOException {
        sardine.unlock(url, token);
    }

    @Override
    public void enableCompression() {
    }

    @Override
    public void disableCompression() {
    }

    @Override
    public void enablePreemptiveAuthentication(final String hostname) {
    }

    @Override
    public void disablePreemptiveAuthentication() {
    }

    /**
     * webdav mkcol class for IIS6 - it just has the URI and no header
     */
    public class HttpMkColNoHeader extends HttpEntityEnclosingRequestBase {

        public HttpMkColNoHeader(String url) {
            this(URI.create(url));
        }

        public HttpMkColNoHeader(URI url) {
            this.setURI(url);
            // do not set the header - IIS6 does not like it
        }

        @Override
        public String getMethod() {
            return HttpMkCol.METHOD_NAME;
        }
    }

}

Original comment by Michael....@gmail.com on 26 Mar 2013 at 2:40