简体   繁体   English

WSDL中的Axis2 WebService和多个ExceptionFault元素

[英]Axis2 WebService and multiple ExceptionFault elements in WSDL

I am not AXIS2 expert, therefore I am using Eclipse to generate bottom - up webservice. 我不是AXIS2专家,因此我正在使用Eclipse生成自底向上的Web服务。 I am publishing 2 methods as webservices. 我正在发布2种方法作为Web服务。 These methods are defined to throw java.lang.Exception in order to produce SOAPFault when calling webservice that ends with exception. 定义这些方法以引发java.lang.Exception,以便在调用以异常结尾的webservice时产生SOAPFault。

public class sample {

 public String someMethod() throws Exception {
  throw new CustomException("Error: blabla");
 }


 public String someOtherMethod() throws Exception {
  throw new CustomException("Error: blabla");
 }

}

After publishing webservice, everything is working OK. 发布Web服务后,一切正常。 But WSDL generated by AXIS2 seems to be defect. 但是AXIS2生成的WSDL似乎是缺陷。 There are 2 ExceptionFault elements (one for each method?), which is problem for some webservice clients. 有2个ExceptionFault元素(每个方法一个?),这对于某些Web服务客户端是有问题的。

<xs:element name="ExceptionFault">
   <xs:complexType>
      <xs:sequence>
         <xs:element name="Exception" nillable="true" type="xs:anyType"/>
      </xs:sequence>
   </xs:complexType>
</xs:element>

What is the problem? 问题是什么? Is there something wrong with my implementation? 我的实现有问题吗? I have also tried to declare methods to throw directly CustomException, or to throw Exception, but with no success... 我也试图声明直接抛出CustomException或抛出Exception的方法,但是没有成功...

Martin 马丁

If you remove the "throws Exception" from the method signatures it won't generate WSDL with an Exception element. 如果您从方法签名中删除“ throws Exception”,它将不会生成带有Exception元素的WSDL。

If your CustomException extends RuntimeException (ie it is an unchecked exception) then you will be fine. 如果您的CustomException扩展了RuntimeException(即它是未经检查的异常),那么您会很好的。 The RuntimeException will get turned into a SOAPFault properly by Axis. Axis会将RuntimeException正确地转换为SOAPFault。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM