You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Crack_David <ko...@christian-busch.com> on 2012/10/25 16:17:56 UTC

Sending return value from Interceptor back to client

Hello there,
Following issue:

I've created a client that communicates with a SAP-BI Webservice. In case
that this Webservice's response doesn't seem to work with the cxf framework
I decided to program an Interceptor that intercepts the invoke() function
right after the RECEIVE state.
In it I am parsing the incoming response stream directly into one object.

My only problem here is how to return this object created in the Interceptor
back to the main()-thread.  Is there any possibility to do that?

Cheers,
Chris  



--
View this message in context: http://cxf.547215.n5.nabble.com/Sending-return-value-from-Interceptor-back-to-client-tp5717416.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Sending return value from Interceptor back to client

Posted by Freeman Fang <fr...@gmail.com>.
Hi Andrei,

FYI, I guess his requirement is from this discussion[1],  obviously he don't like the solution in[1] and wanna get object from input stream directly and bypass all interceptors afterwards.

[1]http://cxf.547215.n5.nabble.com/java-lang-IndexOutOfBoundsException-in-processing-td5716948.html#a5716993
-------------
Freeman(Yue) 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-26, at 下午5:01, Andrei Shakirin wrote:

> I guess you need following code to obtain MessagePart for client incoming chain:
> 
>    public MessagePartInfo getClientInMessagePartInfo(Message message) {
>        Exchange exchange = message.getExchange();
>        BindingOperationInfo operation = (BindingOperationInfo)exchange.get(BindingOperationInfo.class
>            .getName());
> 
>        if (operation == null) {
>            return null;
>        }
> 
>        BindingMessageInfo bmsg = operation.getOutput();
>        if (bmsg == null) {
>            return null;
>        }
> 
>        List<MessagePartInfo> parts = bmsg.getMessageParts();
>        if ((parts != null) && !parts.isEmpty()) {
>            return parts.iterator().next();
>        } else {
>            return null;
>        }
>    }
> 
> May I ask what exactly you update in response from SAP-BI Webservice?
> Is it some payload elements and namespaces or you use own unmarshalling?
> In first case CXF Transformation Feature may be helpful: http://cxf.apache.org/docs/transformationfeature.html.
> 
> Andrei.
> 
> -----Original Message-----
> From: Crack_David [mailto:kontakt@christian-busch.com] 
> Sent: Donnerstag, 25. Oktober 2012 19:44
> To: users@cxf.apache.org
> Subject: Re: Sending return value from Interceptor back to client
> 
> Mhmmm...
> 
> I've tried 
> 
> MessageContentsList.getContentsList(msg).put(0, response); 
> 
> but function "put" has to have the parameters (MessagePartInfo, Object)... 
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Sending-return-value-from-Interceptor-back-to-client-tp5717416p5717452.html
> Sent from the cxf-user mailing list archive at Nabble.com.


RE: Sending return value from Interceptor back to client

Posted by Andrei Shakirin <as...@talend.com>.
I guess you need following code to obtain MessagePart for client incoming chain:

    public MessagePartInfo getClientInMessagePartInfo(Message message) {
        Exchange exchange = message.getExchange();
        BindingOperationInfo operation = (BindingOperationInfo)exchange.get(BindingOperationInfo.class
            .getName());

        if (operation == null) {
            return null;
        }

        BindingMessageInfo bmsg = operation.getOutput();
        if (bmsg == null) {
            return null;
        }

        List<MessagePartInfo> parts = bmsg.getMessageParts();
        if ((parts != null) && !parts.isEmpty()) {
            return parts.iterator().next();
        } else {
            return null;
        }
    }

May I ask what exactly you update in response from SAP-BI Webservice?
Is it some payload elements and namespaces or you use own unmarshalling?
In first case CXF Transformation Feature may be helpful: http://cxf.apache.org/docs/transformationfeature.html.

Andrei.

-----Original Message-----
From: Crack_David [mailto:kontakt@christian-busch.com] 
Sent: Donnerstag, 25. Oktober 2012 19:44
To: users@cxf.apache.org
Subject: Re: Sending return value from Interceptor back to client

Mhmmm...

I've tried 

MessageContentsList.getContentsList(msg).put(0, response); 

but function "put" has to have the parameters (MessagePartInfo, Object)... 



--
View this message in context: http://cxf.547215.n5.nabble.com/Sending-return-value-from-Interceptor-back-to-client-tp5717416p5717452.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Sending return value from Interceptor back to client

Posted by Crack_David <ko...@christian-busch.com>.
Mhmmm...

I've tried 

MessageContentsList.getContentsList(msg).put(0, response); 

but function "put" has to have the parameters (MessagePartInfo, Object)... 



--
View this message in context: http://cxf.547215.n5.nabble.com/Sending-return-value-from-Interceptor-back-to-client-tp5717416p5717452.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Sending return value from Interceptor back to client

Posted by Daniel Kulp <dk...@apache.org>.
On Oct 25, 2012, at 12:26 PM, Crack_David <ko...@christian-busch.com> wrote:

> Yeah I managed adding my Response-Object to the Content of the
> message-Object. 
> I did:
> 
> message.setContent(response.getClass(), response);
> message.getInterceptorChain().doInterceptStartingAt(message, "PRE_LOGICAL");
> 
> But after that the returned Object of invoke is still null. Where is the
> problem?

It needs to go into the MessageContentsList of the message.   Something like:

message.setContent(List.class, new Arrays.asList(response))

might also do it, but I'd recommend:
MessageContentsList.getContentsList(msg).put(0, response);

Dan



> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Sending-return-value-from-Interceptor-back-to-client-tp5717416p5717444.html
> Sent from the cxf-user mailing list archive at Nabble.com.

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


Re: Sending return value from Interceptor back to client

Posted by Crack_David <ko...@christian-busch.com>.
Yeah I managed adding my Response-Object to the Content of the
message-Object. 
I did:

message.setContent(response.getClass(), response);
message.getInterceptorChain().doInterceptStartingAt(message, "PRE_LOGICAL");

But after that the returned Object of invoke is still null. Where is the
problem?



--
View this message in context: http://cxf.547215.n5.nabble.com/Sending-return-value-from-Interceptor-back-to-client-tp5717416p5717444.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Sending return value from Interceptor back to client

Posted by Daniel Kulp <dk...@apache.org>.
On Oct 25, 2012, at 10:17 AM, Crack_David <ko...@christian-busch.com> wrote:

> Hello there,
> Following issue:
> 
> I've created a client that communicates with a SAP-BI Webservice. In case
> that this Webservice's response doesn't seem to work with the cxf framework
> I decided to program an Interceptor that intercepts the invoke() function
> right after the RECEIVE state.
> In it I am parsing the incoming response stream directly into one object.
> 
> My only problem here is how to return this object created in the Interceptor
> back to the main()-thread.  Is there any possibility to do that?

If you do something like:

MessageContentsList.getContentsList(msg).put(0, value);

and then likely grab the chain and pause it, it may work.   If not, you may need to grab the chain and remove all the interceptors from the current interceptor up to the PRE_LOGICAL phase (and maybe more).  You'd need to experiment a little on that.

Dan



> 
> Cheers,
> Chris  
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Sending-return-value-from-Interceptor-back-to-client-tp5717416.html
> Sent from the cxf-user mailing list archive at Nabble.com.

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