0 0

axis2多附件报错,求解。30

我的调用为:

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import javax.activation.DataHandler;
import javax.activation.FileDataSource;

import org.apache.axiom.attachments.utils.IOUtils;
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.axiom.soap.SOAP11Constants;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;

public class FileTransferClient {
   private static EndpointReference targetEPR =
new EndpointReference("http://uip.hq.ctc.com/uip/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);
      System.out.println("The data in method upload: "+data);
      OMElement ome = sender.sendReceive(data);
      System.out.println("Convert the data to element in method upload: "+ome);
      String b = ome.getText();
      return Boolean.parseBoolean(b);
     }
     catch(Exception e) {
       e.printStackTrace();
     }
     return false;
   }
  
   public static boolean download(String userName, String fileName, String fileType) {
     try {
       OMElement data = buildDownloadEnvelope(userName, fileName, fileType);
       Options options = buildOptions();
       ServiceClient sender = new ServiceClient();
       sender.setOptions(options);
       System.out.println("The data in method download: "+data);
       OMElement ome = sender.sendReceive(data);
       System.out.println("Convert the data to element in method download: "+ome);
       OMText binaryNode = (OMText) ome.getFirstOMChild();
       binaryNode.setOptimize(true); //必须加此句,否则会出现ContentID is null的异常!
       DataHandler actualDH = (DataHandler) binaryNode.getDataHandler();
       FileOutputStream imageOutStream = new FileOutputStream("D:/userTemp/xx.gif");
       InputStream is = actualDH.getInputStream();
       imageOutStream.write(IOUtils.getStreamAsByteArray(is));
       return true;
      }
      catch(Exception e) {
        e.printStackTrace();
      }
     return false;
   }
  
   private static OMElement buildUploadEnvelope(String fileName, File file, String fileType) {
     OMFactory fac = OMAbstractFactory.getOMFactory();
     OMNamespace omNs = fac.createOMNamespace("http://impl.server.webservice.docentre.eetrust.com", "fd");
     OMElement data = fac.createOMElement("upload", omNs);
     OMElement fileContent = fac.createOMElement("fileContent", omNs);
//      OMElement aaa = fac.createOMElement("aaa", omNs);
//      fileContent.setText("aaa");
//      OMElement bbb = fac.createOMElement("bbb", omNs);
     FileDataSource dataSource = new FileDataSource(file);
     DataHandler expectedDH = new DataHandler(dataSource);
     OMText textData = fac.createOMText(expectedDH, true);
     fileContent.addChild(textData);
     FileDataSource dataSources = new FileDataSource("D:/工作记录.txt");//测试用的
     DataHandler expectedDHs = new DataHandler(dataSources);
     OMText textDatas = fac.createOMText(expectedDHs, true);
     fileContent.addChild(textDatas);
    
     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 OMElement buildDownloadEnvelope(String userName, String fileName, String fileType) {
     OMFactory fac = OMAbstractFactory.getOMFactory();
     OMNamespace omNs = fac.createOMNamespace("http://example.org/filedata", "fd");
     OMElement data = fac.createOMElement("download", omNs);
     OMElement _userName = fac.createOMElement("userName", omNs);
     _userName.setText(userName);
     OMElement _fileName = fac.createOMElement("fileName", omNs);
     _fileName.setText(fileName);
     OMElement _fileType=fac.createOMElement("fileType", omNs);
     _fileType.setText(fileType);
     data.addChild(_userName);
     data.addChild(_fileName);
     data.addChild(_fileType);
     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:/常用文件.txt";
     String fn = "常用文件";
     String ft="txt";
     boolean rtv = upload(fn,new File(file),ft);
     System.out.println("is upload success: "+rtv);

   }

}
服务端代码为:
      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.getParent().getChildren(); _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));
              // setting response
              OMFactory fac = OMAbstractFactory.getOMFactory();
              OMNamespace ns = fac.createOMNamespace("http://example.org/filedata",
                            "fd");
              OMElement ele = fac.createOMElement("response", ns);
              ele.setText("true");
              return ele;
       }
出错内容为:
org.apache.axis2.AxisFault: javax.xml.stream.XMLStreamException: Expected xop:Include as the sole child of an element information item (see section 3.2 of http://www.w3.org/TR/xop10/)
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:555)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:531)
at FileTransferClient.upload(FileTransferClient.java:33)
at FileTransferClient.main(FileTransferClient.java:121)

问题补充:对了,单个附件调用是没有错的,求解决啊,呵呵。
2013年8月23日 15:04
目前还没有答案

