*/
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;
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();
@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());
}
@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());
}
@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 {
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) {
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());
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);