我有一个场景,我从 HTTP 客户端点击了 cacheRefresh.do URL。它到达 App Server A,A 刷新自己的缓存,然后向 App Server B 发送请求(我使用的是 URLConnection),以刷新其缓存。(我知道这是一个糟糕的设计,但我们别无选择)
现在,当我的请求是刷新小缓存(小响应时间)时,一切看起来都很好,我得到了 200。
但是当我的请求是刷新大缓存时,我得到了 400。
在这种情况下,服务器 A 和 B 也会刷新,但为什么我会得到 400 作为响应?任何想法 ?
下面是控制器代码:
@SuppressWarnings("unused")
public ModelAndView handleRequest(final HttpServletRequest request, final HttpServletResponse response)
throws Exception {
final long cacheRefreshStartTime = System.currentTimeMillis();
final String action = request.getParameter("action");
// Init to 74 since this is the static length that will be appended.
final StringBuffer result = new StringBuffer(74);
final String[] cacheKeys = request.getParameterValues("cacheKeys");
String[] cacheElement = request.getParameterValues("cacheElement");
final String refreshByKeyRegion = request.getParameter("refreshByKeyRegion");
final String refreshByKeyRegionKeys = request.getParameter("refreshByKeyRegionKeys");
final String refreshPartnerInstanceCache = request.getParameter("refreshPartnerInstanceCache");
LOG.debug(" cacheKeys for refresh " + Arrays.toString(cacheKeys));
try {
if (action.equalsIgnoreCase("ALL")) {
performancLogger.info("Cache Refresh requested action=" + action);
this.refreshAllCache();
} else if (action.equalsIgnoreCase("SPECIFIC")) {
performancLogger.info("Cache Refresh requested action=" + action + " keys="
+ Arrays.toString(cacheKeys));
this.refreshSpecificCache(cacheKeys);
} else if (action.equalsIgnoreCase("cacheElement")) {
if (refreshByKeyRegion != null && refreshByKeyRegion.length() > 0 && refreshByKeyRegionKeys != null
&& refreshByKeyRegionKeys.length() > 0) {
cacheElement = new String[] { refreshByKeyRegion + "," + refreshByKeyRegionKeys };
}
performancLogger.info("Cache Refresh requested action=" + action + " element="
+ Arrays.toString(cacheElement));
this.refreshCacheElements(cacheElement);
}
if (!request.getServerName().contains("localhost") && refreshPartnerInstanceCache != null
&& refreshPartnerInstanceCache.equals("true")) {
refreshPartnerInstanceCache(request);
}
result.append("Cache refresh completed successfully.");
if (cacheKeys != null) {
result.append(" Keys - ");
result.append(this.formatArrayAsString(cacheKeys));
}
} catch (final Exception e) {
result.append("Cache refresh failed.");
if (cacheKeys != null) {
result.append(" Keys - ");
result.append(this.formatArrayAsString(cacheKeys));
}
}
if (action != null) {
performancLogger.info("Cache Refresh competed total refresh time = "
+ formatElapsedTime(System.currentTimeMillis() - cacheRefreshStartTime));
}
return new ModelAndView(IVRControllerNames.CACHE_REFRESH_STANDARD_VIEW, "displayInfo", this
.getDisplayInfo(result));
}
请求标头:
POST xxxxx.do HTTP/1.1
Host: xxxxx
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: http://xxx/yyy/zzz/cacheView.do
Cookie: JSESSIONID=xxxxx.x.x
请求正文:
Content-Type: application/x-www-form-urlencoded
Content-Length: 134
action=SPECIFIC&refreshPartnerInstanceCache=true&cacheKeys=xxxx&cacheKeys=xxx&Refresh=yyyy
谢谢!