1
votes

AWS Java SDK 2.15.73 (Current latest version). Java 1.8.222 Operating system IBM AIX 7.1

Developing an application that uploads a file to S3 bucket.

In Maven pom file:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>bom</artifactId>
            <version>2.15.73</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependencies>
    <dependency>
        <groupId>software.amazon.awssdk</groupId>
        <artifactId>s3</artifactId>
    </dependency>
    <dependency>
      <groupId>software.amazon.awssdk</groupId>
      <artifactId>apache-client</artifactId>
      <version>2.0.0-preview-10</version>
    </dependency>           
    <dependency>
      <groupId>software.amazon.awssdk</groupId>
      <artifactId>http-client-spi</artifactId>
      <version>2.0.0-preview-10</version>
    </dependency>           
</dependencies>

Beginning of Stacktrace:

Exception in sendFileToAWSNoAuth=Unable to marshall request to JSON: baseUri must not be null. software.amazon.awssdk.core.exception.SdkClientException: Unable to marshall request to JSON: baseUri must not be null. at software.amazon.awssdk.core.exception.SdkClientException$BuilderImpl.build(SdkClientException.java:98) at software.amazon.awssdk.services.s3.transform.PutObjectRequestMarshaller.marshall(PutObjectRequestMarshaller.java:53) at software.amazon.awssdk.services.s3.transform.PutObjectRequestMarshaller.marshall(PutObjectRequestMarshaller.java:31) at software.amazon.awssdk.core.runtime.transform.StreamingRequestMarshaller.marshall(StreamingRequestMarshaller.java:48)

Java code:

Authentication is needed and execution thru proxy server.

String endPointURL = appParms.getProxyServer() + ":" + appParms.getProxyServerPort();

URI endPointUri = new URI(endPointURL);

ProxyConfiguration proxyConfig = ProxyConfiguration.builder() .endpoint(endPointUri) .build();

SdkHttpClient httpClient = ApacheSdkHttpClientFactory.builder() .proxyConfiguration(proxyConfig) .build() .createHttpClient();

ProfileCredentialsProvider credentialsProfile = ProfileCredentialsProvider.builder().profileName(appParms.getProfileName()).build();

Region region = Region.EU_CENTRAL_1; S3Client s3NonEncryption = S3Client.builder() .credentialsProvider(credentialsProfile) .region(region) .endpointOverride(endPointUri) .httpClient(httpClient) .build();

String folderKey = appParms.getBucketFolder() + "/" + appParms.getFileName();

File aFile = new File(appParms.getFilePath() + "/" + appParms.getFileName());

PutObjectRequest putOb = PutObjectRequest.builder() .bucket(appParms.getBucketNameSSE()) .key(folderKey) .build();

PutObjectResponse response = s3NonEncryption.putObject(putOb, aFile.toPath());

Exception occurs in this last line (s3NonEncryption.putObject)

1

1 Answers

0
votes

This "Base URI must not be null" error was caused by "endpointOverride(endPointUri)" in S3Client.builder. ..

Also in http client creation was used class ApacheSdkHttpClientFactory that caused all kind of class mismatch error in run.

Correct way is to to use class ApacheHttpClient:

SdkHttpClient httpClient = ApacheHttpClient.builder() .proxyConfiguration(proxyConfig) .connectionTimeout(Duration.ofMillis(30000)) .build();

Still there is timeout error in execution.

software.amazon.awssdk.core.exception.SdkClientException: Unable to execute HTTP request: Connect to bdw-landing-sse-test-s3.s3.eu-central-1.amazonaws.com:443 [bdw-landing-sse-test-s3.s3.eu-central-1.amazonaws.com/52.219.72.81] failed: connect timed out at software.amazon.awssdk.core.exception.SdkClientException$BuilderImpl.build(SdkClientException.java:98) at software.amazon.awssdk.core.exception.SdkClientException.create(SdkClientException.java:43) at software.amazon.awssdk.core.internal.http.pipeline.stages.utils.RetryableStageHelper.setLastException(RetryableStageHelper.java:198)