作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 spring-ws-test 如何模拟 SoapFaultDetail 以返回预期的错误负载?
ResponseCreators似乎只支持faultString/faultReason:
mockServer.expect(anything()).andRespond(withClientOrSenderFault(faultStringOrReason, Locale.GERMAN));
未设置详细信息元素。然而,我需要错误来包含我的自定义负载。
是否有高级 API 可以执行此操作?
最佳答案
您可以使用 ResponseCreators
的 withPayload
方法,并向其提供包含自定义负载的 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));
关于java - Spring -WS-测试: How to mock a SoapFaultDetail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40806849/
我是一名优秀的程序员,十分优秀!