I am attempting to perform XSD validation on incoming XML to REST. I'm using
REST 2.3.7.Final (in EAP 6.2.2.GA).
I found a few decent articles...one discussing @Decorator / @DecoratorTypes (
)..also found a few references to defining a MessageBodyReaderInterceptor
(additionally noting its in the 2.3.7 docs -
I initially considered using the @Decorator option - but decided against it as
I'll need to annotate a bunch of params on a bunch of methods across a bunch of
classes. Truthfully, I'll want XSD validation enabled for all calls - which is
why I'm leaning toward MessageBodyReaderInterceptor.
As a side note, I was able to get both options working. Only caveat is with the
MessageBodyReaderInterceptor - it works, but I am hesitant to consider the
"working" version working "correctly." I'll explain shortly...
I note the documentation states " You must call
MessageBodyReaderContext.proceed() or MessageBodyWriterContext.proceed() to go
to the next interceptor or, if there are no more interceptors to invoke, the
readFrom() or writeTo() method of the MessageBodyReader or MessageBodyWriter."
In order for me to XSD validate the XML coming over, I have 2 options - I can
use a Schema creating a new Validator and having it validate using the
MessageBodyReaderContext's input stream...or I can set the schema on an
unmarshaller and have it unmarshal an object. The problem is, in both instances
I am consuming the input stream.
I could return the unmarshalled object - but then no more interceptors (if
there are any) will get an opportunity to process. If I attempt to return
MessageBodyReaderContext.proceed(), the stream is now closed as I consumed it
via the unmarshal. I had no luck trying to reset the input stream as I get an
IOException "mark/reset not supported."
I'm certain I'm not seeing the proper way to do this, or am approaching this
problem incorrectly. As I mentioned above the MessageBodyReaderContext version
I have works if I return the unmarshalled object - but while it works, I think
its improper way to deal with this scenario.
Thanks ahead of time!
Make It So Number One
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
Resteasy-users mailing list