1
我嘗試開發從服務器發送文件到客戶端的Web服務。我使用Apache CXF開發Web Serivce。應用程序是基於Spring的。首先,我試着寫簡單的測試代碼:使用Apache CXF通過Web服務下載文件
的applicationContext.xml
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<bean class="com.llth.paymentgateway.webservice.PaymentGatewayReportingWebServiceImpl" id="paymentGatewayReportingWebService"/>
<jaxws:endpoint id="reportingWebService" implementor="#paymentGatewayReportingWebService" address="/ReportingWebService">
<jaxws:properties>
<entry key="mtom-enabled" value="true"/>
</jaxws:properties>
</jaxws:endpoint>
PaymentGatewayReportingWebService.java Web服務inteface
@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface PaymentGatewayReportingWebService {
@WebMethod(operationName = "downloadFile")
public DataHandler downloadFile(String fileName);
}
PaymentGatewayReportingWebServiceImpl.java實施PaymentGatewayReportingWebService的inteface
@WebService(endpointInterface = "com.llth.paymentgateway.webservice.PaymentGatewayReportingWebService")
public class PaymentGatewayReportingWebServiceImpl implements PaymentGatewayReportingWebService {
@Override
@XmlMimeType("application/octet-stream")
public DataHandler downloadFile(String fileName) {
FileDataSource dataSource = new FileDataSource(fileName);
return new DataHandler(dataSource);
}
}
當我即時通訊端口和執行Web服務方法通過的soapUI我recevie以下響應(從RAW選項卡複製)
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: multipart/related; type="application/xop+xml"; boundary="uuid:9f003136-a7e0-4634-8032-51c1ba701776"; start="<[email protected]>"; start-info="text/xml";charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 12 Mar 2013 12:35:06 GMT
--uuid:9f003136-a7e0-4634-8032-51c1ba701776
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: <[email protected]>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:downloadFileResponse xmlns:ns1="http://webservice.paymentgateway.llth.com/"><return><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:[email protected]"/></return></ns1:downloadFileResponse></soap:Body></soap:Envelope>
--uuid:9f003136-a7e0-4634-8032-51c1ba701776
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <[email protected]>
яШяб'«Exif
and some binary data here
的soapUI不下載任何東西。我不知道一切是否正確。如果soapUI開始下載文件?如果soapUI應該下載文件,那麼有些地方是錯誤的。如果是,那有什麼問題?