代码之家  ›  专栏  ›  技术社区  ›  Kris Swat

解组SOAP错误JAXB

  •  0
  • Kris Swat  · 技术社区  · 6 年前

    我需要帮助来使用JAXB java类解组SOAP响应

     <soapenv:Fault>
          <faultcode>soapenv:Server</faultcode>
          <faultstring>DLResponseException</faultstring>
          <detail>...
         ....
    

    我创建了一个java类,根元素如下

    @XmlRootElement(name="Fault", namespace="http://schemas.xmlsoap.org/soap/envelope/")
    public class MFaultResponse{
    ..
    }
    

    用法:

     InputStream is = new ByteArrayInputStream(sample.getBytes());
    
        JAXBContext jaxbContext = JAXBContext.newInstance(MFaultResponse.class);  
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();  
    
        MFaultResponse response= (MFaultResponse) jaxbUnmarshaller.unmarshal(is);
        System.out.println(response.getFaultCode());
    

    例外情况:

    原因:org.xml.sax.SAXParseException;行号:1;列号:16;未绑定元素“soapenv:Fault”的前缀“soapenv”。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Artem Bilan    6 年前

    这个问题与Spring集成无关,与Spring完全无关。

    当您有一个xml片段时,这是典型的JAXB情况我知道这是SOAP响应的主体,但是正如您看到的那样 soapenv 在SOAP信封的根上声明。

    如果没有这个前缀,就可以对文档进行解组,但因为它是一个片段,而不是整个SOAP响应,所以我建议使用手动XPath来提取这3个标记的值并构建这样一个 MFaultResponse 手动操作。

    但不确定,为什么标准 SoapFault Spring WS中的方法对您不起作用。。