aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/dmaap/mr/client/impl/MRBaseClient.java19
-rw-r--r--src/main/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisher.java34
-rw-r--r--src/main/java/org/onap/dmaap/mr/client/impl/PostAuthDataObject.java105
3 files changed, 133 insertions, 25 deletions
diff --git a/src/main/java/org/onap/dmaap/mr/client/impl/MRBaseClient.java b/src/main/java/org/onap/dmaap/mr/client/impl/MRBaseClient.java
index 8ed7dd8..4c6d74e 100644
--- a/src/main/java/org/onap/dmaap/mr/client/impl/MRBaseClient.java
+++ b/src/main/java/org/onap/dmaap/mr/client/impl/MRBaseClient.java
@@ -160,16 +160,17 @@ public class MRBaseClient extends HttpClient implements MRClient {
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)
+ public JSONObject postAuth(PostAuthDataObject postAuthDO)
throws HttpException, JSONException {
- if ((null != username && null != password)) {
- WebTarget target=null;
- Response response=null;
- target = DmaapClientUtil.getTarget(path, username, password);
- response =DmaapClientUtil.postResponsewtCambriaAuth(target, authKey, authDate, data, contentType);
- return getResponseDataInJson(response);
- } else {
+ if ((null != postAuthDO.getUsername() && null != postAuthDO.getPassword())) {
+ WebTarget target = null;
+ Response response = null;
+ target = DmaapClientUtil.getTarget(postAuthDO.getPath(), postAuthDO.getUsername(),
+ postAuthDO.getPassword());
+ response = DmaapClientUtil.postResponsewtCambriaAuth(target, postAuthDO.getAuthKey(),
+ postAuthDO.getAuthDate(), postAuthDO.getData(), postAuthDO.getContentType());
+ return getResponseDataInJson(response);
+ } else {
throw new HttpException(
"Authentication Failed: Username/password/AuthKey/AuthDate parameter(s) cannot be null or empty.");
}
diff --git a/src/main/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisher.java b/src/main/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisher.java
index c5eb3ba..4d9ab8d 100644
--- a/src/main/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisher.java
+++ b/src/main/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisher.java
@@ -352,22 +352,24 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP
return true;
}
- if (ProtocolTypeConstants.AUTH_KEY.getValue().equalsIgnoreCase(protocolFlag)) {
- getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: "
- + (nowMs - fPending.peek().timestamp) + " ms");
- final JSONObject result = postAuth(httpurl, baseStream.toByteArray(), contentType, authKey, authDate,
- username, password, protocolFlag);
- // 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;
- }
+ if (ProtocolTypeConstants.AUTH_KEY.getValue().equalsIgnoreCase(protocolFlag)) {
+ getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: "
+ + (nowMs - fPending.peek().timestamp) + " ms");
+ final JSONObject result =
+ postAuth(new PostAuthDataObject().setPath(httpurl).setData(baseStream.toByteArray())
+ .setContentType(contentType).setAuthKey(authKey).setAuthDate(authDate)
+ .setUsername(username).setPassword(password).setProtocolFlag(protocolFlag));
+ // 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;
+ }
if (ProtocolTypeConstants.AAF_AUTH.getValue().equalsIgnoreCase(protocolFlag)) {
getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: "
diff --git a/src/main/java/org/onap/dmaap/mr/client/impl/PostAuthDataObject.java b/src/main/java/org/onap/dmaap/mr/client/impl/PostAuthDataObject.java
new file mode 100644
index 0000000..9fa3a5f
--- /dev/null
+++ b/src/main/java/org/onap/dmaap/mr/client/impl/PostAuthDataObject.java
@@ -0,0 +1,105 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Samsung Electronics Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dmaap.mr.client.impl;
+
+public class PostAuthDataObject {
+
+ private String path;
+ private byte[] data;
+ private String contentType;
+ private String authKey;
+ private String authDate;
+ private String username;
+ private String password;
+ private String protocolFlag;
+
+ public String getPath() {
+ return path;
+ }
+
+ public PostAuthDataObject setPath(String path) {
+ this.path = path;
+ return this;
+ }
+
+ public byte[] getData() {
+ return data;
+ }
+
+ public PostAuthDataObject setData(byte[] data) {
+ this.data = data;
+ return this;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ public PostAuthDataObject setContentType(String contentType) {
+ this.contentType = contentType;
+ return this;
+ }
+
+ public String getAuthKey() {
+ return authKey;
+ }
+
+ public PostAuthDataObject setAuthKey(String authKey) {
+ this.authKey = authKey;
+ return this;
+ }
+
+ public String getAuthDate() {
+ return authDate;
+ }
+
+ public PostAuthDataObject setAuthDate(String authDate) {
+ this.authDate = authDate;
+ return this;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public PostAuthDataObject setUsername(String username) {
+ this.username = username;
+ return this;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public PostAuthDataObject setPassword(String password) {
+ this.password = password;
+ return this;
+ }
+
+ public String getProtocolFlag() {
+ return protocolFlag;
+ }
+
+ public PostAuthDataObject setProtocolFlag(String protocolFlag) {
+ this.protocolFlag = protocolFlag;
+ return this;
+ }
+}