From 5519f8372acf8d4f573739b8e819f7a1e569a019 Mon Sep 17 00:00:00 2001 From: su622b Date: Wed, 11 Apr 2018 19:56:37 -0400 Subject: support for post requests with auth Issue-ID: DMAAP-404 Change-Id: Iaa85ab5410472fca4dd6118d2a53efc1737609d5 Signed-off-by: su622b --- pom.xml | 2 +- src/main/java/com/att/nsa/mr/client/impl/DmaapClientUtil.java | 6 ++++++ src/main/java/com/att/nsa/mr/client/impl/MRBaseClient.java | 4 ++-- src/test/java/com/att/nsa/mr/client/impl/MRBaseClientTest.java | 8 ++++---- version.properties | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 9d7e3d2..c903d66 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ org.onap.dmaap.messagerouter.dmaapclient dmaapClient jar - 1.1.5-SNAPSHOT + 1.1.6-SNAPSHOT dmaap-messagerouter-dmaapclient Client library for MR event routing API https://github.com/att/dmaap-framework diff --git a/src/main/java/com/att/nsa/mr/client/impl/DmaapClientUtil.java b/src/main/java/com/att/nsa/mr/client/impl/DmaapClientUtil.java index 17a37d9..a3a2ce1 100644 --- a/src/main/java/com/att/nsa/mr/client/impl/DmaapClientUtil.java +++ b/src/main/java/com/att/nsa/mr/client/impl/DmaapClientUtil.java @@ -64,6 +64,12 @@ public class DmaapClientUtil { return target.request().header("Authorization", "Basic " + authHeader).get(); } + + public static Response postResponsewtBasicAuth(WebTarget target, String authHeader,byte[] data,String contentType) { + + return target.request().header("Authorization", "Basic " + authHeader).post(Entity.entity(data, contentType)); + + } public static Response getResponsewtNoAuth(WebTarget target) { diff --git a/src/main/java/com/att/nsa/mr/client/impl/MRBaseClient.java b/src/main/java/com/att/nsa/mr/client/impl/MRBaseClient.java index c3d1c26..a0c514c 100644 --- a/src/main/java/com/att/nsa/mr/client/impl/MRBaseClient.java +++ b/src/main/java/com/att/nsa/mr/client/impl/MRBaseClient.java @@ -101,7 +101,7 @@ public class MRBaseClient extends HttpClient implements MRClient { target = DmaapClientUtil.getTarget(path, username, password); String encoding = Base64.encodeAsString(username + ":" + password); - response = DmaapClientUtil.getResponsewtBasicAuth(target, encoding); + response = DmaapClientUtil.postResponsewtBasicAuth(target, encoding,data, contentType); return getResponseDataInJson(response); } else { @@ -134,7 +134,7 @@ public class MRBaseClient extends HttpClient implements MRClient { target = DmaapClientUtil.getTarget(path, username, password); String encoding = Base64.encodeAsString(username + ":" + password); - response = DmaapClientUtil.getResponsewtBasicAuth(target, encoding); + response = DmaapClientUtil.postResponsewtBasicAuth(target, encoding,data, contentType); responseData = (String)response.readEntity(String.class); return responseData; diff --git a/src/test/java/com/att/nsa/mr/client/impl/MRBaseClientTest.java b/src/test/java/com/att/nsa/mr/client/impl/MRBaseClientTest.java index b05cc7f..56cf954 100644 --- a/src/test/java/com/att/nsa/mr/client/impl/MRBaseClientTest.java +++ b/src/test/java/com/att/nsa/mr/client/impl/MRBaseClientTest.java @@ -305,8 +305,8 @@ public class MRBaseClientTest { PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}"); PowerMockito.when(response.getHeaders()).thenReturn(map); - PowerMockito.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"), - Base64.encodeAsString("username:password"))).thenReturn(response); + PowerMockito.when(DmaapClientUtil.postResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"), + Base64.encodeAsString("username:password"), new String("{\"test\":\"test\"}").getBytes(), "application/json")).thenReturn(response); mrBaseClient.post("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", "username", "password", "HTTPAUTH"); @@ -378,8 +378,8 @@ public class MRBaseClientTest { PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}"); PowerMockito.when(response.getHeaders()).thenReturn(map); - PowerMockito.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"), - Base64.encodeAsString("username:password"))).thenReturn(response); + PowerMockito.when(DmaapClientUtil.postResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"), + Base64.encodeAsString("username:password"), new String("{\"test\":\"test\"}").getBytes(), "application/json")).thenReturn(response); mrBaseClient.postWithResponse("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", "username", "password", "HTTPAUTH"); diff --git a/version.properties b/version.properties index 7809677..ccd6e4a 100644 --- a/version.properties +++ b/version.properties @@ -27,7 +27,7 @@ major=1 minor=1 -patch=5 +patch=6 base_version=${major}.${minor}.${patch} -- cgit 1.2.3-korg