You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by meteora28 <s....@web.de> on 2012/08/08 16:45:26 UTC

Insert elements in soap header?

Hello there,

is it possible to add some more elements in the soap header?

For example the following elements next to "security" in the header:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:a="http://www.w3.org/2005/08/addressing">
	<s:Header>
		<a:Action
s:mustUnderstand="1">http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/PullMessagesRequest</a:Action>
		<a:MessageID>urn:uuid:5b3d2467-ed65-4fb8-a2c3-174c83f4e113</a:MessageID>
		<a:ReplyTo>
			<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
		</a:ReplyTo>
		<wsse:Security
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
			...
		</wsse:Security>
		<SubscriptionId a:IsReferenceParameter="true"
xmlns="http://www.hitron.co.kr/event"
xmlns:dom0="http://www.hitron.co.kr/event">1</SubscriptionId>
		<a:To s:mustUnderstand="1">http://1.2.3.4/onvif/device_service</a:To>
	</s:Header>
	<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
		<PullMessages xmlns="http://www.onvif.org/ver10/events/wsdl">
			<Timeout>PT20S</Timeout>
			<MessageLimit>2</MessageLimit>
		</PullMessages>
	</s:Body>
</s:Envelope>





--
View this message in context: http://cxf.547215.n5.nabble.com/Insert-elements-in-soap-header-tp5712191.html
Sent from the cxf-user mailing list archive at Nabble.com.

RE: Insert elements in soap header?

Posted by Andrei Shakirin <as...@talend.com>.
Hi Erich,

You can enforce mustUnderstand attribute in WSA SOAP headers using CXF AddressingProperties.
AddressingProperties.getMustUnderstand() should contain list of WSA SOAP headers QNames to be extended with mustUnderstand attribute.
AddressingProperties object itself should be available via message property JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES.
Client code can look like:
        Map<String, Object> requestContext = ((BindingProvider) serviceProxy).getRequestContext();
            AddressingProperties maps = new AddressingPropertiesImpl();
            List<QName> mustUnderstandList = maps.getMustUnderstand();
            mustUnderstandList.add(Names.WSA_ACTION_QNAME);
            mustUnderstandList.add(Names.WSA_ADDRESS_QNAME);
            mustUnderstandList.add(Names.WSA_REPLYTO_QNAME);
            mustUnderstandList.add(Names.WSA_MESSAGEID_QNAME);
            requestContext.put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, maps);

After it all mentioned elements will be sent with mustUnderstand="1".

Of course, you can configure AddressingProperties via Spring/Blueprint for client/endpoint or in interceptors as well.

Regards,
Andrei.

> -----Original Message-----
> From: Eric-01 [mailto:Erich.Gormann@Atos.net]
> Sent: Montag, 4. März 2013 14:18
> To: users@cxf.apache.org
> Subject: RE: Insert elements in soap header?
> 
> Hi Andrei,
> 
> thank you.
> 
> The standard interceptor does not generate a mustUnderstand attribute. So
> do have do add it via java code or can this be done by policy too? Is there an
> extra policy file required or how to add special header elements or attributes
> via policy?
> 
> Eric
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Insert-
> elements-in-soap-header-tp5712191p5724021.html
> Sent from the cxf-user mailing list archive at Nabble.com.

RE: Insert elements in soap header?

Posted by Eric-01 <Er...@Atos.net>.
Hi Andrei, 

thank you. 

The standard interceptor does not generate a mustUnderstand attribute. So do
have do add it via java code or can this be done by policy too? Is there an
extra policy file required or how to add special header elements or
attributes via policy? 

Eric



--
View this message in context: http://cxf.547215.n5.nabble.com/Insert-elements-in-soap-header-tp5712191p5724021.html
Sent from the cxf-user mailing list archive at Nabble.com.

RE: Insert elements in soap header?

Posted by Andrei Shakirin <as...@talend.com>.
Hi Eric,

> 
> I'am new to this forum and I say hello to you all.

You are welcome!

> Since few weeks I'am facing some problems on trying to put additional
> header elements in our SOAP messages, because we have to set
> wsaddressing elements.
> 
> I'am a little bit confused, becuase there seem to exist a lot of ways to do it
> (SPRING config, configuration via cxf-servlet.xml and cxf.xml, adding
> information to the WSDL document's binding section or last but not least to
> manage it via interceptors).

It is true, there are some different ways to do it, but finally all of them add correspondent CXF interceptors into client and service chain.

> 
> The link to the CXF addressing page you mentioned, Andrei, shows how to
> use the respective entry to enable wsaddressing via standard CXF or policy.
> But the page does not show how to add particular header fields like
> "RelatesTo"
> and so on.

