summaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
authorParshad Patel <pars.patel@samsung.com>2019-04-08 17:05:24 +0900
committerParshad Patel <pars.patel@samsung.com>2019-04-08 17:08:07 +0900
commit27643b31978a8600c4c0ad6dbd1e3ceb32ba54b6 (patch)
tree4703d7549396b1c4a17c89a9fb61963cb668e394 /src/main/java/org
parent34615204bca86d54ebfbedb15e8976515688c56c (diff)
Fix sonar issues in dmaap-mr-filter
Fix A "NullPointerException" could be thrown; "jsonObj" is nullable here. Either log or rethrow this exception. Rename field "defaultLength" Issue-ID: DMAAP-894 Change-Id: I663eda653af6b2e092ba10e3fca44f86870d9ef1 Signed-off-by: Parshad Patel <pars.patel@samsung.com>
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/onap/dmaap/mr/filter/ContentLengthFilter.java21
-rw-r--r--src/main/java/org/onap/dmaap/mr/filter/DefaultLength.java6
2 files changed, 13 insertions, 14 deletions
diff --git a/src/main/java/org/onap/dmaap/mr/filter/ContentLengthFilter.java b/src/main/java/org/onap/dmaap/mr/filter/ContentLengthFilter.java
index a175b16..dbf4246 100644
--- a/src/main/java/org/onap/dmaap/mr/filter/ContentLengthFilter.java
+++ b/src/main/java/org/onap/dmaap/mr/filter/ContentLengthFilter.java
@@ -74,8 +74,6 @@ public class ContentLengthFilter implements Filter {
*/
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException,
ServletException {
- // TODO Auto-generated method stub
- // place your code here
log.info("inside servlet do filter content length checking before pub/sub");
HttpServletRequest request = (HttpServletRequest) req;
JSONObject jsonObj = null;
@@ -105,12 +103,14 @@ public class ContentLengthFilter implements Filter {
chain.doFilter(req, res);
}
} catch (CambriaApiException | NumberFormatException e) {
- log.error("message size is greater then default");
- ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_EXPECTATION_FAILED,
- DMaaPResponseCode.MSG_SIZE_EXCEEDS_MSG_LIMIT.getResponseCode(), errorMessages.getMsgSizeExceeds()
- + jsonObj.toString());
- log.info(errRes.toString());
-
+ log.error("message size is greater then default", e);
+ if (jsonObj != null) {
+ ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_EXPECTATION_FAILED,
+ DMaaPResponseCode.MSG_SIZE_EXCEEDS_MSG_LIMIT.getResponseCode(),
+ errorMessages.getMsgSizeExceeds()
+ + jsonObj.toString());
+ log.info(errRes.toString());
+ }
}
}
@@ -119,14 +119,13 @@ public class ContentLengthFilter implements Filter {
* @see Filter#init(FilterConfig)
*/
public void init(FilterConfig fConfig) throws ServletException {
- // TODO Auto-generated method stub
this.filterConfig = fConfig;
log.info("Filter Content Length Initialize");
ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(fConfig
.getServletContext());
DefaultLength defLength = (DefaultLength) ctx.getBean("defLength");
- DMaaPErrorMessages errorMessages = (DMaaPErrorMessages) ctx.getBean("DMaaPErrorMessages");
- this.errorMessages = errorMessages;
+ DMaaPErrorMessages errMessages = (DMaaPErrorMessages) ctx.getBean("DMaaPErrorMessages");
+ this.errorMessages = errMessages;
this.defaultLength = defLength;
}
diff --git a/src/main/java/org/onap/dmaap/mr/filter/DefaultLength.java b/src/main/java/org/onap/dmaap/mr/filter/DefaultLength.java
index 598ef1b..3425823 100644
--- a/src/main/java/org/onap/dmaap/mr/filter/DefaultLength.java
+++ b/src/main/java/org/onap/dmaap/mr/filter/DefaultLength.java
@@ -24,14 +24,14 @@ package org.onap.dmaap.mr.filter;
public class DefaultLength {
- String defaultLength;
+ String defLength;
public String getDefaultLength() {
- return defaultLength;
+ return defLength;
}
public void setDefaultLength(String defaultLength) {
- this.defaultLength = defaultLength;
+ this.defLength = defaultLength;
}
}