- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们使用 REST 端点提供 CMS (Hippo) 内容,我注意到间歇性发生的奇怪行为:
一次又一次,当在一段时间不活动或服务器重新启动后第一次调用端点(例如 http://site.name/api/articles/ )时,它会抛出以下异常。如果第二次刷新页面,一切正常。
Throwable thrown during doFilter on request with URI: /site/fr-ca/api/articles/ and Query: nullResponse already committed after doing buildPage but before writing response from PageInfo.
[INFO] [talledLocalContainer] net.sf.ehcache.constructs.web.AlreadyCommittedException: Response already committed after doing buildPage but before writing response from PageInfo.
[INFO] [talledLocalContainer] at net.sf.ehcache.constructs.web.filter.CachingFilter.doFilter(CachingFilter.java:220)
[INFO] [talledLocalContainer] at net.sf.ehcache.constructs.web.filter.Filter.doFilter(Filter.java:86)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
[INFO] [talledLocalContainer] at org.hippoecm.hst.container.XSSUrlFilter.doFilter(XSSUrlFilter.java:52)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
[INFO] [talledLocalContainer] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
[INFO] [talledLocalContainer] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
[INFO] [talledLocalContainer] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
[INFO] [talledLocalContainer] at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:106)
[INFO] [talledLocalContainer] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
[INFO] [talledLocalContainer] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
[INFO] [talledLocalContainer] at org.apache.catalina.core.StandardHostValve.__invoke(StandardHostValve.java:142)
[INFO] [talledLocalContainer] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)
[INFO] [talledLocalContainer] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
[INFO] [talledLocalContainer] at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
[INFO] [talledLocalContainer] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
[INFO] [talledLocalContainer] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
[INFO] [talledLocalContainer] at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
[INFO] [talledLocalContainer] at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
[INFO] [talledLocalContainer] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
[INFO] [talledLocalContainer] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
[INFO] [talledLocalContainer] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[INFO] [talledLocalContainer] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[INFO] [talledLocalContainer] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
[INFO] [talledLocalContainer] at java.lang.Thread.run(Thread.java:745)
其中罪魁祸首代码如下:
protected void doFilter(final HttpServletRequest request,
final HttpServletResponse response, final FilterChain chain)
throws AlreadyGzippedException, AlreadyCommittedException,
FilterNonReentrantException, LockTimeoutException, Exception {
if (response.isCommitted()) {
throw new AlreadyCommittedException(
"Response already committed before doing buildPage.");
}
logRequestHeaders(request);
PageInfo pageInfo = buildPageInfo(request, response, chain);
if (pageInfo.isOk()) {
if (response.isCommitted()) {
throw new AlreadyCommittedException(
"Response already committed after doing buildPage"
+ " but before writing response from PageInfo.");
}
writeResponse(request, response, pageInfo);
}
}
第 220 行是在 if(response.isCommissed()) {}
内抛出 AlreadyComfilledException()
的行,
这让我认为服务器认为此时响应已经提交。我已经检查了我的代码,并且可以确认我没有进行任何“中间”提交或写入 servlet 的输出流。
但最烦人的是,它只发生在第一个页面调用时,如果我刷新页面,问题就消失了。
其他细节:我们有一个缓存过滤器,可以缓存页面并调用 CacheFilter:
public class WaPageCache extends SimpleCachingHeadersPageCachingFilter {
@Override
protected String calculateKey(HttpServletRequest httpRequest) {
String simpleKey = super.calculateKey(httpRequest);
final String requestURI = httpRequest.getRequestURI();
final String key = requestURI.contains("/binaries/content") ? simpleKey : simpleKey + httpRequest.getHeader("Cookie");
return key;
}
@Override
protected CacheManager getCacheManager() {
ClassLoader standardClassloader = Thread.currentThread().getContextClassLoader();
URL url = null;
if (standardClassloader != null) {
url = standardClassloader.getResource("ehcache-web-caching.xml");
}
return CacheManager.create(url);
}
}
还有其他人遇到过类似的问题吗?可能的原因/解决方案/解决方案的提示是什么?
最佳答案
我找到了一个解决方案:在我的网络应用程序中,我有几个过滤器,诀窍是将缓存过滤器放在所有其他过滤器之后(在我的 Hippo 案例中,特别是在 HstFilter 之后)。好吧,我有另一个设置响应 header 的过滤器,并且可以在缓存过滤器之后使用该过滤器。这是我更新的 web.xml 的片段:
<filter-mapping>
<filter-name>HstFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- This is my filter that was throwing the spanner -->
<filter-mapping>
<filter-name>WaPageCache</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ApiResourceHeadersFilter</filter-name>
<url-pattern>/api/site/*</url-pattern>
</filter-mapping>
关于java - 已经提交异常 : Response already committed after doing buildPage but before writing response from PageInfo (HippoCMS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39147305/
我们使用 REST 端点提供 CMS (Hippo) 内容,我注意到间歇性发生的奇怪行为: 一次又一次,当在一段时间不活动或服务器重新启动后第一次调用端点(例如 http://site.name/ap
我是一名优秀的程序员,十分优秀!