【问题标题】:Spring soap ws is not running with the request having no namespace prefix in xml tagsSpring soap ws 没有在 xml 标签中没有命名空间前缀的请求运行
【发布时间】:2019-10-13 00:41:43
【问题描述】:

我已经生成了一个 wsdl 文件,我用它来编写一个 springboot soap ws,但是当我在soapUi 中加载该 wsdl 文件以创建一个测试我的 ws 的请求时,我收到一个请求,其中包含缺少命名空间前缀的嵌套标签。在触发该请求时,由于没有前缀标签,springboot 给出 saaj soap 异常并出现 404 错误。

当我手动为所有标签添加命名空间前缀时,ws 工作正常。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservice.studentinfo.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <web:studentData>
         <student>
               <name>?</name>
               <roll_number>?</roll_number>
               <address>
                  <house_number>?</house_number>
                  <street>?</street>
                  <city>?</city>
                  <state>?</state>
               </address>
            </student>
    </web:studentData>
   </soapenv:Body>
</soapenv:Envelope>

如果我在标签内的所有嵌套标签中添加“web:”,我的 ws 会按预期工作,但对于上述请求,它不会。由于我无法将 wsdl 格式更改为某个第三方应用程序的输出,有什么办法可以通过调用此请求本身来让我的 ws 工作。

【问题讨论】:

    标签: spring-boot soap


    【解决方案1】:

    您可以像这样添加特定的映射器您的配置

    public class MyNamespaceMapper extends NamespacePrefixMapper {
    
    private static final String FOO_PREFIX = ""; // DEFAULT NAMESPACE
    private static final String FOO_URI = "http://www.example.com/FOO";
    
    private static final String BAR_PREFIX = "bar";
    private static final String BAR_URI = "http://www.example.com/BAR";
    
    @Override
    public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
        if(FOO_URI.equals(namespaceUri)) {
            return FOO_PREFIX;
        } else if(BAR_URI.equals(namespaceUri)) {
            return BAR_PREFIX;
        }
        return suggestion;
    }
    
    @Override
    public String[] getPreDeclaredNamespaceUris() {
        return new String[] { FOO_URI, BAR_URI };
    }
    
    }
    

    你可以关注这个tutorial。但是,你需要添加这个配置 spring ws 的 spring ws 可能会出现问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-04
      • 1970-01-01
      • 2022-08-10
      • 2012-08-27
      • 2021-09-28
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      相关资源
      最近更新 更多