You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Mark Bullathsinghalage Cooray <mb...@groupwise.swin.edu.au> on 2011/12/13 10:09:32 UTC

Axis2: Passing Binary Data as Payload, Data Handler

Hi,


I am accepting a DataHandler object at the server end and Client uses ServiceClient and builds the OMElement. The binary file passes without any problem, however the DataHandler is empty.


Server Side Code:


public void acceptFile(DataHandler dataHandler) {


try {
File outFile = new File("c:/testDataHandler.xml");
FileOutputStream fileOutputStream = new FileOutputStream(outFile);
dataHandler.writeTo(fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}

}



ClientSide Code:


// Building Service Client


try {
serviceClient = new ServiceClient();
serviceClient.engageModule("addressing");


Options options = new Options();
options.setTo(new EndpointReference(serviceDescription2
.getEndpointReference()));
options.setAction("urn:reportTest");
options.setProperty(Constants.Configuration.ENABLE_MTOM,
Constants.VALUE_TRUE);


serviceClient.setOptions(options);
} catch (AxisFault exception) {
exception.printStackTrace();
}


// Building Payload


String namespace = serviceDescription.getTargetNamespace();
Vector operations = serviceDescription.getOperations();
String partName = "";


for (int i = 0; i < operations.size(); i++) {
partName = serviceDescription.getPartName(operations.get(i)
.getName());
}


OMElement methodElement = null;
OMText parameterValueElement = null;


OMFactory objectFactory = OMAbstractFactory.getOMFactory();


OMNamespace objectNamespace = objectFactory.createOMNamespace(
namespace, "ns");


methodElement = objectFactory
.createOMElement(partName, objectNamespace);

DataHandler dataHandler = binaryData.getBase64Binary();

parameterValueElement = objectFactory.createOMText(dataHandler, false);

methodElement.addChild(parameterValueElement);



Could you help me with this.







---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
For additional commands, e-mail: java-user-help@axis.apache.org