CXF Webservice MTOM не может отправить файл с - PullRequest
2 голосов
/ 22 февраля 2012

У меня есть веб-сервис, с которым я хотел бы отправлять большие файлы. Работает, когда размер файла меньше 50 МБ. Кто-нибудь понял, что может быть не так?

@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]
...