gpt4 book ai didi

java - uploadPart 失败,无法执行 HTTP 请求 : Connection reset

转载 作者:搜寻专家 更新时间:2023-10-31 20:34:10 25 4
gpt4 key购买 nike

我正在尝试使用分段上传 AWS S3 java API 执行文件上传(我使用的是 SDK 1.8.1)。我能够成功执行上传。

但是,间歇性地我不断收到此异常。

Jul 31, 2014 4:39:38 AM com.amazonaws.http.AmazonHttpClient executeHelper INFO: Unable to execute HTTP request: Connection reset java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:189) at java.net.SocketInputStream.read(SocketInputStream.java:121) at sun.security.ssl.InputRecord.readFully(InputRecord.java:312) at sun.security.ssl.InputRecord.read(InputRecord.java:350) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927) at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:884) at sun.security.ssl.AppInputStream.read(AppInputStream.java:102) at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:166) at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:90) at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:281) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:92) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:62) at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:254) at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:289) at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:252) at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:191) at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:300) at com.amazonaws.http.protocol.SdkHttpRequestExecutor.doReceiveResponse(SdkHttpRequestExecutor.java:66) at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:127) at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:717) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:522) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805) at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:402) at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:245) at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3711) at com.amazonaws.services.s3.AmazonS3Client.uploadPart(AmazonS3Client.java:2809) at cloud.<-filename->.writeContent(<-filename->.java:<-linenumber->)

在下面的代码中

try {
_partETags.add(_s3.uploadPart(uploadPartReq).getPartETag());
} catch (AmazonClientException e) {
System.out.println("Amazon service error. Retrying...");
printException(e);
} catch (Exception e) {
printException(e);
throw new UserException("Received an exception while performing upload part");
}

如果我查看文档,它说 uploadPart 函数将仅抛出两个类 AmazonClientException 和 AmazonServiceException。

链接:http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3.html#uploadPart(com.amazonaws.services.s3.model.UploadPartRequest)

<documentation>
...
UploadPartResult uploadPart(UploadPartRequest request)
throws AmazonClientException,
AmazonServiceException
...
Throws:
AmazonClientException - If any errors are encountered in the client while making the request or handling the response.
AmazonServiceException - If any errors occurred in Amazon S3 while processing the request.
...
</documentation>

但是,我收到了不同的异常。

我有以下问题

  • 这是预期的行为吗?如果不是,我该如何解决这个问题?
  • 为什么我的 try catch block 无法捕获此异常?
  • 对于 AmazonClient 或 AmazonServiceException,是否建议我们再次重试上传或者这些应该被视为不可恢复的错误?

最佳答案

这是一条来自 AmazonS3Client 的日志消息(在 INFO 级别),告诉您存在暂时性网络错误。默认情况下,AmazonS3Client 会捕获这些类型的异常并为您重试上传。您可以通过 ClientConfiguration 调整此行为.根据文档,如果在配置的重试次数后上传仍未成功,将抛出 AmazonClientException

关于java - uploadPart 失败,无法执行 HTTP 请求 : Connection reset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25306172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com