2012-09-18 76 views
16

關於Stack Overflow的其他問題已經解決了這個問題,但沒有提供的答案幫助我解決了這個問題。處理多部分/表單數據請求失敗。閱讀超時

我想從一個使用Apache HTTP Commons的applet上傳一個10 kB到16 MB之間的文件。一切工作正常在我的本地環境。

我只是我的生產服務器上收到以下異常(Tomcat的6.0,https://www.dailyrazor.com/),無論文件大小:

org.apache.commons.fileupload.FileUploadException: Processing of multipart/form-data request failed. Read timed out 
    at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:384) 
    at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:116) 
    at com.actura.helper.UploadHelper.processUpload(UploadHelper.java:92) 
    at com.actura.voice.upload.FileUploadServlet.process(FileUploadServlet.java:85) 
    at com.actura.voice.upload.FileUploadServlet.doPost(FileUploadServlet.java:75) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) 
    at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190) 
    at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291) 
    at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769) 
    at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698) 
    at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891) 
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690) 
    at java.lang.Thread.run(Thread.java:662) 

這是共享IO的調試日誌:

2012-Sep-18 11:26:28,446 [TP-Processor5] com.actura.voice.upload.MonitoredDiskFileItemFactory 
    DEBUG inside MonitoredDiskFileItemFactory constructor (listener) 
2012-Sep-18 11:26:28,794 [TP-Processor5] com.actura.voice.upload.MonitoredDiskFileItemFactory 
    DEBUG inside MonitoredDiskFileItemFactory createItem 
2012-Sep-18 11:26:28,800 [TP-Processor5] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG inside MonitoredDiskFileItem constructor 
2012-Sep-18 11:26:28,800 [TP-Processor5] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG inside getOutputStream() 
2012-Sep-18 11:26:28,802 [TP-Processor5] com.actura.voice.upload.MonitoredOutputStream 
    DEBUG inside MonitoredOutputStream constructor 
2012-Sep-18 11:26:28,803 [TP-Processor5] com.actura.voice.upload.MonitoredOutputStream 
    DEBUG leaving MonitoredOutputStream contructor 
2012-Sep-18 11:26:28,803 [TP-Processor5] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG leaving getOutputStream() 
2012-Sep-18 11:26:28,803 [TP-Processor5] com.actura.voice.upload.MonitoredDiskFileItemFactory 
    DEBUG inside MonitoredDiskFileItemFactory createItem 
2012-Sep-18 11:26:28,803 [TP-Processor5] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG inside MonitoredDiskFileItem constructor 
2012-Sep-18 11:26:28,803 [TP-Processor5] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG inside getOutputStream() 
2012-Sep-18 11:26:28,803 [TP-Processor5] com.actura.voice.upload.MonitoredOutputStream 
    DEBUG inside MonitoredOutputStream constructor 
2012-Sep-18 11:26:28,803 [TP-Processor5] com.actura.voice.upload.MonitoredOutputStream 
    DEBUG leaving MonitoredOutputStream contructor 
2012-Sep-18 11:26:28,803 [TP-Processor5] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG leaving getOutputStream() 
2012-Sep-18 11:26:28,803 [TP-Processor5] com.actura.voice.upload.MonitoredDiskFileItemFactory 
    DEBUG inside MonitoredDiskFileItemFactory createItem 
2012-Sep-18 11:26:28,803 [TP-Processor5] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG inside MonitoredDiskFileItem constructor 
2012-Sep-18 11:26:28,803 [TP-Processor5] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG inside getOutputStream() 
2012-Sep-18 11:26:28,803 [TP-Processor5] com.actura.voice.upload.MonitoredOutputStream 
    DEBUG inside MonitoredOutputStream constructor 
2012-Sep-18 11:26:28,803 [TP-Processor5] com.actura.voice.upload.MonitoredOutputStream 
    DEBUG leaving MonitoredOutputStream contructor 
2012-Sep-18 11:26:28,804 [TP-Processor5] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG leaving getOutputStream() 
2012-Sep-18 11:26:28,804 [TP-Processor5] com.actura.voice.upload.MonitoredDiskFileItemFactory 
    DEBUG inside MonitoredDiskFileItemFactory createItem 
2012-Sep-18 11:26:28,804 [TP-Processor5] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG inside MonitoredDiskFileItem constructor 
2012-Sep-18 11:26:28,804 [TP-Processor5] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG inside getOutputStream() 
2012-Sep-18 11:26:28,804 [TP-Processor5] com.actura.voice.upload.MonitoredOutputStream 
    DEBUG inside MonitoredOutputStream constructor 
2012-Sep-18 11:26:28,804 [TP-Processor5] com.actura.voice.upload.MonitoredOutputStream 
    DEBUG leaving MonitoredOutputStream contructor 
