This discussion is archived
2 Replies Latest reply: Jan 11, 2013 7:41 AM by 901057 RSS

Extra namespace was added after SOAPBody.addDocument(xmlDoc) is called

901057 Newbie
Currently Being Moderated
Hi all,
I am working on adding SAMLRequest to SOAP message using saaj-api 1.3.4 with Java1.5
However, when I add the XML doc using SOAPBody.addDocument(), extra namespaces were added to the soapBody
The XML I try to add is:
<samlp:Request RequestID="mhdefhnhjladllhdlfeihkcbbcabakodmnnmbjdl" MajorVersion="1" MinorVersion="1" IssueInstant="2013-01-11T00:31:49.492Z" xmlns:samlp="urn:oasis:names:tc:SAML:1.0:protocol"><samlp:AssertionArtifact>QUFFWm9QMkF1N1dCNE1PbHIyS3FUQXlQaTJWR0dXUzB5VmNpUm0vMUtIZ0RQbytjWnFGcFNoSlA=</samlp:AssertionArtifact></samlp:Request>

after soapBody.addDocument(doc)
I get
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body xmlns:samlp="urn:oasis:names:tc:SAML:1.0:protocol">
<samlp:Request xmlns:axis2ns2="urn:oasis:names:tc:SAML:1.0:protocol" IssueInstant="2013-01-11T00:31:49.492Z" MajorVersion="1" MinorVersion="1" RequestID="mhdefhnhjladllhdlfeihkcbbcabakodmnnmbjdl">
<samlp:AssertionArtifact xmlns:axis2ns3="urn:oasis:names:tc:SAML:1.0:protocol">QUFFWm9QMkF1N1dCNE1PbHIyS3FUQXlQaTJWR0dXUzB5VmNpUm0vMUtIZ0RQbytjWnFGcFNoSlA=</samlp:AssertionArtifact>
</samlp:Request>
</soapenv:Body>
</soapenv:Envelope>


As you can see, "xmlns:axis2ns2", "xmlns:axis2ns3" are added to the SAMLRequest and body has xmlns:samlp namespace.

Here is How I did this:

String artRequest = buildSAMLRequest(samlArt);          
//build soap message
     DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware(true);
     InputStream stream = new ByteArrayInputStream(artRequest.getBytes());
Document doc = builderFactory.newDocumentBuilder().parse(stream);
     MessageFactory mf12 = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
     SOAPMessage message = mf12.createMessage();
     SOAPBody soapBody = message.getSOAPBody();     
soapBody.addDocument(doc);


//output as String for HTTP connection
ByteArrayOutputStream xmlout = new ByteArrayOutputStream();
message.writeTo(xmlout);
String strMsg = new String(xmlout.toByteArray());



Does anyone have idea how can I get rid of the extra namespace?

Thank you so much
David

Edited by: 898054 on Jan 10, 2013 4:46 PM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points