-
@Documented @Retention(RUNTIME) @Target(METHOD) public @interface FaultAction
所述FaultAction
注解用于内部Action
注释以允许WS寻址的显式关联Action
与消息寻址属性fault
从异常类映射到的WSDL操作的消息。该
wsam:Action
在属性值fault
在映射所生成的WSDL操作消息className
类是等于在相应的值FaultAction
。 对于故障消息的wsam:Action
值的精确计算,请参考JAX-WS规范中的算法。实施例1:显式指定值
Action
消息寻址属性为input
,output
和fault
消息如果Java方法抛出只有一个服务特定的异常。@WebService(targetNamespace="http://example.com/numbers") public class AddNumbersImpl { @Action( fault = { @FaultAction(className=AddNumbersException.class, value="http://example.com/faultAction") }) public int addNumbers(int number1, int number2) throws AddNumbersException { return number1 + number2; } }
生成的WSDL如下所示:<definitions targetNamespace="http://example.com/numbers" ...> ... <portType name="AddNumbersPortType"> <operation name="AddNumbers"> ... <fault message="tns:AddNumbersException" name="AddNumbersException"
wsam:Action="http://example.com/faultAction"/> </operation> </portType> ... </definitions>
示例2:下面是一个示例,显示服务特定异常的
Action
消息寻址属性的显式值是否不存在。@WebService(targetNamespace="http://example.com/numbers") public class AddNumbersImpl { public int addNumbers(int number1, int number2) throws AddNumbersException { return number1 + number2; } }
生成的WSDL如下所示:<definitions targetNamespace="http://example.com/numbers" ...> ... <portType name="AddNumbersPortType"> <operation name="AddNumbers"> ... <fault message="tns:addNumbersFault" name="InvalidNumbers"
wsam:Action="http://example.com/numbers/AddNumbersPortType/AddNumbers/Fault/AddNumbersException"/> </operation> </portType> ... </definitions>
示例3:这是一个示例,显示如果Java方法抛出多个特定于服务的异常,如何指定
Action
消息寻址属性的显式值。@WebService(targetNamespace="http://example.com/numbers") public class AddNumbersImpl { @Action( fault = { @FaultAction(className=AddNumbersException.class, value="http://example.com/addFaultAction"), @FaultAction(className=TooBigNumbersException.class, value="http://example.com/toobigFaultAction") }) public int addNumbers(int number1, int number2) throws AddNumbersException, TooBigNumbersException { return number1 + number2; } }
生成的WSDL如下所示:<definitions targetNamespace="http://example.com/numbers" ...> ... <portType name="AddNumbersPortType"> <operation name="AddNumbers"> ... <fault message="tns:addNumbersFault" name="AddNumbersException"
wsam:Action="http://example.com/addFaultAction"/> <fault message="tns:tooBigNumbersFault" name="TooBigNumbersException"
wsam:Action="http://example.com/toobigFaultAction"/> </operation> </portType> ... </definitions>
- 从以下版本开始:
- 1.6,JAX-WS 2.1