Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Apache HttpComponents Client dependency adding support for HTTP2. #515

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
17 changes: 14 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@
<maven.compiler.target>11</maven.compiler.target>
<!-- Skip integration tests by default with failsafe plugin -->
<skipITs>false</skipITs>
<httpclient.version>4.5.14</httpclient.version>
<httpclient.version>5.4.1</httpclient.version>
<httpcore.version>5.3.2</httpcore.version>
<slf4j.version>2.0.16</slf4j.version>
</properties>
<dependencyManagement>
Expand All @@ -312,10 +313,20 @@
</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>${httpcore.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5-h2</artifactId>
<version>${httpcore.version}</version>
</dependency>
<!-- Sardine has a runtime dependency to JAXB. As this not part of JDK 11 anymore,
we need a dependency on JAXB-->
<dependency>
Expand Down
15 changes: 10 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 @@ -172,7 +173,9 @@ private int getStatusCode(Response response)
for(Propstat propstat : list) {
if(propstat.getStatus() != null) {
try {
return BasicLineParser.parseStatusLine(propstat.getStatus(), null).getStatusCode();
CharArrayBuffer buffer = new CharArrayBuffer(propstat.getStatus().length());
buffer.append(propstat.getStatus());
return new BasicLineParser().parseStatusLine(buffer).getStatusCode();
}
catch(ParseException e) {
log.warning(String.format("Failed to parse status line: %s", propstat.getStatus()));
Expand All @@ -187,7 +190,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)
{
Expand Down
27 changes: 23 additions & 4 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,16 +25,34 @@ public interface Sardine
* @param username Use in authentication header credentials
* @param password Use in authentication header credentials
*/
@Deprecated
void setCredentials(String username, String password);

/**
* Add credentials to any scope.
*
* @param username Use in authentication header credentials
* @param password Use in authentication header credentials
*/
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
*/
@Deprecated
void setCredentials(String username, String password, String domain, String workstation);

/**
* @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, char[] password, String domain, String workstation);

/**
* @see #list(String)
*/
Expand Down Expand Up @@ -305,10 +321,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 @@ -548,6 +565,8 @@ public interface Sardine
*/
List<String> getPrincipalCollectionSet(String url) throws IOException;

void enableHttp2();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Javadoc describing implications.


/**
* <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
Loading