SdkClientException:无法执行HTTP请求:连接重置 [英] SdkClientException: Unable to execute HTTP request: Connection reset

查看:810
本文介绍了SdkClientException:无法执行HTTP请求:连接重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件上传到AWS s3存储桶.我不断收到此异常"SdkClientException:无法执行HTTP请求:连接重置".

I'm trying to upload file to AWS s3 bucket. I'm continuously getting this exception "SdkClientException: Unable to execute HTTP request: Connection reset".

我正在尝试通过inputstream上传

I'm trying to upload by inputstream

AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                .withRegion(Regions.US_EAST_2)
                .withCredentials(new AWSStaticCredentialsProvider(cred))
                .build();
        try {

            ObjectMetadata metadata = new ObjectMetadata();
            metadata.setContentLength(bytesArray.length);
            metadata.setContentType("text/csv");
            s3Client.putObject(new PutObjectRequest(appConfig.getBucketName(), fileName, inStream, metadata).withCannedAcl(CannedAccessControlList.PublicRead));
        }
    ----

下面是详细的例外情况.可能是什么原因?我的S3存储桶具有具有S3完全访问策略的IAM用户.此问题与网络或任何其他设置有关吗?

Below is the exception in detail. What could be the reason? My S3 bucket has IAM user with S3 full access policy. Is this issue related to network or any other settings?

com.amazonaws.SdkClientException: Unable to execute HTTP request: Connection reset
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleRetryableException(AmazonHttpClient.java:1136)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1082)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:745)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:719)
-------
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:209)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
    at sun.security.ssl.InputRecord.read(InputRecord.java:503)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:396)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:355)
    at com.amazonaws.http.conn.ssl.SdkTLSSocketFactory.connectSocket(SdkTLSSocketFactory.java:142)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142

推荐答案

如果在代理后面运行应用程序,则可能会发生这种情况.您可以将代理设置为

If you are running the application behind a proxy, this may happens. You can set the proxy as,

public static void setProxy() {
        System.setProperty("http.proxyHost", "<http-proxy-url>");
        System.setProperty("http.proxyPort", "<port>");

        System.setProperty("https.proxyHost", "<https-proxy-url>");
        System.setProperty("https.proxyPort", "<port>");
    }

这篇关于SdkClientException:无法执行HTTP请求:连接重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