Skip to content

Commit 1da0330

Browse files
PetrusHaholdkocher
authored andcommitted
ApacheClient 5 + http2 support
1 parent d17b2e0 commit 1da0330

38 files changed

Lines changed: 490 additions & 533 deletions

pom.xml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@
293293
<maven.compiler.target>11</maven.compiler.target>
294294
<!-- Skip integration tests by default with failsafe plugin -->
295295
<skipITs>false</skipITs>
296-
<httpclient.version>4.5.14</httpclient.version>
296+
<httpclient.version>5.4.1</httpclient.version>
297+
<httpcore.version>5.3.2</httpcore.version>
297298
<slf4j.version>2.0.16</slf4j.version>
298299
</properties>
299300
<dependencyManagement>
@@ -312,10 +313,20 @@
312313
</dependencyManagement>
313314
<dependencies>
314315
<dependency>
315-
<groupId>org.apache.httpcomponents</groupId>
316-
<artifactId>httpclient</artifactId>
316+
<groupId>org.apache.httpcomponents.client5</groupId>
317+
<artifactId>httpclient5</artifactId>
317318
<version>${httpclient.version}</version>
318319
</dependency>
320+
<dependency>
321+
<groupId>org.apache.httpcomponents.core5</groupId>
322+
<artifactId>httpcore5</artifactId>
323+
<version>${httpcore.version}</version>
324+
</dependency>
325+
<dependency>
326+
<groupId>org.apache.httpcomponents.core5</groupId>
327+
<artifactId>httpcore5-h2</artifactId>
328+
<version>${httpcore.version}</version>
329+
</dependency>
319330
<!-- Sardine has a runtime dependency to JAXB. As this not part of JDK 11 anymore,
320331
we need a dependency on JAXB-->
321332
<dependency>

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

Lines changed: 10 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;
@@ -172,7 +173,9 @@ private int getStatusCode(Response response)
172173
for(Propstat propstat : list) {
173174
if(propstat.getStatus() != null) {
174175
try {
175-
return BasicLineParser.parseStatusLine(propstat.getStatus(), null).getStatusCode();
176+
CharArrayBuffer buffer = new CharArrayBuffer(propstat.getStatus().length());
177+
buffer.append(propstat.getStatus());
178+
return new BasicLineParser().parseStatusLine(buffer).getStatusCode();
176179
}
177180
catch(ParseException e) {
178181
log.warning(String.format("Failed to parse status line: %s", propstat.getStatus()));
@@ -187,7 +190,9 @@ private int getStatusCode(Response response)
187190
}
188191
try
189192
{
190-
return BasicLineParser.parseStatusLine(response.getStatus(), null).getStatusCode();
193+
CharArrayBuffer buffer = new CharArrayBuffer(response.getStatus().length());
194+
buffer.append(response.getStatus());
195+
return new BasicLineParser().parseStatusLine(buffer).getStatusCode();
191196
}
192197
catch (ParseException e)
193198
{

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)
@@ -192,18 +190,6 @@ public interface Sardine
192190
*/
193191
List<DavResource> patch(String url, List<Element> addProps, List<QName> removeProps) throws IOException;
194192

195-
/**
196-
* Add or remove custom properties for a url using WebDAV <code>PROPPATCH</code>.
197-
*
198-
* @param url Path to the resource including protocol and hostname
199-
* @param addProps Properties to add to resource. If a property already exists then its value is replaced.
200-
* @param removeProps Properties to remove from resource. Specifying the removal of a property that does not exist is not an error.
201-
* @param headers Additional HTTP headers to add to the request
202-
* @return The patched resources from the response
203-
* @throws IOException I/O error or HTTP response validation failure
204-
*/
205-
List<DavResource> patch(String url, List<Element> addProps, List<QName> removeProps, Map<String, String> headers) throws IOException;
206-
207193
/**
208194
* Uses HTTP <code>GET</code> to download data from a server. The stream must be closed after reading.
209195
*
@@ -305,10 +291,11 @@ public interface Sardine
305291
*
306292
* @param url Path to the resource including protocol and hostname (must not point to a directory)
307293
* @param dataStream Input source
294+
* @param contentType MIME type to add to the HTTP request header
308295
* @param headers Additional HTTP headers to add to the request
309296
* @throws IOException I/O error or HTTP response validation failure
310297
*/
311-
void put(String url, InputStream dataStream, Map<String, String> headers) throws IOException;
298+
void put(String url, InputStream dataStream, String contentType, Map<String, String> headers) throws IOException;
312299

313300
/**
314301
* Uses <code>PUT</code> to upload file to a server with specific contentType.
@@ -341,15 +328,6 @@ public interface Sardine
341328
*/
342329
void delete(String url) throws IOException;
343330

344-
/**
345-
* Delete a resource using HTTP <code>DELETE</code> at the specified url
346-
*
347-
* @param url Path to the resource including protocol and hostname
348-
* @param headers Additional HTTP headers to add to the request
349-
* @throws IOException I/O error or HTTP response validation failure
350-
*/
351-
void delete(String url, Map<String, String> headers) throws IOException;
352-
353331
/**
354332
* Uses WebDAV <code>MKCOL</code> to create a directory at the specified url
355333
*
@@ -407,17 +385,6 @@ public interface Sardine
407385
*/
408386
void copy(String sourceUrl, String destinationUrl, boolean overwrite) throws IOException;
409387

410-
/**
411-
* Copy a url from source to destination using WebDAV <code>COPY</code>.
412-
*
413-
* @param sourceUrl Path to the resource including protocol and hostname
414-
* @param destinationUrl Path to the resource including protocol and hostname
415-
* @param overwrite {@code true} to overwrite if the destination exists, {@code false} otherwise.
416-
* @param headers Additional HTTP headers to add to the request
417-
* @throws IOException I/O error or HTTP response validation failure
418-
*/
419-
void copy(String sourceUrl, String destinationUrl, boolean overwrite, Map<String, String> headers) throws IOException;
420-
421388
/**
422389
* Performs a HTTP <code>HEAD</code> request to see if a resource exists or not.
423390
*
@@ -548,6 +515,8 @@ public interface Sardine
548515
*/
549516
List<String> getPrincipalCollectionSet(String url) throws IOException;
550517

518+
void enableHttp2();
519+
551520
/**
552521
* <p>
553522
* 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)