You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-user@jakarta.apache.org by Garret Wilson <ga...@globalmentor.com> on 2004/12/13 02:13:05 UTC

WebdavResouce, putMethod(), and existence

I started using Slide just days ago, and immediately ran into the 
WebdavResource weirdness for non-existent files: constructing a 
WebdavResource for a file that doesn't exist throws an HttpException 
with status code 404.

After searching the archives, I found a workaround of new 
WebdavResouce(httpURL, WebdavResource.NOACTION, 0), which disables PROPFIND:

http://nagoya.apache.org/eyebrowse/ReadMsg?listName=slide-user@jakarta.apache.org&msgId=2039251

Now I can use putMethod() to upload a file whether or not the file 
already exists. But how do I check to see that it already exists? After 
using the above constructor, WebdavResource.exists() always returns 
false---even if I've just uploaded a file to the same URL! Apparently 
disabling PROPFIND keeps WebdavResource from knowing anything about the 
file on the server.

So how can I see if a file exists? I'm guessing the following would work:

WebdavResource webdavresource;
try
{
   webdavresource=new WebdavResource(httpURL);
   webdavresource.setExistence(true);
}
catch(HttpException e)
{
   if(e.getReasonCode()==404)
   {
     webdavresource=new WebdavResource(httpURL, WebdavResource.NOACTION, 0);
     webresource.setExistence(false);
   }
   else
   {
     throw e;
   }
}

If this is the way things are supposed to be done, I'll have to say this 
isn't the best example of API elegance I've seen. :| I'm hoping I'm 
missing something.

How should I be using WebdavResource?

Thanks,

Garret

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org


Re: WebdavResouce, putMethod(), and existence

Posted by Garret Wilson <ga...@globalmentor.com>.
Garret Wilson wrote:
> Because I can't depend on WebdavResource.exists(), I have to call 
> WebdavResource.headMethod(). The API says that this returns a boolean to 
> indicate whether the method succeeded, but what *really* happens is that 
> it either succeeds or throws an exception if the file doesn't exist. Why 
> have a boolean return value if you're going to throw an exception for 
> failure?

Sorry, my mistake---if the file doesn't exist, 
WebdavResource.headMethod(String path) returns false instead of throwing 
an exception. Of course, this is inconsistent with the construction of 
WebdavResource, which throws an exception if the resource doesn't exist.

Garret


---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org


Re: WebdavResouce, putMethod(), and existence

Posted by Garret Wilson <ga...@globalmentor.com>.
Carlos,

Carlos Villegas wrote:
> For "intended" usage patterns check the slide command line sample 
> client. Other ways of using WebdavResource outside of what the command 
> line client does, were probably not thought of carefully or haven't been 
> tested.

(sigh) Thanks for verifying my fears.

It's a shame that the Slide WebDAV client API was just (apparently) 
haphazardly thrown together.

Because I can't depend on WebdavResource.exists(), I have to call 
WebdavResource.headMethod(). The API says that this returns a boolean to 
indicate whether the method succeeded, but what *really* happens is that 
it either succeeds or throws an exception if the file doesn't exist. Why 
have a boolean return value if you're going to throw an exception for 
failure?

Garret


---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org


Re: WebdavResouce, putMethod(), and existence

Posted by Carlos Villegas <ca...@uniscope.jp>.
I suspect WebdavResource was designed to be used the way it is used in 
the slide command line client and that's it. Some functions like 
exists() may have been added just for completeness trying to parallel 
the File API but as you point out, it makes no sense to have a exists() 
function if you can't create a WebdavResource on a non-existent 
resource. Same goes for the mkcolMethod and putMethod's without 
arguments. The way I'm using it, basically, is to work with the parent 
WebdavResource of the resource I'm interested in and use the putMethod 
or other methods that take a relative path as argument. Working on the 
parent resource I know its children so I know if a resource exists or 
not before operating on it. In my case, working this way is fine because 
I need to keep track of the resource hierarchy for other purposes, so my 
parent resource and children are already available!
For "intended" usage patterns check the slide command line sample 
client. Other ways of using WebdavResource outside of what the command 
line client does, were probably not thought of carefully or haven't been 
tested.

