aspose file tools*
The moose likes Web Services and the fly likes adding arbitary xml to soap headers using SAAJ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "adding arbitary xml to soap headers using SAAJ" Watch "adding arbitary xml to soap headers using SAAJ" New topic
Author

adding arbitary xml to soap headers using SAAJ

vignesh bala
Greenhorn

Joined: Aug 19, 2006
Posts: 28

Hi all,
I am using SAAJ to access web service. I am having a arbitary xml in my soap request. I am forming that xml seperately. but the problem is I am unable to add that xml document to the header element(In Soap body I can add another xml through body.addDocument() but Soap Header doesn't have one).I tried using header.addTextNode() but the markups are not coming properly. Please help me.

Thanks & Regards,
Vignesh
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
Seems to me that adding arbitrary XML to SOAP Headersis contrary to the whole SOAP design, where headers are supposed to be processing information and the body is the arbitrary XML message to be delivered.

Why not just attach it as a SAAJ attachment?

Bill
vignesh bala
Greenhorn

Joined: Aug 19, 2006
Posts: 28

Hi guys,
I think should have describe my problem more clearly. I am using xml beans to construct the soap message. my soap message has a message header in the header field. The message header itself is a xml defined by the schema. I am converting these schemas in to java bean format using xml beans. The process I am following is:
1. form message header(xml).
2. form bodyXml (which is again defined by a seperate schema)
3. using saaj form soap request
4. get the soap header
5. add message header(xml) to the header
6. get soap body
7. add bodyXml to soap body
8. send soap message

In the above steps I can't able to perform the 5th step.Please suggest me if there is any way to achive this.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
Like Bill said, it's not a good idea to stuff XML into a SOAP header. But if for some reason (which one?) you have to do it, it should be possible. What does the XML look like that you are trying to put there, and what exactly is happening if you do?


Ping & DNS - my free Android networking tools app
vignesh bala
Greenhorn

Joined: Aug 19, 2006
Posts: 28

I must write a web service client to access a web service which requires the requests in certain format(The request schema requires an xml in header).I give the sample request below:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header >
<MessageHeader MessageID="0000" MessageName="ABCD" TimeStamp="mmddyyHHMMSS"/>
</soap:Header>
<soap:Body >
<..body xml..>
</soap:Body>
</soap:Envelope>


As I already told, I used xml beans to create the message header. when I used header.appendChild(node);, I am getting the below error:



Then I tried converting xml asstring and add it to header using header.setTextNode(String). It ran withoutany exception but the markups are coming like < > etc. so due to this the web service gives fault response. I am new to soap and I am seriously doubting whether my approach is right and also is there any other way to acheive the above message format?.Thaks for all the help
vignesh bala
Greenhorn

Joined: Aug 19, 2006
Posts: 28

Hey sorry guys, In my previous post, I meant to say markups are coming as
<
and
>
. But they came as < and > because I used markup charecters .
vignesh bala
Greenhorn

Joined: Aug 19, 2006
Posts: 28

sorry its lt & rt.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
If this was my problem I would be using TCPMON to capture the exact text being sent.

Why are you generating the String by going through XML, just build it as a string directly and gain control. The XML serialization may be doing stuff to your input.

Bill
vignesh bala
Greenhorn

Joined: Aug 19, 2006
Posts: 28

Thanks Bill,
I'll try your advice
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: adding arbitary xml to soap headers using SAAJ