AWS Java SDK - NoSuchMethodError in Jackson when using Region methods - java

I'm trying to use the AWS Java SDK to access my Elastic Transcoder jobs. But, the jobs are done in a different region than my development machine. When I try to establish the ElasticTranscoderClient and set it's region I get the following error:
java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectMapper.enable([Lcom/fasterxml/jackson/core/JsonParser$Feature;)Lcom/fasterxml/jackson/databind/ObjectMapper;
at com.amazonaws.partitions.PartitionsLoader.<clinit>(PartitionsLoader.java:54)
at com.amazonaws.regions.RegionMetadataFactory.create(RegionMetadataFactory.java:30)
at com.amazonaws.regions.RegionUtils.initialize(RegionUtils.java:66)
at com.amazonaws.regions.RegionUtils.getRegionMetadata(RegionUtils.java:54)
at com.amazonaws.regions.RegionUtils.getRegion(RegionUtils.java:107)
at com.amazonaws.client.builder.AwsClientBuilder.withRegion(AwsClientBuilder.java:233)
at com.amazonaws.client.builder.AwsClientBuilder.withRegion(AwsClientBuilder.java:222)
I will emphasis that this only happens when I try to use regions with the client (true for any AWS client I try to use)
Looking around online it seems that this is likely caused by the Jackson version not being sufficiently high, but I don't know how to fix this since it's the AWS SDK's dependency, not my project's.
Has anyone else had this issue? Is this really a dependency issue or is that just a red herring?
Edit: Using SDK Version 1.11.60

I ran into this as well. So far, the following in my pom.xml (my project uses maven) seems to fix it:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.125</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.3</version>
</dependency>

You can solve this issue by using aws sdk 2.0 for example software.amazon.awssdk:2.15.71

Related

Maven - Unable to resolve dependency conflict b/w google-vision beta & aws-sdk sub-components

I'm trying to use google-vision to fetch text from an image (uploaded to AWS S3) and store it in AWS Dynamo DB. I'm encountering dependency conflicts on jackson-core as both google-api and aws-java-sdk are using two different versions.
Dependency Hierarchy
google-api-client: 1.22.0 uses jackson-core: 2.1.3
google-cloud-vision: 0.22.0-beta uses jackson-core: 2.1.3
aws-java-sdk: 1.11.106 uses jackson-core: 2.6.6
I tried "exclusions" and added explicit dependency in pom.xml to use jackson-core: 2.6.6. Google-vision api works fine with that change. However, AmazonDynamoDBClientBuilder fails with below error:
Exception in thread "main" java.lang.IllegalAccessError: tried to access method com.amazonaws.AmazonWebServiceClient.<init>(Lcom/amazonaws/client/AwsSyncClientParams;)V from class com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder.build(AmazonDynamoDBClientBuilder.java:60)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder.build(AmazonDynamoDBClientBuilder.java:26)
at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)
at com.oneglint.ImageProcessing.AddItem.main(AddItem.java:133)
Following error is displayed when there was version conflict
Exception in thread "main" java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:537)
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:448)
at com.amazonaws.partitions.PartitionsLoader.<clinit>(PartitionsLoader.java:51)
at com.amazonaws.regions.RegionMetadataFactory.create(RegionMetadataFactory.java:30)
at com.amazonaws.regions.RegionUtils.initialize(RegionUtils.java:64)
at com.amazonaws.regions.RegionUtils.getRegionMetadata(RegionUtils.java:52)
at com.amazonaws.regions.RegionUtils.getRegion(RegionUtils.java:105)
at com.amazonaws.client.builder.AwsClientBuilder.withRegion(AwsClientBuilder.java:239)
at com.oneglint.ImageProcessing.AddItem.main(AddItem.java:132)
What am I missing here? Thanks for the help..
BTW, I'm using example code from github to achieve this. Here are the links:
DynamoDB example: https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/java/example_code/dynamodb
Google Vision DetectText example: https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/vision/cloud-client/src/main/java/com/example/vision/Detect.java
Additional Details
Both the examples are working fine if executed as independent projects. The problem occurs ONLY when both PutItem (AWS) & Detect (google-vision) classes are brought together in a single project, with appropriate code changes.
You can only have one version of jackson-core in your project. The easiest way to fix a version is to use <dependencyManagement> to set a version.
Your main problem is that jackson-core: 2.6.6 is not compatible with AmazonDynamoDBClientBuilder. The usual strategy is to try all versions from 2.1.3 to 2.6.6 until one of them works. If not, you can try to find versions of your amazon and google jars that require the same Jackson-core-version. In any case, this stupid and boring try-and-error.
If you do not come to any working solution, you can try to shade classes with maven-shade-plugin (I have not tried this, probably difficult) or you need to change your project in a way that not both dependencies are required.
After a lot of trial and error approach, the issue is finally solved.
It appears that I added multiple versions of aws-java-sdk jars during the process and an opennlp jar was associated with the project for some other module.
I had removed conflicting versions of aws-java-sdk and unnecessary libraries. Also, removed the exclusions and retained only the dependency addition in <dependencymanagement> for jackson-core.
Dependencies in my final pom listed below:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.11.106</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.6.6</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-vision</artifactId>
<version>v1-rev358-1.22.0</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.22.0</version>
<exclusions>
<exclusion> <!-- exclude an old version of Guava -->
<groupId>com.google.guava</groupId>
<artifactId>guava-jdk5</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-vision</artifactId>
<version>0.22.0-beta</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
</dependency>
</dependencies>
Hope this helps others..

java.lang.ClassNotFoundException: com.amazonaws.ClientConfigurationFactory

I am using aws since last 6 months and I developed application that puts batch request to firehose. It was working fine till today but when I redeployed in my local system it is saying java.lang.ClassNotFoundException: com.amazonaws.ClientConfigurationFactory. I know what this error means. But my question is why I got this exception today? I am using following dependency in my project:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<!-- <version>1.10.72</version> --> // I used this version today only for testing purpose
<version>1.10.6</version>
</dependency>
<!-- <dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.10.71</version>
</dependency> -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.10.37</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-kinesis</artifactId>
<version>RELEASE</version>
</dependency>
And I searched ClientConfigurationFactory class but don't find anywhere (anywhere means in my dependency).
My question is where is this class located and why I got this error only today? Because I did not face this error in my initial development (6 months before). I have not changed any dependencies/code today. And I am not using this class in my project (I have doubt aws-sdk may have been using inside).
Note: I can not ask Do I missed any dependency? Because it was working fine before.
Please comment if you have any doubt. Thanks.
This is most likely because you have a mismatch of AWS SDK versions you are including. You are using a combination of SDK version 1.10.6, 1.10.71, 1.10.37 and RELEASE. You are asking for trouble mixing the versions like you are doing. Change all those to the same version and your problem will likely go away.

What are the Maven coordinates for the JCache API jar?

I have an executable JAR (not a web app being deployed to a standard container like Tomcat, etc.) that needs to connect to a DB and cache a lot of stuff.
If at all possible, I'd like to use the JCache API and inject (via Guice) the Hazelcast implementation. I will code 100% against the JCache API, so that if I ever change my mind and choose another implementation, the swap out should be (relatively) painless.
One problem: where can I get the latest stable JCache JAR?!? (What are the Maven coordinates?)
On Maven Central, all I can find are some dev JARs from 2005! So I ask: where is the JCache?
The jar are available here : javax.cache/cache-api
If you want to use Ehcache implementations, copy/past the dependencies below:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.1.1</version>
<scope>runtime</scope>
</dependency>
Find a complete example here.

Dropwizard no longer supports Java 6

I want to use version 0.6.2 of drop wizard, but it seems to not exist on a maven repository anymore.
The original Maven include was:
<dependency>
<groupId>com.yammer.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>0.6.2</version>
</dependency>
but according to the website (http://mvnrepository.com/artifact/com.yammer.dropwizard/dropwizard-core/0.6.2), the group and artifact names have changed. On the new page (http://mvnrepository.com/artifact/io.dropwizard/dropwizard-core), the version 0.6.2 does not exist. When I try to do a include like so:
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>0.6.2</version>
</dependency>
it doesn’t work. Is there any fix for this? I need to use Dropwizard that supports Java 6.
<dependency>
<groupId>com.yammer.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>0.6.2</version>
</dependency>
This still works, don't switch over to io.dropwizard unless you want to switch to 0.7.x. 0.6.2 is not available with groupId io.dropwizard. The message is just telling you that future releases will be in the new groupId.

Trying to use Spring LDAP for coding

I am trying to use Spring LDAP for coding
<ldap-server ldif="classpath:my-ldap-clone.ldif" />
but I get this error
NoClassDefFoundError: org/apache/directory/server/core/DirectoryService
What am I doing wrong?
Using maven :
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-all</artifactId>
<version>1.5.7</version>
</dependency>
If you are using Maven, these actually come from an optional dependency of spring-security-ldap.
Using apacheds-all is a bad idea because it embeds a lot of rather common dependencies, like slf4j and dom4j. You would easily get into classloader issues with it.
Instead, you should look inside the pom of the spring-security-ldap version your are using, for the apacheds optional dependencies, and copy them over to your pom without the <scope> and <optional> elements (unfortunately there is no better way to handle optional dependencies with Maven).
For instance, with spring-security-ldap 4.2.2, it would give:
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-core</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-core-entry</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-protocol-ldap</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-protocol-shared</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-server-jndi</artifactId>
<version>1.5.5</version>
</dependency>
(it looks like it hasn't changed since at least 3.2)
Download ApcheDS from below link
http://directory.apache.org/ or get complete jar from here
I have used to work with Spring Security 3.0.5 with LDAP (Spring LDAP 1.3). That time i didn't met requirement of ApacheDS. Check your version of Spring Secuirty which may have dependency with ApacheDS.

Categories