You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Filipe Amaral <fi...@gmail.com> on 2013/08/08 16:01:34 UTC

Schema validation before Handlers

Hi there

Before putting up my question let me just set up the scenario for you.

My service contains a series of *javax.xml.ws.handler.Handler*s that do a
bunch of validations/rule check in my request's custom SOAP header element,
let's call it /RequestHeader/.
I've turned on CXF's automatic schema validation and it works on the body.
It has come to my attention that CXF schema validation (JAXB) only runs
after the inbound message traverses all handlers defined in the handler
chain (I think both unmarshalling/marshalling and validation happen around
the same time).
Also, as I stated before, only the body is validated, and not the
/RequestHeader/, although I have specified it in the XSD (and also as a
message and binding operations's header inside my WSDL).

Q: Is there any way to apply the Schema validation before any handler is
traversed and also to validate the SOAP header?
I would like that restrictions and patterns defined in the XSD could be
validated before any computation happens inside my handlers. I realize that
JAXB only has to run after the handler chain cause inside of handlers we
have access to the marshalled request, but this could be a nice feature,
otherwise I'll have to design a specific handler to validate /RequestHeader/
and add it to my chain and make it the first to run in an inbound message :/

Best regards



--
View this message in context: http://cxf.547215.n5.nabble.com/Schema-validation-before-Handlers-tp5732112.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Schema validation before Handlers

Posted by Filipe Amaral <fi...@gmail.com>.
Created bug:   CXF-5194 <https://issues.apache.org/jira/browse/CXF-5194>  

Also, i'll try to find if with latest CXF's version same thing happens.

Regards



--
View this message in context: http://cxf.547215.n5.nabble.com/Schema-validation-before-Handlers-tp5732112p5732158.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Schema validation before Handlers

Posted by Filipe Amaral <fi...@gmail.com>.
Ok... I'll create it asap.

Thanks for everything!
Regards



--
View this message in context: http://cxf.547215.n5.nabble.com/Schema-validation-before-Handlers-tp5732112p5732153.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Schema validation before Handlers

Posted by Daniel Kulp <dk...@apache.org>.
Well,  that looks like a bug…   Can you file a JIRA (and hopefully include a small test case?)

Thanks!
Dan



On Aug 8, 2013, at 1:22 PM, Filipe Amaral <fi...@gmail.com> wrote:

> Hi Dan
> 
> I don't know if this issue is also solved but i'm still using CXF 2.7.0
> 
> I understand, but i've tested it and it doesn't work... I've done some debug
> inside the interceptor and the problem relies on validateHeader().
> When findHeader() is called inside validateHeader() it simply returns null,
> although the SoapMessage is correct and apparently the MessagePartInfo too.
> Inside findHeader() the mpi.getConcreteName() returns "RequestHeaderElement"
> as localPart where it should simply return "RequestHeader". If I change the
> value of concreteName in runtime through live debug to "RequestHeader"
> validation is done successfuly, failing with soapfault:
> 
> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
>   <soap:Body>
>      <soap:Fault>
>         <faultcode>soap:Client</faultcode>
>         <faultstring>Could not validate soapheader caused by:
> org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1:
> '2012-05-1T00:00:00' is not a valid value for 'dateTime'..</faultstring>
>      </soap:Fault>
>   </soap:Body>
> </soap:Envelope>
> 
> BTW... I think the faultstring should suffer a bit of rework :P
> 
> Best regards
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Schema-validation-before-Handlers-tp5732112p5732121.html
> Sent from the cxf-user mailing list archive at Nabble.com.

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Re: Schema validation before Handlers

Posted by Filipe Amaral <fi...@gmail.com>.
Hi Dan

I don't know if this issue is also solved but i'm still using CXF 2.7.0

I understand, but i've tested it and it doesn't work... I've done some debug
inside the interceptor and the problem relies on validateHeader().
When findHeader() is called inside validateHeader() it simply returns null,
although the SoapMessage is correct and apparently the MessagePartInfo too.
Inside findHeader() the mpi.getConcreteName() returns "RequestHeaderElement"
as localPart where it should simply return "RequestHeader". If I change the
value of concreteName in runtime through live debug to "RequestHeader"
validation is done successfuly, failing with soapfault:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Client</faultcode>
         <faultstring>Could not validate soapheader caused by:
org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1:
'2012-05-1T00:00:00' is not a valid value for 'dateTime'..</faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

BTW... I think the faultstring should suffer a bit of rework :P

Best regards



--
View this message in context: http://cxf.547215.n5.nabble.com/Schema-validation-before-Handlers-tp5732112p5732121.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Schema validation before Handlers

Posted by Daniel Kulp <dk...@apache.org>.
On Aug 8, 2013, at 10:17 AM, Filipe Amaral <fi...@gmail.com> wrote:

> Thanks, Dan, for your quick feedback :)
> 
> I also thought that the framework isn't prepared for such customization. I
> think I'll leave the auto validation on for the body, and create a manual
> validation for the header through a Handler.

The SOAP Header should also already be validated if it's mapped properly into the WSDL and then mapped to a parameter on the service.   The SoapHeaderInterceptor should be validating it already.

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Re: Schema validation before Handlers

Posted by Filipe Amaral <fi...@gmail.com>.
Thanks, Dan, for your quick feedback :)

I also thought that the framework isn't prepared for such customization. I
think I'll leave the auto validation on for the body, and create a manual
validation for the header through a Handler.

Best regards



--
View this message in context: http://cxf.547215.n5.nabble.com/Schema-validation-before-Handlers-tp5732112p5732115.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Schema validation before Handlers

Posted by Daniel Kulp <dk...@apache.org>.
On Aug 8, 2013, at 10:01 AM, Filipe Amaral <fi...@gmail.com> wrote:

> Hi there
> 
> Before putting up my question let me just set up the scenario for you.
> 
> My service contains a series of *javax.xml.ws.handler.Handler*s that do a
> bunch of validations/rule check in my request's custom SOAP header element,
> let's call it /RequestHeader/.
> I've turned on CXF's automatic schema validation and it works on the body.
> It has come to my attention that CXF schema validation (JAXB) only runs
> after the inbound message traverses all handlers defined in the handler
> chain (I think both unmarshalling/marshalling and validation happen around
> the same time).
> Also, as I stated before, only the body is validated, and not the
> /RequestHeader/, although I have specified it in the XSD (and also as a
> message and binding operations's header inside my WSDL).
> 
> Q: Is there any way to apply the Schema validation before any handler is
> traversed and also to validate the SOAP header?

Not easily, no.   You could write an interceptor (or even your Handler) that would grab the schemas and perform a validation on it.  Since you are using a Handler, you have the full SAAJ model already parsed and in memory so it wouldn't be a huge amount of work to do.


Dan


> I would like that restrictions and patterns defined in the XSD could be
> validated before any computation happens inside my handlers. I realize that
> JAXB only has to run after the handler chain cause inside of handlers we
> have access to the marshalled request, but this could be a nice feature,
> otherwise I'll have to design a specific handler to validate /RequestHeader/
> and add it to my chain and make it the first to run in an inbound message :/
> 
> Best regards
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Schema-validation-before-Handlers-tp5732112.html
> Sent from the cxf-user mailing list archive at Nabble.com.

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com