You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Andrew Clegg <an...@gmail.com> on 2008/09/30 11:54:08 UTC

Schema validation in Provider services

Morning all,

I've noticed that if I 'roll my own' response payload and serve it up
via a class implementing Provider<StreamSource>, the
schema-validation-enabled property in cxf-servlet.xml is ignored. I
can produce non-schema-compliant messages and they will be returned to
the client just fine.

If I produce invalid XML (e.g. mismatched tags) I get "Exception
occurred while marshalling Dispatch object to stream" but things like
incorrect tag names are ignored.

Is this working as designed, or a bug I should post a JIRA for? Or can
I perform validation via different means in this scenario, e.g. by
obtaining a reference to the schema somewhere in my Provider class?

Many thanks!

Andrew.

Re: Schema validation in Provider services

Posted by Andrew Clegg <an...@gmail.com>.
2008/9/30 Lee Breisacher <LB...@seagullsoftware.com>:
> Well...sortof...
>
> I did manage to cobble something together that seems to work for me, but it has some rather my-project-specific stuff in it. Here's the guts of it:
[snip]

Great, thanks, I'll hack around a bit with that.

Andrew.

RE: Schema validation in Provider services

Posted by Lee Breisacher <LB...@seagullsoftware.com>.
Well...sortof...

I did manage to cobble something together that seems to work for me, but it has some rather my-project-specific stuff in it. Here's the guts of it:

An interceptor:

    public class ValidatingInterceptor extends AbstractPhaseInterceptor<Message> {...

A validator field: [I actually have a Map of validators because I have a collection of WSDL(XSD) to validate against]

        private Validator validator;
        public void setValidator(Validator validator) {
            this.validator = validator;
        }

Constructor so the interceptor goes in the right place: [which I'm not real sure about]

        public ValidatingInterceptor() {
            this(Phase.UNMARSHAL);
        }

The handler:

        public void handleMessage(Message message) throws Fault {
            try {
                DOMSource domSource = (DOMSource) message.getContent(Source.class);
                if (domSource == null) {
                    return;
                }
                this.validator.validate(domSource);
            } catch (SAXException e) {
                throw new Fault(e);
            } catch (IOException e) {
                throw new Fault(e);
            }
        }

Then set things up somewhere during init...

        ValidatingInterceptor validatingInterceptor = new ValidatingInterceptor();
        Service service = ...;
        Schema schema = EndpointReferenceUtils.getSchema(service.getServiceInfos().get(0));
        Validator validator = schema.newValidator();
        validatingInterceptor.setValidator(validator);

That's basically it. Hope it helps some...

Lee

> -----Original Message-----
> From: Andrew Clegg [mailto:andrew.clegg@gmail.com]
> Sent: Tuesday, September 30, 2008 6:58 AM
> To: Lee Breisacher
> Cc: users@cxf.apache.org
> Subject: Re: Schema validation in Provider services
>
> Whoops, not sure how I missed that one.
>
> Did you get anywhere with the validating interceptor idea?
>
> Cheers,
>
> Andrew.
>
> 2008/9/30 Lee Breisacher <LB...@seagullsoftware.com>:
> >
> http://www.nabble.com/WebServiceProvider-%2B-schema-validation-td19430
> > 227.html#a19459974
> >
> > Lee
> >
> >> -----Original Message-----
> >> From: Andrew Clegg [mailto:andrew.clegg@gmail.com]
> >> Sent: Tuesday, September 30, 2008 2:54 AM
> >> To: users@cxf.apache.org
> >> Subject: Schema validation in Provider services
> >>
> >> Morning all,
> >>
> >> I've noticed that if I 'roll my own' response payload and
> serve it up
> >> via a class implementing Provider<StreamSource>, the
> >> schema-validation-enabled property in cxf-servlet.xml is
> ignored. I
> >> can produce non-schema-compliant messages and they will be
> returned
> >> to the client just fine.
> >>
> >> If I produce invalid XML (e.g. mismatched tags) I get "Exception
> >> occurred while marshalling Dispatch object to stream" but
> things like
> >> incorrect tag names are ignored.
> >>
> >> Is this working as designed, or a bug I should post a JIRA for? Or
> >> can I perform validation via different means in this
> scenario, e.g.
> >> by obtaining a reference to the schema somewhere in my Provider
> >> class?
> >>
> >> Many thanks!
> >>
> >> Andrew.
> >>
> >
>

Re: Schema validation in Provider services

Posted by Andrew Clegg <an...@gmail.com>.
Whoops, not sure how I missed that one.

Did you get anywhere with the validating interceptor idea?

Cheers,

Andrew.

2008/9/30 Lee Breisacher <LB...@seagullsoftware.com>:
> http://www.nabble.com/WebServiceProvider-%2B-schema-validation-td19430227.html#a19459974
>
> Lee
>
>> -----Original Message-----
>> From: Andrew Clegg [mailto:andrew.clegg@gmail.com]
>> Sent: Tuesday, September 30, 2008 2:54 AM
>> To: users@cxf.apache.org
>> Subject: Schema validation in Provider services
>>
>> Morning all,
>>
>> I've noticed that if I 'roll my own' response payload and
>> serve it up via a class implementing Provider<StreamSource>,
>> the schema-validation-enabled property in cxf-servlet.xml is
>> ignored. I can produce non-schema-compliant messages and they
>> will be returned to the client just fine.
>>
>> If I produce invalid XML (e.g. mismatched tags) I get
>> "Exception occurred while marshalling Dispatch object to
>> stream" but things like incorrect tag names are ignored.
>>
>> Is this working as designed, or a bug I should post a JIRA
>> for? Or can I perform validation via different means in this
>> scenario, e.g. by obtaining a reference to the schema
>> somewhere in my Provider class?
>>
>> Many thanks!
>>
>> Andrew.
>>
>

RE: Schema validation in Provider services

Posted by Lee Breisacher <LB...@seagullsoftware.com>.
http://www.nabble.com/WebServiceProvider-%2B-schema-validation-td19430227.html#a19459974

Lee

> -----Original Message-----
> From: Andrew Clegg [mailto:andrew.clegg@gmail.com]
> Sent: Tuesday, September 30, 2008 2:54 AM
> To: users@cxf.apache.org
> Subject: Schema validation in Provider services
>
> Morning all,
>
> I've noticed that if I 'roll my own' response payload and
> serve it up via a class implementing Provider<StreamSource>,
> the schema-validation-enabled property in cxf-servlet.xml is
> ignored. I can produce non-schema-compliant messages and they
> will be returned to the client just fine.
>
> If I produce invalid XML (e.g. mismatched tags) I get
> "Exception occurred while marshalling Dispatch object to
> stream" but things like incorrect tag names are ignored.
>
> Is this working as designed, or a bug I should post a JIRA
> for? Or can I perform validation via different means in this
> scenario, e.g. by obtaining a reference to the schema
> somewhere in my Provider class?
>
> Many thanks!
>
> Andrew.
>