If you only need standard WS-Addressing in your SOAP envelopers, you shouldn't care about single WSA SOAP headers at all - they will be automatically generated by CXF WSA interceptors.
See CXF MAPCodec and MAPAggregatorImpl code for details.

> 
> Can you or anyone else recommend a "silver bullet" to manage the adding of
> addressing headers?

Officially recommended ways is either configuring WS-Addressing feature or using WS-Policies.

Cheers,
Andrei.

> 
> I'am appreciate for any answer. Thannk you in advance.
> Eric
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Insert-
> elements-in-soap-header-tp5712191p5723721.html
> Sent from the cxf-user mailing list archive at Nabble.com.

RE: Insert elements in soap header?

Posted by Eric-01 <Er...@Atos.net>.
Hi Andrei, 

I'am new to this forum and I say hello to you all. 
Since few weeks I'am facing some problems on trying to put additional header
elements in our SOAP messages, because we have to set wsaddressing elements. 

I'am a little bit confused, becuase there seem to exist a lot of ways to do
it (SPRING config, configuration via cxf-servlet.xml and cxf.xml, adding
information to the WSDL document's binding section or last but not least to
manage it via interceptors). 

The link to the CXF addressing page you mentioned, Andrei, shows how to use
the respective entry to enable wsaddressing via standard CXF or policy. But
the page does not show how to add particular header fields like "RelatesTo"
and so on. 

Can you or anyone else recommend a "silver bullet" to manage the adding of
addressing headers? 

I'am appreciate for any answer. Thannk you in advance. 
Eric



--
View this message in context: http://cxf.547215.n5.nabble.com/Insert-elements-in-soap-header-tp5712191p5723721.html
Sent from the cxf-user mailing list archive at Nabble.com.

RE: Insert elements in soap header?

Posted by meteora28 <s....@web.de>.
Thank you a lot. This is exactly what I was looking for and it works fine!



--
View this message in context: http://cxf.547215.n5.nabble.com/Insert-elements-in-soap-header-tp5712191p5723460.html
Sent from the cxf-user mailing list archive at Nabble.com.

RE: Insert elements in soap header?

Posted by Andrei Shakirin <as...@talend.com>.
Hi,

Basically you can add any custom soap header on client side using this code:

Client proxy = ClientProxy.getClient(serviceClient);
List<Header> headersList = new ArrayList<Header>();
Header testSoapHeader1 = new Header(new QName("uri:singz.ws.sample", "soapheader1"), "SOAP Header Message 1", new JAXBDataBinding(String.class));
Header testSoapHeader2 = new Header(new QName("uri:singz.ws.sample", "soapheader2"), "SOAP Header Message 2", new JAXBDataBinding(String.class));
headersList.add(testSoapHeader1);
headersList.add(testSoapHeader2);
proxy.getRequestContext().put(Header.HEADER_LIST, headersList);

Or in interceptor:
 public void setSoapHeaderValue(SoapMessage soapMessage, QName name, String value) {
                List<Header> headers = soapMessage.getHeaders();
                Header testSoapHeader = new Header(new QName("uri:singz.ws.sample", "soapheader1"), "SOAP Header Message 1", new JAXBDataBinding(String.class));	headers.add(testSoapHeader);
}

Anyway to set WS-Addressing header I would recommend to use standard CXF feature or WS-policy: http://cxf.apache.org/docs/ws-addressing.html

Regards,
Andrei.


