Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS SDK: java.lang.NoSuchMethodError

Whenever I try to send mail via AWS SDK, I get the following exception:

java.lang.NoSuchMethodError: org.apache.http.params.HttpConnectionParams.setSoKeepalive(Lorg/apache/http/params/HttpParams;Z)V

I got a hint here ( https://github.com/aws/aws-sdk-java/issues/422 ) what may be wrong: Apparently there are some conflicts between versions of HttpClient and HttpCore but I can't figure it out no matter which version I try.

part of .classpath file:

<classpathentry kind="lib" path="lib/aws-java-sdk-1.10.69-javadoc.jar"/>
<classpathentry kind="lib" path="lib/aws-java-sdk-1.10.69-sources.jar"/>
<classpathentry kind="lib" path="lib/aws-java-sdk-1.10.69.jar"/>
<classpathentry kind="lib" path="lib/aws-java-sdk-flow-build-tools-1.10.69.jar"/>
<classpathentry kind="lib" path="lib/httpclient-4.3.6.jar"/>
<classpathentry kind="lib" path="lib/httpcore-4.3.3.jar"/>
<classpathentry kind="lib" path="lib/google-http-client-1.18.0-rc.jar"/>
<classpathentry kind="lib" path="lib/google-http-client-appengine-1.18.0-rc.jar"/>
<classpathentry kind="lib" path="lib/google-http-client-gson-1.18.0-rc.jar"/>
<classpathentry kind="lib" path="lib/google-http-client-jackson2-1.18.0-rc.jar"/>
<classpathentry kind="lib" path="lib/google-http-client-jdo-1.18.0-rc.jar"/>
<classpathentry kind="lib" path="lib/httpmime-4.1.3.jar"/

complete exception printStack():

java.lang.NoSuchMethodError: org.apache.http.params.HttpConnectionParams.setSoKeepalive(Lorg/apache/http/params/HttpParams;Z)V
at com.amazonaws.http.HttpClientFactory.createHttpClient(HttpClientFactory.java:96) ~[aws-java-sdk-1.10.69.jar:?]
at com.amazonaws.http.AmazonHttpClient.<init>(AmazonHttpClient.java:187) ~[aws-java-sdk-1.10.69.jar:?]
at com.amazonaws.AmazonWebServiceClient.<init>(AmazonWebServiceClient.java:136) ~[aws-java-sdk-1.10.69.jar:?]
at com.amazonaws.AmazonWebServiceClient.<init>(AmazonWebServiceClient.java:120) ~[aws-java-sdk-1.10.69.jar:?]
at com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient.<init>(AmazonSimpleEmailServiceClient.java:165) ~[aws-java-sdk-1.10.69.jar:?]
at com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient.<init>(AmazonSimpleEmailServiceClient.java:145) ~[aws-java-sdk-1.10.69.jar:?]
at com.fieldoo.service.MailService.send(MailService.java:259) ~[classes/:?]
at com.fieldoo.service.MailService.checkAndSendQueue(MailService.java:222) ~[classes/:?]
at com.fieldoo.service.MailService$$FastClassByCGLIB$$ce530a4.invoke(<generated>) ~[cglib-nodep-2.2.jar:?]
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191) ~[cglib-nodep-2.2.jar:?]
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689) ~[org.springframework.aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) ~[org.springframework.aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) ~[org.springframework.transaction-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[org.springframework.aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622) ~[org.springframework.aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at com.fieldoo.service.MailService$$EnhancerByCGLIB$$382d8989.checkAndSendQueue(<generated>) ~[cglib-nodep-2.2.jar:?]
at com.fieldoo.controller.ScheduleController.sendEmails(ScheduleController.java:196) ~[classes/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_04]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_04]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_04]
at java.lang.reflect.Method.invoke(Method.java:601) ~[?:1.7.0_04]
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:64) ~[org.springframework.context-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53) [org.springframework.context-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81) [org.springframework.context-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [?:1.7.0_04]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) [?:1.7.0_04]
at java.util.concurrent.FutureTask.run(FutureTask.java:166) [?:1.7.0_04]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178) [?:1.7.0_04]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292) [?:1.7.0_04]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [?:1.7.0_04]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [?:1.7.0_04]
at java.lang.Thread.run(Thread.java:722) [?:1.7.0_04]

this exception is caused with the following line of code:

AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials);

where credentials is an instance of AWSCredentials.
If you need any additional information I will be glad to provide it.

like image 362
peech Avatar asked Mar 12 '23 13:03

peech


2 Answers

Make sure your core version and s3 versions are same.

I was getting java.lang.NoSuchMethodError for beforeClientExecution

This worked for me

compile('com.amazonaws:aws-java-sdk-core:1.11.376')
compile('com.amazonaws:aws-java-sdk-s3:1.11.376')
like image 81
Vikrant Kandgaonkar Avatar answered Mar 15 '23 04:03

Vikrant Kandgaonkar


Had the same issue. My solution was to upgrade my AWS version

<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>

in pom.xml from <version>1.10.77</version> to <version>1.11.192</version>

like image 43
Technotronic Avatar answered Mar 15 '23 04:03

Technotronic