From 20f5a4a523b284437dc7f76d2bc012ebb4cd669b Mon Sep 17 00:00:00 2001 From: su622b Date: Mon, 9 Apr 2018 14:47:27 -0400 Subject: Support for post without auth Issue-ID: DMAAP-399 Change-Id: I0e769c5554a8adf7a606bebe1c23b35fbab9c82c Signed-off-by: su622b --- pom.xml | 2 +- .../att/nsa/mr/client/impl/DmaapClientUtil.java | 5 +++++ .../com/att/nsa/mr/client/impl/MRBaseClient.java | 16 +++++++++++++++ .../mr/client/impl/MRSimplerBatchPublisher.java | 24 +++++++++++++++++++++- version.properties | 2 +- 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 4110471..9d7e3d2 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ org.onap.dmaap.messagerouter.dmaapclient dmaapClient jar - 1.1.4-SNAPSHOT + 1.1.5-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 6adf236..17a37d9 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 @@ -70,5 +70,10 @@ public class DmaapClientUtil { return target.request().get(); } + + public static Response postResponsewtNoAuth(WebTarget target, byte[] data, String contentType) { + return target.request().post(Entity.entity(data, contentType)); + + } } 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 b526fed..c7ca529 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 @@ -129,6 +129,22 @@ public class MRBaseClient extends HttpClient implements MRClient { "Authentication Failed: Username/password/AuthKey/AuthDate parameter(s) cannot be null or empty."); } } + + public String postNoAuthWithResponse(final String path, final byte[] data, String contentType) + throws HttpException, JSONException { + + String responseData = null; + WebTarget target = null; + Response response = null; + if (contentType == null) { + contentType = "text/pain"; + } + target = DmaapClientUtil.getTarget(path); + + response = DmaapClientUtil.postResponsewtNoAuth(target, data, contentType); + responseData = (String) response.readEntity(String.class); + return responseData; + } public JSONObject postAuth(final String path, final byte[] data, final String contentType, final String authKey, final String authDate, final String username, final String password, final String protocolFlag) diff --git a/src/main/java/com/att/nsa/mr/client/impl/MRSimplerBatchPublisher.java b/src/main/java/com/att/nsa/mr/client/impl/MRSimplerBatchPublisher.java index 77d47e8..6e1154f 100644 --- a/src/main/java/com/att/nsa/mr/client/impl/MRSimplerBatchPublisher.java +++ b/src/main/java/com/att/nsa/mr/client/impl/MRSimplerBatchPublisher.java @@ -530,6 +530,28 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP fPending.clear(); return pubResponse; } + + if (ProtocolTypeConstants.HTTPNOAUTH.getValue().equalsIgnoreCase(protocolFlag)) { + getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: " + + (nowMs - fPending.peek().timestamp) + " ms"); + final String result = postNoAuthWithResponse(httpurl, baseStream.toByteArray(), contentType); + + // Here we are checking for error response. If HTTP status + // code is not within the http success response code + // then we consider this as error and return false + pubResponse = createMRPublisherResponse(result, pubResponse); + + if (Integer.valueOf(pubResponse.getResponseCode()) < 200 + || Integer.valueOf(pubResponse.getResponseCode()) > 299) { + + return pubResponse; + } + + final String logLine = String.valueOf((Clock.now() - startMs)); + getLog().info(logLine); + fPending.clear(); + return pubResponse; + } } catch (IllegalArgumentException x) { getLog().warn(x.getMessage(), x); pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_BAD_REQUEST)); @@ -572,7 +594,7 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP return pubResponse; } - private MRPublisherResponse createMRPublisherResponse(String reply, MRPublisherResponse mrPubResponse) { + public MRPublisherResponse createMRPublisherResponse(String reply, MRPublisherResponse mrPubResponse) { if (reply.isEmpty()) { diff --git a/version.properties b/version.properties index e7654d1..7809677 100644 --- a/version.properties +++ b/version.properties @@ -27,7 +27,7 @@ major=1 minor=1 -patch=4 +patch=5 base_version=${major}.${minor}.${patch} -- cgit 1.2.3-korg