> -----Original Message-----
> From: meteora28 [mailto:s.r.s@web.de]
> Sent: Dienstag, 19. Februar 2013 16:21
> To: users@cxf.apache.org
> Subject: Re: Insert elements in soap header?
> 
> Thank you for your answers, but I could not solve it yet.
> 
> Currently I have this message:
> 
> POST /onvif/services HTTP/1.1
> Content-Type: application/soap+xml;
> action="http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/Pull
> MessagesRequest";
> charset=UTF-8
> Accept: */*
> User-Agent: Apache CXF 2.7.2
> Cache-Control: no-cache
> Pragma: no-cache
> Host: 172.16.101.130
> Connection: keep-alive
> Content-Length: 1463
> 
> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-
> envelope">
> 	<soap:Header>
> 		<wsse:Security
> xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-
> wssecurity-secext-1.0.xsd"
> xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-
> wssecurity-utility-1.0.xsd"
> soap:mustUnderstand="true">
> 			<wsse:UsernameToken wsu:Id="UsernameToken-
> 14">
> 				<wsse:Username>root</wsse:Username>
> 				<wsse:Password
> Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-
> username-token-profile-
> 1.0#PasswordDigest">FyjTaK5w90bDNRb5hzWwoaYpX5M=</wsse:Passwor
> d>
> 				<wsse:Nonce
> EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-
> soap-message-security-
> 1.0#Base64Binary">VNAN0Nuy6gsm6YwAZh8HwA==</wsse:Nonce>
> 				<wsu:Created>2013-02-
> 19T15:16:46.862Z</wsu:Created>
> 			</wsse:UsernameToken>
> 		</wsse:Security>
> 	</soap:Header>
> 	<soap:Body>
> 		<ns10:PullMessages
> xmlns:ns10="http://www.onvif.org/ver10/events/wsdl"
> xmlns:ns11="http://docs.oasis-open.org/wsrf/r-2"
> xmlns:ns2="http://www.w3.org/2005/08/addressing"
> xmlns:ns3="http://docs.oasis-open.org/wsn/b-2"
> xmlns:ns4="http://docs.oasis-open.org/wsrf/bf-2"
> xmlns:ns5="http://docs.oasis-open.org/wsn/t-1"
> xmlns:ns6="http://www.onvif.org/ver10/schema"
> xmlns:ns7="http://www.w3.org/2004/08/xop/include"
> xmlns:ns9="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xmime="http://www.w3.org/2005/05/xmlmime">
> 			<ns10:Timeout>PT60S</ns10:Timeout>
> 			<ns10:MessageLimit>10</ns10:MessageLimit>
> 		</ns10:PullMessages>
> 	</soap:Body>
> </soap:Envelope>
> 
> I just want to add these lines to the header of this/a certain message:
> 
> <wsa5:To
> xmlns:wsa5="http://www.w3.org/2005/08/addressing">http://172.16.101.13
> 0/onvif/services</wsa5:To>
> <dom0:SubscriptionId
> xmlns:dom0="http://www.axis.com/2009/event">3</dom0:SubscriptionId>
> 
> How can I do that? Do you need some more information about my
> implemenetation?
> 
> Thank you!
> 
> meteora28
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Insert-
> elements-in-soap-header-tp5712191p5723378.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Re: Insert elements in soap header?

Posted by meteora28 <s....@web.de>.
Thank you for your answers, but I could not solve it yet.

Currently I have this message:

POST /onvif/services HTTP/1.1
Content-Type: application/soap+xml;
action="http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/PullMessagesRequest";
charset=UTF-8
Accept: */*
User-Agent: Apache CXF 2.7.2
Cache-Control: no-cache
Pragma: no-cache
Host: 172.16.101.130
Connection: keep-alive
Content-Length: 1463

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
	<soap:Header>
		<wsse:Security
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
soap:mustUnderstand="true">
			<wsse:UsernameToken wsu:Id="UsernameToken-14">
				<wsse:Username>root</wsse:Username>
				<wsse:Password
Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">FyjTaK5w90bDNRb5hzWwoaYpX5M=</wsse:Password>
				<wsse:Nonce
EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">VNAN0Nuy6gsm6YwAZh8HwA==</wsse:Nonce>
				<wsu:Created>2013-02-19T15:16:46.862Z</wsu:Created>
			</wsse:UsernameToken>
		</wsse:Security>
	</soap:Header>
	<soap:Body>
		<ns10:PullMessages xmlns:ns10="http://www.onvif.org/ver10/events/wsdl"
xmlns:ns11="http://docs.oasis-open.org/wsrf/r-2"
xmlns:ns2="http://www.w3.org/2005/08/addressing"
xmlns:ns3="http://docs.oasis-open.org/wsn/b-2"
xmlns:ns4="http://docs.oasis-open.org/wsrf/bf-2"
xmlns:ns5="http://docs.oasis-open.org/wsn/t-1"
xmlns:ns6="http://www.onvif.org/ver10/schema"
xmlns:ns7="http://www.w3.org/2004/08/xop/include"
xmlns:ns9="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xmime="http://www.w3.org/2005/05/xmlmime">
			<ns10:Timeout>PT60S</ns10:Timeout>
			<ns10:MessageLimit>10</ns10:MessageLimit>
		</ns10:PullMessages>
	</soap:Body>
</soap:Envelope>

I just want to add these lines to the header of this/a certain message:

<wsa5:To
xmlns:wsa5="http://www.w3.org/2005/08/addressing">http://172.16.101.130/onvif/services</wsa5:To>
<dom0:SubscriptionId
xmlns:dom0="http://www.axis.com/2009/event">3</dom0:SubscriptionId>

How can I do that? Do you need some more information about my
implemenetation?

Thank you!

meteora28



--
View this message in context: http://cxf.547215.n5.nabble.com/Insert-elements-in-soap-header-tp5712191p5723378.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Insert elements in soap header?

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

