Java Reference
In-Depth Information
@FaultAction(className=HelloException.class,
value="http://soacookbook.com/myFault")})
public String sayHello(String name) throws HelloException {
if (name == null || "".equals(name)) {
throw new HelloException("The name was null or empty.");
}
return "Hello, " + name;
}
}
That's all there is to it. Because the fault attribute of the Action annotation accepts an array,
you can specify multiple FaultAction s, one for each exception your method throws. For this
example, I created a new exception called HelloException , which is shown in Example 12-3 .
Example12-3.Exception that is addressed using FaultAction in web service
package com.soacookbook;
public class HelloException extends Exception {
public HelloException(String msg){
super("Could not say hello: " + msg);
}
}
This class just extends Exception as a checked exception, and because it's not the focus of
this recipe, I haven't added lots of other methods to it. It only exists to show how you could
map to a custom exception.
Deploying this service endpoint implementation code generates the WSDL shown in
Example 12-4 .
Example12-4.The WSDL using WS-Addressing for faults
<definitions xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
targetNamespace="http://soacookbook.com/"...>
<types>
<xsd:schema>
<xsd:import namespace="http://soacookbook.com/"
schemaLocation="http://localhost:7777/TestWS/
HelloAddressingFaultsWSService?xsd=1" />
</xsd:schema>
</types>
<message name="sayHello">
<part name="parameters" element="tns:sayHello" />
</message>
Search WWH ::




Custom Search