aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsunil unnava <su622b@att.com>2019-03-18 15:40:17 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-18 15:40:17 +0000
commite3da91b4013e3c4fea1d2a2c6f0e4a1677fb3ba4 (patch)
treed4645234f1bc489cedd1ab4a26f88de08c2445e7
parent4a8983cbc2b63c24c082efd163a32aa98e2820d8 (diff)
parent2ce8d15a4d5c03bb4f2f676114c466b61c4a3188 (diff)
Merge "Sonar fix too many method param"
-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
-rw-r--r--src/test/java/org/onap/dmaap/mr/client/impl/MRBaseClientTest.java23
4 files changed, 151 insertions, 30 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;
+ }
+}
diff --git a/src/test/java/org/onap/dmaap/mr/client/impl/MRBaseClientTest.java b/src/test/java/org/onap/dmaap/mr/client/impl/MRBaseClientTest.java
index 6279d82..38c7f8a 100644
--- a/src/test/java/org/onap/dmaap/mr/client/impl/MRBaseClientTest.java
+++ b/src/test/java/org/onap/dmaap/mr/client/impl/MRBaseClientTest.java
@@ -251,8 +251,14 @@ public class MRBaseClientTest {
"password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
.thenReturn(response);
- mrBaseClient.postAuth("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", "username",
- "password", "username", "password", "HTTPAUTH");
+ mrBaseClient.postAuth(new PostAuthDataObject().setPath("/path")
+ .setData( new String("{\"test\":\"test\"}").getBytes())
+ .setContentType("application/json")
+ .setAuthKey("username")
+ .setAuthDate("password")
+ .setUsername("username")
+ .setPassword("password")
+ .setProtocolFlag("HTTPAUTH"));
assertTrue(true);
}
@@ -266,9 +272,16 @@ public class MRBaseClientTest {
"password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
.thenReturn(
responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
-
- mrBaseClient.postAuth("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", null, null,
- null, null, "HTTPAUTH");
+
+ mrBaseClient.postAuth(new PostAuthDataObject().setPath("/path")
+ .setData( new String("{\"test\":\"test\"}").getBytes())
+ .setContentType("application/json")
+ .setAuthKey(null)
+ .setAuthDate(null)
+ .setUsername(null)
+ .setPassword(null)
+ .setProtocolFlag("HTTPAUTH"));
+
assertTrue(true);
}