【问题标题】:Ignoring xml namespace during unmarshalling in RestTemplate在 RestTemplate 中解组期间忽略 xml 命名空间
【发布时间】:2016-06-24 20:18:07
【问题描述】:

我通过 Spring RestTemplate 通过 HTTP 请求将 XML 发送到外部网关,并且收到了返回的 XML 响应。

用于验证响应的 XSD 具有目标命名空间,但实际响应不包含命名空间前缀。我已经使用 XSD 生成了 Java 资源,因此在(在解组过程中)获得响应时出现以下错误,

ResponseEntity<Response> responseEntity = restTemplate.exchange(endpointURL, HttpMethod.POST, requestEntity,
                Response.class);

例外情况是:-

Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"Response"). Expected elements are <{http://securetransport.dw/rcservice/xml}Response>

有什么方法可以跳过 Spring ResponseEntity 的命名空间检查?

【问题讨论】:

    标签: java xml spring xsd resttemplate


    【解决方案1】:

    如果您使用 jaxb-plugin 生成了绑定,则应该有一个“package-info.java”。

    例如:

    @javax.xml.bind.annotation.XmlSchema( namespace = "someurl", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED )

    如果你从注解中移除命名空间,它应该可以工作。

    【讨论】:

      猜你喜欢
      • 2010-09-21
      • 2023-03-11
      • 1970-01-01
      • 2015-06-19
      • 2011-12-29
      • 2011-02-17
      • 2011-12-05
      • 2015-02-18
      • 1970-01-01
      相关资源
      最近更新 更多