免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4319 | 回复: 7
打印 上一主题 下一主题

[求助]AXIS2上传附件报错问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-08-08 12:53 |只看该作者 |倒序浏览
使用AXIS2 1.2做webService的引擎,在同一台机器上测试上传附件没有问题,但是把Client端放到其他机器上测试,就报错误
如下:org.apache.axis2.AxisFault: Mime parts not found. Stream ended while searching for the boundary
        at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:434)
        at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:373)
        at org.apache.axis2.description.OutInAxisOperationClient.execute(OutInAxisOperation.java:294)
        at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:520)
        at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:500)
        at sample.FileTransportClient.upload(FileTransportClient.java:34)
        at sample.FileTransportClient.main(FileTransportClient.java:117)


希望达人能帮忙看看,谢谢

论坛徽章:
0
2 [报告]
发表于 2007-08-09 14:43 |只看该作者
顶起来,等待高人。。。。。。。

论坛徽章:
0
3 [报告]
发表于 2007-08-09 15:44 |只看该作者
axis做过一段时间,不过没涉及到上传附件,帮不上忙了
PS:这里的帖子一个月顶一次就够了,沉不了多深的。。。

论坛徽章:
0
4 [报告]
发表于 2007-08-09 17:27 |只看该作者

我也遇到这个问题,请高手指点,不知道怎么解救!

我也遇到这个问题,请高手指点,不知道怎么解救!

论坛徽章:
0
5 [报告]
发表于 2007-08-10 11:22 |只看该作者
server端代码:
public class FileTransferServer {
               public static final String TMP_PATH = "D:/temp";
         
               public OMElement upload(OMElement element) throws Exception {
                      OMElement _fileContent = null;//文件内容
                      OMElement _fileName = null;//文件名
                      OMElement _fileType = null;//文件类型
                      System.out.println("The element for upload: " + element);
                      for (Iterator _iterator = element.getChildElements(); _iterator
                                    .hasNext() {
                             OMElement _ele = (OMElement) _iterator.next();
                             if (_ele.getLocalName().equalsIgnoreCase("fileContent") {
                                    _fileContent = _ele;
                             }
                             if (_ele.getLocalName().equalsIgnoreCase("fileName") {
                                    _fileName = _ele;
                             }
                             if (_ele.getLocalName().equalsIgnoreCase("fileType") {
                                    _fileType = _ele;
                             }
                      }
         
                      if (_fileContent == null || _fileType == null) {
                             throw new AxisFault("Either Image or FileName is null";
                      }
         
                      OMText binaryNode = (OMText) _fileContent.getFirstOMChild();
                      String fileName = _fileName.getText();
                      String fileType = _fileType.getText();
                      String storeDir = TMP_PATH + "/" + "tempTest";
                      File dir = new File(storeDir);
                      if (!dir.exists()) {
                             dir.mkdir();
                      }
                      String filePath = storeDir + "/" + fileName + "." + fileType;
                      File uploadFile = new File(filePath);
                      if (uploadFile.exists()) {
                             filePath = storeDir + "/" + fileName + "(1)" + "." + fileType;
                             uploadFile = new File(filePath);
                      }
         
                      // Extracting the data and saving
                      DataHandler actualDH;
                      actualDH = (DataHandler) binaryNode.getDataHandler();
         
                      FileOutputStream imageOutStream = new FileOutputStream(uploadFile);
                      InputStream is = actualDH.getInputStream();
                      imageOutStream.write(IOUtils.getStreamAsByteArray(is));
                      is.close() ;
                      imageOutStream.close() ;
                      // setting response
                      OMFactory fac = OMAbstractFactory.getOMFactory();
                      OMNamespace ns = fac.createOMNamespace("http://cn.flyingsoft.webService",
                                    "flyingsoft";
                      OMElement ele = fac.createOMElement("response", ns);
                      ele.setText("true";
                      return ele;
               }


client端代码:
public class FileTransportClient {
        private static EndpointReference targetEPR =
                new EndpointReference("http://localhost:8080/jinwei/services/FileOperation";
       
        public static boolean upload(String fileName, File file, String fileType) {
                try {
                       
                        //
                        OMElement data = buildUploadEnvelope(fileName, file, fileType);
                        Options options = buildOptions();
                        ServiceClient sender = new ServiceClient();
                        sender.setOptions(options);
                        OMElement ome = sender.sendReceive(data);
                        System.out.println("Convert the data to element in method upload: "+ome);
                        String b = ome.getText();
                        return true ;
                }
                catch(Exception e) {
                        e.printStackTrace();
                }
                return false;
        }
       
       
        private static OMElement buildUploadEnvelope(String fileName, File file, String fileType) {
                DataHandler expectedDH = null ;
                OMFactory fac = OMAbstractFactory.getOMFactory();
                OMNamespace omNs = fac.createOMNamespace("http://cn.flyingsoft.webService", "flyingsoft";
                OMElement data = fac.createOMElement("upload", omNs);
                OMElement fileContent = fac.createOMElement("fileContent", omNs);
                FileDataSource dataSource = new FileDataSource(file);
                expectedDH = new DataHandler(dataSource);
                OMText textData = fac.createOMText(expectedDH, true);
                fileContent.addChild(textData);
                OMElement _fileName = fac.createOMElement("fileName", omNs);
                _fileName.setText(fileName);
                OMElement _fileType = fac.createOMElement("fileType", omNs);
                _fileType.setText(fileType);
                data.addChild(_fileName);
                data.addChild(_fileType);
                data.addChild(fileContent);
                return data;
        }
       

        private static Options buildOptions() throws AxisFault {
                Options options = new Options();
                options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
                options.setTo(targetEPR);
                // enabling MTOM in the client side
                options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
                options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
                return options;
        }
       
        public static void main(String [] agrs) {
                String file = "D:/xx.zip";
                String fn = "xx";
                String ft="zip";
                boolean rtv = upload(fn,new File(file),ft);
                System.out.println("is upload success: "+rtv);
        }
       
       
}

论坛徽章:
0
6 [报告]
发表于 2007-08-12 15:15 |只看该作者
附件的没做过,记得AXIS2中带了个例子,找找看。

论坛徽章:
0
7 [报告]
发表于 2007-08-12 17:10 |只看该作者
只用过Axis1.4

论坛徽章:
0
8 [报告]
发表于 2007-08-13 09:21 |只看该作者
AXIS2里面带的附件的例子我也试过了,也是同样的错误。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP