6 - Here is the code for the client (It uses the same schema as the server side, already included in one of the previous parts):

package com.oracle.mtom.client;

import java.io.IOException;
import java.io.File;
import java.util.Calendar;
import java.util.TimeZone;
import java.util.GregorianCalendar;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.DatatypeConstants;
import javax.activation.FileDataSource;
import javax.activation.DataHandler;
import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamResult;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlAp plicationContext;
import org.springframework.ws.client.core.support.WebServ iceGatewaySupport;
import org.springframework.xml.transform.StringSource;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.client.core.WebServiceMessa geCallback;
import org.springframework.ws.soap.SoapMessage;
import org.springframework.ws.soap.addressing.core.Endpoi ntReference;
import org.springframework.ws.soap.addressing.client.Acti onCallback;
import java.net.URI;
import org.springframework.ws.soap.addressing.version.Add ressing10;

import javax.xml.bind.JAXBElement;

import com.oracle.mtom.schema.*;

public class MtomServiceClient extends WebServiceGatewaySupport {

private ObjectFactory objectFactory;

private boolean useWSAddressing = false;

private String action;

private String to;

private String replyTo;

public MtomServiceClient(){
objectFactory = new ObjectFactory();
}

public void setUseWSAddressing(boolean value){
useWSAddressing = value;
}

public boolean getUseWSAddressing(){
return useWSAddressing;
}

public void setAction(String value){
action = value;
}

public String getAction(){
return action;
}

public void setTo(String value){
to = value;
}

public String getTo(){
return to;
}

public void setReplyTo(String value){
replyTo = value;
}

public String getReplyTo(){
return replyTo;
}

public void processRequest(String source1, String source2) throws IOException, TransformerException, Exception {

JAXBElement responseElement = null;

com.oracle.mtom.schema.Package pkg = new com.oracle.mtom.schema.Package();
pkg.setPackageTitle("Policy-xyz");
pkg.setRecipient1("Insured");
pkg.setRecipient2("Agent");
pkg.setRecipient3("Carrier");


DatatypeFactory factory = DatatypeFactory.newInstance();
TimeZone tz = TimeZone.getTimeZone("UTC");
GregorianCalendar gc = new GregorianCalendar(tz);
pkg.setStartDate(factory.newXMLGregorianCalendar(g c));
gc.add(Calendar.DATE, 30); //30 days later
pkg.setEndDate(factory.newXMLGregorianCalendar(gc) );


//Optional attachment 1
if (source1 != null && source1.trim().length() > 0){
File f = new File(source1);
FileDataSource fd = new FileDataSource(f);
DataHandler dh = new DataHandler(fd);
Attachment attachment1 = new Attachment();
attachment1.setName(f.getName());
attachment1.setContent(dh);
pkg.getAttachment().add(attachment1);
}

//Optional attachment 2
if (source2 != null && source2.trim().length() > 0){
File f = new File(source2);
FileDataSource fd = new FileDataSource(f);
DataHandler dh = new DataHandler(fd);
Attachment attachment2 = new Attachment();
attachment2.setName(f.getName());
attachment2.setContent(dh);
pkg.getAttachment().add(attachment2);
}

pkg.setOptional1("dummy text");

JAXBElement<com.oracle.mtom.schema.Package> request = objectFactory.createTestRequest(pkg );


if (useWSAddressing){
System.out.println("Using WS-Addressing");
ActionCallback myCallback = new ActionCallback(new URI(action), //Action Header
new Addressing10(), //Version Header
new URI(to)); //To Header

myCallback.setReplyTo(new EndpointReference(new URI(replyTo))); //Reply-To Header

responseElement = (JAXBElement)getWebServiceTemplate().marshalSendAn dReceive(request, myCallback);

}else{
System.out.println("Not using WS-Addressing.");

responseElement = (JAXBElement)getWebServiceTemplate().marshalSendAn dReceive(request);
}

if (responseElement != null){
PackageResponse rsp = (PackageResponse)responseElement.getValue();
System.out.println("Results=<" + rsp.getResults() + ">");
System.out.println("ArchiveDate=<" + rsp.getArchiveDate() + ">");
}

}

public static void main(String[] args) throws IOException {
try {

ApplicationContext ctx = new ClassPathXmlApplicationContext(args[0]);

MtomServiceClient mtomServiceClient = (MtomServiceClient) ctx.getBean("MtomServiceClient", MtomServiceClient.class);

mtomServiceClient.processRequest(args.length > 1? args[1]: null, args.length > 2? args[2] : null);


}catch (Exception e) {
e.printStackTrace();
}

}


}

continues on the next thread...