I'm having an issue with Jax-Ws and also after searching the net for day I found no working solution. I'm running my Soap Ws on a local jboss eap7.
The relevant snippet of my wsdl looks like this:
<xs:complexType name="simpleTravelingDay">
<xs:sequence>
<xs:element name="gid" type="xs:string"/>
<xs:element name="dayType" type="xs:long"/>
<xs:element name="date" type="xs:dateTime"/>
<xs:element name="projectId" type="xs:long"/>
My webservice looks like this:
@WebService(name = "TravelTrackerWS")
public interface TravelTrackerWSLocal {
@WebMethod(operationName = "fillSimpleTravelingDays")
public WsAnswer fillSimpleAndTravelingDays(
@XmlElement(required = true, nillable = false) @WebParam(name = "SimpleAndTravelingDays") List<SimpleTravelingDay> days)
throws InsufficientRightsException;
}
If I do a request like this:
<soapenv:Header/>
<soapenv:Body>
<ser:fillSimpleTravelingDays>
<!--1 or more repetitions:-->
<SimpleAndTravelingDays>
<gid>Z0030UDK</gid>
<date>2014-10-31</date>
<country>AU</country>
<projectId>a</projectId>
</SimpleAndTravelingDays>
</ser:fillSimpleTravelingDays>
I get an Unmarshalling Error, which is correct, because 'a' is a String and not Long.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Unmarshalling Error: For input string: "a"</faultstring>
</soap:Fault>
My Question right now is. How can I catch the Unmarshalling Error, so that I can throw a generic error message instead of the unmarshalling error.
I hope anyone can help me
You can change error message using
ValidationEventHandler
.Eg:
To configure your endpoint to use this handler you can add a interceptor that inserts handler to the context.
Finally your endpoint looks like:
In JBoss 7 for this works you must add the dependency to cxf:
You can see a full example in: https://github.com/fedesierr/schemavalidation-ws