private Gson gson;
private Marshaller marshaller;
@Override
protected void writeResponse(String pathInfo, String acceptHeader, HttpServletResponse resp) throws IOException, JAXBException {
MemcacheService memcacheService = getMemcacheService();
StringBuilder keyBuilder = new StringBuilder(getClass().getSimpleName()).append("|").append(pathInfo).append("|").append(getDumpVersion());
if ("application/json".equals(acceptHeader)) {
String key = keyBuilder.append("|json").toString();
String result = (String) memcacheService.get(key);
if (result == null) {
logger.info("Key was not found in cache: {}, the result will be cached", key);
StringWriter stringWriter = new StringWriter();
getGson().toJson(provideResponse(pathInfo), stringWriter);
result = stringWriter.toString();
memcacheService.put(key, result);
} else {
logger.info("Key was found in cache: {}", key);
}
resp.setContentType("application/json");
resp.getWriter().write(result);
} else {
String key = keyBuilder.append("|xml").toString();
String result = (String) memcacheService.get(key);
if (result == null) {
logger.info("Key was not found in cache: {}, the result will be cached", key);
StringWriter stringWriter = new StringWriter();
writeXml(provideResponse(pathInfo), stringWriter);
result = stringWriter.toString();
memcacheService.put(key, result);
} else {
logger.info("Key was found in cache: {}", key);
}
resp.setContentType("application/xml");
resp.getWriter().write(result);