【问题标题】:cxf generated wsdl: change soap address location protocol to httpscxf 生成的wsdl:将soap地址定位协议改为https
【发布时间】:2018-07-24 14:48:50
【问题描述】:

我使用 spring boot ws 应用程序和 apache cxf 来提供 SOAP Web 服务。所有配置的 URL 都使用相对路径,因此应用程序可以用于灵活的部署。

在生产环境中,应用程序在负载均衡器后面运行,并强制客户端使用 https。但是生成的 wsdl 保留了它的 http 协议,尽管 wsdl 本身是使用 https 公开的。

这是spring端点配置:

@Bean
  public Endpoint endpoint() {
    EndpointImpl endpoint = new EndpointImpl(springBus(), requestStatusApplicationService());
    RequestStatusReceiverService requestStatusReceiverService = requestStatusReceiverService();
    endpoint.setServiceName(requestStatusReceiverService.getServiceName());
    endpoint.setWsdlLocation(requestStatusReceiverService.getWSDLDocumentLocation().toString()); // also a relative path
    endpoint.publish("/relative-path-endpoint");
    return endpoint;
  }

如何调整生成的 wsdl,使其切换到 https? 或者更好:是否可以强制协议使用与暴露的 wsdl 本身相同的协议?

最好, 拉尔斯

【问题讨论】:

    标签: java spring spring-boot cxf spring-ws


    【解决方案1】:

    在您的 spring-boot 应用程序中,如果您使用的是 cxf 框架,那么您可以添加您的自定义拦截器以传递自定义 url。

    public class MyInInterceptor extends AbstractInDatabindingInterceptor {
    
        private String url;
    
        public CustomInInterceptor(String url) {
            super(Phase.USER_STREAM);
            this.url = url;
        }
    
        @Override
        public void handleMessage(Message message) throws Fault {
            message.put("org.apache.cxf.request.url", url);
        }
    }
    

    你需要在你的配置文件中像这样配置这个拦截器。

    EndpointImpl endpoint = new EndpointImpl(bus, communicationPortTypeImpl);
    List<Interceptor<? extends Message>> interceptors = new ArrayList<>();
    interceptors.add(new MyInInterceptor(endpointUrl));
    endpoint.setInInterceptors(interceptors);
    endpoint.publish("/myEndPoint");
    

    【讨论】:

      【解决方案2】:

      我在我的项目中也遇到了类似的问题,我通过使用 spring boot 参数解决了它。我们有一个 ngnix 服务器,它接收请求并转发到具有 Spring Boot 应用程序的后端机器。

      在 ngnix 配置中添加了以下参数。

      proxy_set_header X-Forwarded-Proto https;
      proxy_set_header X-Forwarded-Scheme https;
      

      后来在spring boot应用中添加了如下参数

      server.tomcat.remote-ip-header=x-forwarded-for
      server.tomcat.protocol-header=x-forwarded-proto
      

      在此服务器开始将 https 附加到 URL 之后。

      【讨论】:

      • 我不认为 server.tomcat.* 属性真的需要,如果你只是修复代理标头,是吗?在这里,没有它们似乎也可以工作。
      猜你喜欢
      • 2012-04-21
      • 1970-01-01
      • 2017-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多