cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouble <r.ou...@gmail.com>
Subject Re: Getting aferUnmarshall to throw a meaningful exception
Date Tue, 16 Oct 2012 14:58:30 GMT
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 <freeman.fang@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
>

Mime
View raw message