// Should we use an attachment? Do so if:
// (a) attachment support exists and mUseAttachments == true and
// (b) if we are the server, the client sent us an attachment
// (so we know client wants attachment support as well)]
Message msg = context.getCurrentMessage();
Attachments attachments = msg.getAttachmentsImpl();
boolean useAttachments = (attachments != null) && mUseAttachments;
if (useAttachments) {
useAttachments = !context.getMessageContext().getPastPivot()
|| context.getMessageContext().getRequestMessage().getAttachments().hasNext();
}
// if we have attachment support, do this as an attachment
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.