diff options
Diffstat (limited to 'ecomp-sdk/epsdk-app-common')
-rw-r--r-- | ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/CacheAdminController.java | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/CacheAdminController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/CacheAdminController.java index 34ad676e..9809b78a 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/CacheAdminController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/CacheAdminController.java @@ -37,6 +37,8 @@ */ package org.onap.portalapp.controller.core; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import java.io.IOException; import java.io.PrintWriter; import java.util.HashMap; @@ -71,6 +73,8 @@ import com.fasterxml.jackson.databind.SerializationFeature; public class CacheAdminController extends RestrictedBaseController { private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CacheAdminController.class); + private static final String CACHE_NAME = "cacheName"; + private static final String APPLICATION_JSON = "application/json"; private JCSAdminBean jcsAdminBean = new JCSAdminBean(); @@ -94,9 +98,9 @@ public class CacheAdminController extends RestrictedBaseController { @RequestMapping(value = { "/jcs_admin/clearRegion" }, method = RequestMethod.GET) public void clearRegion(HttpServletRequest request, HttpServletResponse response) throws IOException { - String cacheName = request.getParameter("cacheName"); + String cacheName = request.getParameter(CACHE_NAME); clearCacheRegion(cacheName); - response.setContentType("application/json"); + response.setContentType(APPLICATION_JSON); PrintWriter out = response.getWriter(); out.write(getRegions().toString()); } @@ -104,7 +108,7 @@ public class CacheAdminController extends RestrictedBaseController { @RequestMapping(value = { "/jcs_admin/clearAll" }, method = RequestMethod.GET) public void clearAll(HttpServletResponse response) throws IOException { clearAllRegions(); - response.setContentType("application/json"); + response.setContentType(APPLICATION_JSON); PrintWriter out = response.getWriter(); out.write(getRegions().toString()); } @@ -112,16 +116,16 @@ public class CacheAdminController extends RestrictedBaseController { @RequestMapping(value = { "/jcs_admin/clearItem" }, method = RequestMethod.GET) public void clearItem(HttpServletRequest request, HttpServletResponse response) throws IOException { String keyName = request.getParameter("keyName"); - String cacheName = request.getParameter("cacheName"); + String cacheName = request.getParameter(CACHE_NAME); clearCacheRegionItem(cacheName, keyName); - response.setContentType("application/json"); + response.setContentType(APPLICATION_JSON); PrintWriter out = response.getWriter(); out.write(getRegions().toString()); } @RequestMapping(value = { "/jcs_admin/showItemDetails" }, method = RequestMethod.GET) public void showItemDetails(HttpServletRequest request, HttpServletResponse response) throws IOException { - String cacheName = request.getParameter("cacheName"); + String cacheName = request.getParameter(CACHE_NAME); String keyName = request.getParameter("keyName"); String details = null; try { @@ -131,20 +135,20 @@ public class CacheAdminController extends RestrictedBaseController { logger.error(EELFLoggerDelegate.errorLogger, "showItemDetails failed for cache name " + cacheName, e); } JSONObject j = new JSONObject(details); - response.setContentType("application/json"); + response.setContentType(APPLICATION_JSON); PrintWriter out = response.getWriter(); out.write(j.toString()); } @RequestMapping(value = { "/jcs_admin/showRegionDetails" }, method = RequestMethod.GET) public void showRegionDetails(HttpServletRequest request, HttpServletResponse response) { - String cacheName = request.getParameter("cacheName"); + String cacheName = request.getParameter(CACHE_NAME); ObjectMapper mapper = new ObjectMapper(); try { String details = getRegionStats(cacheName); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(details)); JSONObject j = new JSONObject(msg); - response.setContentType("application/json"); + response.setContentType(APPLICATION_JSON); PrintWriter out = response.getWriter(); out.write(j.toString()); } catch (Exception e) { @@ -163,9 +167,9 @@ public class CacheAdminController extends RestrictedBaseController { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); for (CacheRegionInfo cri : regions) { - if (cri.getCache().getCacheName() != null && !cri.getCache().getCacheName().equals("[object Object]")) { + if (cri.getCache().getCacheName() != null && !"[object Object]".equals(cri.getCache().getCacheName())) { JSONObject jo = new JSONObject(); - jo.put("cacheName", cri.getCache().getCacheName()); + jo.put(CACHE_NAME, cri.getCache().getCacheName()); jo.put("size", cri.getCache().getSize()); jo.put("byteCount", cri.getByteCount()); jo.put("status", cri.getStatus()); @@ -187,11 +191,10 @@ public class CacheAdminController extends RestrictedBaseController { private String getRegionStats(String cacheName) throws CacheException { JCS cache = JCS.getInstance(cacheName); - String stats = cache.getStats(); - return stats; + return cache.getStats(); } - private String getItemDetails(String cacheName, String keyName) throws Exception { + private String getItemDetails(String cacheName, String keyName) throws CacheException,JsonProcessingException { JCS cache = JCS.getInstance(cacheName); ICacheElement element = cache.getCacheElement(keyName); |