spring-ws-test:如何模拟 SoapFaultDetail

spring-ws-test: How to mock a SoapFaultDetail

使用 spring-ws-test 如何将 SoapFaultDetail 模拟为 return 预期的错误负载?

ResponseCreators 似乎只支持 faultString/ faultReason:

mockServer.expect(anything()).andRespond(withClientOrSenderFault(faultStringOrReason, Locale.GERMAN));

未设置详细信息元素。但是,我需要错误来包含我的自定义负载。

是否有高级别API可以做到这一点?

您可以使用 ResponseCreatorswithPayload 方法并为其提供包含您的自定义负载的 SOAP 故障,如下所示:

    Source faultPayload = new StringSource(
            "<SOAP-ENV:Fault xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:v1=\"http://domain/schema/common/fault\">"
                    + "<faultcode>SOAP-ENV:Server</faultcode>"
                    + "<faultstring xml:lang=\"en\">fault</faultstring>"
                    + "<detail>"
                    + "<v1:custompayload>"
                    + "<v1:element1>element1</v1:element1>"
                    + "<v1:element2>element2</v1:element2>"
                    + "</v1:custompayload>" 
                    + "</detail>"
                    + "</SOAP-ENV:Fault>");

    mockWebServiceServer.expect(payload(requestPayload))
            .andRespond(withPayload(faultPayload));