您好:
axis2 缓存文件问题: 
此为axis2.xml中配置 接收大文件的配置 
<!--Uncomment if you want to enable file caching for attachments --> 
    <parameter name="cacheAttachments" locked="false">true </parameter> 
    <parameter name="attachmentDIR" locked="false">/home/oracle/auibdata/cache </parameter> 
    <parameter name="sizeThreshold" locked="false">100000 </parameter> 
在此配置目录下,每次接收一次大文件(1M-2M)文件,此目录会相应生成一个缓存文件:axis2*.att(*为数字), 
缓存文件不能自动删除.现在在传1M以上的文件时报错:(服务器端报错)提示不能创建缓存文件: 
-- ERROR -- Error creating temporary File. 
java.lang.reflect.InvocationTargetException 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at java.lang.reflect.Method.invoke(Method.java:324) 
at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:118) 
at org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver.receive(AbstractInOutSyncMessageReceiver.java:39) 
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:497) 
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:328) 
at org.apache.axis2.transport.http.HTTPWorker.service(HTTPWorker.java:230) 
at org.apache.axis2.transport.http.server.DefaultHttpServiceProcessor.doService(DefaultHttpServiceProcessor.java:189) 
at org.apache.http.protocol.HttpService.handleRequest(HttpService.java:123) 
at org.apache.axis2.transport.http.server.DefaultHttpServiceProcessor.run(DefaultHttpServiceProcessor.java:261) 
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650) 
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675) 
at java.lang.Thread.run(Thread.java:534) 
Caused by: org.apache.axiom.om.OMException: Error creating temporary File. 
at org.apache.axiom.attachments.Attachments.getPart(Attachments.java:487) 
at org.apache.axiom.attachments.Attachments.getNextPartDataHandler(Attachments.java:397) 
at org.apache.axiom.attachments.Attachments.getDataHandler(Attachments.java:240) 
at com.auib.datahandle.transfer.server.DefaultTransferService.uploadFile(DefaultTransferService.java:71) 
... 15 more 
Caused by: org.apache.axiom.om.OMException: Error creating temporary File. 
at org.apache.axiom.attachments.PartOnFile. <init>(PartOnFile.java:86) 
at org.apache.axiom.attachments.Attachments.getPart(Attachments.java:480) 
... 18 more 
Caused by: java.net.SocketTimeoutException: Read timed out 
at java.net.SocketInputStream.socketRead0(Native Method) 
at java.net.SocketInputStream.read(SocketInputStream.java:129) 
at org.apache.http.impl.io.AbstractHttpDataReceiver.fillBuffer(AbstractHttpDataReceiver.java:89) 
at org.apache.http.impl.io.AbstractHttpDataReceiver.read(AbstractHttpDataReceiver.java:105) 
at org.apache.http.io.ChunkedInputStream.read(ChunkedInputStream.java:182) 
at java.io.FilterInputStream.read(FilterInputStream.java:66) 
at java.io.PushbackInputStream.read(PushbackInputStream.java:120) 
at org.apache.axiom.attachments.MIMEBodyPartInputStream.read(MIMEBodyPartInputStream.java:49) 
at org.apache.axiom.attachments.PushbackFilePartInputStream.read(PushbackFilePartInputStream.java:48) 
at org.apache.axiom.attachments.PartOnFile. <init>(PartOnFile.java:77) 
... 19 more 客户端报错:
org.apache.axiom.om.OMException: Error while writing to the OutputStream.
at org.apache.axiom.om.impl.MIMEOutputUtils.writeSOAPWithAttachmentsMessage(MIMEOutputUtils.java:168)
at org.apache.axis2.transport.http.SOAPOverHTTPSender$AxisSOAPRequestEntity.handleOMOutput(SOAPOverHTTPSender.java:185)
at org.apache.axis2.transport.http.SOAPOverHTTPSender$AxisSOAPRequestEntity.writeRequest(SOAPOverHTTPSender.java:232)
at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:495)
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:1973)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:993)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:541)
at org.apache.axis2.transport.http.SOAPOverHTTPSender.send(SOAPOverHTTPSender.java:119)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:335)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:204)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:674)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:237)
at org.apache.axis2.description.OutInAxisOperationClient.execute(OutInAxisOperation.java:202)
at com.auib.datahandle.transfer.client.DefaultTransferClient.sendFile(DefaultTransferClient.java:112)
at com.auib.datahandle.transfer.client.DefaultTransferClient.test(DefaultTransferClient.java:294)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:248)
at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:165)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:66)
at org.quartz.core.JobRunShell.run(JobRunShell.java:195)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
Caused by: java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:66)
at java.io.BufferedOutputStream.write(BufferedOutputStream.java:105)
at org.apache.commons.httpclient.WireLogOutputStream.write(WireLogOutputStream.java:67)
at org.apache.commons.httpclient.ChunkedOutputStream.flushCacheWithAppend(ChunkedOutputStream.java:120)
at org.apache.commons.httpclient.ChunkedOutputStream.write(ChunkedOutputStream.java:178)
at javax.activation.DataHandler.writeTo(DataHandler.java:308)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1350)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:845)
at org.apache.axiom.om.impl.MIMEOutputUtils.writeBodyPart(MIMEOutputUtils.java:119)
at org.apache.axiom.om.impl.MIMEOutputUtils.writeSOAPWithAttachmentsMessage(MIMEOutputUtils.java:163)
... 27 more
不知道是什么原因。原来传1M以上的文件是没有问题的,现在可能由于网络原因传不了了(1M以下的现在还可以传)。另外是不是在哪里有设置连接时间的地方?
谢谢!

