Java CXF Webservice MTOM无法使用发送文件
我有一个网络服务,我想发送大文件与。当文件大小小于50MB时,它可以工作。有人知道会出什么问题吗Java CXF Webservice MTOM无法使用发送文件,java,web-services,cxf,mtom,Java,Web Services,Cxf,Mtom,我有一个网络服务,我想发送大文件与。当文件大小小于50MB时,它可以工作。有人知道会出什么问题吗 @WebService(name = "JobbWebservice", serviceName = "JobbWebservice") @MTOM(threshold = 3072) @BindingType(javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING) @EndpointConfig(configName = "Seam WebSe
@WebService(name = "JobbWebservice", serviceName = "JobbWebservice")
@MTOM(threshold = 3072)
@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING)
@EndpointConfig(configName = "Seam WebService Endpoint")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
public class JobbWebservice {
@Consumes("multipart/form-data")
@POST
@WebMethod
public DataHandlerObject getFile(@WebParam(name = "credentials") Credentials credentials,@WebParam(name = "fileName") String fileName) throws Exception{
JobbComponent jobbComponent = (JobbComponent)Component.getInstance("jobbComponent");
return (DataHandlerObject)jobbComponent.getFile(fileName);
}
}
数据处理程序对象如下所示
@XmlAccessorType(XmlAccessType.FIELD)
public class DataHandlerObject implements DataHandlerInterface,Serializable {
/**
*
*/
private static final long serialVersionUID = -7294059438616965795L;
/** The file name. */
String fileName;
/** The path. */
String path;
/** The data handler. */
@XmlMimeType("application/octet-stream")
DataHandler dataHandler;
创建Datahandlerobject的函数如下
public DataHandlerInterface getFile(String fileName) throws SyllException{
try{
File file = new File(filePath+"\\"+fileName);
DataHandler dataHandler = new DataHandler(new FileDataSource(file));
DataHandlerObject dataHandlerObject = new DataHandlerObject();
dataHandlerObject.setDataHandler(dataHandler);
dataHandlerObject.setFileName(file.getName());
return dataHandlerObject;
}catch(Exception e){
throw new SyllException("Can't send file");
}
}
客户端部分如下所示:
JobbWebservice_Service jobbWebservice_Service= new JobbWebservice_Service();
JobbWebservice jobbWebservice = jobbWebservice_Service.getJobbWebservicePort(new MTOMFeature(true,3072));
Credentials credentials = new Credentials();
DataHandlerObject dataHandler = jobbWebservice.getFile(credentials, "test.java");
DataHandler handler = dataHandler.getDataHandler();
try{
InputStream is = handler.getInputStream();
int nRead;
byte[] data = new byte[3072];
File f=new File("F:\\temp\\downloaded\\");
f.mkdirs();
f = new File(f,dataHandler.getFileName());
OutputStream out=new FileOutputStream(f);
while ((nRead = is.read(data, 0, data.length)) != -1) {
out.write(data,0,nRead);
}
out.close();
is.close();
}catch (Exception e) {
e.printStackTrace();
}
当我在客户端运行它时,会出现以下错误:
12:32:42,916 WARN [org.apache.cxf.phase.PhaseInterceptorChain] Interceptor for JobbWebservice # getFile has thrown exception, unwinding now: org.apache.cxf.interceptor.Fault: Could not write attachments.
at org.apache.cxf.interceptor.AttachmentOutInterceptor$AttachmentOutEndingInterceptor.handleMessage(AttachmentOutInterceptor.java:98) [:2.3.1-patch-01]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255) [:2.3.1-patch-01]
at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:77) [:2.3.1-patch-01]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255) [:2.3.1-patch-01]
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:113) [:2.3.1-patch-01]
at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:97) [:2.3.1-patch-01]
你找到解决方案了吗?哦,我不记得我们在上一次工作时,但我们有一个错误,我们有一个前端限制了请求,并因此给了我们奇怪的错误。但是我们成功了。是的,当我使用CXF 2.2.5从wsdl生成客户端并使用CXF 2.7.2 lib运行该客户端时,一切都进行得很顺利,但如果我同时使用2.7.2生成并运行客户端,则会出现以下异常。你找到解决方案了吗?哦,我不记得我上次工作时,但是我们有一个错误,我们的前端限制了请求,并因此给了我们奇怪的错误。是的,当我使用CXF2.2.5从wsdl生成客户机并使用CXF2.7.2库运行该客户机时,一切都很顺利,但如果我同时使用2.7.2生成并运行客户机,则会出现以下异常。