Coverage Report - org.apache.maven.wagon.providers.webdav.WebDavWagon
 
Classes in this File Line Coverage Branch Coverage Complexity
WebDavWagon
69% 
94% 
7.643
 
 1  
 package org.apache.maven.wagon.providers.webdav;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2006 The Apache Software Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *      http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import org.apache.commons.httpclient.HttpException;
 20  
 import org.apache.commons.httpclient.HttpStatus;
 21  
 import org.apache.commons.httpclient.HttpURL;
 22  
 import org.apache.commons.httpclient.HttpsURL;
 23  
 import org.apache.commons.httpclient.URIException;
 24  
 import org.apache.commons.httpclient.UsernamePasswordCredentials;
 25  
 import org.apache.maven.wagon.AbstractWagon;
 26  
 import org.apache.maven.wagon.ConnectionException;
 27  
 import org.apache.maven.wagon.LazyFileOutputStream;
 28  
 import org.apache.maven.wagon.PathUtils;
 29  
 import org.apache.maven.wagon.ResourceDoesNotExistException;
 30  
 import org.apache.maven.wagon.TransferFailedException;
 31  
 import org.apache.maven.wagon.authentication.AuthenticationException;
 32  
 import org.apache.maven.wagon.authorization.AuthorizationException;
 33  
 import org.apache.maven.wagon.events.TransferEvent;
 34  
 import org.apache.maven.wagon.repository.Repository;
 35  
 import org.apache.maven.wagon.resource.Resource;
 36  
 import org.apache.webdav.lib.WebdavResource;
 37  
 import org.apache.webdav.lib.methods.DepthSupport;
 38  
 import org.codehaus.plexus.util.FileUtils;
 39  
 import org.codehaus.plexus.util.IOUtil;
 40  
 import org.codehaus.plexus.util.StringUtils;
 41  
 
 42  
 import java.io.File;
 43  
 import java.io.FileNotFoundException;
 44  
 import java.io.IOException;
 45  
 import java.io.InputStream;
 46  
 import java.io.OutputStream;
 47  
 import java.net.URL;
 48  
 import java.text.DateFormat;
 49  
 import java.text.SimpleDateFormat;
 50  
 import java.util.ArrayList;
 51  
 import java.util.Arrays;
 52  
 import java.util.Date;
 53  
 import java.util.List;
 54  
 import java.util.Locale;
 55  
 import java.util.Properties;
 56  
 import java.util.TimeZone;
 57  
 
 58  
 /**
 59  
  * <p>WebDavWagon</p>
 60  
  * 
 61  
  * <p>Allows using a webdav remote repository for downloads and deployments</p>
 62  
  * 
 63  
  * <p>TODO: webdav https server is not tested</p>
 64  
  * 
 65  
  * @author <a href="mailto:hisidro@exist.com">Henry Isidro</a>
 66  
  * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
 67  
  * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
 68  
  */
 69  
 public class WebDavWagon
 70  
     extends AbstractWagon
 71  
 {
 72  1
     private static final TimeZone TIMESTAMP_TIME_ZONE = TimeZone.getTimeZone( "GMT" );
 73  
 
 74  
     private static String wagonVersion;
 75  
 
 76  31
     private DateFormat dateFormat = new SimpleDateFormat( "EEE, dd-MMM-yy HH:mm:ss zzz", Locale.US );
 77  
 
 78  
     private CorrectedWebdavResource webdavResource;
 79  
 
 80  
     public WebDavWagon()
 81  31
     {
 82  31
         dateFormat.setTimeZone( TIMESTAMP_TIME_ZONE );
 83  
 
 84  31
         if ( wagonVersion == null )
 85  
         {
 86  1
             URL pomUrl = this.getClass()
 87  
                 .getResource( "/META-INF/maven/org.apache.maven.wagon/wagon-webdav/pom.properties" );
 88  1
             if ( pomUrl == null )
 89  
             {
 90  1
                 wagonVersion = "";
 91  
             }
 92  
             else
 93  
             {
 94  0
                 Properties props = new Properties();
 95  
                 try
 96  
                 {
 97  0
                     props.load( pomUrl.openStream() );
 98  0
                     wagonVersion = props.getProperty( "version" );
 99  0
                     System.out.println( "WAGON_VERSION: " + wagonVersion );
 100  
                 }
 101  0
                 catch ( IOException e )
 102  
                 {
 103  0
                     wagonVersion = "";
 104  0
                 }
 105  
             }
 106  
         }
 107  31
     }
 108  
 
 109  
     /**
 110  
      * Opens a connection via web-dav resource
 111  
      * 
 112  
      * @throws AuthenticationException 
 113  
      * @throws ConnectionException
 114  
      */
 115  
     public void openConnection()
 116  
         throws AuthenticationException, ConnectionException
 117  
     {
 118  33
         final boolean hasProxy = ( proxyInfo != null && proxyInfo.getUserName() != null );
 119  33
         final boolean hasAuthentication = ( authenticationInfo != null && authenticationInfo.getUserName() != null );
 120  
 
 121  33
         String url = getURL( repository );
 122  
 
 123  33
         repository.setUrl( url );
 124  
 
 125  33
         HttpURL httpURL = null;
 126  
 
 127  
         try
 128  
         {
 129  33
             httpURL = urlToHttpURL( url );
 130  
 
 131  33
             if ( hasAuthentication )
 132  
             {
 133  16
                 String userName = authenticationInfo.getUserName();
 134  16
                 String password = authenticationInfo.getPassword();
 135  
 
 136  16
                 if ( userName != null && password != null )
 137  
                 {
 138  16
                     httpURL.setUserinfo( userName, password );
 139  
                 }
 140  
             }
 141  
 
 142  33
             CorrectedWebdavResource.setDefaultAction( CorrectedWebdavResource.NOACTION );
 143  33
             webdavResource = new CorrectedWebdavResource( httpURL );
 144  
 
 145  33
             if ( hasProxy )
 146  
             {
 147  
                 
 148  
                 
 149  0
                 webdavResource.setProxy( proxyInfo.getHost(), proxyInfo.getPort() );
 150  0
                 if ( !StringUtils.isEmpty( proxyInfo.getUserName() ) )
 151  
                 {
 152  0
                     UsernamePasswordCredentials proxyCredentials = new UsernamePasswordCredentials();
 153  0
                     proxyCredentials.setUserName( proxyInfo.getUserName() );
 154  0
                     proxyCredentials.setPassword( proxyInfo.getPassword() );
 155  0
                     webdavResource.setProxyCredentials( proxyCredentials );
 156  
                 }
 157  
             }
 158  
         }
 159  0
         catch ( HttpException he )
 160  
         {
 161  0
             throw new ConnectionException( "Connection Exception: " + url + " " + he.getReasonCode() + " "
 162  
                 + HttpStatus.getStatusText( he.getReasonCode() ), he );
 163  
         }
 164  0
         catch ( URIException urie )
 165  
         {
 166  0
             throw new ConnectionException( "Connection Exception: " + urie.getReason(), urie );
 167  
         }
 168  0
         catch ( IOException ioe )
 169  
         {
 170  0
             throw new ConnectionException( "Connection Exception: " + ioe.getMessage(), ioe );
 171  33
         }
 172  33
     }
 173  
 
 174  
     /**
 175  
      * Closes the connection
 176  
      * 
 177  
      * @throws ConnectionException 
 178  
      */
 179  
     public void closeConnection()
 180  
         throws ConnectionException
 181  
     {
 182  
         try
 183  
         {
 184  33
             if ( webdavResource != null )
 185  
             {
 186  33
                 webdavResource.close();
 187  
             }
 188  
         }
 189  0
         catch ( IOException ioe )
 190  
         {
 191  0
             throw new ConnectionException( "Connection Exception: " + ioe.getMessage(), ioe );
 192  
         }
 193  
         finally
 194  
         {
 195  33
             webdavResource = null;
 196  33
         }
 197  33
     }
 198  
 
 199  
     /**
 200  
      * Puts a file into the remote repository
 201  
      *
 202  
      * @param source the file to transfer
 203  
      * @param resourceName the name of the resource
 204  
      * @throws TransferFailedException
 205  
      * @throws ResourceDoesNotExistException
 206  
      * @throws AuthorizationException
 207  
      */
 208  
     public void put( File source, String resourceName )
 209  
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
 210  
     {
 211  42
         Repository repository = getRepository();
 212  
 
 213  42
         String basedir = repository.getBasedir();
 214  
 
 215  42
         resourceName = StringUtils.replace( resourceName, "\\", "/" );
 216  42
         String dir = PathUtils.dirname( resourceName );
 217  42
         dir = StringUtils.replace( dir, "\\", "/" );
 218  
 
 219  42
         String dest = repository.getUrl();
 220  42
         Resource resource = new Resource( resourceName );
 221  
 
 222  42
         if ( dest.endsWith( "/" ) )
 223  
         {
 224  0
             dest = dest + resource.getName();
 225  
         }
 226  
         else
 227  
         {
 228  42
             dest = dest + "/" + resource.getName();
 229  
         }
 230  
 
 231  42
         firePutInitiated( resource, source );
 232  42
         String oldpath = webdavResource.getPath();
 233  
 
 234  42
         String relpath = getPath( basedir, dir );
 235  
 
 236  
         try
 237  
         {
 238  
             // Test if dest resource path exist.
 239  42
             String cdpath = checkUri( relpath + "/" );
 240  42
             webdavResource.setPath( cdpath );
 241  
 
 242  42
             if ( webdavResource.exists() && !webdavResource.isCollection() )
 243  
             {
 244  0
                 throw new TransferFailedException(
 245  
                     "Destination path exists and is not a WebDAV collection (directory): " + cdpath );
 246  
             }
 247  
 
 248  42
             webdavResource.setPath( oldpath );
 249  
 
 250  
             // if dest resource path does not exist, create it
 251  42
             if ( !webdavResource.exists() )
 252  
             {
 253  
                 // mkcolMethod() cannot create a directory hierarchy at once,
 254  
                 // it has to create each directory one at a time
 255  
                 try
 256  
                 {
 257  42
                     String[] dirs = relpath.split( "/" );
 258  42
                     String createDir = "/";
 259  
 
 260  
                     // start at 1 because first element of dirs[] from split() is ""
 261  262
                     for ( int count = 1; count < dirs.length; count++ )
 262  
                     {
 263  220
                         createDir = createDir + dirs[count] + "/";
 264  220
                         webdavResource.mkcolMethod( createDir );
 265  
                     }
 266  42
                     webdavResource.setPath( oldpath );
 267  
                 }
 268  0
                 catch ( IOException ioe )
 269  
                 {
 270  0
                     throw new TransferFailedException( "Failed to create destination WebDAV collection (directory): "
 271  
                         + relpath, ioe );
 272  42
                 }
 273  
             }
 274  
         }
 275  0
         catch ( IOException e )
 276  
         {
 277  0
             throw new TransferFailedException(
 278  
                 "Failed to create destination WebDAV collection (directory): " + relpath, e );
 279  42
         }
 280  
 
 281  
         try
 282  
         {
 283  
             // Put source into destination path.
 284  42
             firePutStarted( resource, source );
 285  
 
 286  42
             InputStream is = new PutInputStream( source, resource, this, getTransferEventSupport() );
 287  42
             boolean success = webdavResource.putMethod( dest, is, (int) source.length() );
 288  42
             int statusCode = webdavResource.getStatusCode();
 289  
 
 290  42
             switch ( statusCode )
 291  
             {
 292  
                 case HttpStatus.SC_OK:
 293  0
                     break;
 294  
 
 295  
                 case HttpStatus.SC_CREATED:
 296  0
                     break;
 297  
 
 298  
                 case HttpStatus.SC_FORBIDDEN:
 299  0
                     throw new AuthorizationException( "Access denied to: " + dest );
 300  
 
 301  
                 case HttpStatus.SC_NOT_FOUND:
 302  0
                     throw new ResourceDoesNotExistException( "File: " + dest + " does not exist" );
 303  
 
 304  
                 case HttpStatus.SC_LENGTH_REQUIRED:
 305  0
                     throw new ResourceDoesNotExistException( "Transfer failed, server requires Content-Length." );
 306  
 
 307  
                     //add more entries here
 308  
                 default:
 309  42
                     if ( !success )
 310  
                     {
 311  0
                         throw new TransferFailedException( "Failed to transfer file: " + dest + ". Return code is: "
 312  
                             + statusCode + " " + HttpStatus.getStatusText( statusCode ) );
 313  
                     }
 314  
             }
 315  
         }
 316  0
         catch ( FileNotFoundException e )
 317  
         {
 318  0
             throw new TransferFailedException( "Specified source file does not exist: " + source, e );
 319  
         }
 320  0
         catch ( IOException e )
 321  
         {
 322  0
             fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
 323  
 
 324  0
             String msg = "PUT request for: " + resource + " to " + source.getName() + " failed";
 325  
 
 326  0
             throw new TransferFailedException( msg, e );
 327  42
         }
 328  42
         firePutCompleted( resource, source );
 329  42
     }
 330  
 
 331  
     /**
 332  
      * Converts a String url to an HttpURL
 333  
      *
 334  
      * @param url String url to convert to an HttpURL
 335  
      * @return an HttpURL object created from the String url
 336  
      * @throws URIException
 337  
      */
 338  
     private HttpURL urlToHttpURL( String url )
 339  
         throws URIException
 340  
     {
 341  33
         if ( url.startsWith( "https" ) )
 342  
         {
 343  0
             return new HttpsURL( url );
 344  
         }
 345  
         else
 346  
         {
 347  33
             return new HttpURL( url );
 348  
         }
 349  
     }
 350  
 
 351  
     /**
 352  
      * Determine which URI to use at the prompt.
 353  
      *
 354  
      * @param uri the path to be set.
 355  
      * @return the absolute path.
 356  
      */
 357  
     private String checkUri( String uri )
 358  
         throws IOException
 359  
     {
 360  
 
 361  50
         if ( webdavResource == null )
 362  
         {
 363  0
             throw new IOException( "Not connected yet." );
 364  
         }
 365  
 
 366  50
         if ( uri == null )
 367  
         {
 368  0
             uri = webdavResource.getPath();
 369  
         }
 370  
 
 371  50
         return FileUtils.normalize( uri );
 372  
     }
 373  
 
 374  
     public void get( String resourceName, File destination )
 375  
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
 376  
     {
 377  33
         get( resourceName, destination, 0 );
 378  
 
 379  31
     }
 380  
 
 381  
     public boolean getIfNewer( String resourceName, File destination, long timestamp )
 382  
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
 383  
     {
 384  0
         return get( resourceName, destination, timestamp );
 385  
     }
 386  
 
 387  
     /**
 388  
      * Get a file from remote server
 389  
      * 
 390  
      * @param resourceName
 391  
      * @param destination
 392  
      * @param timestamp the timestamp to check against, only downloading if newer. If <code>0</code>, always download
 393  
      * @return <code>true</code> if newer version was downloaded, <code>false</code> otherwise.
 394  
      * @throws TransferFailedException
 395  
      * @throws ResourceDoesNotExistException
 396  
      * @throws AuthorizationException
 397  
      */
 398  
     public boolean get( String resourceName, File destination, long timestamp )
 399  
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
 400  
     {
 401  33
         Resource resource = new Resource( resourceName );
 402  
 
 403  33
         fireGetInitiated( resource, destination );
 404  
 
 405  33
         String url = getRepository().getUrl() + "/" + resourceName;
 406  
 
 407  33
         webdavResource.addRequestHeader( "X-wagon-provider", "wagon-webdav" );
 408  33
         webdavResource.addRequestHeader( "X-wagon-version", wagonVersion );
 409  
 
 410  33
         webdavResource.addRequestHeader( "Cache-control", "no-cache" );
 411  33
         webdavResource.addRequestHeader( "Cache-store", "no-store" );
 412  33
         webdavResource.addRequestHeader( "Pragma", "no-cache" );
 413  33
         webdavResource.addRequestHeader( "Expires", "0" );
 414  33
         webdavResource.addRequestHeader( "Accept-Encoding", "gzip" );
 415  
 
 416  33
         if ( timestamp > 0 )
 417  
         {
 418  0
             webdavResource.addRequestHeader( "If-Modified-Since", dateFormat.format( new Date( timestamp ) ) );
 419  
         }
 420  
 
 421  33
         InputStream is = null;
 422  33
         OutputStream output = new LazyFileOutputStream( destination );
 423  
         try
 424  
         {
 425  33
             is = webdavResource.getMethodData( url );
 426  31
             getTransfer( resource, destination, is );
 427  
         }
 428  0
         catch ( HttpException e )
 429  
         {
 430  0
             fireTransferError( resource, e, TransferEvent.REQUEST_GET );
 431  0
             throw new TransferFailedException( "Failed to transfer file: " + url + ".  Return code is: "
 432  
                 + e.getReasonCode(), e );
 433  
         }
 434  2
         catch ( IOException e )
 435  
         {
 436  2
             fireTransferError( resource, e, TransferEvent.REQUEST_GET );
 437  
 
 438  2
             if ( destination.exists() )
 439  
             {
 440  0
                 boolean deleted = destination.delete();
 441  
 
 442  0
                 if ( !deleted )
 443  
                 {
 444  0
                     destination.deleteOnExit();
 445  
                 }
 446  
             }
 447  
 
 448  2
             int statusCode = webdavResource.getStatusCode();
 449  2
             switch ( statusCode )
 450  
             {
 451  
                 case HttpStatus.SC_NOT_MODIFIED:
 452  0
                     return false;
 453  
 
 454  
                 case HttpStatus.SC_FORBIDDEN:
 455  0
                     throw new AuthorizationException( "Access denied to: " + url );
 456  
 
 457  
                 case HttpStatus.SC_UNAUTHORIZED:
 458  0
                     throw new AuthorizationException( "Not authorized." );
 459  
 
 460  
                 case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
 461  0
                     throw new AuthorizationException( "Not authorized by proxy." );
 462  
 
 463  
                 case HttpStatus.SC_NOT_FOUND:
 464  2
                     throw new ResourceDoesNotExistException( "File: " + url + " does not exist" );
 465  
 
 466  
                 default:
 467  0
                     throw new TransferFailedException( "Failed to transfer file: " + url + ". Return code is: "
 468  
                         + statusCode, e );
 469  
             }
 470  
         }
 471  
         finally
 472  
         {
 473  33
             IOUtil.close( is );
 474  33
             IOUtil.close( output );
 475  31
         }
 476  
 
 477  31
         int statusCode = webdavResource.getStatusCode();
 478  
 
 479  31
         switch ( statusCode )
 480  
         {
 481  
             case HttpStatus.SC_OK:
 482  31
                 return true;
 483  
 
 484  
             case HttpStatus.SC_NOT_MODIFIED:
 485  0
                 return false;
 486  
 
 487  
             case HttpStatus.SC_FORBIDDEN:
 488  0
                 throw new AuthorizationException( "Access denied to: " + url );
 489  
 
 490  
             case HttpStatus.SC_UNAUTHORIZED:
 491  0
                 throw new AuthorizationException( "Not authorized." );
 492  
 
 493  
             case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
 494  0
                 throw new AuthorizationException( "Not authorized by proxy." );
 495  
 
 496  
             case HttpStatus.SC_NOT_FOUND:
 497  0
                 throw new ResourceDoesNotExistException( "File: " + url + " does not exist" );
 498  
 
 499  
             default:
 500  0
                 throw new TransferFailedException( "Failed to transfer file: " + url + ". Return code is: "
 501  
                     + statusCode );
 502  
         }
 503  
 
 504  
     }
 505  
 
 506  
     private String getURL( Repository repository )
 507  
     {
 508  33
         String url = repository.getUrl();
 509  33
         String s = "dav:";
 510  33
         if ( url.startsWith( s ) )
 511  
         {
 512  18
             return url.substring( s.length() );
 513  
         }
 514  
         else
 515  
         {
 516  15
             return url;
 517  
         }
 518  
     }
 519  
 
 520  
     /**
 521  
      * This wagon supports directory copying
 522  
      * 
 523  
      * @return <code>true</code> always
 524  
      */
 525  
     public boolean supportsDirectoryCopy()
 526  
     {
 527  6
         return true;
 528  
     }
 529  
 
 530  
     /**
 531  
      * Copy a directory from local system to remote webdav server
 532  
      * 
 533  
      * @param sourceDirectory the local directory
 534  
      * @param destinationDirectory the remote destination
 535  
      * @throws TransferFailedException
 536  
      * @throws ResourceDoesNotExistException
 537  
      * @throws AuthorizationException
 538  
      */
 539  
     public void putDirectory( File sourceDirectory, String destinationDirectory )
 540  
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
 541  
     {
 542  
 
 543  38
         File[] listFiles = sourceDirectory.listFiles();
 544  
 
 545  98
         for ( int i = 0; i < listFiles.length; i++ )
 546  
         {
 547  60
             if ( listFiles[i].isDirectory() )
 548  
             {
 549  30
                 putDirectory( listFiles[i], destinationDirectory + "/" + listFiles[i].getName() );
 550  
             }
 551  
             else
 552  
             {
 553  30
                 String target = destinationDirectory + "/" + listFiles[i].getName();
 554  
 
 555  30
                 put( listFiles[i], target );
 556  
             }
 557  
         }
 558  
 
 559  38
     }
 560  
 
 561  
     public List getFileList( String destinationDirectory )
 562  
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
 563  
     {
 564  8
         webdavResource.addRequestHeader( "X-wagon-provider", "wagon-webdav" );
 565  8
         webdavResource.addRequestHeader( "X-wagon-version", wagonVersion );
 566  
 
 567  8
         webdavResource.addRequestHeader( "Cache-control", "no-cache" );
 568  8
         webdavResource.addRequestHeader( "Cache-store", "no-store" );
 569  8
         webdavResource.addRequestHeader( "Pragma", "no-cache" );
 570  8
         webdavResource.addRequestHeader( "Expires", "0" );
 571  
 
 572  8
         String basedir = repository.getBasedir();
 573  
 
 574  8
         if ( !destinationDirectory.endsWith( "/" ) )
 575  
         {
 576  8
             destinationDirectory += "/";
 577  
         }
 578  
 
 579  8
         String cleanDestDir = StringUtils.replace( destinationDirectory, "\\", "/" );
 580  8
         String dir = PathUtils.dirname( cleanDestDir );
 581  8
         dir = StringUtils.replace( dir, "\\", "/" );
 582  
 
 583  8
         String oldpath = webdavResource.getPath();
 584  8
         String relpath = getPath( basedir, dir );
 585  
 
 586  
         try
 587  
         {
 588  
             // Test if dest resource path exist.
 589  8
             String cdpath = checkUri( relpath + "/" );
 590  8
             webdavResource.setPath( cdpath );
 591  
 
 592  
             try
 593  
             {
 594  8
                 webdavResource.setProperties( WebdavResource.NAME, DepthSupport.DEPTH_0 );
 595  
 
 596  
                 /* seems this is not needed as Webdav client causes a 404 error in webdavResource.setProperties */
 597  4
                 if ( !webdavResource.exists() )
 598  
                 {
 599  0
                     throw new ResourceDoesNotExistException( "Destination directory does not exist: " + cdpath );
 600  
                 }
 601  
 
 602  4
                 if ( !webdavResource.isCollection() )
 603  
                 {
 604  0
                     throw new ResourceDoesNotExistException( "Destination path exists but is not a "
 605  
                         + "WebDAV collection (directory): " + cdpath );
 606  
                 }
 607  
 
 608  4
                 String[] entries = webdavResource.list();
 609  
 
 610  4
                 List filelist = new ArrayList();
 611  4
                 if ( entries != null )
 612  
                 {
 613  4
                     filelist.addAll( Arrays.asList( entries ) );
 614  
                 }
 615  
 
 616  4
                 return filelist;
 617  
             }
 618  4
             catch ( HttpException e )
 619  
             {
 620  4
                 if ( e.getReasonCode() == HttpStatus.SC_NOT_FOUND )
 621  
                 {
 622  4
                     throw new ResourceDoesNotExistException( "Destination directory does not exist: " + cdpath, e );
 623  
                 }
 624  
                 else
 625  
                 {
 626  0
                     throw new TransferFailedException( "Unable to obtain file list from WebDAV collection, "
 627  
                         + "HTTP error: " + HttpStatus.getStatusText( e.getReasonCode() ), e );
 628  
                 }
 629  
             }
 630  
             finally
 631  
             {
 632  8
                 webdavResource.setPath( oldpath );
 633  
             }
 634  
 
 635  
         }
 636  0
         catch ( IOException e )
 637  
         {
 638  0
             throw new TransferFailedException( "Unable to obtain file list from WebDAV collection.", e );
 639  
         }
 640  
     }
 641  
 
 642  
     public boolean resourceExists( String resourceName )
 643  
         throws TransferFailedException, AuthorizationException
 644  
     {
 645  
         try
 646  
         {
 647  4
             String parentDirectory = PathUtils.dirname( resourceName );
 648  4
             List entries = getFileList( parentDirectory );
 649  2
             return entries.contains( resourceName );
 650  
         }
 651  2
         catch ( ResourceDoesNotExistException e )
 652  
         {
 653  2
             return false;
 654  
         }
 655  
     }
 656  
 }