From 74141a9e2e188718677ba0b78b3df8a5e4182f9e Mon Sep 17 00:00:00 2001 From: Hariprasada Date: Fri, 2 Aug 2024 12:15:45 +0530 Subject: [PATCH 1/2] Implemented PATCH request support Signed-off-by: Hariprasada --- .../java/dev/galasa/http/IHttpClient.java | 14 +++++++++++- .../galasa/http/internal/HttpClientImpl.java | 10 +++++++++ .../http/internal/HttpClientRequest.java | 22 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/galasa-managers-parent/galasa-managers-comms-parent/dev.galasa.http.manager/src/main/java/dev/galasa/http/IHttpClient.java b/galasa-managers-parent/galasa-managers-comms-parent/dev.galasa.http.manager/src/main/java/dev/galasa/http/IHttpClient.java index 06438fb4f..efcc129ab 100644 --- a/galasa-managers-parent/galasa-managers-comms-parent/dev.galasa.http.manager/src/main/java/dev/galasa/http/IHttpClient.java +++ b/galasa-managers-parent/galasa-managers-comms-parent/dev.galasa.http.manager/src/main/java/dev/galasa/http/IHttpClient.java @@ -142,7 +142,19 @@ HttpClientResponse postXML(String url, String xml) */ HttpClientResponse 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 patchJson(String url, JsonObject json) throws HttpClientException; + + + /** * Issue an HTTP PUT to the provided URL, sending the provided * com.google.gson.JsonObject and receiving a com.google.gson.JsonObject in the response. * diff --git a/galasa-managers-parent/galasa-managers-comms-parent/dev.galasa.http.manager/src/main/java/dev/galasa/http/internal/HttpClientImpl.java b/galasa-managers-parent/galasa-managers-comms-parent/dev.galasa.http.manager/src/main/java/dev/galasa/http/internal/HttpClientImpl.java index 1fd6e86e3..bf249d304 100644 --- a/galasa-managers-parent/galasa-managers-comms-parent/dev.galasa.http.manager/src/main/java/dev/galasa/http/internal/HttpClientImpl.java +++ b/galasa-managers-parent/galasa-managers-comms-parent/dev.galasa.http.manager/src/main/java/dev/galasa/http/internal/HttpClientImpl.java @@ -180,6 +180,16 @@ public HttpClientResponse postJson(String url, JsonObject json) thro return executeJsonRequest(request); } + @Override + public HttpClientResponse 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 deleteJson(String url) throws HttpClientException { diff --git a/galasa-managers-parent/galasa-managers-comms-parent/dev.galasa.http.manager/src/main/java/dev/galasa/http/internal/HttpClientRequest.java b/galasa-managers-parent/galasa-managers-comms-parent/dev.galasa.http.manager/src/main/java/dev/galasa/http/internal/HttpClientRequest.java index b9d3c6957..bccfaa711 100644 --- a/galasa-managers-parent/galasa-managers-comms-parent/dev.galasa.http.manager/src/main/java/dev/galasa/http/internal/HttpClientRequest.java +++ b/galasa-managers-parent/galasa-managers-comms-parent/dev.galasa.http.manager/src/main/java/dev/galasa/http/internal/HttpClientRequest.java @@ -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; @@ -53,6 +54,7 @@ private enum RequestType { DELETE, PUT, POST, + PATCH, HEAD; } @@ -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); @@ -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 From 40b57e2fac5a4c9fa827d36b988fe785b2208b8e Mon Sep 17 00:00:00 2001 From: haripra86 <89834381+haripra86@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:06:26 +0530 Subject: [PATCH 2/2] Update build.gradle Signed-off-by: haripra86 <89834381+haripra86@users.noreply.github.com> --- .../dev.galasa.http.manager/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/galasa-managers-parent/galasa-managers-comms-parent/dev.galasa.http.manager/build.gradle b/galasa-managers-parent/galasa-managers-comms-parent/dev.galasa.http.manager/build.gradle index e667531c2..87667a94c 100644 --- a/galasa-managers-parent/galasa-managers-comms-parent/dev.galasa.http.manager/build.gradle +++ b/galasa-managers-parent/galasa-managers-comms-parent/dev.galasa.http.manager/build.gradle @@ -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'