From 6d6872adb775dcf6baabd4b2e80e36796b538af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Apontes?= Date: Tue, 2 Jan 2024 17:00:00 -0300 Subject: [PATCH 1/3] HttpQuery: Allow using http method DELETE. --- .../src/main/java/org/jpos/http/client/HttpQuery.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/http-client/src/main/java/org/jpos/http/client/HttpQuery.java b/modules/http-client/src/main/java/org/jpos/http/client/HttpQuery.java index 4ab3c360a4..268981d9d7 100644 --- a/modules/http-client/src/main/java/org/jpos/http/client/HttpQuery.java +++ b/modules/http-client/src/main/java/org/jpos/http/client/HttpQuery.java @@ -374,6 +374,8 @@ private HttpRequestBase getHttpRequest(Context ctx) { return put; case "GET": return new HttpGet(url); + case "DELETE": + return new HttpDelete(url); } ctx.log ("Invalid request method"); return null; From b1396c72106119983fa6dd52d68d1fb258202e85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Apontes?= Date: Wed, 3 Jan 2024 11:17:29 -0300 Subject: [PATCH 2/3] HttpQuery: Allow http method PATCH. Code reusability. --- .../java/org/jpos/http/client/HttpQuery.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/modules/http-client/src/main/java/org/jpos/http/client/HttpQuery.java b/modules/http-client/src/main/java/org/jpos/http/client/HttpQuery.java index 268981d9d7..c85733b672 100644 --- a/modules/http-client/src/main/java/org/jpos/http/client/HttpQuery.java +++ b/modules/http-client/src/main/java/org/jpos/http/client/HttpQuery.java @@ -31,6 +31,7 @@ import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.*; +import java.util.function.Consumer; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; @@ -356,26 +357,32 @@ private String getURL (Context ctx) { return sb.toString(); } - private HttpRequestBase getHttpRequest(Context ctx) { + private HttpRequestBase getHttpRequest(Context ctx) { + Consumer setBody = (HttpEntityEnclosingRequestBase request) -> { + String payload = ctx.getString(requestName); + if (payload != null) { + request.setEntity(new StringEntity(payload, getContentType(ctx))); + } + }; String url = getURL(ctx); String payload; switch (ctx.getString(methodName)) { case "POST": HttpPost post = new HttpPost(url); - payload = ctx.getString(requestName); - if (payload != null) - post.setEntity(new StringEntity(payload, getContentType(ctx))); + setBody.accept(post); return post; case "PUT": HttpPut put = new HttpPut(url); - payload = ctx.getString(requestName); - if (payload != null) - put.setEntity(new StringEntity(payload, getContentType(ctx))); + setBody.accept(put); return put; case "GET": return new HttpGet(url); case "DELETE": return new HttpDelete(url); + case "PATCH": + HttpPatch patch = new HttpPatch(url); + setBody.accept(patch); + return patch; } ctx.log ("Invalid request method"); return null; From 429a83b403926ac09665ad27aa2df9e24feca898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Apontes?= Date: Wed, 3 Jan 2024 11:19:46 -0300 Subject: [PATCH 3/3] HttpQuery: Clean whitespaces. --- .../src/main/java/org/jpos/http/client/HttpQuery.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/http-client/src/main/java/org/jpos/http/client/HttpQuery.java b/modules/http-client/src/main/java/org/jpos/http/client/HttpQuery.java index c85733b672..ccf040b42b 100644 --- a/modules/http-client/src/main/java/org/jpos/http/client/HttpQuery.java +++ b/modules/http-client/src/main/java/org/jpos/http/client/HttpQuery.java @@ -357,7 +357,7 @@ private String getURL (Context ctx) { return sb.toString(); } - private HttpRequestBase getHttpRequest(Context ctx) { + private HttpRequestBase getHttpRequest(Context ctx) { Consumer setBody = (HttpEntityEnclosingRequestBase request) -> { String payload = ctx.getString(requestName); if (payload != null) {