You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Krzysztof Raszkowski <ra...@datera.pl> on 2010/09/27 09:52:01 UTC

How to change the value of web service invocation attributes?

Hi,
we're dealing a problem with cxf interceptors. Our goal is to change the
value of web service invocation attributes. For instance we have a method
which is invoked with a string "in" and we want it changed to "out" before
we get it in out application. We use a document literal wrapped style, so
this text is a text content of the element "paramName", which is the child
of the element "methodName" inside soapBody. We were trying to write
interceptor but without any success.

We are able to change the expected value but it is only seen in our next
interceptor (when we have two ones, one after another), but the method is
then invoked with a null value. We did it by writing a class extending
AbstractSoapInterceptor and handling a message implementing a SOAPMessage
interface (we're getting a soap body, its nodes and then changing a text
content). We expect, it should work during a pre protocol one, but we were
trying this during many phases, with no success.

The second try was to create a class extending DepthXMLStreamReader class
and overwrite some methods for processing the XML (actually getting the
content, element name etc.). But it only works during a post stream phase in
which there is no access to the whole XML content, only to some headers.

We were looking for the solution but each example we found was showing how
to read some values of the message (for example for logging) and it isn't a
case for us. So we'd like to ask you if it's possible to change a soap body
before web service invocation and if so, how to do it.

The other case, if modifying is possible, is it possible to change value of
the method attribute before it's unmarshalled (but not by parsing input
stream but using SOAPMessage interface (SoapMessage cxf implementation))? If
not, what is the best way to do it?

Thanks in advance. 
-- 
View this message in context: http://cxf.547215.n5.nabble.com/How-to-change-the-value-of-web-service-invocation-attributes-tp2854897p2854897.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to change the value of web service invocation attributes?

Posted by Daniel Kulp <dk...@apache.org>.
On Monday 04 October 2010 7:13:55 am Krzysztof Raszkowski wrote:
> First of all thanks for a response.
> We have analyzed above approaches, but our problem turned out to be more
> complex. We have to modify value, which is sent by flex client and it's NaN
> for decimal. We want it converted to null (which is not only modifying a
> text context in an xml) and it seems to be impossible in a POST_PROTOCOL
> phase (if we do it for Integer we receive 0 in Java, not null - we have set
> "nillable=true" in our wsdl of course).
> So we want to ask, if there is any way to do it without rewriting the whole
> input as a char array or a stream, because it's not very nice. We cannot
> cope with an advice to put our interceptor after StaxInInterceptor. Of
> course we receive there a message content as XMLStreamReader, but we don't
> know how to modify it in an easy way.
> Any help would be appreciated.

Honestly, another option that may be easiest is to configure in the 
SAAJInInterceptor and write a simple interceptor that would manipulate the 
SAAJ DOM model.   It would incur a slight performance penalty, but really not 
much of one if the messages are relatively small.


-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog

Re: How to change the value of web service invocation attributes?

Posted by Krzysztof Raszkowski <ra...@datera.pl>.
First of all thanks for a response. 
We have analyzed above approaches, but our problem turned out to be more
complex. We have to modify value, which is sent by flex client and it's NaN
for decimal. We want it converted to null (which is not only modifying a
text context in an xml) and it seems to be impossible in a POST_PROTOCOL
phase (if we do it for Integer we receive 0 in Java, not null - we have set
"nillable=true" in our wsdl of course). 
So we want to ask, if there is any way to do it without rewriting the whole
input as a char array or a stream, because it's not very nice. We cannot
cope with an advice to put our interceptor after StaxInInterceptor. Of
course we receive there a message content as XMLStreamReader, but we don't
know how to modify it in an easy way. 
Any help would be appreciated.

-- 
View this message in context: http://cxf.547215.n5.nabble.com/How-to-change-the-value-of-web-service-invocation-attributes-tp2854897p3173200.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to change the value of web service invocation attributes?

