繁体   English   中英

如何在Spring Web服务中将复杂的XML添加到SOAP Fault详细信息?

[英]How to add complex XML to SOAP Fault detail in Spring web service?

<soapenv:Fault xmlns:m="http://schemas.xmlsoap.org/soap/envelope/">
     <faultcode>m:Server</faultcode>
     <faultstring>someFaultString</faultstring>
     <detail>
        <NS1:confirmIdentityErrorInfo xmlns:NS1="example.com">
           <faultInfo>
              <faultType>Business Exception</faultType>
              <faultCode>100</faultCode>
              <message>some message</message>
              <faultState>fault state</faultState>
           </faultInfo>
        </NS1:confirmIdentityErrorInfo>
     </detail>
  </soapenv:Fault>

我需要像上面那样生成故障对象。 我能够生成'confirmIdentityErrorInfo'但不能添加子元素。 我试过这个选项,但我无法生成嵌套对象结构。

public class WebServiceConfig extends WsConfigurerAdapter {

 @Bean
    public SoapFaultMappingExceptionResolver exceptionResolver(){
        SoapFaultMappingExceptionResolver exceptionResolver = new DetailSoapFaultDefinitionExceptionResolver();

        SoapFaultDefinition faultDefinition = new SoapFaultDefinition();
        faultDefinition.setFaultCode(SoapFaultDefinition.SERVER);
        exceptionResolver.setDefaultFault(faultDefinition);

        Properties errorMappings = new Properties();
        errorMappings.setProperty(Exception.class.getName(), SoapFaultDefinition.SERVER.toString());
        errorMappings.setProperty(BusinessException.class.getName(), SoapFaultDefinition.SERVER.toString());
        exceptionResolver.setExceptionMappings(errorMappings);
        exceptionResolver.setOrder(1);
        return exceptionResolver;
    }

}


protected void customizeFault(Object endpoint, Exception ex, SoapFault fault) {
    if (ex instanceof BusinessException) {
        SoapFaultDetail detail = fault.addFaultDetail();
        try
        {
            QName entryName = new QName("namespace", "confirmIdentityErrorInfo", "NS1");
            detail.addFaultDetailElement(entryName);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

    }

}

但我不确定如何将子元素添加到QName。 有人可以帮助我如何产生如上所示的故障细节?

这是解决方案。

fault.addFaultDetail();
   this.marshaller.marshal(((AJAXB2MarshalledBusinessException)ex).getMyJAXB2MarshallableComplexMessage(), fault.getFaultDetail().getResult());

更多详细信息在此链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM