Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit 972655f

Browse files
author
Emmanuel Hugonnet
committed
Fxing bug #3467 : 201 is an accepted return value from the Http Server
1 parent e507745 commit 972655f

File tree

2 files changed

+38
-33
lines changed

2 files changed

+38
-33
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/target/
1+
nb-configuration.xml
2+
/target/

src/main/java/com/silverpeas/openoffice/windows/webdav/WebdavManager.java

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
/**
22
* Copyright (C) 2000 - 2009 Silverpeas
33
*
4-
* This program is free software: you can redistribute it and/or modify
5-
* it under the terms of the GNU Affero General Public License as
6-
* published by the Free Software Foundation, either version 3 of the
7-
* License, or (at your option) any later version.
4+
* This program is free software: you can redistribute it and/or modify it under the terms of the
5+
* GNU Affero General Public License as published by the Free Software Foundation, either version 3
6+
* of the License, or (at your option) any later version.
87
*
9-
* As a special exception to the terms and conditions of version 3.0 of
10-
* the GPL, you may redistribute this Program in connection with Free/Libre
11-
* Open Source Software ("FLOSS") applications as described in Silverpeas's
12-
* FLOSS exception. You should have received a copy of the text describing
13-
* the FLOSS exception, and it is also available here:
8+
* As a special exception to the terms and conditions of version 3.0 of the GPL, you may
9+
* redistribute this Program in connection with Free/Libre Open Source Software ("FLOSS")
10+
* applications as described in Silverpeas's FLOSS exception. You should have received a copy of the
11+
* text describing the FLOSS exception, and it is also available here:
1412
* "http://repository.silverpeas.com/legal/licensing"
1513
*
16-
* This program is distributed in the hope that it will be useful,
17-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19-
* GNU Affero General Public License for more details.
14+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
15+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* Affero General Public License for more details.
2017
*
21-
* You should have received a copy of the GNU Affero General Public License
22-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
* You should have received a copy of the GNU Affero General Public License along with this program.
19+
* If not, see <http://www.gnu.org/licenses/>.
2320
*/
24-
2521
package com.silverpeas.openoffice.windows.webdav;
2622

2723
import java.io.IOException;
@@ -59,8 +55,12 @@
5955
import org.apache.jackrabbit.webdav.client.methods.PutMethod;
6056
import org.apache.jackrabbit.webdav.client.methods.UnLockMethod;
6157

