Posted By:
Ed_Ox
Posted On:
Thursday, December 13, 2001 03:16 AM
I have a working soap sample (using apache) and I would like to try JAXM. I am using attachment to send a XML request. When using apache I have the following request sent over the wire and everything works fine: --5678233.1008153460610.JavaMail.fred.fred Content-Type: text/xml Content-Transfer-Encoding: 7bit Content-ID: <8283321.1008153460590.apache-soap.fred> Content-Length: 123 <?xml version="1.0" encoding="iso-8859-1"?> .. my xml request here .. What I would like to do is to build the same request but by using jaxm instead of apache soap. I trie
More>>
I have a working soap sample (using apache) and I would like to try JAXM.
I am using attachment to send a XML request.
When using apache I have the following request sent over the wire and everything works fine:
--5678233.1008153460610.JavaMail.fred.fred
Content-Type: text/xml
Content-Transfer-Encoding: 7bit
Content-ID:
<8283321.1008153460590.apache-soap.fred>
Content-Length: 123
<?xml version="1.0" encoding="iso-8859-1"?>
.. my xml request here ..
What I would like to do is to build the same request but by using jaxm instead of apache soap.
I tried the following code:
// Get a SOAPConnection object
SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
SOAPConnection con = scFactory.createConnection();
// Create message
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
// Access elements of the messae
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPBody body = soapEnvelope.getBody();
SOAPHeader header = soapEnvelope.getHeader();
// Remove useless header
header.detachNode();
// Add content to the body
Name bodyName = soapEnvelope.createName("process","ns1","urn:myUrn");
//Put the request as an attachement to the message
ByteArrayDataSource ds = new ByteArrayDataSource("
<?xml version="1.0" encoding="iso-8859-1"?>
.. my xml request here ..
", "text/xml");
DataHandler dh = new DataHandler(ds);
AttachmentPart attachment = message.createAttachmentPart(dh);
message.addAttachmentPart(attachment);
SOAPBodyElement bodyElements = body.addBodyElement(bodyName);
// Send the message
URLEndpoint endpoint = new URLEndpoint(server_url);
SOAPMessage response = con.call(message, endpoint);
// Close the connection
con.close();
And with this code, the request which is sent is this one:
--1447623.1008232610442.JavaMail.fred.fred
Content-Type: text/xml
<?xml version="1.0" encoding="iso-8859-1"?>
.. my xml request here ..
--1447623.1008232610442.JavaMail.fred.fred--
The attachment is present, but there is no reference to it in the soap envelope.
So my server does not execute the request.
I tried to force it by adding a Content-ID to the attachement:
attachment.setContentId("my_id");
and a
to the envelope:
Name messageName = soapEnvelope.createName("message");
SOAPElement symbol = bodyElements.addChildElement(messageName);
Name hrefName = soapEnvelope.createName("href");
symbol.addAttribute(hrefName,"cid:my_id");
but it still does not work and the server returns :
Attachment tag "message" refers to a Mime attachment with label "cid:my_id" which could not be found.
I don't understand why no reference to the attachemnt is done in the soap message.
Am I doing things in the wrong way ?
Do I forgot an important part ?
Is it a bug ?
Any help will be apprectiated.
Thanks
Ed