[
http://issues.apache.org/jira/browse/AXIS2-1640?page=comments#action_12448511 ]
Camille Nazi commented on AXIS2-1640:
-------------------------------------
Here's the code I use in my Integration Test, and I will be attaching the
MTOMProtoClientModel class that I am using below, if this will help. Thanks.
public void testExercisingService() throws java.lang.Exception {
MTOMProtoClientModel clientModel = new MTOMProtoClientModel();
clientModel.setTargetEPR("http://localhost:8080/axis2/services/MTOMProtoService");
OMElement elementReceivedBackFromService =
clientModel.sendFile("C:/downloads/Ant 1.6.5/apache-ant-1.6.5-bin.zip");
save(elementReceivedBackFromService,
"c:/MTOMTestUT/apache-ant-1.6.5-bin.zip");
}
public void save(OMElement element, String desiredFileName) 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();
}
> Axis2: Loosing Bytes with MTOM
> -------------------------------
>
> Key: AXIS2-1640
> URL: http://issues.apache.org/jira/browse/AXIS2-1640
> Project: Apache Axis 2.0 (Axis2)
> Issue Type: Bug
> Affects Versions: 1.0
> Environment: Windows XP, jdk 1.5, jboss-4.0.3SP1, axis2 WAR deployed
> under jboss.
> Reporter: Camille Nazi
> Attachments: apache-ant-1.6.5-bin.zip
>
>
> 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 = fac.createOMElement("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
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]