1

我尝试开发将文件从服务器发送到客户端的 Web 服务。我使用 Apache CXF 开发 Web 服务。应用程序是基于 Spring 的。首先我尝试编写简单的测试代码:

应用程序上下文.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 服务接口

@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface PaymentGatewayReportingWebService {

    @WebMethod(operationName = "downloadFile")
    public DataHandler downloadFile(String fileName);

}

PaymentGatewayReportingWebServiceImpl.java 实现 PaymentGatewayReportingWebService 接口

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

当我通过 soapUI 导入和执行 Web 服务方法时,我收到以下响应(从 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="<root.message@cxf.apache.org>"; 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: <root.message@cxf.apache.org>

<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:c0836641-6f5f-46ac-9e01-d89eaceafe49-1@cxf.apache.org"/></return></ns1:downloadFileResponse></soap:Body></soap:Envelope>
--uuid:9f003136-a7e0-4634-8032-51c1ba701776
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <c0836641-6f5f-46ac-9e01-d89eaceafe49-1@cxf.apache.org>

яШяб'«Exif
and some binary data here

soapUI 不下载任何东西。我不知道一切是否正确。soapUI 应该开始下载文件吗?如果soapUI 应该下载该文件,那么是有问题的。如果是,有什么问题?

4

1 回答 1

1

事实上,soapUI 正在给你正确的答案。“这里的一些二进制数据”是您要求的文件

于 2013-03-12T12:58:47.563 回答