Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Implemented PATCH request support #968

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,19 @@ HttpClientResponse<String> postXML(String url, String xml)
*/
HttpClientResponse<JsonObject> postJson(String url, JsonObject json) throws HttpClientException;

/**
/**
* Issue an HTTP PATCH to the provided URL, sending the provided
* com.google.gson.JsonObject and receiving a com.google.gson.JsonObject in the response.
*
* @param url
* @param json
* @return - {@link HttpClientResponse} with a com.google.gson.JsonObject content type
* @throws HttpClientException
*/
HttpClientResponse<JsonObject> patchJson(String url, JsonObject json) throws HttpClientException;


/**
* Issue an HTTP PUT to the provided URL, sending the provided
* <code>com.google.gson.JsonObject</code> and receiving a <code>com.google.gson.JsonObject</code> in the response.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ public HttpClientResponse<JsonObject> postJson(String url, JsonObject json) thro
return executeJsonRequest(request);
}

@Override
public HttpClientResponse<JsonObject> patchJson(String url, JsonObject json) throws HttpClientException {

HttpClientRequest request = HttpClientRequest.newPatchRequest(buildUri(url, null).toString(),
new ContentType[] { ContentType.APPLICATION_JSON }, ContentType.APPLICATION_JSON);
request.setJSONBody(json);

return executeJsonRequest(request);
}

@Override
public HttpClientResponse<JsonObject> deleteJson(String url) throws HttpClientException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpPatch;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ByteArrayEntity;
Expand Down Expand Up @@ -53,6 +54,7 @@ private enum RequestType {
DELETE,
PUT,
POST,
PATCH,
HEAD;
}

Expand Down Expand Up @@ -275,6 +277,9 @@ HttpUriRequest buildRequest() throws HttpClientException {
case HEAD:
request = new HttpHead(uri);
break;
case PATCH:
request = new HttpPatch(uri);
break;
case GET:
default:
request = new HttpGet(uri);
Expand Down Expand Up @@ -377,6 +382,23 @@ public static HttpClientRequest newPostRequest(String url, ContentType[] acceptT

return request;
}
/**
* Create a new PATCH request
*
* @param url
* @param acceptTypes
* @param contentType
* @return new POST request
*/
public static HttpClientRequest newPatchRequest(String url, ContentType[] acceptTypes, ContentType contentType) {

HttpClientRequest request = new HttpClientRequest(RequestType.PATCH);
request.setUrl(url);
request.setAcceptTypes(acceptTypes);
request.setContentType(contentType);

return request;
}

/**
* Create a new HEAD request
Expand Down