You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by New Groovy <ne...@gmail.com> on 2014/07/28 04:47:08 UTC

How to retrieve return value in out interceptor?

Hi,

I want to filter some return values in an out interceptor, but am
struggling to figure out how to retrieve it.

I have tried this:

        MessageContentsList outObjects =
MessageContentsList.getContentsList(message);
        Exchange exchange = message.getExchange();
        OperationInfo op = exchange.getBindingOperationInfo() == null
                ? null
                : exchange.getBindingOperationInfo().getOperationInfo();

and see a lot of info...but can't figure out how to retrieve the _return
value I see in the xxx.jaxws_asm

Any pointers?

Re: How to retrieve return value in out interceptor?

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

You can use JAX-RS 2.0 ContainerResponseFilter with 2.0 ResourceInfo [1] 
context injected into it. Or access Response annotations (method 
annotations by default) directly from ContainerResponseFilter response 
context.

In a pure CXF out interceptor you can get it from the exchange:
OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
ori.getMethodToInvoke();

HTH, Sergey

[1] 
https://jax-rs-spec.java.net/nonav/2.0/apidocs/javax/ws/rs/container/ResourceInfo.html

On 31/07/14 17:24, New Groovy wrote:
> Thanks, Dan!
>
> One more question, how do I retrieve the method called (I need to retrieve
> the annotations from it) if it's a JAX-RS method?
>
> I have used this for in interceptors, but doesn't seem to be working for
> out interceptor:
>
>      private Method getTargetMethod(Message m) {
>          BindingOperationInfo bop =
> m.getExchange().get(BindingOperationInfo.class);
>          if (bop != null) {
>              MethodDispatcher md = (MethodDispatcher)
>
> m.getExchange().get(Service.class).get(MethodDispatcher.class.getName());
>              return md.getMethod(bop);
>          }
>
>          return (Method)m.get("org.apache.cxf.resource.method");
>      }
>
>
>
> On Mon, Jul 28, 2014 at 10:06 AM, Daniel Kulp <dk...@apache.org> wrote:
>
>>
>> Move your interceptor up into the PRE_LOGICAL with a
>> addBefore(WrapperClassOutInterceptor.class.getName()).  The list should
>> then just have the return value (and any holders for other outs).   The
>> WrapperClassOutInterceptor combines those into the asm generate object.
>>
>> Dan
>>
>>
>> On Jul 27, 2014, at 10:47 PM, New Groovy <ne...@gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I want to filter some return values in an out interceptor, but am
>>> struggling to figure out how to retrieve it.
>>>
>>> I have tried this:
>>>
>>>         MessageContentsList outObjects =
>>> MessageContentsList.getContentsList(message);
>>>         Exchange exchange = message.getExchange();
>>>         OperationInfo op = exchange.getBindingOperationInfo() == null
>>>                 ? null
>>>                 : exchange.getBindingOperationInfo().getOperationInfo();
>>>
>>> and see a lot of info...but can't figure out how to retrieve the _return
>>> value I see in the xxx.jaxws_asm
>>>
>>> Any pointers?
>>
>> --
>> Daniel Kulp
>> dkulp@apache.org - http://dankulp.com/blog
>> Talend Community Coder - http://coders.talend.com
>>
>>
>


Re: How to retrieve return value in out interceptor?

Posted by New Groovy <ne...@gmail.com>.
Thanks, Dan!

One more question, how do I retrieve the method called (I need to retrieve
the annotations from it) if it's a JAX-RS method?

I have used this for in interceptors, but doesn't seem to be working for
out interceptor:

    private Method getTargetMethod(Message m) {
        BindingOperationInfo bop =
m.getExchange().get(BindingOperationInfo.class);
        if (bop != null) {
            MethodDispatcher md = (MethodDispatcher)

m.getExchange().get(Service.class).get(MethodDispatcher.class.getName());
            return md.getMethod(bop);
        }

        return (Method)m.get("org.apache.cxf.resource.method");
    }



On Mon, Jul 28, 2014 at 10:06 AM, Daniel Kulp <dk...@apache.org> wrote:

>
> Move your interceptor up into the PRE_LOGICAL with a
> addBefore(WrapperClassOutInterceptor.class.getName()).  The list should
> then just have the return value (and any holders for other outs).   The
> WrapperClassOutInterceptor combines those into the asm generate object.
>
> Dan
>
>
> On Jul 27, 2014, at 10:47 PM, New Groovy <ne...@gmail.com> wrote:
>
> > Hi,
> >
> > I want to filter some return values in an out interceptor, but am
> > struggling to figure out how to retrieve it.
> >
> > I have tried this:
> >
> >        MessageContentsList outObjects =
> > MessageContentsList.getContentsList(message);
> >        Exchange exchange = message.getExchange();
> >        OperationInfo op = exchange.getBindingOperationInfo() == null
> >                ? null
> >                : exchange.getBindingOperationInfo().getOperationInfo();
> >
> > and see a lot of info...but can't figure out how to retrieve the _return
> > value I see in the xxx.jaxws_asm
> >
> > Any pointers?
>
> --
> Daniel Kulp
> dkulp@apache.org - http://dankulp.com/blog
> Talend Community Coder - http://coders.talend.com
>
>

Re: How to retrieve return value in out interceptor?

Posted by Daniel Kulp <dk...@apache.org>.
Move your interceptor up into the PRE_LOGICAL with a addBefore(WrapperClassOutInterceptor.class.getName()).  The list should then just have the return value (and any holders for other outs).   The WrapperClassOutInterceptor combines those into the asm generate object.

Dan


On Jul 27, 2014, at 10:47 PM, New Groovy <ne...@gmail.com> wrote:

> Hi,
> 
> I want to filter some return values in an out interceptor, but am
> struggling to figure out how to retrieve it.
> 
> I have tried this:
> 
>        MessageContentsList outObjects =
> MessageContentsList.getContentsList(message);
>        Exchange exchange = message.getExchange();
>        OperationInfo op = exchange.getBindingOperationInfo() == null
>                ? null
>                : exchange.getBindingOperationInfo().getOperationInfo();
> 
> and see a lot of info...but can't figure out how to retrieve the _return
> value I see in the xxx.jaxws_asm
> 
> Any pointers?

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