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

Commit

Permalink
Merge pull request #968 from haripra86/story/hariprasad/galasa-story-…
Browse files Browse the repository at this point in the history
…1951

Implemented PATCH request support
  • Loading branch information
techcobweb authored Aug 7, 2024
2 parents 72c74f0 + 37f0e82 commit 613d3b8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

description = 'HTTP Manager'

version = '0.34.0'
version = '0.36.0'

dependencies {
api 'org.apache.httpcomponents:httpclient-osgi:4.5.13'
Expand Down
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

0 comments on commit 613d3b8

Please sign in to comment.