1

我正在开发 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 数据。

4

1 回答 1

0

班级com.sun.xml.internal.ws.developer.StreamingDataHandlerrt.jar.

无论如何,您不应该在您的应用程序中使用suncom.sun打包。

这篇 Oracle 文章说明了原因:为什么开发人员不应该编写调用“sun”包的程序

这些包不是官方和受支持的 Java 规范的一部分。使用它们可能会导致不同版本的 Java 或不同实现(IBM 和 HP 等专有实现)之间的不兼容。实际上,您不确定您在一个实现中获得的 sun 类是否会成为另一个实现的一部分。

于 2013-02-12T10:33:52.320 回答