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

Feature/apache client5 #515

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 7 additions & 6 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 @@ -263,10 +261,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 @@ -479,6 +478,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