You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Larry Presswood <lp...@me.com> on 2013/01/04 21:48:38 UTC

Intercepting SOAP Message when using JMS Transport

I tried using the stream interceptor when using CXF configured with JMS Transport but it seems that

boolean isOutbound = false;
� � � � isOutbound = message == message.getExchange().getOutMessage()
� � � � � � � �|| message == message.getExchange().getOutFaultMessage();

� � � � if (isOutbound) {
� � � � � � OutputStream os = message.getContent(OutputStream.class);

os is null when using jms but not when using straight http�

both are soap

is this a bug or doe i need to intercept in a different stream

i can see in the code where the message is being put into a JMSMessage but don't seem to find a way to intercept handily like with HTTP

Any ideas or examples?

Thanks
Sent from iCloud

RE: Intercepting SOAP Message when using JMS Transport

Posted by Andrei Shakirin <as...@talend.com>.
I would recommend to try the second way mentioned by Dan:
"you can also wrap the writer with a new FilterWriter that overrides close() to do whatever you want and then call message.setContent(Writer.class, filteredWriter);"

As a sample you can look into implementation of org.apache.cxf.feature.transform.XSLTOutInterceptor method transformWriter() and inner filter class XSLTCachedWriter.
It does basically the same thing as you want: applies XSLT transformation for outgoing SOAP text JMS message.

Cheers,
Andrei.

From: Larry Presswood [mailto:lpresswood@me.com]
Sent: Freitag, 4. Januar 2013 23:27
To: users@cxf.apache.org
Subject: Re: Intercepting SOAP Message when using JMS Transport

Any idea where in stream

I am doing what the StreamIntercepter example had

Phase.PRE_STREAM
addBefore(SoapPreProtocolOutIntercepter )

But nothing in the writer buffer just empty string so i must be too early?


thanks

Sent from iCloud

On Jan 04, 2013, at 05:18 PM, Daniel Kulp <dk...@apache.org>> wrote:

On Jan 4, 2013, at 5:10 PM, Larry Presswood <lp...@me.com>> wrote:

> i am using text
>
> I thought i would get writer on outbound and reader in inbound

Yea. You're correct. My mistake.


> but i want to mutate message both before send and after read
>
> at least in the phase i was using on out didnt seem like soap message was there?

It should behave the same as with the Streams used for HTTP. For outbound, you can probably cast to a StringWriter and call the getBuffer() on it to manipulate the string buffer directly assuming you are very late in the chain. If not, you can also wrap the writer with a new FilterWriter that overrides close() to do whatever you want and then call message.setContent(Writer.class, filteredWriter);


Dan


>
> Sent from my iPhone
>
> On Jan 4, 2013, at 17:05, Daniel Kulp <dk...@apache.org>> wrote:
>
>>
>> On Jan 4, 2013, at 3:48 PM, Larry Presswood <lp...@me.com>> wrote:
>>
>>> I tried using the stream interceptor when using CXF configured with JMS Transport but it seems that
>>>
>>> boolean isOutbound = false;
>>> isOutbound = message == message.getExchange().getOutMessage()
>>> || message == message.getExchange().getOutFaultMessage();
>>>
>>> if (isOutbound) {
>>> OutputStream os = message.getContent(OutputStream.class);
>>>
>>> os is null when using jms but not when using straight http
>>>
>>> both are soap
>>>
>>> is this a bug or doe i need to intercept in a different stream
>>>
>>> i can see in the code where the message is being put into a JMSMessage but don't seem to find a way to intercept handily like with HTTP
>>>
>>> Any ideas or examples?
>>
>> Are you using a text JMS message or binary JMS message? If using a Text message, we keep it as a string and provide a Reader instead to avoid a lot of String -> byte[] -> String type conversions. Try:
>>
>> Reader r = message.getContent(Reader.class);
>>
>> or switch the JMS setup to use binary messages.
>>
>>
>> --
>> Daniel Kulp
>> dkulp@apache.org<ma...@apache.org> - http://dankulp.com/blog
>> Talend Community Coder - http://coders.talend.com
>>

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

Re: Intercepting SOAP Message when using JMS Transport

Posted by Larry Presswood <lp...@me.com>.
Any idea where in stream

I am doing what the StreamIntercepter example had

Phase.PRE_STREAM
addBefore(SoapPreProtocolOutIntercepter )

But nothing in the writer buffer just empty string so i must be too early?


thanks
Sent from iCloud

On Jan 04, 2013, at 05:18 PM, Daniel Kulp <dk...@apache.org> wrote:


On Jan 4, 2013, at 5:10 PM, Larry Presswood <lp...@me.com> wrote:

> i am using text
> 
> I thought i would get writer on outbound and reader in inbound

Yea. You're correct. My mistake.


> but i want to mutate message both before send and after read
> 
> at least in the phase i was using on out didnt seem like soap message was there?

It should behave the same as with the Streams used for HTTP. For outbound, you can probably cast to a StringWriter and call the getBuffer() on it to manipulate the string buffer directly assuming you are very late in the chain. If not, you can also wrap the writer with a new FilterWriter that overrides close() to do whatever you want and then call message.setContent(Writer.class, filteredWriter);


Dan


> 
> Sent from my iPhone
> 
> On Jan 4, 2013, at 17:05, Daniel Kulp <dk...@apache.org> wrote:
> 
>> 
>> On Jan 4, 2013, at 3:48 PM, Larry Presswood <lp...@me.com> wrote:
>> 
>>> I tried using the stream interceptor when using CXF configured with JMS Transport but it seems that
>>> 
>>> boolean isOutbound = false;
>>> isOutbound = message == message.getExchange().getOutMessage()
>>> || message == message.getExchange().getOutFaultMessage();
>>> 
>>> if (isOutbound) {
>>> OutputStream os = message.getContent(OutputStream.class);
>>> 
>>> os is null when using jms but not when using straight http 
>>> 
>>> both are soap
>>> 
>>> is this a bug or doe i need to intercept in a different stream
>>> 
>>> i can see in the code where the message is being put into a JMSMessage but don't seem to find a way to intercept handily like with HTTP
>>> 
>>> Any ideas or examples?
>> 
>> Are you using a text JMS message or binary JMS message? If using a Text message, we keep it as a string and provide a Reader instead to avoid a lot of String -> byte[] -> String type conversions. Try:
>> 
>> Reader r = message.getContent(Reader.class);
>> 
>> or switch the JMS setup to use binary messages.
>> 
>> 
>> -- 
>> Daniel Kulp
>> dkulp@apache.org - http://dankulp.com/blog
>> Talend Community Coder - http://coders.talend.com
>> 

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


Re: Intercepting SOAP Message when using JMS Transport

Posted by Daniel Kulp <dk...@apache.org>.
On Jan 4, 2013, at 5:10 PM, Larry Presswood <lp...@me.com> wrote:

> i am using text
> 
> I thought i would get writer on outbound and reader in inbound

Yea.  You're correct.   My mistake.


> but i want to mutate message both before send and after read
> 
> at least in the phase i was using on out didnt seem like soap message was there?

It should behave the same as with the Streams used for HTTP.   For outbound, you can probably cast to a StringWriter and call the getBuffer() on it to manipulate the string buffer directly assuming you are very late in the chain.   If not, you can also wrap the writer with a new FilterWriter that overrides close() to do whatever you want and then call message.setContent(Writer.class, filteredWriter);


Dan


> 
> Sent from my iPhone
> 
> On Jan 4, 2013, at 17:05, Daniel Kulp <dk...@apache.org> wrote:
> 
>> 
>> On Jan 4, 2013, at 3:48 PM, Larry Presswood <lp...@me.com> wrote:
>> 
>>> I tried using the stream interceptor when using CXF configured with JMS Transport but it seems that
>>> 
>>> boolean isOutbound = false;
>>>       isOutbound = message == message.getExchange().getOutMessage()
>>>              || message == message.getExchange().getOutFaultMessage();
>>> 
>>>       if (isOutbound) {
>>>           OutputStream os = message.getContent(OutputStream.class);
>>> 
>>> os is null when using jms but not when using straight http 
>>> 
>>> both are soap
>>> 
>>> is this a bug or doe i need to intercept in a different stream
>>> 
>>> i can see in the code where the message is being put into a JMSMessage but don't seem to find a way to intercept handily like with HTTP
>>> 
>>> Any ideas or examples?
>> 
>> Are you using a text JMS message or binary JMS message?   If using a Text message, we keep it as a string and provide a Reader instead to avoid a lot of String -> byte[] -> String type conversions.   Try:
>> 
>> Reader r = message.getContent(Reader.class);
>> 
>> or switch the JMS setup to use binary messages.
>> 
>> 
>> -- 
>> Daniel Kulp
>> dkulp@apache.org - http://dankulp.com/blog
>> Talend Community Coder - http://coders.talend.com
>> 

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


Re: Intercepting SOAP Message when using JMS Transport

Posted by Larry Presswood <lp...@me.com>.
i am using text

I thought i would get writer on outbound and reader in invound

but i want to mutate message both before send and after read

at least in the phase i was using on out didnt seem like soap message was there?

Sent from my iPhone

On Jan 4, 2013, at 17:05, Daniel Kulp <dk...@apache.org> wrote:

> 
> On Jan 4, 2013, at 3:48 PM, Larry Presswood <lp...@me.com> wrote:
> 
>> I tried using the stream interceptor when using CXF configured with JMS Transport but it seems that
>> 
>> boolean isOutbound = false;
>>        isOutbound = message == message.getExchange().getOutMessage()
>>               || message == message.getExchange().getOutFaultMessage();
>> 
>>        if (isOutbound) {
>>            OutputStream os = message.getContent(OutputStream.class);
>> 
>> os is null when using jms but not when using straight http 
>> 
>> both are soap
>> 
>> is this a bug or doe i need to intercept in a different stream
>> 
>> i can see in the code where the message is being put into a JMSMessage but don't seem to find a way to intercept handily like with HTTP
>> 
>> Any ideas or examples?
> 
> Are you using a text JMS message or binary JMS message?   If using a Text message, we keep it as a string and provide a Reader instead to avoid a lot of String -> byte[] -> String type conversions.   Try:
> 
> Reader r = message.getContent(Reader.class);
> 
> or switch the JMS setup to use binary messages.
> 
> 
> -- 
> Daniel Kulp
> dkulp@apache.org - http://dankulp.com/blog
> Talend Community Coder - http://coders.talend.com
> 

Re: Intercepting SOAP Message when using JMS Transport

Posted by Daniel Kulp <dk...@apache.org>.
On Jan 4, 2013, at 3:48 PM, Larry Presswood <lp...@me.com> wrote:

> I tried using the stream interceptor when using CXF configured with JMS Transport but it seems that
> 
> boolean isOutbound = false;
>         isOutbound = message == message.getExchange().getOutMessage()
>                || message == message.getExchange().getOutFaultMessage();
> 
>         if (isOutbound) {
>             OutputStream os = message.getContent(OutputStream.class);
> 
> os is null when using jms but not when using straight http 
> 
> both are soap
> 
> is this a bug or doe i need to intercept in a different stream
> 
> i can see in the code where the message is being put into a JMSMessage but don't seem to find a way to intercept handily like with HTTP
> 
> Any ideas or examples?

Are you using a text JMS message or binary JMS message?   If using a Text message, we keep it as a string and provide a Reader instead to avoid a lot of String -> byte[] -> String type conversions.   Try:

Reader r = message.getContent(Reader.class);

or switch the JMS setup to use binary messages.


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