System.out.println(">>MTOM Dispatch Test");
init();
// Set the data inside of the appropriate object
ImageDepot imageDepot = new ObjectFactory().createImageDepot();
imageDepot.setImageData(content);
if (soap12) {
svc = Service.create(serviceName12);
svc.addPort(portNameDispatch, SOAPBinding.SOAP12HTTP_BINDING, uriString + urlSuffix);
} else {
svc = Service.create(serviceName11);
svc.addPort(portNameDispatch, SOAPBinding.SOAP11HTTP_BINDING, uriString + urlSuffix);
}
// Setup the necessary JAX-WS artifacts
JAXBContext jbc = JAXBContext
.newInstance("org.apache.axis2.jaxws.samples.mtom");
Dispatch<Object> dispatch = svc.createDispatch(portNameDispatch, jbc,
Service.Mode.PAYLOAD);
BindingProvider bp = (BindingProvider) dispatch;
bp.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY,
Boolean.TRUE);
bp.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY,
"sendImage");
// Set the actual flag to enable MTOM
SOAPBinding binding = (SOAPBinding) dispatch.getBinding();
binding.setMTOMEnabled(true);
// Create the request wrapper bean
ObjectFactory factory = new ObjectFactory();
SendImage request = factory.createSendImage();
request.setInput(imageDepot);
if (null != result) {
result = result.concat("Invoking Dispatch<Object> with a binary payload\n");
} else {
System.out
.println(">>MTOM Invoking Dispatch<Object> with a binary payload");
}
// Send the image and process the response image
try {
SendImageResponse response = (SendImageResponse) dispatch.invoke(request);
if (null != result) {
if (response != null) {
result = result.concat("MTOM Dispatch Response received - " + response.getOutput().getImageData().getContentType());
} else {
result = result.concat("ERROR: MTOM Dispatch NULL Response received");
}
} else {
if (response != null) {
System.out.println(">>MTOM Response received");
System.out
.println(">>MTOM Writing returned image to dispatch_response.gif");
ImageDepot responseContent = response.getOutput();
processImageDepot(responseContent, "dispatch_response.gif");
} else {
System.out.println(">> [ERROR] - Response from the server was NULL");
}