aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-prov/src/main/java
diff options
context:
space:
mode:
authorAmaresh Kumar <kamaresh@in.ibm.com>2018-08-29 18:50:48 +0530
committerAmaresh Kumar <kamaresh@in.ibm.com>2018-08-29 18:52:55 +0530
commit27bba9734e136e06c3562767c1c54b330cd49f75 (patch)
treebad8fd0df19a122726756e981c98d8d6304a2398 /datarouter-prov/src/main/java
parent04dd60b7f0ebdadd5af0a4147a3e601734d6e3dc (diff)
Fixed Blocker Sonar issues in ProxyServlet.java
Fixed 2 Sonar blocker issues in proxyServelet.java https://sonar.onap.org/project/issues?id=org.onap.dmaap.datarouter%3Aparent&open=AWHpc14DRGy6eclHCoS-&resolved=false&severities=BLOCKER&types=BUG https://sonar.onap.org/project/issues?id=org.onap.dmaap.datarouter%3Aparent&open=AWHpc14DRGy6eclHCoS9&resolved=false&severities=BLOCKER&types=BUG Issue-ID: DMAAP-673 Change-Id: Iafa0e0cfedb3fbb29b202d069c2bc0c90d962bfa Signed-off-by: Amaresh Kumar <kamaresh@in.ibm.com>
Diffstat (limited to 'datarouter-prov/src/main/java')
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java65
1 files changed, 34 insertions, 31 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java
index 6564e175..c560299a 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java
@@ -181,7 +181,7 @@ public class ProxyServlet extends BaseServlet {
if (inited) {
String url = buildUrl(req);
intlogger.info("ProxyServlet: proxying with fallback GET "+url);
- AbstractHttpClient httpclient = new DefaultHttpClient();
+ try(AbstractHttpClient httpclient = new DefaultHttpClient()){
HttpRequestBase proxy = new HttpGet(url);
try {
httpclient.getConnectionManager().getSchemeRegistry().register(sch);
@@ -204,6 +204,7 @@ public class ProxyServlet extends BaseServlet {
in.close();
}
rv = true;
+
} catch (IOException e) {
System.err.println("ProxyServlet: "+e);
e.printStackTrace();
@@ -211,6 +212,7 @@ public class ProxyServlet extends BaseServlet {
proxy.releaseConnection();
httpclient.getConnectionManager().shutdown();
}
+ }
} else {
intlogger.warn("ProxyServlet: proxy disabled");
}
@@ -220,41 +222,42 @@ public class ProxyServlet extends BaseServlet {
if (inited && isProxyServer()) {
String url = buildUrl(req);
intlogger.info("ProxyServlet: proxying "+method + " "+url);
- AbstractHttpClient httpclient = new DefaultHttpClient();
- ProxyHttpRequest proxy = new ProxyHttpRequest(method, url);
- try {
- httpclient.getConnectionManager().getSchemeRegistry().register(sch);
+ try(AbstractHttpClient httpclient = new DefaultHttpClient()) {
+ ProxyHttpRequest proxy = new ProxyHttpRequest(method, url);
+ try {
+ httpclient.getConnectionManager().getSchemeRegistry().register(sch);
- // Copy request headers and request body
- copyRequestHeaders(req, proxy);
- if (method.equals("POST") || method.equals("PUT")){
- BasicHttpEntity body = new BasicHttpEntity();
- body.setContent(req.getInputStream());
- body.setContentLength(-1); // -1 = unknown
- proxy.setEntity(body);
- }
+ // Copy request headers and request body
+ copyRequestHeaders(req, proxy);
+ if (method.equals("POST") || method.equals("PUT")) {
+ BasicHttpEntity body = new BasicHttpEntity();
+ body.setContent(req.getInputStream());
+ body.setContentLength(-1); // -1 = unknown
+ proxy.setEntity(body);
+ }
- // Execute the request
- HttpResponse pxy_response = httpclient.execute(proxy);
+ // Execute the request
+ HttpResponse pxy_response = httpclient.execute(proxy);
- // Get response headers and body
- int code = pxy_response.getStatusLine().getStatusCode();
- resp.setStatus(code);
- copyResponseHeaders(pxy_response, resp);
+ // Get response headers and body
+ int code = pxy_response.getStatusLine().getStatusCode();
+ resp.setStatus(code);
+ copyResponseHeaders(pxy_response, resp);
- HttpEntity entity = pxy_response.getEntity();
- if (entity != null) {
- InputStream in = entity.getContent();
- IOUtils.copy(in, resp.getOutputStream());
- in.close();
+ HttpEntity entity = pxy_response.getEntity();
+ if (entity != null) {
+ InputStream in = entity.getContent();
+ IOUtils.copy(in, resp.getOutputStream());
+ in.close();
+ }
+ } catch (IOException e) {
+ intlogger.warn("ProxyServlet: " + e);
+ resp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
+ e.printStackTrace();
+ } finally {
+ proxy.releaseConnection();
+ httpclient.getConnectionManager().shutdown();
}
- } catch (IOException e) {
- intlogger.warn("ProxyServlet: "+e);
- resp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
- e.printStackTrace();
- } finally {
- proxy.releaseConnection();
- httpclient.getConnectionManager().shutdown();
}
} else {
intlogger.warn("ProxyServlet: proxy disabled");