4

I have a JAX-WS RI server that does MTOM streaming. From the client, everything is fine. The server receives a StreamingDataHandler, and neither side uses much memory sending 1 GB. Retrieving the file, however, the server is reading the entire contents before sending it. The client is OK. I'm using DataHandler on both ends, so that aspect of things is fine. I just don't want the server to read all the data from the InputStream before it starts sending. I have the following annotations on the impl:

@MTOM
@StreamingAttachment(parseEagerly = false, memoryThreshold = 1L)
@WebService(...)

I've tried parseEagerly true and false. I set the memory threshold low because I'm not concerned about small performance hits for small files.

Is this a bug with JAX-WS RI?

4

1 回答 1

1

这就是我所做的。像魅力一样工作。

界面(认为它很像你所做的)

@WebService
@SOAPBinding(style = Style.RPC)
public interface ResultsServer {    
    @WebMethod
    @XmlMimeType("application/octet-stream")
    public DataHandler getResultDataAsXML(@WebParam Integer raceId) throws Exception;
}

执行

@MTOM
@WebService(endpointInterface = "ca.sportstats.wtc.ResultsServer")
@StreamingAttachment(parseEagerly=true, memoryThreshold=4000000L)
public class ResultsServerImpl implements ResultsServer {

    @Override
    public DataHandler getResultDataAsXML(@WebParam Integer raceId) throws Exception {
        File xmlFile = new File("c:/tmp/xml/response.xml");
        //... write my xml file using an XMLStreamWriter
        return new DataHandler(new FileDataSource(xmlFile));
    }
}

测试

public class Test {
    public static void main(String[] args) throws Exception {

       URL url = new URL("http://url/to/ipmlementation/ResultsServerImplService?wsdl");
       QName qname = new QName("http://test.test.com/", "ResultsServer");

       Service service = Service.create(url, qname);
       ResultsServerImpl resultServer = service.getPort(ResultsServerImpl.class);

       /************  test download  ***************/
       DataHandler handler = resultServer.getResultDataAsXML(4);
       StreamingDataHandler dh = (StreamingDataHandler) handler;
       File file = File.createTempFile("test-received.xml", "");
       dh.moveTo(file);
       dh.close();

    }
}

这对我来说可以流式传输(从服务器)一个大型 XML 文件,而无需在内存中读取它。

也可以看看

于 2013-05-23T16:15:20.980 回答