* @throws SOAPException if there was a problem saving changes to this message.
*/
public void saveChanges() throws SOAPException {
try {
String contentTypeValue = getSingleHeaderValue(HTTPConstants.HEADER_CONTENT_TYPE);
ContentType contentType = null;
if (isEmptyString(contentTypeValue)) {
if (attachmentParts.size() > 0) {
contentTypeValue = HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED;
} else {
contentTypeValue = getBaseType();
}
}
contentType = new ContentType(contentTypeValue);
//Use configures the baseType with multipart/related while no attachment exists or all the attachments are removed
if(contentType.getBaseType().equals(HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED) && attachmentParts.size() == 0) {
contentType = new ContentType(getBaseType());
}
//If it is of multipart/related, initialize those required values in the content-type, including boundary etc.
if (contentType.getBaseType().equals(HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED)) {
//Configure boundary
String boundaryParam = contentType.getParameter("boundary");
if (isEmptyString(boundaryParam)) {
contentType.setParameter("boundary", UIDGenerator.generateMimeBoundary());
}
//Configure start content id, always get it from soapPart in case it is changed
String soapPartContentId = soapPart.getContentId();
if (isEmptyString(soapPartContentId)) {
soapPartContentId = "<" + UIDGenerator.generateContentId() + ">";
soapPart.setContentId(soapPartContentId);
}
contentType.setParameter("start", soapPartContentId);
//Configure contentId for each attachments
for(AttachmentPart attachmentPart : attachmentParts) {
if(isEmptyString(attachmentPart.getContentId())) {
attachmentPart.setContentId("<" + UIDGenerator.generateContentId() + ">");
}
}
//Configure type
contentType.setParameter("type", getBaseType());
//Configure charset
String soapPartContentTypeValue = getSingleHeaderValue(soapPart.getMimeHeader(HTTPConstants.HEADER_CONTENT_TYPE));
ContentType soapPartContentType = null;
if (isEmptyString(soapPartContentTypeValue)) {
soapPartContentType = new ContentType(soapPartContentTypeValue);
} else {
soapPartContentType = new ContentType(getBaseType());
}
setCharsetParameter(soapPartContentType);
} else {
//Configure charset
setCharsetParameter(contentType);