diff options
author | micdzied <michal.1.dziedzic@nokia.com> | 2019-07-04 14:01:31 +0200 |
---|---|---|
committer | micdzied <michal.1.dziedzic@nokia.com> | 2019-07-04 14:01:31 +0200 |
commit | 5d8ec67db97bdb61b0c07c46afb3a58a02661274 (patch) | |
tree | 45d79130517d85d69fc3a08a146574ac9317ee58 /src/main/java/org | |
parent | 3815da092efa0a1047b276fba2ce01ad3cb2a0ab (diff) |
code improvement5.0.2-ONAPelalto
Change-Id: Idc402a05d24c89e5cafc3a4d4221ec2158876f0a
Issue-ID: DMAAP-1229
Signed-off-by: micdzied <michal.1.dziedzic@nokia.com>
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/onap/dmaap/mr/client/impl/MRConstants.java | 3 | ||||
-rw-r--r-- | src/main/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisher.java | 45 |
2 files changed, 21 insertions, 27 deletions
diff --git a/src/main/java/org/onap/dmaap/mr/client/impl/MRConstants.java b/src/main/java/org/onap/dmaap/mr/client/impl/MRConstants.java index 5ed44c6..ec17610 100644 --- a/src/main/java/org/onap/dmaap/mr/client/impl/MRConstants.java +++ b/src/main/java/org/onap/dmaap/mr/client/impl/MRConstants.java @@ -62,10 +62,9 @@ class MRConstants public static String makeUrl ( final String host, final String rawTopic ) { final String cleanTopic = escape ( rawTopic ); - final StringBuffer url = new StringBuffer(); - if (!host.startsWith("http") || !host.startsWith("https") ) { + if (!host.startsWith("http") && !host.startsWith("https") ) { url.append( PROTOCOL + "://" ); } url.append(host); 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 fb57b94..d9076a4 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 @@ -178,8 +178,8 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP try { final List<message> remains = close(Long.MAX_VALUE, TimeUnit.MILLISECONDS); if (remains.isEmpty()) { - getLog().warn("Closing publisher with " + remains.size() + " messages unsent. " - + "Consider using MRBatchingPublisher.close( long timeout, TimeUnit timeoutUnits ) to recapture unsent messages on close."); + getLog().warn("Closing publisher with {} messages unsent. Consider using MRBatchingPublisher.close( long timeout, TimeUnit timeoutUnits ) to recapture unsent messages on close.", + remains.size()); } } catch (InterruptedException e) { getLog().warn("Possible message loss. " + e.getMessage(), e); @@ -339,8 +339,9 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP DME2Configue(); Thread.sleep(5); - getLog().info("sending " + fPending.size() + " msgs to " + url + subContextPath + ". Oldest: " - + (nowMs - fPending.peek().timestamp) + " ms"); + getLog().info(String + .format("sending %d msgs to %s%s. Oldest: %d ms", fPending.size(), url, subContextPath, + nowMs - fPending.peek().timestamp)); sender.setPayload(os.toString()); String dmeResponse = sender.sendAndWait(5000L); @@ -351,8 +352,8 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP } if (ProtocolTypeConstants.AUTH_KEY.getValue().equalsIgnoreCase(protocolFlag)) { - getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: " - + (nowMs - fPending.peek().timestamp) + " ms"); + getLog().info("sending {} msgs to {}. Oldest: {} ms", fPending.size(), httpurl, + nowMs - fPending.peek().timestamp); final JSONObject result = postAuth(new PostAuthDataObject().setPath(httpurl).setData(baseStream.toByteArray()) .setContentType(contentType).setAuthKey(authKey).setAuthDate(authDate) @@ -370,8 +371,8 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP } if (ProtocolTypeConstants.AAF_AUTH.getValue().equalsIgnoreCase(protocolFlag)) { - getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: " - + (nowMs - fPending.peek().timestamp) + " ms"); + getLog().info("sending {} msgs to {}. Oldest: {} ms", fPending.size(), httpurl, + nowMs - fPending.peek().timestamp); final JSONObject result = post(httpurl, baseStream.toByteArray(), contentType, username, password, protocolFlag); @@ -388,8 +389,8 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP } if (ProtocolTypeConstants.HTTPNOAUTH.getValue().equalsIgnoreCase(protocolFlag)) { - getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: " - + (nowMs - fPending.peek().timestamp) + " ms"); + getLog().info("sending {} msgs to {}. Oldest: {} ms", fPending.size(), httpurl, + nowMs - fPending.peek().timestamp); final JSONObject result = postNoAuth(httpurl, baseStream.toByteArray(), contentType); // Here we are checking for error response. If HTTP status @@ -468,8 +469,8 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP DME2Configue(); Thread.sleep(5); - getLog().info("sending " + fPending.size() + " msgs to " + url + subContextPath + ". Oldest: " - + (nowMs - fPending.peek().timestamp) + " ms"); + getLog().info("sending {} msgs to {}{}. Oldest: {} ms", fPending.size(), url, subContextPath, + nowMs - fPending.peek().timestamp); sender.setPayload(os.toString()); String dmeResponse = sender.sendAndWait(5000L); @@ -506,8 +507,8 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP } if (ProtocolTypeConstants.AUTH_KEY.getValue().equalsIgnoreCase(protocolFlag)) { - getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: " - + (nowMs - fPending.peek().timestamp) + " ms"); + getLog().info("sending {} msgs to {}. Oldest: {} ms", fPending.size(), httpurl, + nowMs - fPending.peek().timestamp); final String result = postAuthwithResponse(httpurl, baseStream.toByteArray(), contentType, authKey, authDate, username, password, protocolFlag); // Here we are checking for error response. If HTTP status @@ -529,8 +530,8 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP } if (ProtocolTypeConstants.AAF_AUTH.getValue().equalsIgnoreCase(protocolFlag)) { - getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: " - + (nowMs - fPending.peek().timestamp) + " ms"); + getLog().info("sending {} msgs to {}. Oldest: {} ms", fPending.size(), httpurl, + nowMs - fPending.peek().timestamp); final String result = postWithResponse(httpurl, baseStream.toByteArray(), contentType, username, password, protocolFlag); @@ -552,8 +553,8 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP } if (ProtocolTypeConstants.HTTPNOAUTH.getValue().equalsIgnoreCase(protocolFlag)) { - getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: " - + (nowMs - fPending.peek().timestamp) + " ms"); + getLog().info("sending {} msgs to {}. Oldest: {} ms", fPending.size(), httpurl, + nowMs - fPending.peek().timestamp); final String result = postNoAuthWithResponse(httpurl, baseStream.toByteArray(), contentType); // Here we are checking for error response. If HTTP status @@ -572,7 +573,7 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP fPending.clear(); return pubResponse; } - } catch (IllegalArgumentException x) { + } catch (IllegalArgumentException | HttpException x) { getLog().warn(x.getMessage(), x); pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_BAD_REQUEST)); pubResponse.setResponseMessage(x.getMessage()); @@ -581,12 +582,6 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP getLog().warn(x.getMessage(), x); pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR)); pubResponse.setResponseMessage(x.getMessage()); - - } catch (HttpException x) { - getLog().warn(x.getMessage(), x); - pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_BAD_REQUEST)); - pubResponse.setResponseMessage(x.getMessage()); - } catch (Exception x) { getLog().warn(x.getMessage(), x); |