Skip to content
Open
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
40 changes: 38 additions & 2 deletions src/com/androidquery/AbstractAQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -2159,8 +2159,44 @@ public <K> T put(String url, JSONObject jo, Class<K> type, AjaxCallback<K> callb


}



/**
* Ajax HTTP patch.
*
* The handler signature must be (String url, <K> object, AjaxStatus status)
*
* @param url url
* @param contentHeader Content header
* @param entity entity
* @param type reponse type
* @param callback callback method name
* @return self
*/
public <K> T patch(String url, String contentHeader, HttpEntity entity, Class<K> type, AjaxCallback<K> callback) {
callback.url(url).type(type).method(AQuery.METHOD_PATCH).header("Content-Type", contentHeader).param(AQuery.POST_ENTITY, entity);
return ajax(callback);
}

/**
* Ajax HTTP patch.
*
* The handler signature must be (String url, <K> object, AjaxStatus status)
*
* @param url url
* @param jo JSON object
* @param type reponse type
* @param callback callback method name
* @return self
*/
public <K> T patch(String url, JSONObject jo, Class<K> type, AjaxCallback<K> callback) {
try {
StringEntity entity = new StringEntity(jo.toString(), "UTF-8");
return patch(url, "application/json", entity, type, callback);
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException(e);
}
}


/**
* Ajax HTTP delete.
Expand Down
18 changes: 15 additions & 3 deletions src/com/androidquery/callback/AbstractAjaxCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
import com.androidquery.util.AQUtility;
import com.androidquery.util.Common;
import com.androidquery.util.Constants;
import com.androidquery.util.HttpPatch;
import com.androidquery.util.PredefinedBAOS;
import com.androidquery.util.Progress;
import com.androidquery.util.XmlDom;
Expand Down Expand Up @@ -1364,7 +1365,9 @@ private void network() throws IOException{
}else{
if(isMultiPart(params)){
httpMulti(url, params, status);
}else{
}else if (Constants.METHOD_PATCH == method){
httpPatch(url, params, status);
} else {
httpPost(url, params, status);
}

Expand Down Expand Up @@ -1495,8 +1498,17 @@ private void httpPut(String url, Map<String, Object> params, AjaxStatus status)
httpEntity(url, req, params, status);

}



private void httpPatch(String url, Map<String, Object> params, AjaxStatus status) throws ClientProtocolException, IOException{

AQUtility.debug("patch", url);

HttpEntityEnclosingRequestBase req = new HttpPatch(url);

httpEntity(url, req, params, status);

}

private void httpEntity(String url, HttpEntityEnclosingRequestBase req, Map<String, Object> params, AjaxStatus status) throws ClientProtocolException, IOException{

//This setting seems to improve post performance
Expand Down
3 changes: 2 additions & 1 deletion src/com/androidquery/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public interface Constants {
public static final int METHOD_DELETE = 2;
public static final int METHOD_PUT = 3;
public static final int METHOD_DETECT = 4;

public static final int METHOD_PATCH = 5;

public static final int TAG_URL = 0x40FF0001;
public static final int TAG_SCROLL_LISTENER = 0x40FF0002;
public static final int TAG_LAYOUT = 0x40FF0003;
Expand Down
16 changes: 16 additions & 0 deletions src/com/androidquery/util/HttpPatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.androidquery.util;

import org.apache.http.client.methods.HttpPost;

public class HttpPatch extends HttpPost {
public static final String METHOD_PATCH = "PATCH";

public HttpPatch(final String url) {
super(url);
}

@Override
public String getMethod() {
return METHOD_PATCH;
}
}