I used JWSDP 2.0 to generate my client stubs from a WSDL file. I have one web service method that is supposed to allow the client to send a file as a SOAP attachment. Info on defining the WSDL for web service methods that receive attachments from the client seems to be sparse. The one example I found said to set up the WSDL like this:
<operation name="sendFile">
<soap:operation soapAction="" />
<input>
<mime:multipartRelated>
<mime:part>
<soap:body use="literal" namespace="com.blankety.SomeWSInterface"/>
</mime:part>
<mime:part>
<mime:content part="fileHandler" type="application/octet-stream" />
</mime:part>
</mime:multipartRelated>
</input>
<output>
<soap:body use="literal" namespace="com.blankety.SomeWSInterface"/>
</output>
</operation>
Actually, the original example didn't have the namespace attribute but wscompile would not create the stub without the namespace defined. So I added that.
Anyway, the client stub for the above method gets generated fine. But at runtime, the stub throws the following exception:
javax.xml.rpc.soap.SOAPFaultException: JAXRPCTIE01:
caught exception while handling request: no attachment with id "fileHandler" found in message
at com.sun.xml.rpc.client.StreamingSender._raiseFault(StreamingSender.java:528)
at com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:307)
at com.blankety.SomeWSInterfacePortType_Stub.sendFile(SomeWSInterfacePortType_Stub.java:498)
...
Some research showed that the client has to properly set the Content Id for the attachment. But I looks to me like the code IS properly setting the Content Id, according to the one source I found. Here is the addAttachment method where the id is created. The value of the part argument is "fileHandler", which is what the above Exception is complaining about:
private void addAttachment(javax.xml.soap.SOAPMessage message, Object value,
java.lang.String mimeType, java.lang.String part) throws Exception{
java.lang.String contentId = part + "="
+ com.sun.xml.rpc.util.JAXRPCUtils.getUUID() + "@jaxrpc.sun.com";
javax.xml.soap.AttachmentPart _attPart = null;
if (value == null || mimeType == null){
return;
}
if (value instanceof javax.activation.DataHandler){
_attPart = message
.createAttachmentPart((javax.activation.DataHandler) value);
} else if (value instanceof javax.mail.internet.MimeMultipart){
java.lang.String contentType =
((javax.mail.internet.MimeMultipart) value).getContentType();
javax.activation.DataHandler dataHandler =
new javax.activation.DataHandler(value, contentType);
_attPart = message.createAttachmentPart(dataHandler);
} else{
_attPart = message.createAttachmentPart(value, mimeType);
}
_attPart.setContentId("<" + contentId + ">");
message.addAttachmentPart(_attPart);
}
The statement that calls this method is:
addAttachment(_state.getRequest().getMessage(),
(Object)fileHandler,
((javax.activation.DataHandler)fileHandler).getContentType(),
"fileHandler");
I've run this in the debugger and can see that the attachment is created and that there is a Content Id. Debugger output:
mimeType "text/plain" (id=74)
part "fileHandler" (id=81)
contentId "fileHandler=ff29e7ba-2b66-4214-abac-3687af439166@jaxrpc.sun.com" (id=82)
_attPart AttachmentPartImpl (id=52)
dataHandler DataHandler (id=56)
currentCommandMap null
dataContentHandler null
dataSource FileDataSource (id=84)
_file File (id=96)
typeMap null
factoryDCH null
objDataSource null
object null
objectMimeType null
oldFactory null
shortType null
transferFlavors DataFlavor[0] (id=87)
headers MimeHeaders (id=60)
rawContent null
Obviously com.sun.xml.rpc.client.StreamingSender is not finding the Content Id. But why? Is it looking in the wrong place? Or is my client stub setting it in the wrong place?
Edited by: jimgood on Mar 1, 2009 1:13 PM
Edited by: jimgood on Mar 1, 2009 1:14 PM
Edited by: jimgood on Mar 1, 2009 1:16 PM