|
HI all, I am using MTOM with Axis2. I took the MTOM
sample bundled with Axis2 and switched it around to where the client sends in
the name of the file to retrieve and the Service returns the file back to the
Client and then the client saves the file to disk (All this is done on my
desktop in windows XP). I am running axis2 WAR under JBOSS-4.03SP1. The problem I am running into is that for Zip files larger
in size than 3.4 Meg, I am losing bytes (checked this via chsum command). This
does not happen on all File extensions, I noticed it so far on zip, jar and xls
extensions. Has anyone run into a similar issue, and how did you resolve
it? Your help is greatly appreciated !!! Here’s the code I am using: Here’s my Service code: import java.io.File; import
java.util.Iterator; import
javax.activation.DataHandler; import
javax.activation.FileDataSource; import
org.apache.axiom.om.OMAbstractFactory; import
org.apache.axiom.om.OMElement; import
org.apache.axiom.om.OMFactory; import org.apache.axiom.om.OMNamespace; import
org.apache.axiom.om.OMText; import
org.apache.axis2.AxisFault; public class MTOMProtoService {
public OMElement
getFile(OMElement element) throws Exception {
OMElement _fileNameEle = null;
OMElement _imageElement = null;
File inputFile = null;
System.out.println("in Method getFile, OMElement
received = " +
element.toString());
for (Iterator _iterator
= element.getChildElements(); _iterator.hasNext();) {
OMElement _ele = (OMElement) _iterator.next();
System.out.println("in Method for loop in getFile,
OMElement = " +
_ele.toString());
if (_ele.getLocalName().equalsIgnoreCase("fileName")) {
_fileNameEle = _ele;
System.out.println(" Found _fileNameEle =
" +
_fileNameEle);
}
}
if (_fileNameEle
== null ) {
throw new AxisFault("Either Image or FileName is null");
}
String fileName = _fileNameEle.getText();
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
OMElement data = "">"getFile", omNs);
OMElement fileOME = fac.createOMElement("file", omNs);
FileDataSource dataSource = new
FileDataSource(fileName);
DataHandler expectedDH = new DataHandler(dataSource);
OMText textData = fac.createOMText(expectedDH, true);
fileOME.addChild(textData);
OMElement fileOMEName = fac.createOMElement("fileName", omNs);
if (fileName != null) {
fileOMEName.setText(fileName);
}
data.addChild(fileOMEName);
data.addChild(fileOME);
return data;
} Save in Client Code:
public void save(OMElement element) throws Exception {
OMElement _fileNameEle = null;
OMElement _fileElement = null;
for (Iterator _iterator = element.getChildElements();
_iterator.hasNext();) {
OMElement _ele = (OMElement) _iterator.next();
if (_ele.getLocalName().equalsIgnoreCase("fileName")) {
_fileNameEle =
_ele;
}
if (_ele.getLocalName().equalsIgnoreCase("file")) {
_fileElement =
_ele;
}
}
OMText binaryNode = (OMText) _fileElement.getFirstOMChild();
//Extracting
the data and saving
DataHandler actualDH = (DataHandler)
binaryNode.getDataHandler(); //
File file = new File(desiredFileName);
// desiredFileName is the output filename to save it under.
OutputStream os = new FileOutputStream(desiredFileName);
actualDH.writeTo(os);
os.close(); } Thanks in advance, Camille |
- Axis2: Loosing Bytes with MTOM Nazi, Camille
- Re: Axis2: Loosing Bytes with MTOM Davanum Srinivas
