1

I'm trying to get and S3 object size via Java AWS SDK (v2), and send it back via HTTP response (this is all inside a HTTP Server using com.sun.net.httpserver.HttpServer). But it doesn't work and shows me the following debug messages.

What's going wrong here? Am I missing anything?

        AwsBasicCredentials awsCreds = AwsBasicCredentials.create(
                AdapterMain.ACCESS_KEY,
                AdapterMain.SECRET_KEY);

        s3Client = S3Client.builder().region(region)
                                    .endpointOverride(URI.create(AdapterMain.S3server))
                                   .credentialsProvider(StaticCredentialsProvider.create(awsCreds))
                                   .build();
                    //TODO
                    HeadObjectRequest getObjectRequest = HeadObjectRequest.builder()
                            .bucket(bucketName).key("FILES/"+getMD5(id)+"/FILES/"+id+"/"+id+".txt").build();

                    HeadObjectResponse objectHead = s3Client.headObject(getObjectRequest);
                    long size = objectHead.contentLength();
                    System.out.println("=================================="+size);
                    response=size+"";
                    he.sendResponseHeaders(200, response.length());

And here are the logs:

18:44:14.898 [HTTP-Dispatcher] DEBUG software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain - Creating an interceptor chain that will apply interceptors in the following order: [software.amazon.awssdk.core.internal.interceptor.HttpChecksumRequiredInterceptor@62ec69e1, software.amazon.awssdk.awscore.interceptor.HelpfulUnknownHostExceptionInterceptor@1d17dde7, software.amazon.awssdk.services.s3.internal.handlers.EnableChunkedEncodingInterceptor@339b31af, software.amazon.awssdk.services.s3.internal.handlers.DisableDoubleUrlEncodingInterceptor@3d96c2f6, software.amazon.awssdk.services.s3.internal.handlers.EnableTrailingChecksumInterceptor@3cb417c4, software.amazon.awssdk.services.s3.internal.handlers.CreateMultipartUploadRequestInterceptor@1f6f0d50, software.amazon.awssdk.services.s3.internal.handlers.GetObjectInterceptor@7513515b, software.amazon.awssdk.services.s3.internal.handlers.AsyncChecksumValidationInterceptor@7e99ac7d, software.amazon.awssdk.services.s3.internal.handlers.EndpointAddressInterceptor@620f9e5d, software.amazon.awssdk.services.s3.internal.handlers.ExceptionTranslationInterceptor@56d0ac1, software.amazon.awssdk.services.s3.internal.handlers.GetBucketPolicyInterceptor@6a1b0abe, software.amazon.awssdk.services.s3.internal.handlers.PutObjectInterceptor@5952b9c4, software.amazon.awssdk.services.s3.internal.handlers.SyncChecksumValidationInterceptor@473129c5, software.amazon.awssdk.services.s3.internal.handlers.DecodeUrlEncodedResponseInterceptor@2ae718e0, software.amazon.awssdk.services.s3.internal.handlers.CreateBucketInterceptor@181bb9f8]
18:44:14.939 [HTTP-Dispatcher] DEBUG software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain - Interceptor 'software.amazon.awssdk.services.s3.internal.handlers.EndpointAddressInterceptor@620f9e5d' modified the message with its modifyHttpRequest method.
18:44:14.967 [HTTP-Dispatcher] DEBUG software.amazon.awssdk.request - Sending Request: DefaultSdkHttpFullRequest(httpMethod=HEAD, protocol=https, host=file-store.s3-server.dcstore.company.net, port=443, encodedPath=/FILES/f13e/FILES/id_1234/id_1234.txt, headers=[amz-sdk-invocation-id, User-Agent], queryParameters=[])
18:44:14.978 [HTTP-Dispatcher] DEBUG software.amazon.awssdk.auth.signer.Aws4Signer - AWS4 String to sign: AWS4-HMAC-SHA256
20210305T014414Z
20210305/us-east-1/s3/aws4_request
9bfed5fd14903f65ac34647985e2c8a4bbe0fbf311982cfbeb2e44b2b58a2390
18:44:14.991 [HTTP-Dispatcher] WARN software.amazon.awssdk.http.apache.internal.utils.ApacheUtils - NoSuchMethodException was thrown when disabling normalizeUri. This indicates you are using an old version (< 4.5.8) of Apache http client. It is recommended to use http client version >= 4.5.9 to avoid the breaking change introduced in apache client 4.5.7 and the latency in exception handling. See https://github.com/aws/aws-sdk-java/issues/1919 for more information
18:44:15.098 [HTTP-Dispatcher] DEBUG software.amazon.awssdk.http.apache.internal.conn.SdkTlsSocketFactory - socket.getSupportedProtocols(): [TLSv1.3, TLSv1.2, TLSv1.1, TLSv1, SSLv3, SSLv2Hello], socket.getEnabledProtocols(): [TLSv1.3, TLSv1.2, TLSv1.1, TLSv1]
18:44:15.099 [HTTP-Dispatcher] DEBUG software.amazon.awssdk.http.apache.internal.conn.SdkTlsSocketFactory - TLS protocol enabled for SSL handshake: [TLSv1.2, TLSv1.1, TLSv1, TLSv1.3]
18:44:15.506 [HTTP-Dispatcher] DEBUG software.amazon.awssdk.http.apache.internal.net.SdkSslSocket - created: file-store.s3-server.dcstore.company.net/10.111.111.20:443
Tina J
  • 4,983
  • 13
  • 59
  • 125
  • Random q, but have you updated your apache client? – SomeStudent Mar 05 '21 at 02:34
  • I see a message showing there...but where is Apache client used?! Doesn't it come with the SDK itself? – Tina J Mar 05 '21 at 02:35
  • And btw, is that WARN just a warning, or an error causing the program not to run?! – Tina J Mar 05 '21 at 02:36
  • This link might help https://github.com/aws/aws-sdk-java-v2/issues/1372, the warning does seem as if something internally is blowing up, but like is your s3client not being properly created? – SomeStudent Mar 05 '21 at 02:45
  • I'm not sure. My code shows how I created it. – Tina J Mar 05 '21 at 02:49
  • Btw, I don't have any http client in pom or anywhere. – Tina J Mar 05 '21 at 02:51
  • 1
    It must be a transitive dependency, you can see all dependencies by running ```mvn dependency:tree``` or just try to explicitly define org.apache.httpcomponents:httpclient:4.5.9 in your project pom file. – Ilya Lapitan Mar 05 '21 at 03:51
  • Wow yes, at least the file size is working now. I added the `org.apache.httpcomponents:httpclient:4.5.9` in pom and it fixed the issue! – Tina J Mar 05 '21 at 15:49
  • @IlyaLapitan I really didnt expect it as it was just a WARN. You can write a response if you like and I can mark it as answer. – Tina J Mar 05 '21 at 15:50

1 Answers1

4

The warning message there is a little bit misleading and technically should be error in this particular case as this is a breaking change in httpclinet library which can cause unexpected behavior of the program. This dependency itself comes as a transitive dependency from aws-java-sdk. So, to get it fixed just follow recommendation provided in the warning message and explicitly define the required version of httpclinet in your project pom file:

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.9</version>
</dependency>
Ilya Lapitan
  • 986
  • 15
  • 23
  • Alternatively, I added the line `org.apache.httpcomponents:httpclient:4.5.9` in pom and it fixed the issue! – Tina J Mar 05 '21 at 17:57