1313import org .cryptomator .cloudaccess .api .exceptions .CloudProviderException ;
1414import org .cryptomator .cloudaccess .api .exceptions .InsufficientStorageException ;
1515import org .cryptomator .cloudaccess .api .exceptions .NotFoundException ;
16+ import org .slf4j .Logger ;
17+ import org .slf4j .LoggerFactory ;
1618import org .xml .sax .SAXException ;
1719
1820import java .io .ByteArrayInputStream ;
3032
3133public class WebDavClient {
3234
35+ private static final Logger LOG = LoggerFactory .getLogger (WebDavClient .class );
3336 private static final Comparator <PropfindEntryData > ASCENDING_BY_DEPTH = Comparator .comparingLong (PropfindEntryData ::getDepth );
3437
3538 private final WebDavCompatibleHttpClient httpClient ;
@@ -42,6 +45,7 @@ public class WebDavClient {
4245 }
4346
4447 CloudItemList list (final CloudPath folder ) throws CloudProviderException {
48+ LOG .trace ("list {}" , folder );
4549 try (final var response = executePropfindRequest (folder , PropfindDepth .ONE )) {
4650 checkExecutionSucceeded (response .code ());
4751
@@ -54,6 +58,7 @@ CloudItemList list(final CloudPath folder) throws CloudProviderException {
5458 }
5559
5660 CloudItemMetadata itemMetadata (final CloudPath path ) throws CloudProviderException {
61+ LOG .trace ("itemMetadata {}" , path );
5762 try (final var response = executePropfindRequest (path , PropfindDepth .ZERO )) {
5863 checkExecutionSucceeded (response .code ());
5964
@@ -120,6 +125,7 @@ private CloudItemMetadata toCloudItem(final PropfindEntryData data, final CloudP
120125 }
121126
122127 CloudPath move (final CloudPath from , final CloudPath to , boolean replace ) throws CloudProviderException {
128+ LOG .trace ("move {} to {} (replace: {})" , from , to , replace ? "true" : "false" );
123129 final var builder = new Request .Builder () //
124130 .method ("MOVE" , null ) //
125131 .url (absoluteURLFrom (from )) //
@@ -145,13 +151,15 @@ CloudPath move(final CloudPath from, final CloudPath to, boolean replace) throws
145151 }
146152
147153 InputStream read (final CloudPath path , final ProgressListener progressListener ) throws CloudProviderException {
154+ LOG .trace ("read {}" , path );
148155 final var getRequest = new Request .Builder () //
149156 .get () //
150157 .url (absoluteURLFrom (path ));
151158 return read (getRequest , progressListener );
152159 }
153160
154161 InputStream read (final CloudPath path , final long offset , final long count , final ProgressListener progressListener ) throws CloudProviderException {
162+ LOG .trace ("read {} (offset: {}, count: {})" , path , offset , count );
155163 final var getRequest = new Request .Builder () //
156164 .header ("Range" , String .format ("bytes=%d-%d" , offset , offset + count - 1 )) //
157165 .get () //
@@ -184,6 +192,7 @@ private InputStream read(final Request.Builder getRequest, final ProgressListene
184192 }
185193
186194 void write (final CloudPath file , final boolean replace , final InputStream data , final long size , final Optional <Instant > lastModified , final ProgressListener progressListener ) throws CloudProviderException {
195+ LOG .trace ("write {} (size: {}, lastModified: {}, replace: {})" , file , size , lastModified , replace ? "true" : "false" );
187196 if (!replace && exists (file )) {
188197 throw new AlreadyExistsException ("CloudNode already exists and replace is false" );
189198 }
@@ -211,6 +220,7 @@ private boolean exists(CloudPath path) throws CloudProviderException {
211220 }
212221
213222 CloudPath createFolder (final CloudPath path ) throws CloudProviderException {
223+ LOG .trace ("createFolder {}" , path );
214224 if (exists (path )) {
215225 throw new AlreadyExistsException (String .format ("Folder %s already exists" , path .toString ()));
216226 }
@@ -228,6 +238,7 @@ CloudPath createFolder(final CloudPath path) throws CloudProviderException {
228238 }
229239
230240 void delete (final CloudPath path ) throws CloudProviderException {
241+ LOG .trace ("delete {}" , path );
231242 final var builder = new Request .Builder () //
232243 .delete () //
233244 .url (absoluteURLFrom (path ));
@@ -240,6 +251,7 @@ void delete(final CloudPath path) throws CloudProviderException {
240251 }
241252
242253 void checkServerCompatibility () throws ServerNotWebdavCompatibleException {
254+ LOG .trace ("checkServerCompatibility" );
243255 final var optionsRequest = new Request .Builder () //
244256 .method ("OPTIONS" , null ) //
245257 .url (baseUrl );
@@ -256,6 +268,7 @@ void checkServerCompatibility() throws ServerNotWebdavCompatibleException {
256268 }
257269
258270 void tryAuthenticatedRequest () throws UnauthorizedException {
271+ LOG .trace ("tryAuthenticatedRequest" );
259272 try {
260273 itemMetadata (CloudPath .of ("/" ));
261274 } catch (Exception e ) {
0 commit comments