2014-11-21 54 views
0

我嘗試從使用MTOM和ADB的Axis2 web服務服務器下載文件。 如果我不在服務器和客戶端啓用MTOM,我可以下載該文件。任何建議或代碼示例將是很好:)使用MTOM和Axis2存根無法從webservice下載文件

客戶端

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(); 
} 

任何

回答

1

我終於得到了解決方案,我猜。在流關閉客戶端獲取之前整個文件這就是爲什麼我首先使用的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: <[email protected]> 

<?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:[email protected]" /></ns:return></ns:downloadResponse></soapenv:Body></soapenv:Envelope> 
--MIMEBoundary_e56e8a77b94fbdd7678582aa5ca53f50b1d56c0d828499ea 
Content-Type: text/plain 
Content-Transfer-Encoding: binary 
Content-ID: <[email protected]> 
binary code here 
0

只需添加Apache的mime4j核-0.7.2.jarWEB-INF /在服務(服務器)側的lib。該罐可以發現here