gpt4 book ai didi

apache - "Not Modified"标题后跟带有 sitemesh3 和 mod-jk 的意外内容正文

转载 作者:行者123 更新时间:2023-11-28 21:49:54 26 4
gpt4 key购买 nike

在我的 Java/Struts2/Tomcat 应用程序中,当请求生成“304 Not Modified”响应的某些资源时,文件仍在响应中发送。

这是使用 Fiddler 捕获的响应示例:

HTTP/1.1 304 Not Modified
Date: Thu, 26 Jun 2014 11:27:27 GMT
Server: Apache/2.2.16 (Ubuntu)
Connection: Keep-Alive
Keep-Alive: timeout=15, max=100
Vary: Accept-Encoding

/*! jQuery v1.7.2 jquery.com | jquery.org/license */
(function(a,b){function cy(a){return f.isWindow(a)?a:a.nodeType===9?
a.defaultView||a.parentWindow:!1}function cu(a){if(!cj[a]){var b=c.body,d=f("
<"+a+">").appendTo(b),e=d.css("display");d.remove();if(e==="none"||e===""){ck||
[...]

这是一个问题,因为返回文件的内容被插入到下一个请求的文件中,最终导致损坏和奇怪的行为。

这只发生在从“/struts”路径加载的资源上,例如:

/struts/utils.js
/struts/js/base/jquery-1.10.2.min.js
/struts/js/base/jquery.ui.core.min.js?s2j=3.7.0

“/struts”路径由struts2类处理

org.apache.struts2.dispatcher.DefaultStaticContentLoader

这些是系统的相关元素:

  • Ubuntu 12.04.4 LTS(GNU/Linux 3.5.0-27-generic x86_64)
  • JVM 1.6.0_31-b31 Sun Microsystems Inc.(也尝试使用 ibm-java-x86_64-71)
  • Apache2 2.2.22-1ubuntu1.6 与 modjk
  • Apache Tomcat/6.0.35
  • Struts 2.3.16
  • 站点网 3.0.0

当直接连接到 tomcat 时,在 Not Modified header 之后我没有收到任何意外数据。

Apache Server 配置没有太多修改,只是/contents 的别名和两个 modjk 指令:

JkMount /* ajp13_worker
JkUnMount /contents/* ajp13_worker

与/struts 或缓存或任何异国情调无关。 ModJK 配置是默认设置。

有什么建议吗?

最佳答案

这个答案并没有解决问题,而是提出了新的问题。

在 apache 服务器后面使用 sitemesh3 时会发生响应损坏。如果我直接访问 tomcat 服务器,响应是干净的 304。如果我通过 modjk/apache 访问,则响应包含意外数据。

意外数据的原因是由于 sitemesh 的工作方式:发送响应时,在某些时候它会强制 struts 忽略任何“If-Modified-Since” header ,将请求的内容写入响应缓冲区。然后继续在缓冲区的开头添加 304 header 。

先看看

org.sitemesh.webapp.contentfilter.HttpServletRequestFilterable
org.apache.struts2.dispatcher.DefaultStaticContentLoader.process()

我不知道从这里去哪里。这是一个错误吗?它是 Apache 服务器错误、Tomcat 错误、Struts 错误还是 Sitemesh 错误?!

要重现该问题,您需要在 apache 后面运行一个带有 sitemesh 的 struts webapp 的 tomcat,并在 fiddler2 处于事件状态时获取此 url 两次:

http://[test.server.address]/struts/utils.js

小菜一碟o_O'

编辑:

如果我查看 modjk 日志,我可以清楚地看到传输回 Apache 服务器的文件:

: trying to connect socket 29 to 127.0.0.1:9009                                                     
: socket 29 [127.0.0.1:57195 -> 127.0.0.1:9009] connected
: sending to ajp13 pos=4 len=581 max=8192
.4.A....HTTP/1.1
.../struts/utils
.js...2.235.97.2
[...]
...Accept-Langua
ge..#en,en-US;q=
0.8,it-IT;q=0.6,
it;q=0.4....+JSE
SSIONID=B77369AB
D8239724A27A5CC5
6E06DED8...If-Mo
dified-Since...F
ri,.27.Jun.2014.
08:37:46.GMT....
.0....AJP_REMOTE
_PORT...19143...
.JK_LB_ACTIVATIO
N...............
: (rdp_worker) request body to send 0 - request body to resend 0
: received from ajp13 pos=0 len=20 max=8192
..0..Not.Modifie
d...............
: status = 304
: Number of headers is = 0
: received from ajp13 pos=0 len=4767 max=8192
.../*..*.$Id:.ut
ils.js.1240312.2
012-02-03.19:44:
51Z.jogep.$..*..
*.Licensed.to.th
e.Apache.Softwar
e.Foundation.(AS
F).under.one..*.
or.more.contribu
tor.license.agre
ements...See.the
[...]
the.ajaxValidati
on.interceptor.S
trutsUtils.getVa
lidationErrors.=
: ws_write::mod_jk.c (537): written 4763 out of 4763
: received from ajp13 pos=0 len=4 max=8192
................
: received from ajp13 pos=0 len=2 max=8192
................
: AJP13 protocol: Reuse is OK

当我直接访问 tomcat 并使用 tcpflow 转储 TCP 流量时,我没有看到任何虚假数据:

# tcpflow -p -s -c host xxx.xxx.xxx.xxx and port 8080

xxx.xxx.xxx.xxx.19292-yyy.yyy.yyy.yyy.08080: GET /rdp/struts/utils.js HTTP/1.1
Host: xxx.net:8080
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en,en-US;q=0.8,it-IT;q=0.6,it;q=0.4
Cookie: JSESSIONID=B0F02CXXXEC3448F1B927C0E8C579A9B
If-Modified-Since: Fri, 27 Jun 2014 08:49:23 GMT


yyy.yyy.yyy.yyy.08080-xxx.xxx.xxx.xxx.19292: HTTP/1.1 304 Not Modified
Server: Apache-Coyote/1.1
Date: Fri, 27 Jun 2014 08:52:43 GMT

因此,将缓冲区返回到 ajp 端口和将其返回到网络套接字似乎有不同的行为。这水平太低了,我无法进一步了解。

编辑:

解决方法

我实现的变通方法是让 Apache 服务器处理/struts 上下文:

  • 从 struts 和 struts-jquery-plugin jar 中提取所有受影响的文件(分别是 org\apache\struts2\static 的内容和模板的内容)
  • 将这些文件复制到服务器上的一个目录中
  • 在 apache 中创建一个别名以在遇到/struts 路径时为该目录提供服务
  • 从 modJK 取消映射/struts 路径

关于apache - "Not Modified"标题后跟带有 sitemesh3 和 mod-jk 的意外内容正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24430135/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com