我正在尝试实现下面的自定义soap故障:
@SoapFault(faultCode = FaultCode.CUSTOM, customFaultCode="{namespace}Server Error", faultStringOrReason="Error encountered when processing request message.")
public class SystemFault extends BusinessException{ }.
抛出的肥皂故障具有以下格式:
<.SOAP-ENV:Fault>
<.faultcode xmlns:ns0="namespace">ns0:star:Server Error<./faultcode>
<.faultstring xml:lang="en">Error Encountered when processing the request.<./faultstring>
<./SOAP-ENV:Fault>
如您所见,故障代码标记出现在命名空间声明中。如果有任何方法可以避免这种情况,请告诉我。 soap fault客户端期望的格式是:
<.soapenv:Fault xmlns:star="http://www.starstandard.org/STAR/5">
<.faultcode>star:Custom Fault Code<./faultcode>
<.faultstring>Custom Fault message<./faultstring>
<./soapenv:Fault>
我检查了AbstractSoapFaultDefinitionExceptionResolver.resolveExceptionInternal()
方法,它期望QName
实例用于故障代码而不是字符串。请让我知道如何解决这个问题。
答案 0 :(得分:0)
您的Live example note
We have to be get tricky when we run the live example because the host service sets the application base address dynamically. That's why we replace the <base href...> with a script that writes a <base> tag on the fly to match.
<script>document.write('<base href="' + document.location + '" />');</script>
We should only need this trick for the live example, not production code.
语法几乎就在那里!
让我们再一次修改JavaDoc:
customFaultCode
所以,我刚刚决定看看/**
* The custom fault code, to be used if {@link #faultCode()} is set to {@link FaultCode#CUSTOM}.
*
* <p>The format used is that of {@link QName#toString()}, i.e. "{" + Namespace URI + "}" + local part, where the
* namespace is optional.
*
* <p>Note that custom Fault Codes are only supported on SOAP 1.1.
*/
String customFaultCode() default "";
:
{@link QName#toString()}
public String toString() {
if (namespaceURI.equals(XMLConstants.NULL_NS_URI)) {
return localPart;
} else {
return "{" + namespaceURI + "}" + localPart;
}
}
之类的地方:
XMLConstants.NULL_NS_URI
从这里开始看起来就足以让你像普通字符串一样声明:
public static final String NULL_NS_URI = "";
虽然如果您想将customFaultCode="Server Error"
声明移至顶级,则应考虑在自定义xmlns
扩展程序中使用更多低级API:
AbstractSoapFaultDefinitionExceptionResolver
然后,使用带有原始前缀的((SoapMessage) messageContext.getResponse()).getEnvelope().addNamespaceDeclaration("star", "http://www.starstandard.org/STAR/5");
:
customFaultCode
答案 1 :(得分:0)
这似乎是一个老帖子,但只是想尝试帮忙。我认为你不应该担心故障代码和故障描述。 soapFault元素中实际上有第三个字段,它被命名为detail。该元素有两个名为code和description的子元素。用它来携带故障信息。
查看此帖子:http://memorynotfound.com/spring-ws-add-detail-soapfault-exception-handling/
希望这可以提供帮助。 感谢