You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by eddgrant <ed...@eddgrant.com> on 2015/06/11 11:28:15 UTC

Handle validation errors in JAX-WS service and obtain whole request body

Hi folks,

Using CXF 3.1.0 I am writing a JAX-WS service which uses JAXB bindings. My
service has schema validation enabled, in the event that it receives a
message which doesn't validate I want to be able to grab the entire request
body and ship it off somewhere.

I found DefaultValidationEventHandler and had hoped that I would be able to
access the request body in handleEvent(ValidationEvent) however the
ValidationEvent passed doesn't contain the body.

The Service I'm writing is a Spring application so as an alternative
approach I also tried @Autowiring the request scoped HttpServletRequest
object in to my DefaultValidationEventHandler subclass, however I was unable
to read the body from here as the stream has already been consumed.

Can anyone point me in the right direction here?

Many thanks,

Edd



--
View this message in context: http://cxf.547215.n5.nabble.com/Handle-validation-errors-in-JAX-WS-service-and-obtain-whole-request-body-tp5758197.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Handle validation errors in JAX-WS service and obtain whole request body

Posted by eddgrant <ed...@eddgrant.com>.
ok, understood. Still I think that feels a bit nicer as the intention is
slightly clearer.

Many thanks!

On Fri, Jun 12, 2015 at 4:39 PM Daniel Kulp [via CXF] <
ml-node+s547215n5758265h25@n5.nabble.com> wrote:

>
> > On Jun 12, 2015, at 11:26 AM, eddgrant <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=5758265&i=0>> wrote:
> >
> > Thanks Dan, I have written a LoggingInterceptor subclass which does the
> job
> > nicely!
> >
> > I'm storing the request body in a ThreadLocal which I'm then accessing
> later
> > on in a DefaultValidationEventHandler subclass where I detect if
> validation
> > has failed. It feels a bit hacky but I haven't yet found a cleaner way
> to
> > pass my data around.
> >
> > I did see a suggestion of using the Exchange as a message passing
> mechanism
> > however I can't find a way to access the Exchange within
> > formatLoggingMessage(LoggingMessage loggingMessage). Any thoughts here?
>
> You should be able to grab the current message via
> PhaseInterceptorChain.getCurrentMessage() and grab the exchange from there.
>   That said, that’s just through a tread local as well.
>
>
>
> --
> Daniel Kulp
> [hidden email] <http:///user/SendEmail.jtp?type=node&node=5758265&i=1> -
> http://dankulp.com/blog
> Talend Community Coder - http://coders.talend.com
>
>
>
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://cxf.547215.n5.nabble.com/Handle-validation-errors-in-JAX-WS-service-and-obtain-whole-request-body-tp5758197p5758265.html
>  To unsubscribe from Handle validation errors in JAX-WS service and obtain
> whole request body, click here
> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5758197&code=ZWRkQGVkZGdyYW50LmNvbXw1NzU4MTk3fDYzMzkwODQ3MQ==>
> .
> NAML
> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://cxf.547215.n5.nabble.com/Handle-validation-errors-in-JAX-WS-service-and-obtain-whole-request-body-tp5758197p5758266.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Handle validation errors in JAX-WS service and obtain whole request body

Posted by Daniel Kulp <dk...@apache.org>.
> On Jun 12, 2015, at 11:26 AM, eddgrant <ed...@eddgrant.com> wrote:
> 
> Thanks Dan, I have written a LoggingInterceptor subclass which does the job
> nicely!
> 
> I'm storing the request body in a ThreadLocal which I'm then accessing later
> on in a DefaultValidationEventHandler subclass where I detect if validation
> has failed. It feels a bit hacky but I haven't yet found a cleaner way to
> pass my data around.
> 
> I did see a suggestion of using the Exchange as a message passing mechanism
> however I can't find a way to access the Exchange within
> formatLoggingMessage(LoggingMessage loggingMessage). Any thoughts here?

You should be able to grab the current message via PhaseInterceptorChain.getCurrentMessage() and grab the exchange from there.   That said, that’s just through a tread local as well.



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


Re: Handle validation errors in JAX-WS service and obtain whole request body

Posted by eddgrant <ed...@eddgrant.com>.
Thanks Dan, I have written a LoggingInterceptor subclass which does the job
nicely!

I'm storing the request body in a ThreadLocal which I'm then accessing later
on in a DefaultValidationEventHandler subclass where I detect if validation
has failed. It feels a bit hacky but I haven't yet found a cleaner way to
pass my data around.

I did see a suggestion of using the Exchange as a message passing mechanism
however I can't find a way to access the Exchange within
formatLoggingMessage(LoggingMessage loggingMessage). Any thoughts here?

Thanks again!



--
View this message in context: http://cxf.547215.n5.nabble.com/Handle-validation-errors-in-JAX-WS-service-and-obtain-whole-request-body-tp5758197p5758264.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Handle validation errors in JAX-WS service and obtain whole request body

Posted by Daniel Kulp <dk...@apache.org>.
You would need to wire in the Logging interceptors or subclasses of the logging interceptors or similar that would capture the entire message and make it available.  By default, everything is streamed and is discarded as soon as it’s read.

Dan


> On Jun 11, 2015, at 5:28 AM, eddgrant <ed...@eddgrant.com> wrote:
> 
> Hi folks,
> 
> Using CXF 3.1.0 I am writing a JAX-WS service which uses JAXB bindings. My
> service has schema validation enabled, in the event that it receives a
> message which doesn't validate I want to be able to grab the entire request
> body and ship it off somewhere.
> 
> I found DefaultValidationEventHandler and had hoped that I would be able to
> access the request body in handleEvent(ValidationEvent) however the
> ValidationEvent passed doesn't contain the body.
> 
> The Service I'm writing is a Spring application so as an alternative
> approach I also tried @Autowiring the request scoped HttpServletRequest
> object in to my DefaultValidationEventHandler subclass, however I was unable
> to read the body from here as the stream has already been consumed.
> 
> Can anyone point me in the right direction here?
> 
> Many thanks,
> 
> Edd
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Handle-validation-errors-in-JAX-WS-service-and-obtain-whole-request-body-tp5758197.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