【问题标题】:Cant download file from webservice using MTOM and Axis2 stub无法使用 MTOM 和 Axis2 存根从 Web 服务下载文件
【发布时间】:2015-01-19 23:03:37
【问题描述】:

我正在尝试使用 MTOM 和 ADB 从我的 Axis2 Web 服务服务器下载文件。 如果我不在服务器端和客户端都启用 MTOM,我可以下载该文件。任何建议或代码示例都会很好:)

客户端

ServerWSStub stub = new ServerWSStub();
stub._getServiceClient().getOptions().setProperty(Constants.Configuration.ENABLE_MTOM,Constants.VALUE_TRUE);

服务器端axis2.xml

<parameter name="enableMTOM">optional</parameter>

这是我的服务器

public DataHandler download(String konum) throws Exception {
        System.out.println("The filePath for download: " + konum);
        FileDataSource dataSource = new FileDataSource(konum);
        DataHandler datahandler = new DataHandler(dataSource);

        OMFactory fac = OMAbstractFactory.getOMFactory();
        OMNamespace ns = fac.createOMNamespace("http://benim.projem.org/dosya", "dosyam");
        OMText textData = fac.createOMText(datahandler, true);
        OMElement ele = fac.createOMElement("sonuc", ns);
        ele.addChild(textData);
        System.out.println(ele);
        return datahandler;

这是我的客户

ServerWSStub stub = new ServerWSStub();          

//stub._getServiceClient().getOptions().setProperty(Constants.Configuration.ENABLE_MTOM,Constants.VALUE_TRUE); 

//when uncommented i get java.lang.NoClassDefFoundError: org/apache/james/mime4j/MimeException 
//while trying to invoke _operationClient.execute(true); in ServerWSStub 
//I guess it is because of wrong unparsing


Download download = new Download();
download.setKonum(konum);
try {
    DownloadResponse downloadResponse = stub.download(download);
    DataHandler dh =(DataHandler) downloadResponse.get_return();
    File file = new File("C:/dosya/"+fileNameType);

    if (!file.getParentFile().exists())
        file.getParentFile().mkdirs();
    if(!file.exists()){
        file.createNewFile();
    }
    FileOutputStream fileOutputStream = new FileOutputStream(file);

    dh.writeTo(fileOutputStream);
    fileOutputStream.flush();
    fileOutputStream.close();
} catch (ServerWSExceptionException e) {
    e.printStackTrace();
}

任何

【问题讨论】:

    标签: file axis2 transfer mtom axiom


    【解决方案1】:

    只需将 apache-mime4j-core-0.7.2.jar 添加到服务(服务器)端的 WEB-INF/lib 中。罐子可以在here找到。

    【讨论】:

      【解决方案2】:

      我终于得到了我猜想的解决方案。流在客户端获取整个文件之前关闭,这就是为什么我首先使用 getOptions().setTimeOutInMilliSeconds(10000) 方法,但它也没用,然后在存根文件中我评论了

      _messageContext.getTransportOut().getSender().cleanup(_messageContext);//look for the method's finally part
      

      部分,以便在大文件传输期间流没有关闭,我可以下载整个文件而没有任何愚蠢的例外:)

      --MIMEBoundary_e56e8a77b94fbdd7678582aa5ca53f50b1d56c0d828499ea
      Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
      Content-Transfer-Encoding: binary
      Content-ID: <0.146e8a77b94fbdd7678582aa5ca53f50b1d56c0d828499ea@apache.org>
      
      <?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns:downloadResponse xmlns:ns="http://servis.ws.projem.tez.benim"><ns:return><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:1.046e8a77b94fbdd7678582aa5ca53f50b1d56c0d828499ea@apache.org" /></ns:return></ns:downloadResponse></soapenv:Body></soapenv:Envelope>
      --MIMEBoundary_e56e8a77b94fbdd7678582aa5ca53f50b1d56c0d828499ea
      Content-Type: text/plain
      Content-Transfer-Encoding: binary
      Content-ID: <1.046e8a77b94fbdd7678582aa5ca53f50b1d56c0d828499ea@apache.org>
      binary code here
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-05-29
        • 1970-01-01
        • 2020-07-02
        • 1970-01-01
        • 2012-05-25
        • 2011-12-21
        • 1970-01-01
        相关资源
        最近更新 更多