In trying to debug this, I arrived at SOAPBindingCodec.getEncoder()
where this code lies:
Message m = p.getMessage();
if(m==null || m.getAttachments().isEmpty())
return xmlSoapCodec;
else
return xmlSwaCodec;
In the debugger:
p.invocationProperties: (java.util.HashMap<K,V>)
{javax.xml.ws.binding.attachments.outbound={<123_at_example.com>=javax.acti
vation.DataHandler_at_659078}}
p.getMessage().getAttachments().isEmpty(): (boolean) true
So the xmlSoapCodec is selected instead of the xmlSwaCodec. Should
getMessage().getAttachments() be populated from invocationProperties
somewhere prior to this point? Alternatively, should
invocationProperties be checked here instead of getAttachments()?
I'm using JAX-WS 2.1.1 RC1.
________________________________
From: Fisher, Brice A [mailto:bafishe_at_sandia.gov]
Sent: Monday, April 16, 2007 11:41 AM
To: users_at_jax-ws.dev.java.net
Subject: Attachments not appearing in SOAP message
I'm trying to implement SOAP attachments as described here
http://www.nabble.com/Soap-With-Attachments-t3567874.html
<
http://www.nabble.com/Soap-With-Attachments-t3567874.html> and here
http://forums.java.net/jive/thread.jspa?threadID=14026&messageID=94882
<
http://forums.java.net/jive/thread.jspa?threadID=14026&messageID=94882>
. However, looking at the SOAP message with TCPMON, there are no
attachments generated. Below is my code and the generated SOAP. Can
someone point out what I'm doing wrong?
My function:
private static void uploadFile(GSWebService2 proxy, String
localFileName, String fileName) {
File sourceFile = new File("C:/"+localFileName);
DataHandler dh = new DataHandler(new
FileDataSource(sourceFile));
// Get a reference to the request context.
Map requestContext = ((BindingProvider)
proxy).getRequestContext();
// Get a reference to the attachments map.
Map<String, DataHandler> attachments = (Map<String,
DataHandler>)
requestContext.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
// If the attachments map is null, then create a new map
if (attachments == null) {
attachments = new HashMap<String, DataHandler>();
}
// Add the data handler to the list of outbound attachments.
attachments.put("multipart/*", dh);
// place it in the request context.
requestContext.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS,
attachments);
// Invoke the webservice call.
proxy.uploadFile(fileName);
}
The SOAP:
POST /Java6WS/GSWebService2 HTTP/1.1
SOAPAction: ""
Accept: text/xml, multipart/related, text/html, image/gif, image/jpeg,
*; q=.2, */*; q=.2
Content-Type:
multipart/related;type="application/xop+xml";boundary="uuid:74f1b1e2-95c
c-4226-b5c9-e2bfcc4cf4a2";start-info="text/xml"
User-Agent: Java/1.6.0
Host: localhost:8081
Connection: keep-alive
Transfer-Encoding: chunked
174
--uuid:74f1b1e2-95cc-4226-b5c9-e2bfcc4cf4a2
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary
<?xml version="1.0" ?><S:Envelope
xmlns:S="
http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:uploadF
ile
xmlns:ns2="
http://GroupService.cip.company.com/"><arg0>backgrounds.zip</
arg0></ns2:uploadFile></S:Body></S:Envelope>
2f
--uuid:74f1b1e2-95cc-4226-b5c9-e2bfcc4cf4a2--
0