使用java下载文件时出现AmazonS3错误

时间:2017-12-18 03:44:15

标签: amazon-web-services

尝试从AmazonS3存储桶下载文件时出现以下异常。这在Java IDE中运行良好,但是当我从其他基于java的产品运行相同的代码时,它失败了。我已经加载了所有客户端所需的jar文件,

VENDOR_JAR=/u01/app/sterling/jar/amazons3/1_0/aws-java-sdk-core-1.11.250.jar
VENDOR_JAR=/u01/app/sterling/jar/amazons3/1_0/aws-java-sdk-s3-1.11.250.jar
VENDOR_JAR=/u01/app/sterling/jar/amazons3/1_0/httpclient-4.5.2.jar
VENDOR_JAR=/u01/app/sterling/jar/amazons3/1_0/httpcore-4.4.4.jar
VENDOR_JAR=/u01/app/sterling/jar/amazons3/1_0/jackson-annotations-2.6.0.jar
VENDOR_JAR=/u01/app/sterling/jar/amazons3/1_0/jackson-core-2.6.7.jar
VENDOR_JAR=/u01/app/sterling/jar/amazons3/1_0/jackson-databind-2.6.7.1.jar
VENDOR_JAR=/u01/app/sterling/jar/amazons3/1_0/joda-time-2.8.1.jar

Caused by: java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(SocketInputStream.java:168)
        at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:293)
        at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:331)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:798)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1138)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1165)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1149)
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394)
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353)
        at com.amazonaws.http.conn.ssl.SdkTLSSocketFactory.connectSocket(SdkTLSSocketFactory.java:132)
        at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:141)
        at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
        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:597)
        at com.amazonaws.http.conn.ClientConnectionManagerFactory$Handler.invoke(ClientConnectionManagerFactory.java:76)
        at com.amazonaws.http.conn.$Proxy15.connect(Unknown Source)
        at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
        at com.amazonaws.http.apache.client.impl.SdkHttpClient.execute(SdkHttpClient.java:72)
        at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1236)
        at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1056)
        ... 24 more


Java Code:

    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
            AmazonS3 s3Client = new AmazonS3Client(credentials);
            System.out.println("Initialized Client Finally!!");
            S3Object object = s3Client.getObject(new GetObjectRequest(bucketName, fileName));
     displayTextInputStream(object.getObjectContent());

    public void displayTextInputStream(InputStream input)throws IOException {
            System.out.println("Inside displayTextInputStream()..........");
            // Read one text line at a time and display.
            BufferedReader reader = new BufferedReader(new InputStreamReader(input));
            while (true) {
                String line = reader.readLine();
                if (line == null) break;

                System.out.println("    " + line);
            }
            System.out.println();
        }

0 个答案:

没有答案