Spring 生成的 WSDL 公开了错误的协议(HTTP 与 HTTPS)端点位置

Spring Generated WSDL exposes wrong protocol (HTTP vs HTTPS) endpoint location

我有一个 Tomcat 服务器 运行 "behind" 一个 Apache 2(通过 mod_proxy),在 Tomcat 中有一个 WAR 为 Spring 生成的 Web 服务提供服务,它公开这样的服务:

<wsdl:service name="EcoboxPortService">
    <wsdl:port binding="tns:EcoboxPortSoap11" name="EcoboxPortSoap11">
        <soap:address location="http://host:80/ecobox-ws/Ecobox"/>
    </wsdl:port>
</wsdl:service>

问题是WSDL其实是通过下面URL得到的:

https://host/ecobox-ws/ecobox.wsdl (Please note it uses HTTPS)

鉴于以上2个问题出现:

  1. 为什么 WSDL 将“80”端口添加到端点位置?可以覆盖吗?
  2. 为什么它得到 'http' 协议,尽管实际 URL 请求是通过 'https'? Spring 不解释 'X-forwarded-for' headers 吗?

类似的问题,但不是完全有用:change the soap:address location in generated wsdl

相关依赖项:

    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-ws-core</artifactId>
        <version>2.2.2.RELEASE</version>
    </dependency>

相关web.xml摘录:

<servlet>
    <servlet-name>spring-ws</servlet-name>
    <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
    <init-param>
        <param-name>transformWsdlLocations</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

看看here

您需要告诉 MessageDispatcherServlet 变换位置:

<servlet>
 <servlet-name>spring-ws</servlet-name>
 <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
 <init-param>
  <param-name>transformWsdlLocations</param-name>
  <param-value>true</param-value>
 </init-param>
</servlet>

或者如果您使用 Java 配置

If you use the AbstractAnnotationConfigMessageDispatcherServletInitializer, enabling transformation is as simple as overriding the isTransformWsdlLocations() method to return true.

您可能需要检查 Tomcat 配置,您需要在其中设置 "proxyName" 和 "proxyPort"。 JAX-WS auto-generation 应该从那里 / request-headers 那里捡起来。 此处有更多信息:http://tomcat.apache.org/tomcat-6.0-doc/proxy-howto.html