You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Benson Margulies <bi...@gmail.com> on 2013/02/26 16:18:56 UTC

JAX-RS handling an exception in the middle of an output writer

So, I've absently-constructed the following problem.

I've got a JAX-RS service that does, essentially, all of its work in a
StreamingOutput object. It also has an error mapper that produces a
Json body to go with the 400 status code in the error response.

You can see where this goes: the code succeeds in writing *some* of
the output, encounters an exception, and then sets up the error
response. CXF dutifully serializes it, resulting in a mess consisting
of the beginning of the original output followed by the error output.

Is this a CXF problem? Does the standard offer any guidance?

Re: JAX-RS handling an exception in the middle of an output writer

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 26/02/13 15:18, Benson Margulies wrote:
> So, I've absently-constructed the following problem.
>
> I've got a JAX-RS service that does, essentially, all of its work in a
> StreamingOutput object. It also has an error mapper that produces a
> Json body to go with the 400 status code in the error response.
>
> You can see where this goes: the code succeeds in writing *some* of
> the output, encounters an exception, and then sets up the error
> response. CXF dutifully serializes it, resulting in a mess consisting
> of the beginning of the original output followed by the error output.
>
> Is this a CXF problem? Does the standard offer any guidance?

CXF can help a bit, if you set an "org.apache.cxf.output.buffering" 
contextual property, or "enableBuffering" directly on 
BinaryDataProvider, then it will work as expected, but at the cost of 
buffering the data and then flushing them at a later stage, so the 
benefits of using StreamingOutput will be lost...

Cheers, Sergey