private AttachmentPart createAttachmentPart(ParameterMetaData paramMetaData, Object value, CIDGenerator cidGenerator) throws SOAPException, BindingException
{
String partName = paramMetaData.getXmlName().getLocalPart();
Set mimeTypes = paramMetaData.getMimeTypes();
AttachmentPart part = new AttachmentPartImpl();
if (value instanceof DataHandler)
{
DataHandler handler = (DataHandler)value;
String mimeType = MimeUtils.getBaseMimeType(handler.getContentType());
// JAX-WS 2.0, 2.6.3.1 MIME Content
// Conformance (MIME type mismatch): On receipt of a message where the MIME type of a part does not
// match that described in the WSDL an implementation SHOULD throw a WebServiceException.
if (mimeTypes != null && !MimeUtils.isMemberOf(mimeType, mimeTypes))
log.warn("Mime type " + mimeType + " not allowed for parameter " + partName + " allowed types are " + mimeTypes);
part.setDataHandler((DataHandler)value);
}
else
{
String mimeType = null;
if (mimeTypes != null && mimeTypes.size() > 0)
{
mimeType = (String)mimeTypes.iterator().next();
}
else
{
mimeType = MimeUtils.resolveMimeType(value);
}
if (mimeType == null)
throw new BindingException("Could not determine mime type for attachment parameter: " + partName);
part.setContent(value, mimeType);
}
if (paramMetaData.isSwA())
{
String swaCID = '<' + partName + "=" + cidGenerator.generateFromCount() + '>';
part.setContentId(swaCID);
}
if (paramMetaData.isXOP())
{
String xopCID = '<' + cidGenerator.generateFromName(partName) + '>';
part.setContentId(xopCID);
}
return part;
}