spring-boot - 覆盖 WSDL 中的整个地址

标签 spring-boot soap wsdl

我使用本指南创建了一个简单的 spring-boot SOAP 网络服务:
https://spring.io/guides/gs/producing-web-service/

我正在将它部署到云服务,但在它前面会有一个 API 管理层。

我希望 WSDL 能够使用 API 管理层的 URL。 (基本上对地址进行硬编码。)

我尝试了两种方法:

  • 使用 DefaultWsdl11Definition.setLocationUri()
    @Bean(name = "countries")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
    DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
    wsdl11Definition.setPortTypeName("CountriesPort");
    wsdl11Definition.setLocationUri("http://example.com/ws");
    wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");
    wsdl11Definition.setSchema(countriesSchema);
    return wsdl11Definition;
    }
    
  • 使用 SimpleWsdl11Definition.setWsdl() 指向手动编辑的 WSDL
    @Bean(name = "countries")
    public SimpleWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
    SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
    wsdl11Definition.setWsdl(new ClassPathResource("countries.wsdl")); //this WSDL was edited to have the path I want
    return wsdl11Definition;
    } 
    

  • 我正在用 Maven 构建。在这两种情况下,应用程序托管的 WSDL 用它运行的服务器替换主机名,例如http://localhost:8080/然后使用 URI 的其余部分。
        <wsdl:service name="CountriesPortService">
        <wsdl:port binding="tns:CountriesPortSoap11" name="CountriesPortSoap11">
        <soap:address location="http://localhost:8080/ws"/>
        </wsdl:port>
        </wsdl:service>
    

    如何设置/覆盖主机名部分

    最佳答案

    我认为您正在使用 setTransformWsdlLocations(true) messageDispatcherServlet Web 服务配置类的方法。此设置将根据它运行的环境转换 URL。
    删除此行,以便它将采用默认设置 fals 并且不会覆盖。

    关于spring-boot - 覆盖 WSDL 中的整个地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48793251/

    相关文章:

    sockets - HTTP/SOAP 数据包大小

    wsdl - 如何恢复xsd :elements in xsd:sequence wrappers when websphere is upgraded?的原始顺序

    visual-studio-2010 - 无法使用自动创建的 WSDL 代理类发送 SOAP 请求

    java - 如何在 Spring Boot 中发送请求范围 bean 作为响应

    java - 尝试使用 Spring Boot 通过 Oauth2 和 Strava 验证 Web 应用程序时出错

    xml - Powershell invoke-webrequest with xml soap envelope body containing £ char 错误

    PHP SoapClient 发送转义的 XML 字符

    php - FEDEX 网络服务 wsdl 文件

    java - Spring 启动/Tomcat : HTTP -> HTTPS 301 Redirects

    spring-boot - Spring 启动 : Custome @Query with 2 consecutive brackets cause that one pair is ignored