You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jose María Zaragoza <de...@gmail.com> on 2014/02/10 10:36:09 UTC
Format message returned by REST service after schema-validation
Hello:
I'm using Apache CXF 2.7.3 and JAX-RS to deploy a REST webservice.
The format of messages is only JSON
I've enabled schema-validation and response looks like
Response-Code: 400
Content-Type: text/plain
Headers: {Content-Type=[text/plain], Date=[Mon, 10 Feb 2014 09:25:19 GMT]}
Payload: JAXBException occurred : cvc-pattern-valid: Value 'xxxxxxxx'
is not facet-valid ...
I would like to capture this exception and format the payload
I tried this CustomOutInterceptor
http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomOutFaultInterceptor.java
but it doesn't work for me: message content never is an exception My
CustomOutInterceptor is invoked but it doesn't receive an exception
despite of an exception is thrown
in server side.
10:25:19.823 [http-8080-3] WARN [AbstractJAXBProvider]
[handleExceptionStart] - javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: cvc-pattern-valid: Value 'xxxxx' is
not facet-valid
any ideas ? any example ?
Regards
Re: Format message returned by REST service after schema-validation
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 10/02/14 15:20, Jose María Zaragoza wrote:
> Thank Sergey.
>
> I answer you below
>
> 2014-02-10 12:37 GMT+01:00 Sergey Beryozkin <sb...@gmail.com>:
>> Hi
>>
>> In CXF 2.7.3 you should use JAX-RS ExceptionMapper,
>
> I've read in http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Exceptionhandling
>
> "Starting from CXF 2.7.8 it is also possible to use registered
> ExceptionMappers to map the exceptions thrown from CXF server[...]In
> earlier CXF versions such exceptions are only possible to handle with
> CXF fault in interceptors."
>
> Anyway, I tried it and that works.
>
>
>>>
>>>
>>> 10:25:19.823 [http-8080-3] WARN [AbstractJAXBProvider]
>>> [handleExceptionStart] - javax.xml.bind.UnmarshalException
>>> - with linked exception:
>>> [org.xml.sax.SAXParseException: cvc-pattern-valid: Value 'xxxxx' is
>>> not facet-valid
>>>
>> Do you mean you custom out fault interceptor is not even invoked ? Register
>> it in jaxrs:outFaultInterceptors, you should get it invoked,
>> but try the exception mappers if you can
>>
>
>
> Right. If I configure that interceptor
> (http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomOutFaultInterceptor.java)
> as out fault interceptor , it's never invoked after schema validation
> fails.
>
> I don't know why. Maybe is captured by a previous out fault
> interceptor and it's not propagate
>
It may be it is because it is wrapped in WebApplicationException which
is mapped by the default CXF WebApplicationException mapper. That must
be it; so simply register your custom WebApplicationException mapper and
it should do
Thanks, Sergey
>
> Thanks
>
>
>
>> Sergey
>>
>>>
>>> any ideas ? any example ?
>>>
>>>
>>> Regards
>>>
>>
Re: Format message returned by REST service after schema-validation
Posted by Jose María Zaragoza <de...@gmail.com>.
Thank Sergey.
I answer you below
2014-02-10 12:37 GMT+01:00 Sergey Beryozkin <sb...@gmail.com>:
> Hi
>
> In CXF 2.7.3 you should use JAX-RS ExceptionMapper,
I've read in http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Exceptionhandling
"Starting from CXF 2.7.8 it is also possible to use registered
ExceptionMappers to map the exceptions thrown from CXF server[...]In
earlier CXF versions such exceptions are only possible to handle with
CXF fault in interceptors."
Anyway, I tried it and that works.
>>
>>
>> 10:25:19.823 [http-8080-3] WARN [AbstractJAXBProvider]
>> [handleExceptionStart] - javax.xml.bind.UnmarshalException
>> - with linked exception:
>> [org.xml.sax.SAXParseException: cvc-pattern-valid: Value 'xxxxx' is
>> not facet-valid
>>
> Do you mean you custom out fault interceptor is not even invoked ? Register
> it in jaxrs:outFaultInterceptors, you should get it invoked,
> but try the exception mappers if you can
>
Right. If I configure that interceptor
(http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomOutFaultInterceptor.java)
as out fault interceptor , it's never invoked after schema validation
fails.
I don't know why. Maybe is captured by a previous out fault
interceptor and it's not propagate
Thanks
> Sergey
>
>>
>> any ideas ? any example ?
>>
>>
>> Regards
>>
>
Re: Format message returned by REST service after schema-validation
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
In CXF 2.7.3 you should use JAX-RS ExceptionMapper,
On 10/02/14 09:36, Jose María Zaragoza wrote:
> Hello:
>
> I'm using Apache CXF 2.7.3 and JAX-RS to deploy a REST webservice.
> The format of messages is only JSON
>
> I've enabled schema-validation and response looks like
>
> Response-Code: 400
> Content-Type: text/plain
> Headers: {Content-Type=[text/plain], Date=[Mon, 10 Feb 2014 09:25:19 GMT]}
> Payload: JAXBException occurred : cvc-pattern-valid: Value 'xxxxxxxx'
> is not facet-valid ...
>
>
> I would like to capture this exception and format the payload
> I tried this CustomOutInterceptor
>
> http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomOutFaultInterceptor.java
>
> but it doesn't work for me: message content never is an exception My
> CustomOutInterceptor is invoked but it doesn't receive an exception
> despite of an exception is thrown
> in server side.
>
> 10:25:19.823 [http-8080-3] WARN [AbstractJAXBProvider]
> [handleExceptionStart] - javax.xml.bind.UnmarshalException
> - with linked exception:
> [org.xml.sax.SAXParseException: cvc-pattern-valid: Value 'xxxxx' is
> not facet-valid
>
Do you mean you custom out fault interceptor is not even invoked ?
Register it in jaxrs:outFaultInterceptors, you should get it invoked,
but try the exception mappers if you can
Sergey
>
> any ideas ? any example ?
>
>
> Regards
>