Skip to content

Commit 948c524

Browse files
committed
ApacheClient 5 + http2 support
1 parent fa17c2e commit 948c524

35 files changed

Lines changed: 480 additions & 519 deletions

pom.xml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
<maven.compiler.target>8</maven.compiler.target>
259259
<!-- Skip integration tests by default with failsafe plugin -->
260260
<skipITs>false</skipITs>
261-
<httpclient.version>4.5.14</httpclient.version>
261+
<httpclient.version>5.1</httpclient.version>
262262
<slf4j.version>2.0.13</slf4j.version>
263263
</properties>
264264
<dependencyManagement>
@@ -277,8 +277,18 @@
277277
</dependencyManagement>
278278
<dependencies>
279279
<dependency>
280-
<groupId>org.apache.httpcomponents</groupId>
281-
<artifactId>httpclient</artifactId>
280+
<groupId>org.apache.httpcomponents.client5</groupId>
281+
<artifactId>httpclient5</artifactId>
282+
<version>${httpclient.version}</version>
283+
</dependency>
284+
<dependency>
285+
<groupId>org.apache.httpcomponents.core5</groupId>
286+
<artifactId>httpcore5</artifactId>
287+
<version>${httpclient.version}</version>
288+
</dependency>
289+
<dependency>
290+
<groupId>org.apache.httpcomponents.core5</groupId>
291+
<artifactId>httpcore5-h2</artifactId>
282292
<version>${httpclient.version}</version>
283293
</dependency>
284294
<!-- Sardine has a runtime dependency to JAXB. As this not part of JDK 11 anymore,

src/main/java/com/github/sardine/DavResource.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020

2121
import javax.xml.namespace.QName;
2222

23-
import org.apache.http.HttpStatus;
24-
import org.apache.http.ParseException;
25-
import org.apache.http.message.BasicLineParser;
23+
import org.apache.hc.core5.http.HttpStatus;
24+
import org.apache.hc.core5.http.ParseException;
25+
import org.apache.hc.core5.http.message.BasicLineParser;
26+
import org.apache.hc.core5.util.CharArrayBuffer;
2627
import org.w3c.dom.Element;
2728