Carlos

Garret Wilson wrote:
> James,
> 
> James Mason wrote:
> 
>> After you construct your WebdavResource you should be able to call
>> headMethod() to see if the remote resource exists. I don't know if this
>> is the best method, but it should work.
> 
> 
> There are a 100 ways that would work, I'm sure---but how was 
> WebdavResource *designed* to be used?
> 
> Why doesn't WebdavResource call headMethod() itself when I check its 
> existence? Why does it try to gather properties when I create a 
> WebdavResource instance? If it for some reason *has* to do a PROPFIND, 
> why doesn't it determine the nonexistence and just set the existence 
> flag to false?
> 
> As I mentioned to someone off the list: Imagine if creating a 
> java.io.File for a non-existent file threw an IOException, and you had 
> to try to open up an InputStream using low-level disk I/O just to see if 
> you could create a java.io.File. (You could always create a 
> java.io.File(boolean dontcheckdisk), but this would return incorrect 
> information for java.io.File.exists().
> 
> Garret
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: slide-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org


Re: WebdavResouce, putMethod(), and existence

Posted by Garret Wilson <ga...@globalmentor.com>.
James,

James Mason wrote:
> After you construct your WebdavResource you should be able to call
> headMethod() to see if the remote resource exists. I don't know if this
> is the best method, but it should work.

There are a 100 ways that would work, I'm sure---but how was 
WebdavResource *designed* to be used?

Why doesn't WebdavResource call headMethod() itself when I check its 
existence? Why does it try to gather properties when I create a 
WebdavResource instance? If it for some reason *has* to do a PROPFIND, 
why doesn't it determine the nonexistence and just set the existence 
flag to false?

As I mentioned to someone off the list: Imagine if creating a 
java.io.File for a non-existent file threw an IOException, and you had 
to try to open up an InputStream using low-level disk I/O just to see if 
you could create a java.io.File. (You could always create a 
java.io.File(boolean dontcheckdisk), but this would return incorrect 
information for java.io.File.exists().

Garret

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org


Re: WebdavResouce, putMethod(), and existence

Posted by James Mason <ma...@apache.org>.
Garret,

After you construct your WebdavResource you should be able to call
headMethod() to see if the remote resource exists. I don't know if this
is the best method, but it should work.

-James

On Sun, 2004-12-12 at 17:13 -0800, Garret Wilson wrote:
> I started using Slide just days ago, and immediately ran into the 
> WebdavResource weirdness for non-existent files: constructing a 
> WebdavResource for a file that doesn't exist throws an HttpException 
> with status code 404.
> 
> After searching the archives, I found a workaround of new 
> WebdavResouce(httpURL, WebdavResource.NOACTION, 0), which disables PROPFIND:
> 
> http://nagoya.apache.org/eyebrowse/ReadMsg?listName=slide-user@jakarta.apache.org&msgId=2039251
> 
> Now I can use putMethod() to upload a file whether or not the file 
> already exists. But how do I check to see that it already exists? After 
> using the above constructor, WebdavResource.exists() always returns 
> false---even if I've just uploaded a file to the same URL! Apparently 
> disabling PROPFIND keeps WebdavResource from knowing anything about the 
> file on the server.
> 
> So how can I see if a file exists? I'm guessing the following would work:
> 
> WebdavResource webdavresource;
> try
> {
>    webdavresource=new WebdavResource(httpURL);
>    webdavresource.setExistence(true);
> }
> catch(HttpException e)
> {
>    if(e.getReasonCode()==404)
>    {
>      webdavresource=new WebdavResource(httpURL, WebdavResource.NOACTION, 0);
>      webresource.setExistence(false);
>    }
>    else
>    {
>      throw e;
>    }
> }
> 
> If this is the way things are supposed to be done, I'll have to say this 
> isn't the best example of API elegance I've seen. :| I'm hoping I'm 
> missing something.
> 
> How should I be using WebdavResource?
> 
> Thanks,
> 
> Garret
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: slide-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org