boolean isInput)
throws WSIFException {
Trc.entry(this, mimeMultipart);
ArrayList mimePartNames = new ArrayList();
SOAPBody soapBody = null;
Operation op = bindingOperation.getOperation();
Map mapInParts = op.getInput().getMessage().getParts();
Map mapOutParts =
op.getOutput() == null
? new HashMap()
: op.getOutput().getMessage().getParts();
List mimeParts = mimeMultipart.getMIMEParts();
Iterator mimePartIt = mimeParts.iterator();
while (mimePartIt.hasNext()) {
Object nextMimePart = mimePartIt.next();
if (nextMimePart instanceof MIMEPart) {
MIMEPart mimePart = (MIMEPart) nextMimePart;
if (!MIMEConstants
.NS_URI_MIME
.equals(mimePart.getElementType().getNamespaceURI()))
throw new WSIFException(
"A MIME part in binding operation "
+ bindingOperation.getName()
+ " did not have the correct namespace URI of "
+ MIMEConstants.NS_URI_MIME
+ ".");
boolean containsSoapBody = false;
boolean containsMimeContent = false;
List mimePartChildren = mimePart.getExtensibilityElements();
Iterator mimePartChildrenIt = mimePartChildren.iterator();
while (mimePartChildrenIt.hasNext()) {
Object nextChild = mimePartChildrenIt.next();
if (nextChild instanceof MIMEContent) {
MIMEContent mimeContent = (MIMEContent) nextChild;
if (!MIMEConstants
.NS_URI_MIME
.equals(
mimePart.getElementType().getNamespaceURI()))
throw new WSIFException(
"A MIME part in binding operation "
+ bindingOperation.getName()
+ " did not have the correct namespace URI of "
+ MIMEConstants.NS_URI_MIME
+ ".");
containsMimeContent = true;
if (containsSoapBody)
throw new WSIFException(
"A mime:part that contains a mime:content also "
+ "contains a soap:body. Operation="
+ getName());
String partName = mimeContent.getPart();
if (partName == null || partName.length() == 0)
throw new WSIFException(
"No part name for a mime:content. Operation="
+ getName());
if ((isInput && mapInParts.get(partName) == null)
|| (!isInput && mapOutParts.get(partName) == null))
throw new WSIFException(
"The part specified in a mime:content does "
+ "not exist in the operation. Operation="
+ getName()
+ " Part="
+ partName);
mimePartNames.add(partName);
} else if (nextChild instanceof SOAPBody) {
if (soapBody!=null) {
throw new WSIFException(
"Multiple soap:body tags found in a "
+ "mime:multipartRelated. Operation="
+ getName());
}
soapBody = (SOAPBody)nextChild;
containsSoapBody = true;
if (containsMimeContent)
throw new WSIFException(
"A mime:part that contains a mime:content also "
+ "contains a soap:body. Operation="
+ getName());
} else if (nextChild instanceof MIMEMultipartRelated) {
throw new WSIFException(
"WSIF does not support nesting mime:multipartRelated "
+ "inside a mime:part. Operation="
+ getName());
} else if (nextChild instanceof MIMEMimeXml) {
throw new WSIFException(
"WSIF does not support mime:mimeXml. Operation="
+ getName());
}
}
}
}
// There is at most one soap:body so process it here.
if (soapBody != null)
{
List soapBodyParts = soapBody.getParts();
if (soapBodyParts == null && !mimePartNames.isEmpty())
{
/* In the WSDL (containing attachments and non-attachment
* parts), if there is a soap:body that does not have
* the parts attribute, which parts should the soap body
* contain? The WSDL spec is not clear so this code
* fixes the soap body to contain only the non-attachment
* parts, which is the kinder option. The alternative which
* is making the soap body contain all the parts (so duplicating
* the attachments) is cruel since this is probably not
* what the backend is expecting.
*/
Map soapParts;
if (isInput)
soapParts = mapInParts;
else
soapParts = mapOutParts;
if (soapParts != null && !soapParts.isEmpty())
{
ArrayList nonMimeParts =
new ArrayList(
Arrays.asList(soapParts.keySet().toArray()));
nonMimeParts.removeAll(
Arrays.asList(soapParts.keySet().toArray()));
soapBody.setParts(nonMimeParts);
}
}
List soapParts = parseSoapBody(soapBody, isInput);
if (isInput)