2829
import com.github.sardine.model.Creationdate;
@@ -175,8 +176,9 @@ private int getStatusCode(Response response)
175176
}
176177
try
177178
{
178-
return BasicLineParser.parseStatusLine(response.getStatus(), null).getStatusCode();
179-
}
179+
CharArrayBuffer buffer = new CharArrayBuffer(response.getStatus().length());
180+
buffer.append(response.getStatus());
181+
return new BasicLineParser().parseStatusLine(buffer).getStatusCode(); }
180182
catch (ParseException e)
181183
{
182184
log.warning(String.format("Failed to parse status line: %s", status));

src/main/java/com/github/sardine/Sardine.java

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
import java.util.List;
88
import java.util.Map;
99
import java.util.Set;
10-
1110
import javax.xml.namespace.QName;
1211

13-
import org.w3c.dom.Element;
14-
1512
import com.github.sardine.report.SardineReport;
13+
import org.w3c.dom.Element;
1614

1715
/**
1816
* The main interface for Sardine operations.
@@ -27,15 +25,15 @@ public interface Sardine
2725
* @param username Use in authentication header credentials
2826
* @param password Use in authentication header credentials
2927
*/
30-
void setCredentials(String username, String password);
28+
void setCredentials(String username, char[] password);
3129

3230
/**
3331
* @param username Use in authentication header credentials
3432
* @param password Use in authentication header credentials
3533
* @param domain NTLM authentication
3634
* @param workstation NTLM authentication
3735
*/
38-
void setCredentials(String username, String password, String domain, String workstation);
36+
void setCredentials(String username, char[] password, String domain, String workstation);
3937

4038
/**
4139
* @see #list(String)
@@ -161,18 +159,6 @@ public interface Sardine
161159
*/
162160
List<DavResource> patch(String url, List<Element> addProps, List<QName> removeProps) throws IOException;
163161

164-
/**
165-
* Add or remove custom properties for a url using WebDAV <code>PROPPATCH</code>.
166-
*
167-
* @param url Path to the resource including protocol and hostname
168-
* @param addProps Properties to add to resource. If a property already exists then its value is replaced.
169-
* @param removeProps Properties to remove from resource. Specifying the removal of a property that does not exist is not an error.
170-
* @param headers Additional HTTP headers to add to the request
171-
* @return The patched resources from the response
172-
* @throws IOException I/O error or HTTP response validation failure
173-
*/
174-
List<DavResource> patch(String url, List<Element> addProps, List<QName> removeProps, Map<String, String> headers) throws IOException;
175-
176162
/**
177163
* Uses HTTP <code>GET</code> to download data from a server. The stream must be closed after reading.
178164
*
@@ -263,10 +249,11 @@ public interface Sardine
263249
*
264250
* @param url Path to the resource including protocol and hostname (must not point to a directory)
265251
* @param dataStream Input source
252+
* @param contentType MIME type to add to the HTTP request header
266253
* @param headers Additional HTTP headers to add to the request
267254
* @throws IOException I/O error or HTTP response validation failure
268255
*/
269-
void put(String url, InputStream dataStream, Map<String, String> headers) throws IOException;
256+
void put(String url, InputStream dataStream, String contentType, Map<String, String> headers) throws IOException;
270257

271258
/**
272259
* Uses <code>PUT</code> to upload file to a server with specific contentType.
@@ -299,15 +286,6 @@ public interface Sardine
299286
*/
300287
void delete(String url) throws IOException;
301288

302-
/**
303-
* Delete a resource using HTTP <code>DELETE</code> at the specified url
304-
*
305-
* @param url Path to the resource including protocol and hostname
306-
* @param headers Additional HTTP headers to add to the request
307-
* @throws IOException I/O error or HTTP response validation failure
308-
*/
309-
void delete(String url, Map<String, String> headers) throws IOException;
310-
311289
/**
312290
* Uses WebDAV <code>MKCOL</code> to create a directory at the specified url
313291
*
@@ -365,17 +343,6 @@ public interface Sardine
365343
*/
366344
void copy(String sourceUrl, String destinationUrl, boolean overwrite) throws IOException;
367345

368-
/**
369-
* Copy a url from source to destination using WebDAV <code>COPY</code>.
370-
*
371-
* @param sourceUrl Path to the resource including protocol and hostname
372-
* @param destinationUrl Path to the resource including protocol and hostname
373-
* @param overwrite {@code true} to overwrite if the destination exists, {@code false} otherwise.
374-
* @param headers Additional HTTP headers to add to the request
375-
* @throws IOException I/O error or HTTP response validation failure
376-
*/
377-
void copy(String sourceUrl, String destinationUrl, boolean overwrite, Map<String, String> headers) throws IOException;
378-
379346
/**
380347
* Performs a HTTP <code>HEAD</code> request to see if a resource exists or not.
381348
*
@@ -479,6 +446,8 @@ public interface Sardine
479446
*/
480447
List<String> getPrincipalCollectionSet(String url) throws IOException;
481448

449+
void enableHttp2();
450+
482451
/**
483452
* <p>
484453
* Enables HTTP GZIP compression. If enabled, requests originating from Sardine

src/main/java/com/github/sardine/SardineFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ public static Sardine begin(String username, String password)
4141
*/
4242
public static Sardine begin(String username, String password, ProxySelector proxy)
4343
{
44-
return new SardineImpl(username, password, proxy);
44+
return new SardineImpl(username, password != null ? password.toCharArray() : null, proxy);
4545
}
46-
}
46+
}

src/main/java/com/github/sardine/ant/SardineTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void execute() throws BuildException {
101101
sardine = SardineFactory.begin(username, password);
102102
} else {
103103
sardine = SardineFactory.begin();
104-
sardine.setCredentials(username, password, domain, workstation);
104+
sardine.setCredentials(username, password.toCharArray(), domain, workstation);
105105
}
106106

107107
if (ignoreCookies) {

src/main/java/com/github/sardine/impl/SardineException.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
package com.github.sardine.impl;
1818

19-
import org.apache.http.client.HttpResponseException;
19+
20+
import org.apache.hc.client5.http.HttpResponseException;
2021

2122
/**
2223
* Specialized type of exception for Sardine so
@@ -56,4 +57,4 @@ public String getMessage()
5657
{
5758
return String.format("%s (%d %s)", super.getMessage(), this.getStatusCode(), this.getResponsePhrase());
5859
}
59-
}
60+
}

0 commit comments

Comments
 (0)