From 37b7b57fc51f25079b13a016945e5e1f318dc361 Mon Sep 17 00:00:00 2001 From: su622b Date: Mon, 9 Apr 2018 18:51:28 -0400 Subject: Support for post without auth Issue-ID: DMAAP-399 Change-Id: I51f1ff8ed978e3e00fccd63edf421c794f6e7f32 Signed-off-by: su622b --- .../java/com/att/nsa/mr/client/impl/MRBaseClient.java | 14 ++++++++++++++ .../att/nsa/mr/client/impl/MRSimplerBatchPublisher.java | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) 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 c7ca529..c3d1c26 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 @@ -109,6 +109,20 @@ public class MRBaseClient extends HttpClient implements MRClient { "Authentication Failed: Username/password/AuthKey/AuthDate parameter(s) cannot be null or empty."); } } + + public JSONObject postNoAuth(final String path, final byte[] data, String contentType) + throws HttpException, JSONException { + WebTarget target = null; + Response response = null; + if (contentType == null) { + contentType = "text/pain"; + } + target = DmaapClientUtil.getTarget(path); + + response = DmaapClientUtil.postResponsewtNoAuth(target, data, contentType); + + return getResponseDataInJson(response); + } public String postWithResponse(final String path, final byte[] data, final String contentType, 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 6e1154f..c034e4f 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 @@ -377,6 +377,23 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP fPending.clear(); return true; } + + if (ProtocolTypeConstants.HTTPNOAUTH.getValue().equalsIgnoreCase(protocolFlag)) { + getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: " + + (nowMs - fPending.peek().timestamp) + " ms"); + final JSONObject result = postNoAuth(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 + if (result.getInt("status") < 200 || result.getInt("status") > 299) { + return false; + } + final String logLine = "MR reply ok (" + (Clock.now() - startMs) + " ms):" + result.toString(); + getLog().info(logLine); + fPending.clear(); + return true; + } } catch (IllegalArgumentException x) { getLog().warn(x.getMessage(), x); } catch (IOException x) { -- cgit 1.2.3-korg