Skip to content

Commit

Permalink
added abort
Browse files Browse the repository at this point in the history
  • Loading branch information
aflx committed Feb 20, 2012
1 parent 2212951 commit ce1380b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/de/aflx/sardine/Sardine.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
*/
public interface Sardine
{
void abort();

boolean isAborted();

/**
* Add credentials to any scope.
*
Expand Down
32 changes: 21 additions & 11 deletions src/de/aflx/sardine/impl/SardineImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
import java.util.List;
import java.util.Map;

//import javax.xml.namespace.QName;
import de.aflx.sardine.util.QName;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
//import org.apache.http.HttpHeaders;
import org.apache.http.HttpException;
Expand All @@ -39,7 +37,6 @@
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.ProtocolException;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.AuthState;
import org.apache.http.auth.Credentials;
Expand All @@ -54,7 +51,6 @@
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.params.AuthPolicy;
import org.apache.http.client.protocol.ClientContext;
//import org.apache.http.client.protocol.RequestAcceptEncoding;
Expand All @@ -76,7 +72,6 @@
import org.apache.http.impl.conn.ProxySelectorRoutePlanner;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
Expand All @@ -85,7 +80,6 @@
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.VersionInfo;
import org.simpleframework.xml.Element;

import de.aflx.sardine.DavResource;
import de.aflx.sardine.Sardine;
Expand All @@ -100,20 +94,15 @@
import de.aflx.sardine.impl.methods.HttpMkCol;
import de.aflx.sardine.impl.methods.HttpMove;
import de.aflx.sardine.impl.methods.HttpPropFind;
import de.aflx.sardine.impl.methods.HttpPropPatch;
import de.aflx.sardine.impl.methods.HttpUnlock;
import de.aflx.sardine.model.Allprop;
import de.aflx.sardine.model.Exclusive;
import de.aflx.sardine.model.Lockinfo;
import de.aflx.sardine.model.Lockscope;
import de.aflx.sardine.model.Locktype;
import de.aflx.sardine.model.Multistatus;
import de.aflx.sardine.model.Prop;
import de.aflx.sardine.model.Propertyupdate;
import de.aflx.sardine.model.Propfind;
import de.aflx.sardine.model.Remove;
import de.aflx.sardine.model.Response;
import de.aflx.sardine.model.Set;
import de.aflx.sardine.model.Write;
import de.aflx.sardine.util.Logger;
import de.aflx.sardine.util.SardineUtil;
Expand All @@ -130,6 +119,9 @@ public class SardineImpl implements Sardine {

private static final String UTF_8 = "UTF-8";

protected HttpRequestBase _currentRequest;
protected boolean _isAborted = false;

/**
* HTTP Implementation
*/
Expand Down Expand Up @@ -251,6 +243,19 @@ private void init(AbstractHttpClient http, String username, String password) {
log.warn("init");
}

public HttpRequestBase getCurrentRequest() {
return _currentRequest;
}

public void abort() {
_isAborted = true;
_currentRequest.abort();
}

public boolean isAborted() {
return _isAborted;
}

/**
* Add credentials to any scope. Supports Basic, Digest and NTLM
* authentication methods.
Expand Down Expand Up @@ -655,7 +660,11 @@ public void put(String url, HttpEntity entity, String contentType,
*/
public void put(String url, HttpEntity entity, Map<String, String> headers)
throws IOException {

HttpPut put = new HttpPut(url);
_currentRequest = put;
_isAborted = false;

put.setEntity(entity);
for (String header : headers.keySet()) {
put.addHeader(header, headers.get(header));
Expand All @@ -674,6 +683,7 @@ public void put(String url, HttpEntity entity, Map<String, String> headers)
return;
}
}

throw e;
}
}
Expand Down

0 comments on commit ce1380b

Please sign in to comment.