我遇到了 HTTP 响应不正确的问题Content-Type
通过 AJP/1.3 连接器访问 Apache 后面的 Tomcat 中托管的 Axis2 Web 服务时,会使用此标头。
我可以通过其 RESTful 接口在浏览器中毫无问题地访问 Web 服务,并且可以看到结果,但不知何故 Apache 正在更改响应Content-Type
Tomcat 发送的标头来自text/xml
to text/plain
它阻止我通过 NetBeans 中的 SOAP 使用 Web 服务,因为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" />
如果我使用端口 8080 上的默认连接器直接在 Tomcat 中访问 WS,我会得到正确的结果content-type
但如果我通过 Apache 访问它,我就会得到text/plain
,所以肯定是代理的问题。
我怎么解决这个问题?
EDIT:我通过使用 Tomcat HTTP 连接器(而不是 AJP 连接器)进行代理来使其工作,但如果我找到可行的解决方案,我更愿意使用 mod_ajp。
我刚刚改变了
ProxyPass ajp://localhost:8009/axis2/services
ProxyPassReverse ajp://localhost:8009/axis2/services
lines to
ProxyPass http://localhost:8080/axis2/services
ProxyPassReverse http://localhost:8080/axis2/services