我创建了文件上传网络服务:
@SchemaValidation
@WebService(endpointInterface = "com.ws.server.ExchangeEndpoint")
public class ExchangeEndpoint {
@Override
public String uploadDocument(long residentId, String fileName, String mimeType, DataHandler data) {
try {
StreamingDataHandler dh = (StreamingDataHandler) data; //it cast exception
这是界面:
@WebService
@StreamingAttachment(parseEagerly = true, memoryThreshold = 4194304L)
@MTOM
public interface ExchangeEndpoint {
@WebMethod String uploadDocument(@XmlElement(name = "residentId",required = true) long residentId,
@XmlElement(name = "fileName",required = true) String fileName,
@XmlElement(name = "mimeType",required = true) String mimeType,
@XmlElement(name = "data",required = true) @XmlMimeType("application/octet-stream") DataHandler data);
它抛出 ClassCastException 异常:
java.lang.ClassCastException: javax.activation.DataHandler cannot be cast to com.sun.xml.ws.developer.StreamingDataHandler
但是当我删除 @SchemaValidation 注释时一切正常!!!
那么为什么@SchemaValidation 会破坏 DataHandler 对象呢?
当我尝试上传大于 300mb 的大文件时,我得到 OutOfMemoryError:
java.lang.OutOfMemoryError: Java heap space at org.jvnet.staxex.ByteArrayOutputStreamEx.readFrom(ByteArrayOutputStreamEx.java:75) at org.jvnet.staxex.Base64Data.get(Base64Data.java:331)
而且没有@SchemaValidation 一切正常!!!