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:[EMAIL PROTECTED]
> Sent: Tuesday, September 30, 2008 6:58 AM
> To: Lee Breisacher
> Cc: [email protected]
> 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 <[EMAIL PROTECTED]>:
> >
> http://www.nabble.com/WebServiceProvider-%2B-schema-validation-td19430
> > 227.html#a19459974
> >
> > Lee
> >
> >> -----Original Message-----
> >> From: Andrew Clegg [mailto:[EMAIL PROTECTED]
> >> Sent: Tuesday, September 30, 2008 2:54 AM
> >> To: [email protected]
> >> 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.
> >>
> >
>