if (useAttachments) {
// System.out.println("Creating attachment"); //DEBUG
SOAPConstants soapConstants = context.getMessageContext().getSOAPConstants();
DataHandler dataHandler = new DataHandler(new OctetStreamDataSource("test",
new OctetStream(bytes)));
Part attachmentPart = attachments.createAttachmentPart(dataHandler);
AttributesImpl attrs = new AttributesImpl();
if (attributes != null && 0 < attributes.getLength())
attrs.setAttributes(attributes); // copy the existing ones.
int typeIndex = -1;
if ((typeIndex = attrs.getIndex(Constants.URI_DEFAULT_SCHEMA_XSI, "type")) != -1) {
// Found a xsi:type which should not be there for attachments.
attrs.removeAttribute(typeIndex);
}
attrs.addAttribute("", soapConstants.getAttrHref(), soapConstants.getAttrHref(), "CDATA",
attachmentPart.getContentIdRef());
context.startElement(name, attrs);
context.endElement();
} else {
// no attachment support - Base64 encode
// System.out.println("No attachment support"); //DEBUG