summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
62e6233)
Fixed sonar issues/code-smells across this file
Issue-ID: CCSDK-879
Change-Id: I037ff59f5cb1b6855b62db434236fc2e567608a9
Signed-off-by: Arundathi Patil <arundpil@in.ibm.com>
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights
* reserved.
+ * Modifications Copyright © 2018 IBM.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
private String uebServers;
private String defaultUebTemplateFileName = "/opt/bvc/restapi/templates/default-ueb-message.json";
private String uebServers;
private String defaultUebTemplateFileName = "/opt/bvc/restapi/templates/default-ueb-message.json";
+ private String responseReceivedMessage = "Response received. Time: {}";
+ private String responseHttpCodeMessage = "HTTP response code: {}";
+ private String requestPostingException = "Exception while posting http request to client ";
+ private static String skipSendingMessage = "skipSending";
+ private static String responsePrefix = "responsePrefix";
+ private static String restapiUrlString = "restapiUrl";
+
public RestapiCallNode() {
String configDir = System.getProperty(PROPERTIES_DIR_KEY, DEFAULT_PROPERTIES_DIR);
public RestapiCallNode() {
String configDir = System.getProperty(PROPERTIES_DIR_KEY, DEFAULT_PROPERTIES_DIR);
p.templateFileName = parseParam(paramMap, "templateFileName",
false, null);
p.requestBody = parseParam(paramMap, "requestBody", false, null);
p.templateFileName = parseParam(paramMap, "templateFileName",
false, null);
p.requestBody = parseParam(paramMap, "requestBody", false, null);
- p.restapiUrl = parseParam(paramMap, "restapiUrl", true, null);
+ p.restapiUrl = parseParam(paramMap, restapiUrlString, true, null);
validateUrl(p.restapiUrl);
p.restapiUser = parseParam(paramMap, "restapiUser", false, null);
p.restapiPassword = parseParam(paramMap, "restapiPassword", false,
validateUrl(p.restapiUrl);
p.restapiUser = parseParam(paramMap, "restapiUser", false, null);
p.restapiPassword = parseParam(paramMap, "restapiPassword", false,
"unspecified"));
p.httpMethod = HttpMethod.fromString(parseParam(paramMap, "httpMethod",
false, "post"));
"unspecified"));
p.httpMethod = HttpMethod.fromString(parseParam(paramMap, "httpMethod",
false, "post"));
- p.responsePrefix = parseParam(paramMap, "responsePrefix", false, null);
+ p.responsePrefix = parseParam(paramMap, responsePrefix, false, null);
p.listNameList = getListNameList(paramMap);
p.listNameList = getListNameList(paramMap);
- String skipSendingStr = paramMap.get("skipSending");
+ String skipSendingStr = paramMap.get(skipSendingMessage);
p.skipSending = "true".equalsIgnoreCase(skipSendingStr);
p.convertResponse = valueOf(parseParam(paramMap, "convertResponse",
false, "true"));
p.skipSending = "true".equalsIgnoreCase(skipSendingStr);
p.convertResponse = valueOf(parseParam(paramMap, "convertResponse",
false, "true"));
}
log.error("Error sending the request: " + e.getMessage(), e);
}
log.error("Error sending the request: " + e.getMessage(), e);
- String prefix = parseParam(paramMap, "responsePrefix", false, null);
- if (retryPolicy == null || shouldRetry == false) {
+ String prefix = parseParam(paramMap, responsePrefix, false, null);
+ if (retryPolicy == null || !shouldRetry) {
setFailureResponseStatus(ctx, prefix, e.getMessage(), r);
} else {
if (retryCount == null) {
setFailureResponseStatus(ctx, prefix, e.getMessage(), r);
} else {
if (retryCount == null) {
try {
retryCount = retryCount + 1;
if (retryCount < retryPolicy.getMaximumRetries() + 1) {
try {
retryCount = retryCount + 1;
if (retryCount < retryPolicy.getMaximumRetries() + 1) {
- URI uri = new URI(paramMap.get("restapiUrl"));
+ URI uri = new URI(paramMap.get(restapiUrlString));
String hostname = uri.getHost();
String retryString = retryPolicy.getNextHostName(uri.toString());
URI uriTwo = new URI(retryString);
URI retryUri = UriBuilder.fromUri(uri).host(uriTwo.getHost()).port(uriTwo.getPort()).scheme(
uriTwo.getScheme()).build();
String hostname = uri.getHost();
String retryString = retryPolicy.getNextHostName(uri.toString());
URI uriTwo = new URI(retryString);
URI retryUri = UriBuilder.fromUri(uri).host(uriTwo.getHost()).port(uriTwo.getPort()).scheme(
uriTwo.getScheme()).build();
- paramMap.put("restapiUrl", retryUri.toString());
+ paramMap.put(restapiUrlString, retryUri.toString());
log.debug("URL was set to {}", retryUri.toString());
log.debug("Failed to communicate with host {}. Request will be re-attempted using the host {}.",
hostname, retryString);
log.debug("URL was set to {}", retryUri.toString());
log.debug("Failed to communicate with host {}. Request will be re-attempted using the host {}.",
hostname, retryString);
String var1 = template.substring(i1 + 2, i2);
String value1 = format == Format.XML ? XmlJsonUtil.getXml(mm, var1) : XmlJsonUtil.getJson(mm, var1);
String var1 = template.substring(i1 + 2, i2);
String value1 = format == Format.XML ? XmlJsonUtil.getXml(mm, var1) : XmlJsonUtil.getJson(mm, var1);
- // log.info(" " + var1 + ": " + value1);
if (value1 == null || value1.trim().length() == 0) {
// delete the whole element (line)
int i3 = template.lastIndexOf('\n', i1);
if (value1 == null || value1.trim().length() == 0) {
// delete the whole element (line)
int i3 = template.lastIndexOf('\n', i1);
try {
response = invocationBuilder.method(p.httpMethod.toString(), entity(request, tt1));
} catch (ProcessingException | IllegalStateException e) {
try {
response = invocationBuilder.method(p.httpMethod.toString(), entity(request, tt1));
} catch (ProcessingException | IllegalStateException e) {
- throw new SvcLogicException("Exception while posting http request to client " +
+ throw new SvcLogicException(requestPostingException +
e.getLocalizedMessage(), e);
}
e.getLocalizedMessage(), e);
}
}
long t2 = System.currentTimeMillis();
}
long t2 = System.currentTimeMillis();
- log.info("Response received. Time: {}", (t2 - t1));
- log.info("HTTP response code: {}", r.code);
+ log.info(responseReceivedMessage, (t2 - t1));
+ log.info(responseHttpCodeMessage, r.code);
log.info("HTTP response message: {}", r.message);
logHeaders(r.headers);
log.info("HTTP response: {}", r.body);
log.info("HTTP response message: {}", r.message);
logHeaders(r.headers);
log.info("HTTP response: {}", r.body);
r = new HttpResponse();
r.code = 500;
r.message = e.getMessage();
r = new HttpResponse();
r.code = 500;
r.message = e.getMessage();
- String prefix = parseParam(paramMap, "responsePrefix", false, null);
+ String prefix = parseParam(paramMap, responsePrefix, false, null);
setResponseStatus(ctx, prefix, r);
}
setResponseStatus(ctx, prefix, r);
}
p.user = parseParam(paramMap, "user", false, null);
p.password = parseParam(paramMap, "password", false, null);
p.httpMethod = HttpMethod.fromString(parseParam(paramMap, "httpMethod", false, "post"));
p.user = parseParam(paramMap, "user", false, null);
p.password = parseParam(paramMap, "password", false, null);
p.httpMethod = HttpMethod.fromString(parseParam(paramMap, "httpMethod", false, "post"));
- p.responsePrefix = parseParam(paramMap, "responsePrefix", false, null);
- String skipSendingStr = paramMap.get("skipSending");
+ p.responsePrefix = parseParam(paramMap, responsePrefix, false, null);
+ String skipSendingStr = paramMap.get(skipSendingMessage);
p.skipSending = "true".equalsIgnoreCase(skipSendingStr);
p.oAuthConsumerKey = parseParam(paramMap, "oAuthConsumerKey", false, null);
p.oAuthVersion = parseParam(paramMap, "oAuthVersion", false, null);
p.skipSending = "true".equalsIgnoreCase(skipSendingStr);
p.oAuthConsumerKey = parseParam(paramMap, "oAuthConsumerKey", false, null);
p.oAuthVersion = parseParam(paramMap, "oAuthVersion", false, null);
r = new HttpResponse();
r.code = 500;
r.message = e.getMessage();
r = new HttpResponse();
r.code = 500;
r.message = e.getMessage();
- String prefix = parseParam(paramMap, "responsePrefix", false, null);
+ String prefix = parseParam(paramMap, responsePrefix, false, null);
setResponseStatus(ctx, prefix, r);
}
setResponseStatus(ctx, prefix, r);
}
throw new SvcLogicException("Http operation" + p.httpMethod + "not supported");
}
} catch (ProcessingException e) {
throw new SvcLogicException("Http operation" + p.httpMethod + "not supported");
}
} catch (ProcessingException e) {
- throw new SvcLogicException("Exception while posting http request to client " +
+ throw new SvcLogicException(requestPostingException +
e.getLocalizedMessage(), e);
}
e.getLocalizedMessage(), e);
}
throw new SvcLogicException("Http operation" + p.httpMethod + "not supported");
}
} catch (ProcessingException e) {
throw new SvcLogicException("Http operation" + p.httpMethod + "not supported");
}
} catch (ProcessingException e) {
- throw new SvcLogicException("Exception while posting http request to client " +
+ throw new SvcLogicException(requestPostingException +
e.getLocalizedMessage(), e);
}
e.getLocalizedMessage(), e);
}
}
long t2 = System.currentTimeMillis();
}
long t2 = System.currentTimeMillis();
- log.info("Response received. Time: {}", (t2 - t1));
- log.info("HTTP response code: {}", r.code);
+ log.info(responseReceivedMessage, (t2 - t1));
+ log.info(responseHttpCodeMessage, r.code);
log.info("HTTP response message: {}", r.message);
logHeaders(r.headers);
log.info("HTTP response: {}", r.body);
log.info("HTTP response message: {}", r.message);
logHeaders(r.headers);
log.info("HTTP response: {}", r.body);
p.topic = parseParam(paramMap, "topic", true, null);
p.templateFileName = parseParam(paramMap, "templateFileName", false, null);
p.rootVarName = parseParam(paramMap, "rootVarName", false, null);
p.topic = parseParam(paramMap, "topic", true, null);
p.templateFileName = parseParam(paramMap, "templateFileName", false, null);
p.rootVarName = parseParam(paramMap, "rootVarName", false, null);
- p.responsePrefix = parseParam(paramMap, "responsePrefix", false, null);
- String skipSendingStr = paramMap.get("skipSending");
+ p.responsePrefix = parseParam(paramMap, responsePrefix, false, null);
+ String skipSendingStr = paramMap.get(skipSendingMessage);
p.skipSending = "true".equalsIgnoreCase(skipSendingStr);
return p;
}
p.skipSending = "true".equalsIgnoreCase(skipSendingStr);
return p;
}
try {
response = invocationBuilder.post(Entity.entity(request, tt1));
} catch (ProcessingException e) {
try {
response = invocationBuilder.post(Entity.entity(request, tt1));
} catch (ProcessingException e) {
- throw new SvcLogicException("Exception while posting http request to client " +
+ throw new SvcLogicException(requestPostingException +
e.getLocalizedMessage(), e);
}
r.code = response.getStatus();
e.getLocalizedMessage(), e);
}
r.code = response.getStatus();
}
long t2 = System.currentTimeMillis();
}
long t2 = System.currentTimeMillis();
- log.info("Response received. Time: {}", (t2 - t1));
- log.info("HTTP response code: {}", r.code);
+ log.info(responseReceivedMessage, (t2 - t1));
+ log.info(responseHttpCodeMessage, r.code);
logHeaders(r.headers);
log.info("HTTP response:\n {}", r.body);
logHeaders(r.headers);
log.info("HTTP response:\n {}", r.body);