2

I created a WebService client from a provided WSDL-File, using the already in the JRE bundled JAX-WS API. I generated the proxy classes with the wsimport tool of JDK6 Update 37.

The client should be able to download large files/data, using MTOM and streaming.

I followed the instructions provided in the Metro user guide.

The proxy method I'm calling returns a DateHandler object.

package de.christopherhuebner.webservicetest.client;                                                   

import java.io.FileOutputStream;                                                                       
import java.io.OutputStream;                                                                           
import java.net.URL;                                                                                   

import javax.activation.DataHandler;                                                                   
import javax.xml.namespace.QName;                                                                      

import de.christopherhuebner.webservicetest.ImageServer;                                               
import de.christopherhuebner.webservicetest.ImageServerService;                                        

public class ImageServiceClient {                                                                      

    public static void main(String[] args) throws Exception {                                          
        URL url = new URL("http://localhost:8080/ImageWebService?wsdl");                               
        QName qname = new QName("http://webservicetest.christopherhuebner.de/", "ImageServerService"); 
        ImageServerService is = new ImageServerService(url, qname);                                    
        MTOMFeature mtom = new MTOMFeature();
        StreamingAttachmentFeature stf = new StreamingAttachmentFeature(null, true, 4000000L);
        ImageServer port = is.getImageServerPort(mtom, stf);                                                  
        DataHandler dh = port.getImage();                                                              
        System.out.println("Java-Version: " + System.getProperty("java.version"));                     
        System.out.println("DataHandler: " + dh.getClass());                                           
        System.out.println("DataSource: " + dh.getDataSource().getClass());                            
        OutputStream out = new FileOutputStream("test.jpg");                                           
        dh.writeTo(out);                                                                               
        out.close();                                                                                   
    }                                                                                                  
}                                                                                                      

When running this code with JRE6, the following output is printed to the console:

Java-Version: 1.6.0_37
DataHandler: class javax.activation.DataHandler
DataSource: class com.sun.istack.internal.ByteArrayDataSource

Unfortunately there is no streaming possible, as the ByteArrayDataSource is filled in the clients memory which causes an OutOfMemoryException when receiving data larger than the max heap size. When I dare to cast this DataHandler to a StreamingDataHandler as suggested in the already mentioned user guide, a ClassCastException is thrown.

When running the client with JRE7, everything is fine, as described in the user guide:

Java-Version: 1.7.0_10
DataHandler: class com.sun.xml.internal.ws.encoding.MIMEPartStreamingDataHandler
DataSource: class com.sun.xml.internal.ws.encoding.MIMEPartStreamingDataHandler$StreamingDataSource

Is there any possibility to get a StreamingDataHandler back, when using JRE6? Or am I really forced to use a newer JAX-WS RI version (Metro, which seems to be included in the JRE) via the -Djava.endorsed.dirs=path_to_newer_jaxws_libs mechanism?

When are the temp files, which are generated during streaming (MIMExxxxx.tmp, see StreamingAttachmentFeature for configuration), deleted?

Christopher
  • 694
  • 7
  • 15

0 Answers0