Title: [Axis2] schema validation
Hi Andreas,

Although I'm not sure wheter my suggestion would addresse to your needs, I'll try to write what I did for schema validation.

1) Used xmlbeans databinding instead of adb. Therefore, I passed "-d xmlbeans" to WSDL2Java.
2) In generated skeleton class I added following methods:

    // This method is not generated by WSDL2Java
    protected void log (String desc, String str) {
        System.out.println(desc + ": " + str);       
    }
   
    // This method is not generated by WSDL2Java and can be put in a util
    // class to make it globally accessible.
    protected void validate (org.apache.xmlbeans.XmlObject param) throws AxisFault {
        // Set up the validation error listener.
        ; ArrayList validationErrors = new ArrayList();
        XmlOptions validationOptions = new XmlOptions();
        validationOptions.setErrorListener(validationErrors);

        // During validation, errors are added to the ArrayList for
        // retrieval and printed.
        boolean isValid = param.validate(validationOptions);
        log("Incoming soap message is valid", "" + isValid);

        // Print the errors if the XML is invalid.
        if (!isValid) {
            Iterator iter = validationErrors.iterator();
            StringBuffer sb = new StringBuffer(256);
      &nb sp;     while (iter.hasNext()) {
                sb.append(iter.next());
                sb.append("\n");
            }           
            log ("Validation error",  sb.toString());
            throw new AxisFault (sb.toString());
        }       
    }

3) Say I have following method in my generated skeleton class:

    public com.mycompany.service.test.schemas.account.OpenAccountResultDocument OpenAccount(
        com.mycompany.service.test.schemas.account.OpenAccountDocument param0) {
   ; // Auto generated
}

I added "throws AxisFault" to it and called validate () before doing anything.

4) In this way, if client's request soap is not validated against the schema, then validate() method throws and AxisFault and the client gets an soap fault message that exactly shows the validation error. Here is the sample soap fault:

<?xml version="1.0" encoding="http://schemas.xmlsoap.org/soap/envelope/"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<soapenv:Fault>
<faultcode>Client</faultcode>
<faultstring>error: cvc-maxLength-valid.1.1: string length (string) is greater than maxLength facet (3) for 2
</faultstring>
<faultactor>http://myAxisServer/role/default</faultactor>
<detail>
<soapenv:Exception>org.apache.axis2.AxisFault: error: cvc-maxLength-valid.1.1: string length (string) is greater than maxLength facet (3) for 2

    at com.mycompany.service.test.account.AccountServicesPortTypeSkeleton.OpenAccount(AccountServicesPortTypeSkeleton.java:57)
    at com.mycompany.service.test.account.AccountServicesPortTypeMessageReceiver.invokeBusinessLogic(AccountServicesPortTypeMessageReceiver.java:48)
...
</soapenv:Exception>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>

Hope this helps.

Ali Sadik Kumlali

"Sensen, Andreas (external)" <[EMAIL PROTECTED]> wrote:
Hi everybody ,
I am trying to enable schema validation for my Web service using Axis2 0.94
under linux with the included xerces 2.7.1 parser. I've a couple of questions
i hope you can help me with:
1. Is it possible to enable schema validation for a particular service using the
default parsing steps taken by the engine? I noticed the XmlSchema-SNAPSHOT.jar in
the lib directory, but didn't find any further documentation on this topic.
2. Since i couldn't figure out an answer two question 1, i implemented a "validation
module", according to the module example and user documentation, that validates
incoming messages. But h ow can i stop message processing if validation fails? The
module throws an AxisFault on invalid messages, but the messages are still relayed to
the other handlers and finally the service implementation.
I searched the web, documentation, mailing list archive and the API reference but
couldn't find an answer. Maybe you could point me to an example or further
documentation i missed.
Best regards and thanks in advance,
Andreas


New Yahoo! Messenger with Voice. Call regular phones from your PC and save big.

Reply via email to