Hi Sergey,
My extended JAXRSServiceImpl was basically the following:
private volatile List<ServiceInfo> serviceInfos;
@Override
public List<ServiceInfo> getServiceInfos() {
if (serviceInfos != null) return serviceInfos;
return makeServiceInfos();
}
private synchronized List<ServiceInfo> makeServiceInfos() {
if (serviceInfos == null) serviceInfos =
super.getServiceInfos();
return serviceInfos;
}
If you would prefer an actual patch, I can do so at some point - but
given the simplicity of the change, it might be easier without.
If Benson or anyone else would like to help out with why I don't get
validation failures, I'd be happy to give anything a try - I could
probably do with a bit of a guide for how it's supposed to work - does
the validation actually happen in that reader2.validationAgainst(vs)
call in Stax2ValidationUtils.setupValidtion, or is this just setting
something up for validation to actually happen later on?
Cheers,
James
-----Original Message-----
From: Sergey Beryozkin [mailto:[email protected]]
Sent: 20 October 2011 17:12
To: [email protected]
Subject: Re: Schema Validation in JAX-RS service using Aegis data
bindings
Hi James
sorry for a delay,
I'm wondering if you could provide a patch for JAXRSServiceImpl ?
You are probably the first one who tried to validate Aegis payloads with
JAX-RS :-), so I can imagine it's not easy. I guess when JAXRS runtime
delegates to CXF DataBindings it does need to keep those ServiceInfo/etc
objects, though I thought naively there were kept by the data bindings
themselves...So please provide that patch
Re ValidationProblemHandler - I'm not sure either, may be Benson has
some ideas, may be you can provide a relevant patch too :-)
Thanks, Sergey
On 20/10/11 16:42, Phillpotts, James wrote:
> Hi all,
>
> I'm afraid to say I've given up trying to get this to work.
>
> Where I got to was:
>
> - Implemented an interceptor to create an XMLStreamReader and set it
> in the message.
>
> Once that was done, I discovered that even though the AegisDatabinding
> sets XmlSchemas on the ServiceInfo objects, those ServiceInfo objects
> weren't ever kept anywhere, so when they were used in the
> AegisSchemaValidationInInterceptor the schemas were there. So I made
> the following changes:
>
> - Extended JAXRSServiceImpl to initialise the service info objects
> once, and always keep those copies.
> - Extended JAXRSServiceFactoryBean to use my JAXRSServiceBean extended
> class
> - Switched spring config to vanilla bean declarations, so that I could
> use my own JAXRSServiceFactoryBean as a constructor-arg to
> JAXRSServerFactoryBean
>
> Where I got stuck was:
>
> - Validation seems to now be set up correctly - I see log output from
> Stax2ValidationUtils for each schema fragment. However, when passing
> in some invalid XML, the ValidationProblemHandler is never triggered.
>
> If anyone has any suggestions for how to get faults to be returned,
> I'd be happy to keep trying.
>
> Cheers,
> James
>
>
> -----Original Message-----
> From: Phillpotts, James [mailto:[email protected]]
> Sent: 20 October 2011 12:19
> To: [email protected]
> Subject: Schema Validation in JAX-RS service using Aegis data bindings
>
> Hi all,
>
> I wonder if anyone might be able to give me some pointers about using
> schema validation in JAX-RS services?
>
> I've currently got spring config:
>
> <bean id="aegisBean"
> class="acme.services.ws.databinding.aegis.AegisDatabinding"
> scope="singleton"/>
>
> <jaxrs:server id="restServer" address="/rest">
> <jaxrs:properties>
> <entry key="schema-validation-enabled"><ref
> bean="isValidateIncomingEAIMessages" /></entry>
> </jaxrs:properties>
> <jaxrs:serviceBeans>
> <ref bean="bookstoreService" />
> </jaxrs:serviceBeans>
> <jaxrs:dataBinding><ref
> bean="aegisBean"/></jaxrs:dataBinding>
> </jaxrs:server>
>
> This does successfully enable schema validation in
> AegisSchemaValidationInInterceptor, but I get a null pointer
exception:
>
> java.lang.NullPointerException
> at
> org.apache.cxf.wstx_msv_validation.Stax2ValidationUtils.setupValidatio
> n(
> Stax2ValidationUtils.java:71)
> at
> org.apache.cxf.wstx_msv_validation.WoodstoxValidationImpl.setupValidat
> io
> n(WoodstoxValidationImpl.java:67)
> at
> org.apache.cxf.aegis.databinding.AegisSchemaValidationInInterceptor.se
> tS
> chemaInMessage(AegisSchemaValidationInInterceptor.java:68)
> at
> org.apache.cxf.aegis.databinding.AegisSchemaValidationInInterceptor.ha
> nd
> leMessage(AegisSchemaValidationInInterceptor.java:56)
>
> From debugging, the XMLStreamReader is null. This is presumably
> because somewhere along the way, the JAX-WS service/interceptors set a
> XMLStreamReader in the message, but the JAX-RS ones don't.
>
> My next step was going to be creating an interceptor that sets a
> XMLStreamReader in the message for any message received whose content
> is XML. Is this sensible? Is there something else I should be doing?
>
> Thanks in advance,
> James
>
>
> PS - sorry for the auto-legal-waffle...
>
>
>
> Information in this e-mail and any attachments is confidential, and
> may not be copied or used by anyone other than the addressee, nor
> disclosed to any third party without our permission. There is no
> intention to create any legally binding contract or other binding
> commitment through the use of this electronic communication unless it
> is issued in accordance with the Experian Limited standard terms and
> conditions of purchase or other express written agreement between
> Experian Limited and the recipient. Although Experian has taken
> reasonable steps to ensure that this communication and any attachments
> are free from computer virus, you are advised to take your own steps
> to ensure that they are actually virus free.
>
> Companies Act information: Registered name: Experian Limited.
> Registered
> office: Landmark House, Experian Way, NG2 Business Park, Nottingham,
> NG80 1ZZ, United Kingdom. Place of registration: England and Wales.
> Registered number: 653331
>