2012-Sep-18 11:26:28,804 [TP-Processor5] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG leaving getOutputStream() 
processing folder... /home/dixieh83/public_html/ActuraVoiceRecorderDemo/temp 
2012-Sep-18 11:27:47,062 [TP-Processor4] com.actura.voice.upload.MonitoredDiskFileItemFactory 
    DEBUG inside MonitoredDiskFileItemFactory constructor (listener) 
2012-Sep-18 11:27:47,461 [TP-Processor4] com.actura.voice.upload.MonitoredDiskFileItemFactory 
    DEBUG inside MonitoredDiskFileItemFactory createItem 
2012-Sep-18 11:27:47,461 [TP-Processor4] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG inside MonitoredDiskFileItem constructor 
2012-Sep-18 11:27:47,462 [TP-Processor4] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG inside getOutputStream() 
2012-Sep-18 11:27:47,462 [TP-Processor4] com.actura.voice.upload.MonitoredOutputStream 
    DEBUG inside MonitoredOutputStream constructor 
2012-Sep-18 11:27:47,462 [TP-Processor4] com.actura.voice.upload.MonitoredOutputStream 
    DEBUG leaving MonitoredOutputStream contructor 
2012-Sep-18 11:27:47,462 [TP-Processor4] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG leaving getOutputStream() 
2012-Sep-18 11:27:47,462 [TP-Processor4] com.actura.voice.upload.MonitoredDiskFileItemFactory 
    DEBUG inside MonitoredDiskFileItemFactory createItem 
2012-Sep-18 11:27:47,462 [TP-Processor4] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG inside MonitoredDiskFileItem constructor 
2012-Sep-18 11:27:47,462 [TP-Processor4] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG inside getOutputStream() 
2012-Sep-18 11:27:47,462 [TP-Processor4] com.actura.voice.upload.MonitoredOutputStream 
    DEBUG inside MonitoredOutputStream constructor 
2012-Sep-18 11:27:47,462 [TP-Processor4] com.actura.voice.upload.MonitoredOutputStream 
    DEBUG leaving MonitoredOutputStream contructor 
2012-Sep-18 11:27:47,462 [TP-Processor4] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG leaving getOutputStream() 
2012-Sep-18 11:27:47,463 [TP-Processor4] com.actura.voice.upload.MonitoredDiskFileItemFactory 
    DEBUG inside MonitoredDiskFileItemFactory createItem 
2012-Sep-18 11:27:47,463 [TP-Processor4] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG inside MonitoredDiskFileItem constructor 
2012-Sep-18 11:27:47,463 [TP-Processor4] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG inside getOutputStream() 
2012-Sep-18 11:27:47,463 [TP-Processor4] com.actura.voice.upload.MonitoredOutputStream 
    DEBUG inside MonitoredOutputStream constructor 
2012-Sep-18 11:27:47,463 [TP-Processor4] com.actura.voice.upload.MonitoredOutputStream 
    DEBUG leaving MonitoredOutputStream contructor 
2012-Sep-18 11:27:47,463 [TP-Processor4] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG leaving getOutputStream() 
2012-Sep-18 11:27:47,463 [TP-Processor4] com.actura.voice.upload.MonitoredDiskFileItemFactory 
    DEBUG inside MonitoredDiskFileItemFactory createItem 
2012-Sep-18 11:27:47,463 [TP-Processor4] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG inside MonitoredDiskFileItem constructor 
2012-Sep-18 11:27:47,463 [TP-Processor4] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG inside getOutputStream() 
2012-Sep-18 11:27:47,463 [TP-Processor4] com.actura.voice.upload.MonitoredOutputStream 
    DEBUG inside MonitoredOutputStream constructor 
2012-Sep-18 11:27:47,463 [TP-Processor4] com.actura.voice.upload.MonitoredOutputStream 
    DEBUG leaving MonitoredOutputStream contructor 
2012-Sep-18 11:27:47,463 [TP-Processor4] com.actura.voice.upload.MonitoredDiskFileItem 
    DEBUG leaving getOutputStream() 

除了這個上傳問題,我的小程序工作正常。

這是在我的生產服務器的server.xml文件中描述的服務器的配置:

<!-- Define an AJP 1.3 Connector on port 8009 --> <Connector address="127.0.0.1" port="9609" enableLookups="false" protocol="AJP/1.3" connectionTimeout="30000" maxThreads="50" minSpareThreads="1" maxSpareThreads="3" disableUploadTimeout="true" /> 

