如何扩展 wsimport 生成的带有 WebFault 注释的异常?
我正在根据现有的 WSDL 使用 Java 构建 Web 服务。 wsimport
工具已生成绑定到服务架构中的元素的所有 Java 类。特别是,错误声明生成以下类:
@javax.xml.ws.WebFault(name = "Fault", targetNamespace = "http://my.company.com/service-1")
public class ServiceFault extends java.lang.Exception {
// constructors and faulInfo getter
}
现在我想扩展此类,以便添加更多行为:
public class MyServiceFault extends ServiceFault {
// some behavior
}
当我现在从应用程序中抛出 MyServiceFault
实例时,我预计会出现这些错误在 SOAP 应答中正确序列化为 XML。但相反,我得到的是这样的结果:
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header/>
<env:Body>
<env:Fault>
<faultcode>env:Server</faultcode>
<faultstring>Some fault string.</faultstring>
</env:Fault>
</env:Body>
</env:Envelope>
也就是说,我完全丢失了 failureInfo 元素。我的 SOAP 堆栈将 MyServiceFault
视为任何其他异常,而不是视为表示服务中的错误的异常。
我首先认为这是因为 @WebFault
注解没有被 MyServiceFault
继承,但我在显式添加此注解后再次尝试,没有成功。
知道我在这里做错了什么吗?
I'm building a web service in Java from an existing WSDL. The wsimport
tool has generated all the Java classes bound to the elements in the service's schema. In particular, the fault declaration yields the following class:
@javax.xml.ws.WebFault(name = "Fault", targetNamespace = "http://my.company.com/service-1")
public class ServiceFault extends java.lang.Exception {
// constructors and faulInfo getter
}
Now I'd like to extend this class, so I can add more behavior:
public class MyServiceFault extends ServiceFault {
// some behavior
}
When I now throw instances of MyServiceFault
from my application, I expect these errors to be properly serialized to XML in the SOAP answer. But instead, I get something like this:
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header/>
<env:Body>
<env:Fault>
<faultcode>env:Server</faultcode>
<faultstring>Some fault string.</faultstring>
</env:Fault>
</env:Body>
</env:Envelope>
That is, I am completely missing the faultInfo element. My SOAP stack treats MyServiceFault
as any other exception, not as an exception representing a fault in the service.
I thought first it was because the @WebFault
annotation wasn't inherited by MyServiceFault
, but I've tried again after explicitly adding this annotation, without success.
Any idea what I am doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于它的价值,我已经以这种方式实现了。
它会产生类似的东西:
For what it's worth, I've implemented it this way.
which produces something like: