aws / aws-sdk-java

The official AWS SDK for Java 1.x (In Maintenance Mode, End-of-Life on 12/31/2025). The AWS SDK for Java 2.x is available here: https://github.com/aws/aws-sdk-java-v2/
https://aws.amazon.com/sdkforjava
Apache License 2.0
4.13k stars 2.83k forks source link

com.amazonaws.auth package from different aws-java-xxx projects is causing problems when used in felix OSGI container. #3116

Closed aballa-perforce closed 5 months ago

aballa-perforce commented 5 months ago

Upcoming End-of-Support

Describe the bug

As far as I know aws-java-xxx projects does not support OSGI.

https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-bundle - this has bundle in its name but it is not actually a OSGI bundle. It is merge of all aws-java-xxx projects.

We have OSGI-fied below jars ourselves and are using in our product.

  1. aws-java-sdk-core-1.12.682.jar
  2. aws-java-sdk-rds-1.12.682.jar
  3. aws-java-sdk-sts-1.12.682.jar
  4. jmespath-java-1.12.682.jar

com.amazonaws.auth package is available in all the aws-xxx bundles and all bundles are exporting the same package. OSGI expects unique package to be exported from each bundle. OSGI can not resolve dependencies in this case and you will get java.lang.NoClassDefFoundError.

Correct fix Rename packages.

Alternate solutions

  1. Locally refer the jar files using Bundle-ClassPath: directive in MANIFEST.MF which will load the classes in JVM standard way and ignore all the manifest entries). This solution does not work when aws-xxx bundles is referenced across different project in our product.
  2. We can merge all jar file into one jar file and there will be only one MANIFEST.MF which will export all packages and use that but we are changing AWS way of packaging. Every time we need to a new jar or we integrate with new release we need to generate the merged-jar.

What do you suggest?

Expected Behavior

Should be able to reference class in OSGI container.

Current Behavior

Throws java.lang.NoClassDefFoundError.

Exception in thread "Schema Configured Thread" java.lang.NoClassDefFoundError: com/amazonaws/auth/STSAssumeRoleWithWebIdentitySessionCredentialsProvider$Builder
    at com.amazonaws.services.securitytoken.internal.STSProfileCredentialsService.getAssumeRoleCredentialsProvider(STSProfileCredentialsService.java:36)
    at com.amazonaws.auth.profile.internal.securitytoken.STSProfileCredentialsServiceProvider.getProfileCredentialsProvider(STSProfileCredentialsServiceProvider.java:39)
    at com.amazonaws.auth.profile.internal.securitytoken.STSProfileCredentialsServiceProvider.getCredentials(STSProfileCredentialsServiceProvider.java:71)
    at com.amazonaws.auth.WebIdentityTokenCredentialsProvider.getCredentials(WebIdentityTokenCredentialsProvider.java:76)
    at com.amazonaws.auth.AWSCredentialsProviderChain.getCredentials(AWSCredentialsProviderChain.java:118)
    at com.amazonaws.auth.presign.PresignerFacade.presign(PresignerFacade.java:60)
    at com.amazonaws.services.rds.auth.RdsIamAuthTokenGenerator.getAuthToken(RdsIamAuthTokenGenerator.java:88)
    at com.soa.database.service.impl.DatabaseConfigFactory.getToken(DatabaseConfigFactory.java:705)
    at com.soa.database.service.impl.DatabaseConfigFactory.createConnection(DatabaseConfigFactory.java:653)
    at com.soa.database.install.DatabaseConnection.getConnection(DatabaseConnection.java:50)
    at com.soa.database.install.InstallationManager.getConnection(InstallationManager.java:502)
    at com.soa.database.install.InstallationManager.getInstalledSchemas(InstallationManager.java:135)
    at com.soa.database.schema.impl.DatabaseSchemaServiceImpl.getInstalledSchemas(DatabaseSchemaServiceImpl.java:142)
    at com.soa.database.tasks.ConfigureSchemaTask$SchemaServiceStatus.run(ConfigureSchemaTask.java:248)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

Reproduction Steps

See description.

Possible Solution

See description.

Additional Information/Context

No response

AWS Java SDK version used

1.12.682

JDK version used

1.8

Operating System and version

Linux

debora-ito commented 5 months ago

You are correct, Java SDK v1 doesn't support OSGi. A feature request was submitted in the past but it wasn't prioritized, and we don't have plans to support in V1.

aballa-perforce commented 5 months ago

@debora-ito Thanks for the response. We can OSGI-fy ourselves but the problem is having same package name com.amazonaws.auth different jars files. Even standard JAVA coding practice discourages this but will not have problem as long as class names are different but in OSGI it does not work even if class names are different.

Any plans to change and have jar specific package names? If not, I have to tinker with aws jars to merge all jars as one jar and use. Do you recommend that?

debora-ito commented 5 months ago

The com.amazonaws.auth packages were created that way for the IAM Policy Builder, each service module contains its own policy actions. There's no plans to change the package names ahead of the upcoming v1 Maintenance Mode. I don't have specific recommendations for a workaround in this case, sorry :/

I'll say that even though OSGi is not supported in Java SDK v2 either (tracking here), the IAM Policy actions were implemented differently so there should not be split packages in v2. If you can give v2 a try, please add your findings to that tracking issue.

github-actions[bot] commented 5 months ago

This issue is now closed.

Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.