2014-11-21 2 views
0

MTOM과 ADB를 사용하여 Axis2 웹 서비스 서버에서 파일을 다운로드하려고합니다. 서버 측과 클라이언트 측에서 MTOM을 사용하지 않으면 파일을 다운로드 할 수 있습니다. 어떤 제안이나 코드 샘플 :이MTOM과 Axis2 스텁을 사용하여 webservice에서 Cant 다운로드 파일

클라이언트 측

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

이 내 서버

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; 

입니다

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

서버 측 axis2.xml이 내 클라이언트입니다 좋은 것

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

결국 나는 해결책을 얻었습니다. 그래서 나는 동안

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

부분을 주석 스텁 파일에 다음 클라이언트가 처음 나는 getOptions(). setTimeOutInMilliSeconds (10000) 방법을 사용하는 이유는 전체 파일 먹으 렴를 얻을 수 있지만, 그것은 또한 쓸모가 없었습니다 그리고 전에 스트림을 닫습니다 큰 파일의 운송은 스트림이 폐쇄되지 않은 그리고 난 어떤 바보 예외 :

--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

간단히 추가 아파치 mime4j 코어-0.7.2.jar/WEB-INF 에없이 전체 파일을 다운로드 할 수 있습니다 lib 서비스 (서버) 쪽. 항아리는 here입니다.

관련 문제