Posted by Daniel Kulp <dk...@apache.org>.
On Monday 27 September 2010 5:14:25 am Krzysztof Raszkowski wrote:
> Hi,
> we're dealing a problem with cxf interceptors. Our goal is to change the
> value of web service invocation attributes. For instance we have a method
> which is invoked with a string "in" and we want it changed to "out" before
> we get it in out application. We use a document literal wrapped style, so
> this text is a text content of the element "paramName", which is the child
> of the element "methodName" inside soapBody. We were trying to write
> interceptor but without any success.
> 
> We are able to change the expected value but it is only seen in our next
> interceptor (when we have two ones, one after another), but the method is
> then invoked with a null value. We did it by writing a class extending
> AbstractSoapInterceptor and handling a message implementing a SOAPMessage
> interface (we're getting a soap body, its nodes and then changing a text
> content). We expect, it should work during a pre protocol one, but we were
> trying this during many phases, with no success.

This should work.   What version of CXF are you using?  Can you produce a 
small testcase?   Maybe take our hello world and change the incoming text?

That said, using SAAJ is probably not the best idea from a performance 
standpoint.

> The second try was to create a class extending DepthXMLStreamReader class
> and overwrite some methods for processing the XML (actually getting the
> content, element name etc.). But it only works during a post stream phase
> in which there is no access to the whole XML content, only to some
> headers.

This is probably better from a performance standpoint.  The BEST place to put 
this is in POST_STREAM with and addAfter(StaxInInterceptor.class.getName()) 
set to put it immediately after the StaxInInterceptor.   Again, if it's not 
working, a testcase would be great.


The THIRD option that you didn't pursue is to not work at the XML level for 
this.   In an interceptor in the USER_LOGICAL phase, you can get the actual 
parameters (message.getContent(List.class)) and manipulate the already parsed  
objects. 


Hope that helps!
Dan



> We were looking for the solution but each example we found was showing how
> to read some values of the message (for example for logging) and it isn't a
> case for us. So we'd like to ask you if it's possible to change a soap body
> before web service invocation and if so, how to do it.
> 
> The other case, if modifying is possible, is it possible to change value of
> the method attribute before it's unmarshalled (but not by parsing input
> stream but using SOAPMessage interface (SoapMessage cxf implementation))?
> If not, what is the best way to do it?
> 
> Thanks in advance.

-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog

How to change the value of web service invocation attributes?

Posted by Krzysztof Raszkowski <ra...@datera.pl>.
Hi, 
we're dealing a problem with cxf interceptors. Our goal is to change the
value of web service invocation attributes. For instance we have a method
which is invoked with a string "in" and we want it changed to "out" before
we get it in out application. We use a document literal wrapped style, so
this text is a text content of the element "paramName", which is the child
of the element "methodName" inside soapBody. We were trying to write
interceptor but without any success. 

We are able to change the expected value but it is only seen in our next
interceptor (when we have two ones, one after another), but the method is
then invoked with a null value. We did it by writing a class extending
AbstractSoapInterceptor and handling a message implementing a SOAPMessage
interface (we're getting a soap body, its nodes and then changing a text
content). We expect, it should work during a pre protocol one, but we were
trying this during many phases, with no success. 

The second try was to create a class extending DepthXMLStreamReader class
and overwrite some methods for processing the XML (actually getting the
content, element name etc.). But it only works during a post stream phase in
which there is no access to the whole XML content, only to some headers. 

We were looking for the solution but each example we found was showing how
to read some values of the message (for example for logging) and it isn't a
case for us. So we'd like to ask you if it's possible to change a soap body
before web service invocation and if so, how to do it. 

The other case, if modifying is possible, is it possible to change value of
the method attribute before it's unmarshalled (but not by parsing input
stream but using SOAPMessage interface (SoapMessage cxf implementation))? If
not, what is the best way to do it? 

Thanks in advance.
-- 
View this message in context: http://cxf.547215.n5.nabble.com/How-to-change-the-value-of-web-service-invocation-attributes-tp2854897p2854974.html
Sent from the cxf-user mailing list archive at Nabble.com.