我正在开发 MTOM 流式 Web 服务并遇到以下问题。我的网络服务实现类中有以下代码:
@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);
}
}
问题是 Eclipse 提示我按以下方式导入 StreamingDataHandler(编译和部署 - ok):
import com.sun.xml.internal.ws.developer.StreamingDataHandler;
但是,我在运行时收到 ClassNotFoundException。你能告诉我应该导出什么以便它简单地工作吗?我尝试将 jaxws-ri.jar 和 stax-ex.jar (v 2.2.7) 包含到我的模块中,但没有任何运气(出现其他错误)。StreamingDataHandler 类也位于其中的不同包下(与 Eclipse 提示的相同,但没有“内部”)。我的项目方面是:Dynamic Web-Module 3.0、Java 1.7、Javascript 1.0、JBoss Web Services Core,服务器运行时是 JBoss 7.1.1。我该如何解决这种困惑?谢谢。
更新:(解决方案)
使用此代码写入数据:
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();
刚刚在两台主机之间发送了 5.9Gb 数据。