Skip to content

Commit

Permalink
ApacheClient 5 + http2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrusHahol committed Aug 20, 2024
1 parent fa17c2e commit 948c524
Show file tree
Hide file tree
Showing 35 changed files with 480 additions and 519 deletions.
16 changes: 13 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
<maven.compiler.target>8</maven.compiler.target>
<!-- Skip integration tests by default with failsafe plugin -->
<skipITs>false</skipITs>
<httpclient.version>4.5.14</httpclient.version>
<httpclient.version>5.1</httpclient.version>
<slf4j.version>2.0.13</slf4j.version>
</properties>
<dependencyManagement>
Expand All @@ -277,8 +277,18 @@
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5-h2</artifactId>
<version>${httpclient.version}</version>
</dependency>
<!-- Sardine has a runtime dependency to JAXB. As this not part of JDK 11 anymore,
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/github/sardine/DavResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@

import javax.xml.namespace.QName;

import org.apache.http.HttpStatus;
import org.apache.http.ParseException;
import org.apache.http.message.BasicLineParser;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.ParseException;
import org.apache.hc.core5.http.message.BasicLineParser;
import org.apache.hc.core5.util.CharArrayBuffer;
import org.w3c.dom.Element;

import com.github.sardine.model.Creationdate;
Expand Down Expand Up @@ -175,8 +176,9 @@ private int getStatusCode(Response response)
}
try
{
return BasicLineParser.parseStatusLine(response.getStatus(), null).getStatusCode();
}
CharArrayBuffer buffer = new CharArrayBuffer(response.getStatus().length());
buffer.append(response.getStatus());
return new BasicLineParser().parseStatusLine(buffer).getStatusCode(); }
catch (ParseException e)
{
log.warning(String.format("Failed to parse status line: %s", status));
Expand Down
45 changes: 7 additions & 38 deletions src/main/java/com/github/sardine/Sardine.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.xml.namespace.QName;

import org.w3c.dom.Element;

import com.github.sardine.report.SardineReport;
import org.w3c.dom.Element;

/**
* The main interface for Sardine operations.
Expand All @@ -27,15 +25,15 @@ public interface Sardine
* @param username Use in authentication header credentials
* @param password Use in authentication header credentials
*/
void setCredentials(String username, String password);
void setCredentials(String username, char[] password);

/**
* @param username Use in authentication header credentials
* @param password Use in authentication header credentials
* @param domain NTLM authentication
* @param workstation NTLM authentication
*/
void setCredentials(String username, String password, String domain, String workstation);
void setCredentials(String username, char[] password, String domain, String workstation);

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

/**
* Add or remove custom properties for a url using WebDAV <code>PROPPATCH</code>.
*
* @param url Path to the resource including protocol and hostname
* @param addProps Properties to add to resource. If a property already exists then its value is replaced.
* @param removeProps Properties to remove from resource. Specifying the removal of a property that does not exist is not an error.
* @param headers Additional HTTP headers to add to the request
* @return The patched resources from the response
* @throws IOException I/O error or HTTP response validation failure
*/
List<DavResource> patch(String url, List<Element> addProps, List<QName> removeProps, Map<String, String> headers) throws IOException;

/**
* Uses HTTP <code>GET</code> to download data from a server. The stream must be closed after reading.
*
Expand Down Expand Up @@ -263,10 +249,11 @@ public interface Sardine
*
* @param url Path to the resource including protocol and hostname (must not point to a directory)
* @param dataStream Input source
* @param contentType MIME type to add to the HTTP request header
* @param headers Additional HTTP headers to add to the request
* @throws IOException I/O error or HTTP response validation failure
*/
void put(String url, InputStream dataStream, Map<String, String> headers) throws IOException;
void put(String url, InputStream dataStream, String contentType, Map<String, String> headers) throws IOException;

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

/**
* Delete a resource using HTTP <code>DELETE</code> at the specified url
*
* @param url Path to the resource including protocol and hostname
* @param headers Additional HTTP headers to add to the request
* @throws IOException I/O error or HTTP response validation failure
*/
void delete(String url, Map<String, String> headers) throws IOException;

/**
* Uses WebDAV <code>MKCOL</code> to create a directory at the specified url
*
Expand Down Expand Up @@ -365,17 +343,6 @@ public interface Sardine
*/
void copy(String sourceUrl, String destinationUrl, boolean overwrite) throws IOException;

/**
* Copy a url from source to destination using WebDAV <code>COPY</code>.
*
* @param sourceUrl Path to the resource including protocol and hostname
* @param destinationUrl Path to the resource including protocol and hostname
* @param overwrite {@code true} to overwrite if the destination exists, {@code false} otherwise.
* @param headers Additional HTTP headers to add to the request
* @throws IOException I/O error or HTTP response validation failure
*/
void copy(String sourceUrl, String destinationUrl, boolean overwrite, Map<String, String> headers) throws IOException;

/**
* Performs a HTTP <code>HEAD</code> request to see if a resource exists or not.
*
Expand Down Expand Up @@ -479,6 +446,8 @@ public interface Sardine
*/
List<String> getPrincipalCollectionSet(String url) throws IOException;

void enableHttp2();

/**
* <p>
* Enables HTTP GZIP compression. If enabled, requests originating from Sardine
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/github/sardine/SardineFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public static Sardine begin(String username, String password)
*/
public static Sardine begin(String username, String password, ProxySelector proxy)
{
return new SardineImpl(username, password, proxy);
return new SardineImpl(username, password != null ? password.toCharArray() : null, proxy);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/github/sardine/ant/SardineTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void execute() throws BuildException {
sardine = SardineFactory.begin(username, password);
} else {
sardine = SardineFactory.begin();
sardine.setCredentials(username, password, domain, workstation);
sardine.setCredentials(username, password.toCharArray(), domain, workstation);
}

if (ignoreCookies) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/github/sardine/impl/SardineException.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package com.github.sardine.impl;

import org.apache.http.client.HttpResponseException;

import org.apache.hc.client5.http.HttpResponseException;

/**
* Specialized type of exception for Sardine so
Expand Down Expand Up @@ -56,4 +57,4 @@ public String getMessage()
{
return String.format("%s (%d %s)", super.getMessage(), this.getStatusCode(), this.getResponsePhrase());
}
}
}
Loading

0 comments on commit 948c524

Please sign in to comment.