OMOutputFormat baseOutputFormat = new OMOutputFormat();
baseOutputFormat.setDoOptimize(false);
OMNamespaceImpl soap = new OMNamespaceImpl(
"http://schemas.xmlsoap.org/soap/envelope/", "soap");
OMElement envelope = new OMElementImpl("Envelope", soap);
OMElement body = new OMElementImpl("Body", soap);
OMNamespaceImpl dataName = new OMNamespaceImpl(
"http://www.example.org/stuff", "m");
OMElement data = new OMElementImpl("data", dataName);
expectedImage =
new ImageIO().loadImage(
new FileInputStream(
getTestResourceFile(imageInFileName)));
ImageDataSource dataSource = new ImageDataSource("WaterLilies.jpg",
expectedImage);
expectedDH = new DataHandler(dataSource);
OMText binaryNode = new OMTextImpl(expectedDH, true);
envelope.addChild(body);
body.addChild(data);
data.addChild(binaryNode);
envelope.serializeAndConsume(new FileOutputStream(outBase64File), baseOutputFormat);
envelope.serializeAndConsume(new FileOutputStream(outMTOMFile), mtomOutputFormat);
}