我的互聯網連接的速度罰款(2.01 Mbps的下降和0.42 Mbps的了),所以這個例外給我留下困惑。我已經將connectionTimeOut設置爲3000000,但我仍然有例外。我是否應該將connectionTimeOut設置爲-1以使其無限制?

我上傳目錄的文件權限設置爲777,我使用JDK版本7在瀏覽器中運行小程序。

Java控制檯輸出:

Java Plug-in 10.7.2.10 
Using JRE version 1.7.0_07-b10 Java HotSpot(TM) Client VM 

當上傳失敗,我得到這個在控制檯:

java.net.SocketException: Connection reset by peer: socket write error 
    at java.net.SocketOutputStream.socketWrite0(Native Method) 
    at java.net.SocketOutputStream.socketWrite(Unknown Source) 
    at java.net.SocketOutputStream.write(Unknown Source) 
    at org.apache.http.impl.io.AbstractSessionOutputBuffer.write(AbstractSessionOutputBuffer.java:169) 
    at org.apache.http.impl.io.ContentLengthOutputStream.write(ContentLengthOutputStream.java:119) 
    at org.apache.http.entity.mime.content.InputStreamBody.writeTo(InputStreamBody.java:70) 
    at org.apache.http.entity.mime.HttpMultipart.doWriteTo(HttpMultipart.java:206) 
    at org.apache.http.entity.mime.HttpMultipart.writeTo(HttpMultipart.java:224) 
    at org.apache.http.entity.mime.MultipartEntity.writeTo(MultipartEntity.java:183) 
    at org.apache.http.entity.HttpEntityWrapper.writeTo(HttpEntityWrapper.java:98) 
    at org.apache.http.impl.client.EntityEnclosingRequestWrapper$EntityWrapper.writeTo(EntityEnclosingRequestWrapper.java:108) 
    at org.apache.http.impl.entity.EntitySerializer.serialize(EntitySerializer.java:122) 
    at org.apache.http.impl.AbstractHttpClientConnection.sendRequestEntity(AbstractHttpClientConnection.java:271) 
    at org.apache.http.impl.conn.ManagedClientConnectionImpl.sendRequestEntity(ManagedClientConnectionImpl.java:197) 
    at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:257) 
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125) 
    at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:712) 
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:517) 
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906) 
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1066) 
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1044) 
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1035) 
    at com.actura.app.util.ApplicationUtil.uploadUsingApache(ApplicationUtil.java:143) 
    at com.actura.app.util.ApplicationUtil.saveWaveToServer(ApplicationUtil.java:90) 
    at com.actura.app.capture.RecorderUI.saveButtonActionPerformed(RecorderUI.java:1856) 
    at com.actura.app.capture.RecorderUI.access$17(RecorderUI.java:1824) 
    at com.actura.app.capture.RecorderUI$7.actionPerformed(RecorderUI.java:1325) 
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) 
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) 
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) 
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source) 
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) 
    at java.awt.Component.processMouseEvent(Unknown Source) 
    at javax.swing.JComponent.processMouseEvent(Unknown Source) 
    at java.awt.Component.processEvent(Unknown Source) 
    at java.awt.Container.processEvent(Unknown Source) 
    at java.awt.Component.dispatchEventImpl(Unknown Source) 
    at java.awt.Container.dispatchEventImpl(Unknown Source) 
    at java.awt.Component.dispatchEvent(Unknown Source) 
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) 
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) 
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) 
    at java.awt.Container.dispatchEventImpl(Unknown Source) 
    at java.awt.Component.dispatchEvent(Unknown Source) 
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source) 
    at java.awt.EventQueue.access$200(Unknown Source) 
    at java.awt.EventQueue$3.run(Unknown Source) 
    at java.awt.EventQueue$3.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
    at java.awt.EventQueue$4.run(Unknown Source) 
    at java.awt.EventQueue$4.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
    at java.awt.EventQueue.dispatchEvent(Unknown Source) 
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
    at java.awt.EventDispatchThread.run(Unknown Source) 

我已經知道這可能是我的ISP的問題。我只是想知道這是否是iSP的問題,爲什麼我可以順利使用像temviewer和Skype這樣的軟件?

下面是執行上傳代碼:

