I'm developing a MTOM streaming web-service and have run into the following problem.
I have the following code in my webservice implementing class:
@Override
public void fileUpload(String name, DataHandler data)
{
System.out.println("INVOKING FILE UPLOAD!");
try
{
StreamingDataHandler dh = (StreamingDataHandler) data;
File file = File.createTempFile("result.txt", "");
dh.moveTo(file);
dh.close();
System.out.println("TEMP FILE WITH DATA: " + file.getAbsolutePath());
}
catch(Exception e)
{
throw new WebServiceException(e);
}
}
The problem is that Eclipse prompts me to import the StreamingDataHandler in the following way (compiles and deploys - ok):
import com.sun.xml.internal.ws.developer.StreamingDataHandler;
However, I get a ClassNotFoundException at runtime. Could you tell me what should be exported so that it simply works? I tried to include jaxws-ri.jar and stax-ex.jar (v 2.2.7) into my module but without any luck (get other errors). Also the StreamingDataHandler class is under a different package in them (same as prompted by Eclipse but without "internal"). My Project Facets are: Dynamic Web-Module 3.0, Java 1.7, Javascript 1.0, JBoss Web Services Core, server runtime is JBoss 7.1.1. How could I resolve the confusion? Thx.
UPDATE: (solution)
Use this code to write the data:
InputStream is = data.getInputStream(); // DataHandler
File file = File.createTempFile("result.txt", "");
OutputStream os = new FileOutputStream(file.getAbsolutePath());
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = is.read(buffer)) != -1)
{
os.write(buffer, 0, bytesRead);
}
os.flush();
os.close();
Just sent 5.9Gb data between two hosts.