wsimport将返回类型更改为字节数组

时间:2014-12-23 09:45:16

标签: java web-services

我想制作一个简单的网络服务,允许我下载文件(主要是.zip)。

我正在尝试使用DataHandler,但是wsimport将返回类型更改为byte []。

package mainpackage;

import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.bind.annotation.XmlMimeType;

@WebService(name = "FileWs")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle =  SOAPBinding.ParameterStyle.WRAPPED)
public class FileWs {
    private String path = "C:/Temp/Data/";
    @XmlMimeType("application/zip")
    protected DataHandler dh;

    @WebMethod
    public  DataHandler downloadFile(@WebParam(name = "filename") String fileName) {
        FileDataSource dataSource = new FileDataSource(this.path+ fileName);
        dh = new DataHandler(dataSource);
        return dh;
    }

}

这是生成的代码:

/**
 * 
 * @param filename
 * @return
 *     returns byte[]
 */
@WebMethod
@WebResult(targetNamespace = "")
@RequestWrapper(localName = "downloadFile", targetNamespace = "http://mainpackage/", className = "mainpackage.DownloadFile")
@ResponseWrapper(localName = "downloadFileResponse", targetNamespace = "http://mainpackage/", className = "mainpackage.DownloadFileResponse")
public byte[] downloadFile(
    @WebParam(name = "filename", targetNamespace = "")
    String filename);

0 个答案:

没有答案