public class MD5AttachTest {
static void main(String[] args) throws Exception {
Options opts = new Options(args);
String action = opts.isValueSet('a');
ServiceClient sc = new ServiceClient(opts.getURL());
//if (action != null) sc.set(HTTPTransport.ACTION, action);
sc.set(HTTPTransport.ACTION, "");
args = opts.getRemainingArgs();
if(null == args || args.length != 1) {
System.err.println("Must specify file to send as an attachment!");
System.exit(8);
}
//Create the attachment.
javax.activation.DataHandler dh= new javax.activation.DataHandler( new javax.activation.FileDataSource( args[0] ));
org.apache.axis.message.SOAPEnvelope env= new org.apache.axis.message.SOAPEnvelope();
//Build the body elements.
javax.xml.parsers.DocumentBuilderFactory dbf= javax.xml.parsers.DocumentBuilderFactory.newInstance();
javax.xml.parsers.DocumentBuilder db= dbf.newDocumentBuilder();
org.w3c.dom.Document doc= db.newDocument();
org.w3c.dom.Element methodElement= doc.createElementNS("foo", "foo:MD5Attach");
org.w3c.dom.Element paramElement= doc.createElementNS("foo", "foo:thefile");
long startTime= System.currentTimeMillis();
methodElement.appendChild(paramElement);
paramElement.appendChild( doc.createTextNode(""+startTime));
org.apache.axis.message.SOAPBodyElement sbe= new org.apache.axis.message.SOAPBodyElement( methodElement);
env.addBodyElement(sbe);
org.apache.axis.Message msg= new org.apache.axis.Message(env);
//Add the attachment content to the message.
org.apache.axis.attachments.Attachments attachments= msg.getAttachments();
org.apache.axis.Part attachmentPart= attachments.createAttachmentPart(dh);
String href= attachmentPart.getContentId();
//Have the parameter element set an href attribute to the attachment.
paramElement.setAttribute(org.apache.axis.Constants.ATTR_HREF, href );
env.clearBody();
env.addBodyElement(sbe);
msg.getSOAPPart().setSOAPEnvelope(env);
sc.setRequestMessage(msg);
//go on now....
sc.invoke();
MessageContext mc = sc.getMessageContext();
// System.out.println(mc.getResponseMessage().getAsString());
env = mc.getResponseMessage().getSOAPPart().getAsSOAPEnvelope();
sbe= env.getFirstBody();
org.w3c.dom.Element sbElement= sbe.getAsDOM();