相关推荐

    axis2 发送附件

    axis2 发送附件axis2 发送附件axis2 发送附件axis2 发送附件

    (转)Axis2 附件传输

    【标题】"Axis2 附件传输" 在Web服务开发中,有时我们需要传递不仅仅是XML数据,还包括文件、图像等非结构化的“附件”。Apache Axis2,作为一款强大的SOAP(Simple Object Access Protocol)服务框架,提供了这样...

    axis2-idea-plugin-1.7.9.zip_axis2_axis2-idea-plugin_idea导入axis2_

    标题中的"axis2-idea-plugin-1.7.9.zip_axis2_axis2-idea-plugin_idea导入axis2_"提到了几个关键元素,分别是"axis2"、"idea-plugin"和"idea导入axis2",这暗示了这个压缩包是用于在IntelliJ IDEA这款集成开发环境...

    cxf客户端调用axis服务端流程

    Axis1.x版本是较老的实现,而Axis2是其后续版本,提供了更好的性能和模块化设计。 ### 二、CXF客户端调用Axis服务端步骤 #### 1. 获取服务端WSDL 首先,你需要获取Axis服务端的WSDL(Web Service Definition ...

    axis2相关的jar包

    axis2-adb-1.5.4.jar axis2-adb-codegen-1.5.4.jar axis2-codegen-1.5.4.jar axis2-corba-1.5.4.jar axis2-fastinfoset-1.5.4.jar axis2-java2wsdl-1.5.4.jar axis2-jaxbri-1.5.4.jar axis2-jaxws-1.5.4.jar axis2-...

    axis2-1.5.1-bin.zip axis2-1.5.1-war.zip axis2部署使用

    Apache Axis2是著名的开源Web服务框架,用于构建和部署高效且灵活的Web服务。这个框架是基于Axis1的升级版,提供了许多改进和新特性,包括更好的性能、模块化架构和增强的MIME支持。标题提到的“axis2-1.5.1-bin.zip...

    axis2-1.6.2

    axis2-1.6.2.zip, windows axis2工具,根据 WSDL生成java文件。 1、axis2客户端下载地址:http://mirror.esocc.com/apache//axis/axis2/java/core/1.6.2/axis2-1.6.2-bin.zip; 2、下载解压在D:\Work_Program_...

    axis2的API,axis2 API,axis2帮助文档

    Axis2是Apache软件基金会开发的一个开源Web服务引擎,它提供了基于SOAP(Simple Object Access Protocol)的Web服务实现。本文将详细介绍Axis2的API及其在Web服务开发中的应用,同时也会探讨Axis2的帮助文档如何协助...

    axis和axis2的一些发布差异(WSDL2Java) 收藏

    通过对Axis与Axis2在使用WSDL2Java工具时的不同之处的详细探讨,我们可以看到,虽然两种工具都实现了相似的功能,但Axis2在很多方面都进行了优化和改进,尤其是在命令行参数、部署描述文件生成以及数据绑定等方面。...

    Axis1,Axis2,Xfire,CXF区别

    Axis1, Axis2, Xfire, CXF 区别 ...Axis2 支持多语言,除了 Java,还支持 C/C++版本。CXF 只支持 JAXB 和 Aegis。 Axis1, Axis2, Xfire, CXF 四种框架都有其特点和应用场景。开发者应该根据自己的需求选择合适的框架。

    axis 1.x与axis2.x开发

    而Axis2.x的依赖更多,包括axis2-*.jar、axiom-*.jar、wsdl4j-*.jar等,还需要根据具体需求选择相应的模块jar。 开发Web服务时,开发者需要注意版本兼容性和选择合适的版本。如果项目需要高性能和模块化设计,那么...

    axis2-1.6.1

    - 多协议支持:除了基本的SOAP 1.1和1.2,Axis2还支持REST、MTOM(Message Transmission Optimization Mechanism)和SwA(Soap with Attachments)等传输方式。 - 高效的消息处理:使用了基于内存的数据结构,Axis2...

    axis1.4和axis2相关jar文件

    3. **多协议支持**:除了SOAP 1.1,Axis2还支持SOAP 1.2,甚至RESTful服务,以及WS-*家族的多种标准,如WS-Security、WS-ReliableMessaging等。 4. **服务组件化**:Axis2引入了Web服务组件(Web Service Components...

    Axis_API和axis2_API

    因此,Apache社区推出了Axis2,它是Axis的升级版,旨在解决这些问题并提供更多的功能。Axis2采用了模块化架构,允许开发者根据需要选择和加载特定功能模块,这极大地提高了性能和可扩展性。此外,Axis2支持多种传输...

    axis2-1.6.2.zip

    8. **多语言支持**:尽管轴心是Java实现,但通过 Axis2 的AXIOM(抽象XML信息模型)层,可以与其他语言如C、PHP和Python进行交互。 在压缩包"axis2-1.6.2"中,你可以找到以下组件: - **库文件**:包含各种jar文件...

    axis2发布webservice和调用axis2服务接口

    在IT行业中,Axis2是Apache软件基金会开发的一个用于构建Web服务和Web服务客户端的框架,主要基于Java语言。本文将详细讲解如何使用Axis2来发布Web服务以及如何生成客户端代码来调用这些服务。 首先,让我们了解...

    springboot集成axis2-1.7.9实例

    在本文中,我们将深入探讨如何将Apache Axis2与Spring Boot集成,以构建一个高效、可扩展的Web服务应用。Apache Axis2是Java平台上的一个Web服务框架,它提供了高性能、灵活的服务开发和部署机制。而Spring Boot是...

    webservice学习二之(1)axis2服务器端方式开发总结(附件含有项目)

    本篇文章将聚焦于Axis2框架在服务器端进行Web服务开发的总结。 Axis2是Apache软件基金会的一个开源项目,它是用于构建高性能、灵活且可扩展的Web服务的下一代Web服务引擎。相比早期的Axis,Axis2提供了更强大的...

    axis2 包括源码 文档

    3. **多传输支持**:Axis2 支持多种传输协议,如HTTP、HTTPS、JMS等,使服务能在各种网络环境中工作。 4. **服务组件模型**:它允许服务以各种方式打包,例如作为WAR文件或AAR(Axis Archive)文件,便于部署和管理...

Global site tag (gtag.js) - Google Analytics