"未修改"头,紧跟着意想不到的内容主体与sitemesh3和MOD-JK [英] "Not Modified" header followed by unexpected content body with sitemesh3 and mod-jk

查看:693
本文介绍了"未修改"头,紧跟着意想不到的内容主体与sitemesh3和MOD-JK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Java / Struts2的/ Tomcat应用程序,要求一些资源生成一个304未修改响应时,该文件仍然在响应中发送。

In my Java / Struts2 / Tomcat application, when requesting some resources that generate a "304 Not Modified" response, the file is still being sent in the response.

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

This is a response example captured with 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||
[...]

这是因为返回的文件的内容插入到下一个请求的文件,在腐败和怪异的行为结束了一个问题。

This is a problem because the content of the returned file is inserted into the next requested file, ending up in corruption and weird behavior.

这只是发生在从/支柱路径加载的资源,如:

This only happens on resources loaded from the "/struts" path, like:

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

在/支柱路径由Struts2的类处理

The "/struts" path is handled by the struts2 class

org.apache.struts2.dispatcher.DefaultStaticContentLoader

这些是该系统的相关要素:

These are the relevant elements of the system:


  • 的Ubuntu 12.04.4 LTS(GNU / Linux的3.5.0-27-x86_64的仿制)

  • JVM 1.6.0_31-b31的Sun微系统公司(也试图与IBM-java的x86_64-71)

  • 的Apache2 2.2.22-1ubuntu1.6与modjk

  • 的Apache Tomcat / 6.0.35

  • 的Struts 2.3.16

  • SiteMesh的3.0.0

当直接连接到Tomcat我不的不修改头之后得到任何意外的数据。

When connecting directly to tomcat I don't get any unexpected data after the Not Modified header.

Apache服务器的配置没有被修改过了,只是一个别名/内容和两个modjk指令:

The Apache Server configuration hasn't been modified much, just an alias for /contents and two modjk directives:

JkMount /* ajp13_worker
JkUnMount /contents/* ajp13_worker

有什么关系/支柱或缓存或任何东西异国情调。 ModJK配置为默认设置。

There is nothing related to /struts or caching or anything exotic. ModJK configuration is the default settings.

任何建议?

推荐答案

这是不解决问题的答案,但开辟了新的问题。

This is an answer that doesn't solve the problem, but opens new questions.

背后使用Apache服务器sitemesh3时出现的反应腐败。
如果我直接访问Tomcat服务器,响应是一种清洁304。
如果我通过modjk / Apache访问,响应包含意外的数据。

The response corruption occurs when using sitemesh3 behind apache server. If I access the tomcat server directly, the response is a clean 304. If I access through a modjk/apache, the response contains unexpected data.

的原因意外的数据是由于怎样的sitemesh作品:发送响应时,在某些时候它迫使支柱忽略任何如果-Modified-Since的标题,写请求的内容来响应缓冲区。然后,它通过添加304标头以及在缓冲器的开头继续。

The reason for the unexpected data is due to how sitemesh works: when sending the response, at some point it forces struts to ignore any "If-Modified-Since" header, writing the requested content to the response buffer. It then goes on by adding the 304 headers as well at the beginning of the buffer.

见启动

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

我不知道在哪里可以从这里走。它是一个错误吗?它是一个Apache服务器错误或一个Tomcat错误或一个Struts错误或一个错误的sitemesh?!

I don't know where to go from here. Is it a bug? Is it an Apache Server bug or a Tomcat bug or a Struts bug or a Sitemesh bug?!

要复制的问题,你需要运行在它的sitemesh一个Struts web应用背后的Apache Tomcat的,并两次抓取该网址而fiddler2是活动:

To replicate the problem, you need a tomcat behind apache running a struts webapp with sitemesh in it, and fetch this url twice while fiddler2 is active:

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

O_O蛋糕这块

Piece of cake o_O'

编辑:

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

If I check the modjk log, I can clearly see the file transmitted back to Apache server:

: 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流量,我没有看到任何虚假数据:

When I access tomcat directly and dump the TCP traffic with tcpflow, I don't see any spurious data:

# 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端口,并返回到网络套接字一个不同的行为。这是级别太低,我进一步得到任何。

So there seems to be a different behavior in returning the buffer to an ajp port and returning it to a network socket. This is too low level for me to get any further.

编辑:

解决方法

我已实施的解决方法在于让Apache服务器处理/ struts的背景:

The workaround I have implemented consists in letting Apache Server handle the /struts context:


  • 从Struts和Struts的jQuery的,插件罐提取物,所有受影响的文件
  • (组织\\阿帕奇\\ struts2的\\静态和模板分别是内容的内容)
  • 复制服务器上的目录中这些文件

  • 创建Apache中的别名担任该目录时/支柱路径遇到

  • 取消映射/支柱从modJK路径

  • extract from the struts and struts-jquery-plugin jars all files that are affected (the content of org\apache\struts2\static and the content of template respectively)
  • copy these files on a directory on the server
  • create an alias in apache to serve that directory when the /struts path is encountered
  • unmap the /struts path from modJK

这篇关于&QUOT;未修改&QUOT;头,紧跟着意想不到的内容主体与sitemesh3和MOD-JK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