This is
frustrating. My service sends an attachment along with some body
content. Can someone spot where I am going wrong?
Thanks much in
advance.
The code to create
the soap response is:
SOAPMessage reply = mf.createMessage(); //mf is
javax.xml.soap.MessageFactory
SOAPPart sp = reply.getSOAPPart();
SOAPEnvelope envelope = sp.getEnvelope();
SOAPBody body = envelope.getBody();
SOAPEnvelope envelope = sp.getEnvelope();
SOAPBody body = envelope.getBody();
<add body content>
AttachmentPart ap =
reply.createAttachmentPart();
ap.setContent("Hello world", "text/plain");
ap.setContentType("text/plain");
reply.addAttachmentPart(ap);
ap.setContent("Hello world", "text/plain");
ap.setContentType("text/plain");
reply.addAttachmentPart(ap);
OutputStream os = resp.getOutputStream(); //resp
is HttpServletResponse
reply.writeTo(os);
os.flush();
reply.writeTo(os);
os.flush();
The reponse in
TCPMonitor looks right.
HTTP/1.1 200 OK
Server: WebSphere Application
Server/5.0
Content-Type: text/xml
Content-Language: en-US
Transfer-Encoding: chunked
2f6
------=_Part_253_1453525045.1075659147844
Content-Type: text/xml;
charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id:
<55845AE6F8C3F5C10F9BC0B1C55E4852>
<?xml version="1.0"
encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ComposedOutput xmlns=""><PageCount xmlns="">1</PageCount><Filetype xmlns="">text</Filetype><OutputLength xmlns="">4853</OutputLength><MessageLength xmlns="">0</MessageLength><UserDataLength xmlns="">0</UserDataLength><ReturnCode xmlns="">0</ReturnCode></ComposedOutput></soapenv:Body></soapenv:Envelope>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ComposedOutput xmlns=""><PageCount xmlns="">1</PageCount><Filetype xmlns="">text</Filetype><OutputLength xmlns="">4853</OutputLength><MessageLength xmlns="">0</MessageLength><UserDataLength xmlns="">0</UserDataLength><ReturnCode xmlns="">0</ReturnCode></ComposedOutput></soapenv:Body></soapenv:Envelope>
a7
------=_Part_253_1453525045.1075659147844
Content-Type: text/plain
Content-Transfer-Encoding: binary
Content-Id:
<D73FB9876DE71FA69AD338C9CC5F80C3>
Hello
world
2f
------=_Part_253_1453525045.1075659147844--
0
But, when I try to
get my attachment I am told there are no attachments. The client code
is:
SOAPMessage reply = con.call(msg, endpoint);
Iterator it = reply.getAttachments();
if(it.hasNext()) ... //returns false
Iterator it = reply.getAttachments();
if(it.hasNext()) ... //returns false
When I dump out the reply contents via
reply.writeTo(System.out);
I get:
------=_Part_255_354535470.1075659594906
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id: <2AFD7CBEAACE2BBD6E04276133ABA759>
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id: <2AFD7CBEAACE2BBD6E04276133ABA759>
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ComposedOutput xmlns=""><PageCount xmlns="">3</PageCount><Filetype xmlns="">pdf</Filetype><OutputLength xmlns="">4853</OutputLength><MessageLength xmlns="">0</MessageLength><UserDataLength xmlns="">0</UserDataLength><ReturnCode xmlns="">0</ReturnCode></ComposedOutput></soapenv:Body></soapenv:Envelope>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ComposedOutput xmlns=""><PageCount xmlns="">3</PageCount><Filetype xmlns="">pdf</Filetype><OutputLength xmlns="">4853</OutputLength><MessageLength xmlns="">0</MessageLength><UserDataLength xmlns="">0</UserDataLength><ReturnCode xmlns="">0</ReturnCode></ComposedOutput></soapenv:Body></soapenv:Envelope>
------=_Part_255_354535470.1075659594906
Content-Type: text/plain
Content-Transfer-Encoding: binary
Content-Id: <56B762E91F1D90F082AB059B26A3E0C7>
Content-Transfer-Encoding: binary
Content-Id: <56B762E91F1D90F082AB059B26A3E0C7>
Hello world
------=_Part_255_354535470.1075659594906--
