2010-08-03 79 views
7

我在与一个不正确的HTTP响应Content-Type头一个问题,同时通过访问在Tomcat中托管后面的Apache Axis2 Web服务,通​​过AJP连接器发送到Apache Tomcat的HTTP响应的Content-Type头一个AJP/1.3连接器。如何保存使用mod_proxy

我可以通过它的RESTful接口没有问题访问Web服务在浏览器中,我可以看到的结果,但不知何故Apache是​​改变从text/xml被Tomcat发送的响应Content-Typetext/plain,它使我从使用Web服务通过NetBeans中的SOAP,因为Unsupported Content-Type: text/plain Supported ones are: [text/xml]异常。

这里是我的Apache虚拟主机配置的相关章节:

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    ServerName myserver.example 
    ServerAlias other.myserver.example 

    ProxyPreserveHost On 
    SetEnv force-proxy-request-1.0 1 
    SetEnv proxy-nokeepalive 1 

    <Location /axis2/services> 
     ProxyPass ajp://localhost:8009/axis2/services 
     ProxyPassReverse ajp://localhost:8009/axis2/services 
    </Location> 
</VirtualHost> 

我的Tomcat的server.xml中的相关章节:

<Connector port="8009" protocol="AJP/1.3" redirectPort="9443" /> 

<Connector port="9443" protocol="HTTP/1.1" SSLEnabled="true" maxHttpHeaderSize="8192" 
    maxThreads="150" minSpareThreads="25" maxSpareThreads="75" 
    enableLookups="false" disableUploadTimeout="true" 
    acceptCount="100" scheme="https" secure="true" 
    clientAuth="false" sslProtocol="TLS" 
    SSLCertificateFile="path/to/bundle" 
    SSLCertificateKeyFile="path/to/key" 
    SSLPassword="S3cr3t" 
    proxyName="myserver.example" proxyPort="443" /> 

如果我使用默认的直接访问WS在Tomcat中8080端口连接器,我得到了正确的content-type但如果我通过Apache访问它,然后我得到text/plain,所以它肯定与代理问题。

我该如何解决这个问题?

编辑:我通过使用代理的Tomcat HTTP连接器,而不是AJP之一,但我更喜欢使用mod_ajp,如果我找到一个工作的解决方案。

我只是改变了

ProxyPass ajp://localhost:8009/axis2/services 
ProxyPassReverse ajp://localhost:8009/axis2/services 

线

ProxyPass http://localhost:8080/axis2/services 
ProxyPassReverse http://localhost:8080/axis2/services 
+0

http://markmail.org/message/btwcnbl2i7ftwj4n#query:apache%20ajp%20changes%20Content -type%2Bpage + page:1 + mid:btwcnbl2i7ftwj4n + state:结果似乎与您的问题相关 – JoseK 2010-08-04 06:32:58

+1

是的,这是同样的问题,我已经发现了一些类似于2007年的邮件存档之前发布的问题在这里,但我仍然可以找不到解决这个问题的办法。 – tsbnunes 2010-08-04 13:50:51

回答

2

我花了近两天在工作跟踪与此类似。

已经有生产在过去类似这样的问题了几个错误,在双方的Apache httpd和Tomcat的,但大多数人似乎已经至少2年前解决。我觉得这个人是用什么软件,目前任何人都可能是击球 - 这是肯定是我目前遇到:

https://issues.apache.org/bugzilla/show_bug.cgi?id=49929

有可能是在Tomcat中7.x的一个补丁,但没有人测试过然而。 我打算这样做,当我在一个星期左右时间,以及产生一个可靠的测试情况下,所以这可以得到固定在Tomcat中的所有相关版本。

这仅使用APR时发生,所以一个中间的解决方案是,以避免(但可能有性能后果)。

9
# DefaultType: the default MIME type the server will use for a document 
# if it cannot otherwise determine one, such as from filename extensions. 
# If your server contains mostly text or HTML documents, "text/plain" is 
# a good value. If most of your content is binary, such as applications 
# or images, you may want to use "application/octet-stream" instead to 
# keep browsers from trying to display binary files as though they are 
# text. 
# 
DefaultType None 

这是解决方案。 看这部分在httpd.conf,这一点很重要DefalutType是无。 如果您看到纯文本/文本,这是问题所在。 对不起,这个解决方案不是我的,但我没有找到我在哪个博客找到它:-)

+0

它适用于我,许多thx – zhiyelee 2014-01-16 14:21:09

+0

谢谢。该代理人正在与401结盟。这项工作! – matzeihnsein 2015-09-24 11:28:08

1

这解决了我的头疼。我将Apache 2.2作为前端,mod_proxy_ajp和jboss作为后端。几个交易失败

Message: Client found response content type of 'text/plain; charset=UTF-8', but expected 'text/xml'. 

我的Apache确实有'text/plain'作为DefaultType。然而,我没有在全球层面(httpd.conf)改变这一点。我去了,在<proxy>配置部分的虚拟主机配置中添加了一条新线,将其设置为text/xml

DefaultType text/xml 

我曾尝试使用None我没有工作,然后我刚:

'' in the error msg instead of 'text/plain'.