I have a @Webservice
that requires XSD validation of the input.
Both inputTime
and userInput
of PingInput
are required in my WSDL XSD.
I decorate my webservice with @SchemaValidation
with a custom SchemaValidationErrorHandler
as below.
Because my SchemaValidationErrorHandler
methods below only do a packet.invocationProperties.put
and don't throw an exception , I am expecting that when ping is called, it should still enter my ping method.
What do I need to do to enable this behavior ?
Webservice :
@WebService
@Stateless
@SchemaValidation(handler = SchemaValidationErrorHandler.class)
class MyWebservice {
public PingResponse ping(PingInput input) throws PingFault{
//never gets here when there is a XSD error
Object errorException = messageContext.get(SchemaValidationErrorHandler.ERROR);
...
}
}
SchemaValidationErrorHandler :
import org.xml.sax.SAXParseException;
import com.sun.xml.ws.developer.ValidationErrorHandler;
public class SchemaValidationErrorHandler extends ValidationErrorHandler {
public static final String WARNING = "Warning";
public static final String ERROR = "Error";
public static final String FATAL_ERROR = "Fatal";
public void warning(SAXParseException exception) {
packet.invocationProperties.put(WARNING, exception);
}
public void error(SAXParseException exception) {
packet.invocationProperties.put(ERROR, exception);
}
public void fatalError(SAXParseException exception) {
packet.invocationProperties.put(FATAL_ERROR, exception);
}
Input:
class PingInput {
long inputTime;//required
String userInput;//required
}
I spent more than half a day trying to get this to work, so I am posting an answer. I hope it helps someone else.
It seems that the JavaWS bundled with my application server was the problem.
After including the below dependency in my WAR , it worked like a charm. Previously I marked it as provided.
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
version>2.2.10</version>
</dependency>