public static String uploadUsingApache(URL url, List<File> list, 
      String userId, String accountId, String waveDuration) 
      throws Exception { 

     // The execution: 
     DefaultHttpClient httpclient = new DefaultHttpClient(); 

     HttpPost method = new HttpPost(url.toString()); 

     MultipartEntity entity = new MultipartEntity(); 
     entity.addPart("userId", new StringBody(userId, Charset 
       .forName("UTF-8"))); 
     entity.addPart(IVR_ACCOUNT_KEY, new StringBody(accountId, Charset 
       .forName("UTF-8"))); 
     entity.addPart(IVR_MP3LEN_KEY, new StringBody(waveDuration, Charset 
       .forName("UTF-8"))); 

     // FileBody fileBody = new FileBody(list.get(0)); 
     // entity.addPart("file", fileBody); 

     for (File f : list) { 

      byte[] imageBytes = fileToByteArray(f); 
      entity.addPart("attachment_field", new InputStreamKnownSizeBody(
        new ByteArrayInputStream(imageBytes), imageBytes.length, 
        "audio/wav", f.getName())); 
      method.setEntity(entity); 
     } 

     ResponseHandler<String> responseHandler = new BasicResponseHandler(); 

     // HttpResponse response = httpclient.execute(method,responseHandler); 
     String responseText = httpclient.execute(method, responseHandler); 

     // error text 
     if (responseText.contains("<exception>")) { 
      responseText = responseText.replace("<exception>", ""); 
      responseText = responseText.replace("</exception>", ""); 
      throw new Exception(responseText); 
     } 

     // System.out.println(" Status " +response.getStatusLine()); 
     List<String> deleteList = Arrays.asList(responseText.split(",")); 

     StringBuffer sb = new StringBuffer(); 
     int cnt = 1; 
     for (File f : list) { 
      if (deleteList.contains(f.getName())) { 
       sb.append(f.getName() + (cnt == deleteList.size() ? "" : ", ")); 
       f.delete(); 
       cnt++; 
      } 

     } 

     if (deleteList.size() > 1) { 
      sb.append(" are "); 
     } else if (deleteList.size() == 1) { 
      sb.append(" is "); 
     } else { 

     } 

     sb.append(" successfully saved."); 

     return sb.toString(); 
    } 

當我按我的applet的GUI上傳按鈕,它會調用上面的方法,並在同一時間的GUI凍結。 10到50秒後,服務器會拋出FileUploadException。該servlet通知小程序有關該異常,但該小程序會在通知用戶異常之前掛起四五分鐘。

如果服務器端出現問題,爲什麼會有這麼多延遲?

+1

如果您鏈接到類似的問題(一個或多個),這將是有益的你」 d已經發布了,特別是如果你詳細說明了你已經嘗試了哪些步驟,爲什麼他們不適合你,以及你的環境與那些解決方案的工作方式不同。 –

+0

在瀏覽器中運行applet的Java版本是什麼?除了這個上傳功能,applet是否可以加載並正常工作? –

+0

是的,我正在使用Jdk 7運行小程序。除了這個上傳功能,該小程序還可以正常工作。上傳速度有沒有問題? – Mihir

回答

27

這幫助了我很多:http://blog.somepixels.net/en/502-proxy-error-uploading-from-apache-mod_proxy-to-tomcat-7/

基本上在我的server.xml中我把它設置爲:

<Connector port="8080" protocol="HTTP/1.1" URIEncoding="UTF-8" 
     connectionUploadTimeout="36000000" disableUploadTimeout="false" 
     connectionTimeout="60000" redirectPort="8443" /> 
+0

[connectionUploadTimeout]:指定在數據上傳過程中使用的超時時間(以毫秒爲單位)。這隻有在disableUploadTimeout設置爲false時纔會生效。 [disableUploadTimeout]:此標誌允許servlet容器在數據上載期間使用不同的通常較長的連接超時。如果未指定,則將此屬性設置爲true,以禁用此較長的超時。 [source]:https://tomcat.apache.org/tomcat-7.0-doc/config/http.html –

4

從問題中不清楚你正在運行的是什麼配置(或者你已經嘗試了什麼),但問題幾乎是根據定義,在上載過程中超出套接字超時。

由於在達到相關超時之前沒有完全接收文件,因此拋出錯誤。這與在測試中工作的東西(在本地網絡上)是一致的,但在慢速互聯網上運行時(尤其是在上傳速度方面)則不一致。

查看您的server.xml的相關<Connector>定義。您會對connectionTimeoutconnectionUploadTimeout屬性的值感興趣(後者如果disableUploadTimeout設置爲true)。

在沒有證據表明存在更多惡意問題的情況下,我希望您只需增加連接超時即可解決此問題。

+0

這是從我的生產服務器的server.xml複製的xml。 <! - 在端口8009上定義AJP 1.3連接器 - > Mihir

+0

也我的互聯網速度非常好,我不明白什麼是生產服務器的問題,我應該使connectionTimeOut -1爲無限制? – Mihir

+0

我剛剛用speedtest.com檢查了我的速度,結果是下載速度爲2.01 mbps,上傳速度爲0.42 mbps我已經將connectionTimeout設置爲3000000,但同樣的例外。我怎麼能擺脫這個? – Mihir

相關問題