You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by rouble <r....@gmail.com> on 2012/10/10 22:45:33 UTC
Getting aferUnmarshall to throw a meaningful exception
CXF Gurus,
We were looking into using the afterUnmarshal(Unmarshaller, Object
parent) method to validate data beans. This works well, except we
can't seem to send back a meaningful exception. We tried throwing a
new UnmarshallException("Some text", "Some other text") but it does
not matter what we throw inside afterUnmarshall it always looks like
this on the client:
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Unmarshalling Error: null </faultstring>
</soap:Fault>
Is it possible to throw a meaningful exception that will get properly
unmarshalled into XML/text to the client? We want to be able to tell
the client something like: "Field ABC is mandatory".
Note here that we tried to enable schema validation to do this
validation for us but that has some drawbacks which I won't get into
for now.
tia,
rouble
Re: Getting aferUnmarshall to throw a meaningful exception
Posted by rouble <r....@gmail.com>.
Daniel,
One comment inline.
>> Thinking out loud of another way, is it possible to access all the
>> input beans in an interceptor after the UNMARSHAL phase? That way I
>> can do my validation in that interceptor and throw an exception from
>> there. Let me know if there is a way to do this?
>
> Yep. The USER_LOGICAL phase is designed specifically for this. If you do a message.getContent(List.class), you should get back a list of the unmarshalled objects that you can then validate.
We tried USER_LOGICAL, but it did not work as we expected. When we
called message.getContent(List.class) we were getting what looked to
be a representation of the request bean and thats it. Then we tried
POST_LOGICAL and we got the input beans.
We are using CXF 2.4.3.
Apart from that, this approach worked well. We do have issues
validating invalid enum values - but I will start a separate thread on
that topic.
tia,
rouble
>
>> Also - do you kow why is it not possible to set the error code in the
>> exception from afterUnmarshall() - is that just a deficiency in the
>> system? Should we have a jira for this?
>
> If you can create a small test case, we can look at it. It may be a deficiency in JAXB though. JAXB tends to catch exceptions and pass them into various error handlers that may then throw a completely different exception. I've seen that in a couple instances.
>
> Dan
>
>
>>
>> tia,
>> rouble
>>
>> On Wed, Oct 10, 2012 at 9:11 PM, Freeman Fang <fr...@gmail.com> wrote:
>>> Hi,
>>>
>>> You can save the message whatever you want to the cxf Message/Exchange, and then add another interceptor for the OutFaultChain(at the very beginning), where you can get the exception by means like
>>> message.getContent(Exception.class)
>>> You can modify this exception and set any cause text you saved before
>>> -------------
>>> Freeman Fang
>>>
>>> Red Hat, Inc.
>>> FuseSource is now part of Red Hat
>>> Web: http://fusesource.com | http://www.redhat.com/
>>> Twitter: freemanfang
>>> Blog: http://freemanfang.blogspot.com
>>> http://blog.sina.com.cn/u/1473905042
>>> weibo: http://weibo.com/u/1473905042
>>>
>>> On 2012-10-11, at 上午4:45, rouble wrote:
>>>
>>>> CXF Gurus,
>>>>
>>>> We were looking into using the afterUnmarshal(Unmarshaller, Object
>>>> parent) method to validate data beans. This works well, except we
>>>> can't seem to send back a meaningful exception. We tried throwing a
>>>> new UnmarshallException("Some text", "Some other text") but it does
>>>> not matter what we throw inside afterUnmarshall it always looks like
>>>> this on the client:
>>>> <soap:Fault>
>>>> <faultcode>soap:Client</faultcode>
>>>> <faultstring>Unmarshalling Error: null </faultstring>
>>>> </soap:Fault>
>>>>
>>>> Is it possible to throw a meaningful exception that will get properly
>>>> unmarshalled into XML/text to the client? We want to be able to tell
>>>> the client something like: "Field ABC is mandatory".
>>>>
>>>> Note here that we tried to enable schema validation to do this
>>>> validation for us but that has some drawbacks which I won't get into
>>>> for now.
>>>>
>>>> tia,
>>>> rouble
>>>
>
> --
> Daniel Kulp
> dkulp@apache.org - http://dankulp.com/blog
> Talend Community Coder - http://coders.talend.com
>
Re: Getting aferUnmarshall to throw a meaningful exception
Posted by Daniel Kulp <dk...@apache.org>.
On Oct 11, 2012, at 10:30 AM, rouble <r....@gmail.com> wrote:
> Thats an interesting way to do it. Just to be clear you want me to
> save some text in afterUnmarshal() into the CXF Message exchange and
> come back in an interceptor to pick up that text and set it.
>
> Thinking out loud of another way, is it possible to access all the
> input beans in an interceptor after the UNMARSHAL phase? That way I
> can do my validation in that interceptor and throw an exception from
> there. Let me know if there is a way to do this?
Yep. The USER_LOGICAL phase is designed specifically for this. If you do a message.getContent(List.class), you should get back a list of the unmarshalled objects that you can then validate.
> Also - do you kow why is it not possible to set the error code in the
> exception from afterUnmarshall() - is that just a deficiency in the
> system? Should we have a jira for this?
If you can create a small test case, we can look at it. It may be a deficiency in JAXB though. JAXB tends to catch exceptions and pass them into various error handlers that may then throw a completely different exception. I've seen that in a couple instances.
Dan
>
> tia,
> rouble
>
> On Wed, Oct 10, 2012 at 9:11 PM, Freeman Fang <fr...@gmail.com> wrote:
>> Hi,
>>
>> You can save the message whatever you want to the cxf Message/Exchange, and then add another interceptor for the OutFaultChain(at the very beginning), where you can get the exception by means like
>> message.getContent(Exception.class)
>> You can modify this exception and set any cause text you saved before
>> -------------
>> Freeman Fang
>>
>> Red Hat, Inc.
>> FuseSource is now part of Red Hat
>> Web: http://fusesource.com | http://www.redhat.com/
>> Twitter: freemanfang
>> Blog: http://freemanfang.blogspot.com
>> http://blog.sina.com.cn/u/1473905042
>> weibo: http://weibo.com/u/1473905042
>>
>> On 2012-10-11, at 上午4:45, rouble wrote:
>>
>>> CXF Gurus,
>>>
>>> We were looking into using the afterUnmarshal(Unmarshaller, Object
>>> parent) method to validate data beans. This works well, except we
>>> can't seem to send back a meaningful exception. We tried throwing a
>>> new UnmarshallException("Some text", "Some other text") but it does
>>> not matter what we throw inside afterUnmarshall it always looks like
>>> this on the client:
>>> <soap:Fault>
>>> <faultcode>soap:Client</faultcode>
>>> <faultstring>Unmarshalling Error: null </faultstring>
>>> </soap:Fault>
>>>
>>> Is it possible to throw a meaningful exception that will get properly
>>> unmarshalled into XML/text to the client? We want to be able to tell
>>> the client something like: "Field ABC is mandatory".
>>>
>>> Note here that we tried to enable schema validation to do this
>>> validation for us but that has some drawbacks which I won't get into
>>> for now.
>>>
>>> tia,
>>> rouble
>>
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com
Re: Getting aferUnmarshall to throw a meaningful exception
Posted by rouble <r....@gmail.com>.
Thats an interesting way to do it. Just to be clear you want me to
save some text in afterUnmarshal() into the CXF Message exchange and
come back in an interceptor to pick up that text and set it.
Thinking out loud of another way, is it possible to access all the
input beans in an interceptor after the UNMARSHAL phase? That way I
can do my validation in that interceptor and throw an exception from
there. Let me know if there is a way to do this?
Also - do you kow why is it not possible to set the error code in the
exception from afterUnmarshall() - is that just a deficiency in the
system? Should we have a jira for this?
tia,
rouble
On Wed, Oct 10, 2012 at 9:11 PM, Freeman Fang <fr...@gmail.com> wrote:
> Hi,
>
> You can save the message whatever you want to the cxf Message/Exchange, and then add another interceptor for the OutFaultChain(at the very beginning), where you can get the exception by means like
> message.getContent(Exception.class)
> You can modify this exception and set any cause text you saved before
> -------------
> Freeman Fang
>
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Web: http://fusesource.com | http://www.redhat.com/
> Twitter: freemanfang
> Blog: http://freemanfang.blogspot.com
> http://blog.sina.com.cn/u/1473905042
> weibo: http://weibo.com/u/1473905042
>
> On 2012-10-11, at 上午4:45, rouble wrote:
>
>> CXF Gurus,
>>
>> We were looking into using the afterUnmarshal(Unmarshaller, Object
>> parent) method to validate data beans. This works well, except we
>> can't seem to send back a meaningful exception. We tried throwing a
>> new UnmarshallException("Some text", "Some other text") but it does
>> not matter what we throw inside afterUnmarshall it always looks like
>> this on the client:
>> <soap:Fault>
>> <faultcode>soap:Client</faultcode>
>> <faultstring>Unmarshalling Error: null </faultstring>
>> </soap:Fault>
>>
>> Is it possible to throw a meaningful exception that will get properly
>> unmarshalled into XML/text to the client? We want to be able to tell
>> the client something like: "Field ABC is mandatory".
>>
>> Note here that we tried to enable schema validation to do this
>> validation for us but that has some drawbacks which I won't get into
>> for now.
>>
>> tia,
>> rouble
>
Re: Getting aferUnmarshall to throw a meaningful exception
Posted by Freeman Fang <fr...@gmail.com>.
Hi,
You can save the message whatever you want to the cxf Message/Exchange, and then add another interceptor for the OutFaultChain(at the very beginning), where you can get the exception by means like
message.getContent(Exception.class)
You can modify this exception and set any cause text you saved before
-------------
Freeman Fang
Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://fusesource.com | http://www.redhat.com/
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com
http://blog.sina.com.cn/u/1473905042
weibo: http://weibo.com/u/1473905042
On 2012-10-11, at 上午4:45, rouble wrote:
> CXF Gurus,
>
> We were looking into using the afterUnmarshal(Unmarshaller, Object
> parent) method to validate data beans. This works well, except we
> can't seem to send back a meaningful exception. We tried throwing a
> new UnmarshallException("Some text", "Some other text") but it does
> not matter what we throw inside afterUnmarshall it always looks like
> this on the client:
> <soap:Fault>
> <faultcode>soap:Client</faultcode>
> <faultstring>Unmarshalling Error: null </faultstring>
> </soap:Fault>
>
> Is it possible to throw a meaningful exception that will get properly
> unmarshalled into XML/text to the client? We want to be able to tell
> the client something like: "Field ABC is mandatory".
>
> Note here that we tried to enable schema validation to do this
> validation for us but that has some drawbacks which I won't get into
> for now.
>
> tia,
> rouble