Performing schema validation on incoming SOAP messages in WebSphere

I've got some webservices and I'd like to do schema validation on the incoming messages. From my research, I've seen that there is an annotation @SchemaValidation, but it's only available on Oracle's JBoss (and possibly on WebLogic and Glassfish as well?) and not on WebSphere.

The only solution I could think of for WebSphere was to write a custom SOAP handler and validate incoming XML there, but the problem is I don't know how to pass the validation errors to my web service implementation class so I can return a fault that contains the errors to the client.

Are there any better ways to validate SOAP messages on WebSphere (version 7)?

Upvotes: 2

Views: 2572

Answers (1)

Aha... I had to throw a SOAPFaultException from the custom SOAPHandler, like this:

try
{
    ...
    ...
    validator.validate(source); 
}
catch (SAXException saxe)
{
    System.out.println("SAXException occurred");
    SOAPFault fault = null;
    try
    {
        fault = SOAPFactory.newInstance().createFault();
        fault.setFaultString(saxe.getMessage());
    }
    catch (SOAPException soape)
    {
        LOG.error("Error creating SOAPFault: "+soape.getMessage());
    }
    throw new SOAPFaultException(fault);
}

The SOAPFaultException gets sent back the calling client and they can see the validation error that their message caused.

Upvotes: 2

Related Questions