saaj namespace issue
p_nevilleuk Dec 14, 2004 8:22 AMHi,
I am trying to using saaj to create ebXML soap message. I have two problems:
1) I cannot change the prefix of the Envelope, Header etc. I would like SOAP instead of soapenv.
2) More importantly, it repeats the namespace uri on each element, which is not necessary as it is declared in a parent element.
Example soap message from code:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmls
oap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP="http://schemas.xmlsoap.or
g/soap/envelope" xmlns:eb="http://www.oasis-open.org/committees/ebxml-msg/schema
/mgs-header-2_0.xsd">
<soapenv:Header>
<eb:MessageHeader xmlns:eb="http://www.oasis-open.org/committees/ebxml-msg/sch
ema/mgs-header-2_0.xsd">
<eb:From xmlns:eb="http://www.oasis-open.org/committees/ebxml-msg/schema/mgs-
header-2_0.xsd">
<eb:PartyId xmlns:eb="http://www.oasis-open.org/committees/ebxml-msg/schema/
mgs-header-2_0.xsd"/>
</eb:From>
</eb:MessageHeader>
</soapenv:Header>
<soapenv:Body/>
I would like:
<SOAP:Envelope xmlns:SOAP="http://schemas.xmls
oap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP="http://schemas.xmlsoap.or
g/soap/envelope" xmlns:eb="http://www.oasis-open.org/committees/ebxml-msg/schema
/mgs-header-2_0.xsd">
<SOAP:Header>
<eb:MessageHeader>
<eb:From>
<eb:PartyId/>
</eb:From>
</eb:MessageHeader>
</SOAP:Header>
<SOAP:Body/>
Following is my code:
SOAPConnectionFactory connFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = connFactory.createConnection();
SOAPMessage message = MessageFactory.newInstance().createMessage();
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.setPrefix("SOAP");
envelope.addNamespaceDeclaration("SOAP", "http://schemas.xmlsoap.org/soap/envelope");
envelope.addNamespaceDeclaration("eb", "http://www.oasis-open.org/committees/ebxml-msg/schema/mgs-header-2_0.xsd");
SOAPFactory soapFactory = SOAPFactory.newInstance();
Name messageHeader = soapFactory.createName("MessageHeader","eb","http://www.oasis-open.org/committe es/ebxml-msg/schema/mgs-header-2_0.xsd");
SOAPHeader header = message.getSOAPHeader();
SOAPHeaderElement headerElement = header.addHeaderElement(messageHeader);
SOAPElement from = headerElement.addChildElement("From", "eb");
from.addChildElement("PartyId", "eb");
SOAPElement to = headerElement.addChildElement("To", "eb");
to.addChildElement("PartyId", "eb");
Any ideas?
Many thanks for anyone able to help with this.