解决方案 »

  1.   


    Caused by: java.net.SocketTimeoutException: Read timed out 
    我认为是连接的timeout时间太短,可以考虑忽略http连接的超时时间 
    client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, "0");如果还是错的话,那么高人解决
      

  2.   

    axis2.xml中为:
    <transportReceiver name="http" class="org.apache.axis2.transport.http.SimpleHTTPServer">
    <parameter name="port" locked="false">8088</parameter>
    我的客户端代码为: public static void transferFile(File file, String destinationFile)
    throws Exception { Options options = new Options();
    options.setTo(targetEPR);
    options.setProperty(Constants.Configuration.ENABLE_SWA,
    Constants.VALUE_TRUE);
    options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
    // Increase the time out when sending large attachments
    options.setTimeOutInMilliSeconds(10000);
    options.setTo(targetEPR);
    options.setAction("urn:uploadFile"); // assume the use runs this sample at
    // <axis2home>/samples/soapwithattachments/ dir
    ConfigurationContext configContext = ConfigurationContextFactory
    .createConfigurationContextFromFileSystem("../../repository",
    null); ServiceClient sender = new ServiceClient(configContext, null);
    sender.setOptions(options);
    OperationClient mepClient = sender
    .createClient(ServiceClient.ANON_OUT_IN_OP); MessageContext mc = new MessageContext();
    FileDataSource fileDataSource = new FileDataSource(file); // Create a dataHandler using the fileDataSource. Any implementation of
    // javax.activation.DataSource interface can fit here.
    DataHandler dataHandler = new DataHandler(fileDataSource);
    String attachmentID = mc.addAttachment(dataHandler); SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope env = fac.getDefaultEnvelope();
    OMNamespace omNs = fac.createOMNamespace(
    "http://service.soapwithattachments.sample", "swa");
    OMElement uploadFile = fac.createOMElement("uploadFile", omNs);
    OMElement nameEle = fac.createOMElement("name", omNs);
    nameEle.setText(destinationFile);
    OMElement idEle = fac.createOMElement("attchmentID", omNs);
    idEle.setText(attachmentID);
    uploadFile.addChild(nameEle);
    uploadFile.addChild(idEle);
    env.getBody().addChild(uploadFile);
    mc.setEnvelope(env); mepClient.addMessageContext(mc);
    mepClient.execute(true);
    MessageContext response = mepClient
    .getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
       SOAPBody body = response.getEnvelope().getBody();
       OMElement element = body.getFirstElement().getFirstChildWithName(
       new QName("http://service.soapwithattachments.sample","return"));
    System.out.println(element.getText());
    }
    服务器端代码为:
     MessageContext msgCtx = MessageContext.getCurrentMessageContext();
            Attachments attachment = msgCtx.getAttachmentMap();
            DataHandler dataHandler = attachment.getDataHandler(attchmentID);
            File file = new File(
    name);
    FileOutputStream fileOutputStream = new FileOutputStream(file);
    dataHandler.writeTo(fileOutputStream);
    fileOutputStream.flush();
    fileOutputStream.close();
    程序用了axis2自带的samples\soapwithattachments,这个传附件的例子。
      

  3.   

    Caused by: org.apache.axiom.om.OMException: Error creating temporary File. 
    创建临时文件失败?我个人看法是某个默认配置是1M。 去仔细看看各个配置说明文档。弄好了给我一个消息,我收藏一下。
      

  4.   

    File Caching for Attachments
    Axis2 comes handy with a file caching mechanism for incoming attachments, which gives Axis2 the ability to handle very large attachments without buffering them in the memory at any time. Axis2 file caching streams the incoming MIME parts directly into the files, after reading the MIME part headers.Also, a user can specify a size threshold for the File caching (in bytes). When this threshold value is specified, only the attachments whose size is bigger than the threshold value will get cached in the files. Smaller attachments will remain in the memory.Note : It is a must to specify a directory to temporarily store the attachments. Also care should be taken to clean that directory from time to time.The following parameters need to be set in Axis2.xml in order to enable file caching.<axisconfig name="AxisJava2.0">    <!-- ================================================= -->
        <!-- Parameters -->
        <!-- ================================================= -->
        <parameter name="cacheAttachments" locked="false">true</parameter>
        <parameter name="attachmentDIR" locked="false">temp directory</parameter>    <parameter name="sizeThreshold" locked="false">4000</parameter>
        .........
        .........
    </axisconfig>我这里的设置为:
    <!-- ================================================= -->
    <!-- Parameters -->
    <!-- ================================================= -->
    <parameter name="hotdeployment" locked="false">true</parameter>
    <parameter name="hotupdate" locked="false">false</parameter>
    <parameter name="enableMTOM" locked="false">false</parameter>
    <parameter name="enableSwA" locked="false">false</parameter>
    <!--Uncomment if you want to enable file caching for attachments -->
    <parameter name="cacheAttachments" locked="false">true</parameter>
            <parameter name="attachmentDIR" locked="false">/usr/cache</parameter>
            <parameter name="sizeThreshold" locked="false">100000</parameter><!--我这里设置为100000,上面的设置为4000-->
    <!--This will give out the timout of the configuration contexts, in seconds-->
    <parameter name="ConfigContextTimeoutInterval" locked="false">300</parameter><!--这个默认为30-->
    <parameter name="CONNECTION_TIMEOUT" locked="false">300</parameter><!--我这里添加了这个参数的设置-->
    另外,我现在的测试环境是局域网,上面的问题无法重现,所以改了这些配置也没法测试。
    这两天会在广域网上测试,有什么结果会及时来这里回复,谢谢!
    个人感觉一个是服务器端配置的问题,另外一个是网络环境的问题。因为这个运行一年多也没有出现过这个问题,现在服务器那边的网络环境性能有变化后,这个问就一直存在了。
      

  5.   

    Also, a user can specify a size threshold for the File caching (in bytes). When this threshold value is specified, only the attachments whose size is bigger than the threshold value will get cached in the files. Smaller attachments will remain in the memory. 另外,用户可以指定缓存大小的临界值来缓存文件(以字节为单位) 。当这个值到指定的时,附件大于指定值时将缓存在文件中。规模较小的附件,将留在内存中。
    sizeThreshold默认为单位字节?这个没有注意过,我再把这个设置大一些。
    设置到3M。
    设置到3M后,只要小于3M的都不用创建缓存文件,但大于3M时是要创建缓存文件的,是不是又会创建不了呢?
      

  6.   

    File caching allows Web Services to handle very large attachments without
    buffering them in memory. If it is not enabled during large transfer sizes, all
    of the Java Virtual Machine's memory may be utilized and replication may fail.
    Note:
    File caching decreases performance as the Web Services process to files
    instead of memory. You may use a combination of both options and send
    large transfers to a file and smaller ones into memory.
    To enable file caching, modify the “Axis2.xml” located at:Enter the following:
    <parameter name="cacheAttachments" locked="false">true</parameter>
    <parameter name="attachmentDIR" locked="false">temp directory</parameter>
    <parameter name="sizeThreshold" locked="false">4000</parameter>
    Note:
    Threshold size is measured in bytes.