Also please take a look at our FAQ about this issue here[1]
[1]http://cxf.apache.org/faq.html#FAQ-HowcanIaddsoapheaderstotherequest%2Fresponse%3F

Freeman
-------------
Freeman Fang

FuseSource
Email:ffang@fusesource.com
Web: fusesource.com
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com
http://blog.sina.com.cn/u/1473905042
weibo: http://weibo.com/u/1473905042

On 2012-8-8, at 下午11:00, Glen Mazza wrote:

> If those elements are already defined in the wsdl:binding section, those are implicit headers -- see article #56 of http://www.jroller.com/gmazza/entry/blog_article_index, else you can use either JAX-WS handlers or CXF interceptors (articles #52 - #53), as an alternative to #52-#53 CXF's transformation feature (which I haven't used before) might be able to help you: http://cxf.apache.org/docs/transformationfeature.html.
> 
> HTH,
> Glen
> 
> On 08/08/2012 10:45 AM, meteora28 wrote:
>> Hello there,
>> 
>> is it possible to add some more elements in the soap header?
>> 
>> For example the following elements next to "security" in the header:
>> 
>> <?xml version="1.0" encoding="utf-8"?>
>> <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
>> xmlns:a="http://www.w3.org/2005/08/addressing">
>> 	<s:Header>
>> 		<a:Action
>> s:mustUnderstand="1">http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/PullMessagesRequest</a:Action>
>> 		<a:MessageID>urn:uuid:5b3d2467-ed65-4fb8-a2c3-174c83f4e113</a:MessageID>
>> 		<a:ReplyTo>
>> 			<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
>> 		</a:ReplyTo>
>> 		<wsse:Security
>> xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
>> xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
>> 			...
>> 		</wsse:Security>
>> 		<SubscriptionId a:IsReferenceParameter="true"
>> xmlns="http://www.hitron.co.kr/event"
>> xmlns:dom0="http://www.hitron.co.kr/event">1</SubscriptionId>
>> 		<a:To s:mustUnderstand="1">http://1.2.3.4/onvif/device_service</a:To>
>> 	</s:Header>
>> 	<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>> 		<PullMessages xmlns="http://www.onvif.org/ver10/events/wsdl">
>> 			<Timeout>PT20S</Timeout>
>> 			<MessageLimit>2</MessageLimit>
>> 		</PullMessages>
>> 	</s:Body>
>> </s:Envelope>
>> 
>> 
>> 
>> 
>> 
>> --
>> View this message in context: http://cxf.547215.n5.nabble.com/Insert-elements-in-soap-header-tp5712191.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
> 


Re: Insert elements in soap header?

Posted by Glen Mazza <gm...@talend.com>.
If those elements are already defined in the wsdl:binding section, those 
are implicit headers -- see article #56 of 
http://www.jroller.com/gmazza/entry/blog_article_index, else you can use 
either JAX-WS handlers or CXF interceptors (articles #52 - #53), as an 
alternative to #52-#53 CXF's transformation feature (which I haven't 
used before) might be able to help you: 
http://cxf.apache.org/docs/transformationfeature.html.

HTH,
Glen

On 08/08/2012 10:45 AM, meteora28 wrote:
> Hello there,
>
> is it possible to add some more elements in the soap header?
>
> For example the following elements next to "security" in the header:
>
> <?xml version="1.0" encoding="utf-8"?>
> <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
> xmlns:a="http://www.w3.org/2005/08/addressing">
> 	<s:Header>
> 		<a:Action
> s:mustUnderstand="1">http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/PullMessagesRequest</a:Action>
> 		<a:MessageID>urn:uuid:5b3d2467-ed65-4fb8-a2c3-174c83f4e113</a:MessageID>
> 		<a:ReplyTo>
> 			<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
> 		</a:ReplyTo>
> 		<wsse:Security
> xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
> xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
> 			...
> 		</wsse:Security>
> 		<SubscriptionId a:IsReferenceParameter="true"
> xmlns="http://www.hitron.co.kr/event"
> xmlns:dom0="http://www.hitron.co.kr/event">1</SubscriptionId>
> 		<a:To s:mustUnderstand="1">http://1.2.3.4/onvif/device_service</a:To>
> 	</s:Header>
> 	<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> 		<PullMessages xmlns="http://www.onvif.org/ver10/events/wsdl">
> 			<Timeout>PT20S</Timeout>
> 			<MessageLimit>2</MessageLimit>
> 		</PullMessages>
> 	</s:Body>
> </s:Envelope>
>
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Insert-elements-in-soap-header-tp5712191.html
> Sent from the cxf-user mailing list archive at Nabble.com.