58+
import static java.net.HttpURLConnection.HTTP_OK;
59+
import static java.net.HttpURLConnection.HTTP_CREATED;
60+
6261
/**
6362
* Simple class to help manipulate Webdav ressources.
63+
*
6464
* @author ehugonnet
6565
*/
6666
public class WebdavManager {
@@ -70,15 +70,15 @@ public class WebdavManager {
7070

7171
/**
7272
* Prepare HTTP connections to the WebDav server
73+
*
7374
* @param host the webdav server host name.
7475
* @param login the login for the user on the webdav server.
7576
* @param password the login for the user on the webdav server.
7677
*/
7778
public WebdavManager(String host, String login, String password) {
7879
HostConfiguration hostConfig = new HostConfiguration();
7980
hostConfig.setHost(host);
80-
HttpConnectionManager connectionManager =
81-
new MultiThreadedHttpConnectionManager();
81+
HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
8282
HttpConnectionManagerParams connectionParams = new HttpConnectionManagerParams();
8383
int maxHostConnections = 20;
8484
connectionParams.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
@@ -94,14 +94,15 @@ public WebdavManager(String host, String login, String password) {
9494

9595
/**
9696
* Lock a ressource on a webdav server.
97+
*
9798
* @param uri the URI to the ressource to be locked.
9899
* @param login the user locking the ressource.
99100
* @return the lock token.
100101
* @throws IOException
101102
*/
102103
public String lockFile(URI uri, String login) throws IOException {
103-
logger.log(Level.INFO, MessageUtil.getMessage("info.webdav.locking")
104-
+ ' ' + uri.getEscapedURI());
104+
logger.log(Level.INFO, "{0} {1}", new Object[]{MessageUtil.getMessage("info.webdav.locking"),
105+
uri.getEscapedURI()});
105106
// Let's lock the file
106107
LockMethod lockMethod = new LockMethod(uri.getEscapedURI(),
107108
Scope.EXCLUSIVE, Type.WRITE, login, 600000l, false);
@@ -113,13 +114,13 @@ public String lockFile(URI uri, String login) throws IOException {
113114
throw new IOException(MessageUtil.getMessage("error.webdav.already.locked"));
114115
}
115116
throw new IOException(MessageUtil.getMessage("error.webdav.locking")
116-
+ ' ' + lockMethod.getStatusCode() + " - "
117-
+ lockMethod.getStatusText());
117+
+ ' ' + lockMethod.getStatusCode() + " - " + lockMethod.getStatusText());
118118
}
119119
}
120120

121121
/**
122122
* Unlock a ressource on a webdav server.
123+
*
123124
* @param uri the URI to the ressource to be unlocked.
124125
* @param lockToken the current lock token.
125126
* @throws IOException
@@ -131,22 +132,23 @@ public void unlockFile(URI uri, String lockToken) throws IOException {
131132
UnLockMethod unlockMethod = new UnLockMethod(uri.getEscapedURI(), lockToken);
132133
client.executeMethod(unlockMethod);
133134
if (unlockMethod.getStatusCode() != 200 && unlockMethod.getStatusCode() != 204) {
134-
logger.log(Level.INFO, MessageUtil.getMessage("error.webdav.unlocking") + ' '
135-
+ unlockMethod.getStatusCode());
135+
logger.log(Level.INFO, "{0} {1}", new Object[]{MessageUtil.
136+
getMessage("error.webdav.unlocking"),
137+
unlockMethod.getStatusCode()});
136138
}
137139
try {
138140
unlockMethod.checkSuccess();
139141
logger.log(Level.INFO, MessageUtil.getMessage("info.webdav.unlocked"));
140142
} catch (DavException ex) {
141143
logger.log(Level.SEVERE,
142144
MessageUtil.getMessage("error.webdav.unlocking"), ex);
143-
throw new IOException(MessageUtil.getMessage("error.webdav.unlocking"),
144-
ex);
145+
throw new IOException(MessageUtil.getMessage("error.webdav.unlocking"), ex);
145146
}
146147
}
147148

148149
/**
149150
* Get the ressource from the webdav server.
151+
*
150152
* @param uri the uri to the ressource.
151153
* @param lockToken the current lock token.
152154
* @return the path to the saved file on the filesystem.
@@ -178,8 +180,8 @@ public String getFile(URI uri, String lockToken) throws IOException {
178180
fos.write(data, 0, c);
179181
}
180182
} catch (InterruptedIOException ioinex) {
181-
logger.log(Level.INFO, MessageUtil.getMessage("info.user.cancel") + ' '
182-
+ ioinex.getMessage());
183+
logger.log(Level.INFO, "{0} {1}", new Object[]{MessageUtil.getMessage("info.user.cancel"),
184+
ioinex.getMessage()});
183185
unlockFile(uri, lockToken);
184186
System.exit(0);
185187
} finally {
@@ -190,6 +192,7 @@ public String getFile(URI uri, String lockToken) throws IOException {
190192

191193
/**
192194
* Update a ressource on the webdav file server.
195+
*
193196
* @param uri the uri to the ressource.
194197
* @param localFilePath the path to the file to be uploaded on the filesystem.
195198
* @param lockToken the current lock token.
@@ -204,12 +207,13 @@ public void putFile(URI uri, String localFilePath, String lockToken) throws IOEx
204207
throw new IOException(MessageUtil.getMessage("error.remote.file"));
205208
}
206209
PutMethod putMethod = new PutMethod(uri.getEscapedURI());
207-
logger.log(Level.INFO, MessageUtil.getMessage("info.webdav.put") + ' ' + localFilePath);
210+
logger.log(Level.INFO, "{0} {1}", new Object[]{MessageUtil.getMessage("info.webdav.put"),
211+
localFilePath});
208212
File file = new File(localFilePath);
209213
UploadProgressBar progress = new UploadProgressBar();
210214
progress.setMaximum(new Long(file.length()).intValue());
211-
progress.setMessage(MessageUtil.getMessage("uploading.remote.file") + ' ' +
212-
uri.getPath().substring(
215+
progress.setMessage(MessageUtil.getMessage("uploading.remote.file") + ' ' + uri.getPath().
216+
substring(
213217
uri.getPath().lastIndexOf('/') + 1));
214218
MonitoredInputStream is =
215219
new MonitoredInputStream(new BufferedInputStream(new FileInputStream(file)));
@@ -238,7 +242,7 @@ private GetMethod executeGetFile(URI uri) throws IOException {
238242
GetMethod method = new GetMethod();
239243
method.setURI(uri);
240244
client.executeMethod(method);
241-
if (method.getStatusCode() != 200) {
245+
if (method.getStatusCode() != HTTP_CREATED && method.getStatusCode() != HTTP_OK) {
242246
throw new IOException(MessageUtil.getMessage("error.get.remote.file")
243247
+ ' ' + method.getStatusCode() + " - " + method.getStatusText());
244248
}

0 commit comments

Comments
 (0)