Spring WS 管理自定义故障
我正在使用配方处理我的定制肥皂故障: http://www.stevideter.com/2009/02/ 18/of-exceptionresolvers-and-xmlbeans/
将(使用身份转换 - 无 XSLT)XML 转换为soap 错误的代码部分详细信息是:
protected void customizeFault(MessageContext messageContext, Object endpoint, Exception ex, SoapFault soapFault) {
Transformer trn = null;
Result result = null;
SoapFaultDetail faultDetail = null;
try {
trn = TransformerFactory.newInstance().newTransformer();
faultDetail = soapFault.addFaultDetail();
// detail contains org.apache.xmlbeans marshalled xml
StreamSource detail = ...
result = faultDetail.getResult();
trn.transform(detail, result);
...
}
当我使用 SoapUI 测试输出时,我收到架构验证错误,因为响应是:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring xml:lang="en">it.fault.InputFault</faultstring>
<detail>
<inputFault xmlns="http://fault.my.it">
<code>ERR-INPUT 003</code>
<message>Dati in input non completi</message>
</inputFault>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我的 XSD 没有 elementFormDefault
所以它是 unqualified
并且响应应如下所示:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring xml:lang="en">it.fault.InputFault</faultstring>
<detail>
<inputFault xmlns="http://fault.my.it">
<code xmlns="">ERR-INPUT 003</code>
<message xmlns="">Dati in input non completi</message>
</inputFault>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
结果应与 xmlnbeans 编组对象相同,并且应包含 xmlns=""
。
有人可以帮助我理解为什么转换删除了 xmlns 声明吗?
谢谢。
I'm handling my custom soap fault using the recipe:
http://www.stevideter.com/2009/02/18/of-exceptionresolvers-and-xmlbeans/
The part of the code which transforms (using identity transformation - no XSLT) XML to soap fault detail is:
protected void customizeFault(MessageContext messageContext, Object endpoint, Exception ex, SoapFault soapFault) {
Transformer trn = null;
Result result = null;
SoapFaultDetail faultDetail = null;
try {
trn = TransformerFactory.newInstance().newTransformer();
faultDetail = soapFault.addFaultDetail();
// detail contains org.apache.xmlbeans marshalled xml
StreamSource detail = ...
result = faultDetail.getResult();
trn.transform(detail, result);
...
}
When I test the output with SoapUI, I'm getting schema validation errors, because the response is:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring xml:lang="en">it.fault.InputFault</faultstring>
<detail>
<inputFault xmlns="http://fault.my.it">
<code>ERR-INPUT 003</code>
<message>Dati in input non completi</message>
</inputFault>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
My XSD has no elementFormDefault
so it is unqualified
and the response should look like this:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring xml:lang="en">it.fault.InputFault</faultstring>
<detail>
<inputFault xmlns="http://fault.my.it">
<code xmlns="">ERR-INPUT 003</code>
<message xmlns="">Dati in input non completi</message>
</inputFault>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The result should be the same as xmlnbeans marshalled object and it should contain xmlns=""
.
Can someone help me to understand why the transformation removed the xmlns
declarations?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以...感谢 Grzegorz Grzybek,我发现 xalan.jar 工作得不太好,如果你将它放在 Jboss 4.2 的“endorsed”目录中并且使用 java 1.5 进行编译。解决方案是下载 xalan-2.7.1.jar 并将其与 xalan all 一起使用应该可以正常工作,将 xmlns="" 放入 SoapREsponse 中,如下所示:
SO... Thanks to Grzegorz Grzybek I have found that xalan.jar, didn't work so well, if you have it on the directory "endorsed" of Jboss 4.2 and you compile with java 1.5. The solution is to download xalan-2.7.1.jar and sostituite it with xalan all should work fine to have xmlns="" into the SoapREsponse like: