Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.AbstractMethodError: I get this exception when I am trying to initiate an outbound voice call using nexmo(vonage) API

My pom.xml for all the relevant dependencies. No other dependencies use the below dependencies internally.

<dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.9.9</version>
    </dependency>
<dependency>
      <groupId>com.sparkjava</groupId>
      <artifactId>spark-core</artifactId>
      <version>2.6.0</version>
    </dependency>
    <dependency>
      <groupId>com.vonage</groupId>
      <artifactId>client</artifactId>
      <version>6.0.0</version>
    </dependency>

    <dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt-api</artifactId>
      <version>0.11.0</version>
    </dependency>
    <dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt-impl</artifactId>
      <version>0.11.0</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt-jackson</artifactId>
      <version>0.11.0</version>
      <scope>runtime</scope>
    </dependency>
<dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt</artifactId>
      <version>0.9.1</version>
    </dependency>

Java Code to initiate outbound voice call using vonage SDK.

VonageClient client = VonageClient.builder().applicationId(APPLICATION_ID).privateKeyContents(PRIVATE_KEY).build();
    
Ncco ncco = new Ncco(TalkAction.builder(MESSAGE).voiceName(VOICE_TYPE).build());
CallEvent callEvent=client.getVoiceClient().createCall(newCall(TO_NUMBER,FROM_NUMBER, ncco));

Exception thrown when executing the code.

java.lang.AbstractMethodError: Receiver class io.jsonwebtoken.impl.DefaultJwtBuilder does not define or inherit an implementation of the resolved method 'abstract io.jsonwebtoken.JwtBuilder signWith(java.security.Key, io.jsonwebtoken.SignatureAlgorithm)' of interface io.jsonwebtoken.JwtBuilder. at com.nexmo.jwt.JwtGenerator.generate(JwtGenerator.kt:49) ~[jwt-1.0.1.jar:?] at com.nexmo.jwt.Jwt.generate(Jwt.kt:44) ~[jwt-1.0.1.jar:?] at com.nexmo.jwt.Jwt.generate$default(Jwt.kt:43) ~[jwt-1.0.1.jar:?] at com.nexmo.jwt.Jwt.generate(Jwt.kt) ~[jwt-1.0.1.jar:?] at com.vonage.client.auth.JWTAuthMethod.apply(JWTAuthMethod.java:43) ~[client-6.0.0.jar:6.0.0] at com.vonage.client.AbstractMethod.applyAuth(AbstractMethod.java:127) ~[client-6.0.0.jar:6.0.0] at com.vonage.client.AbstractMethod.execute(AbstractMethod.java:73) ~[client-6.0.0.jar:6.0.0] at com.vonage.client.voice.CallsEndpoint.post(CallsEndpoint.java:57) ~[client-6.0.0.jar:6.0.0] at com.vonage.client.voice.VoiceClient.createCall(VoiceClient.java:61) ~[client-6.0.0.jar:6.0.0] at com.senpiper.core.listener.VoiceCallListener.listen(VoiceCallListener.java:37) ~[classes/:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?] at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]

like image 833
Dhyey Vachhani Avatar asked Oct 26 '22 14:10

Dhyey Vachhani


1 Answers

The issue is the reference to:

<dependency>
    <groupId>io.jsonwebtoken</groupId>
    <artifactId>jjwt</artifactId>
    <version>0.9.1</version>        
</dependency>

Deleteing this dependency will resolve your issue. This package is superseded by the three preceding it which are the modularized versions of that same package see v0.10.0 release notes for details the following from you POM file will suffice:

<dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt-api</artifactId>
      <version>0.11.0</version>
</dependency>
<dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt-impl</artifactId>
      <version>0.11.0</version>
      <scope>runtime</scope>
</dependency>
<dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt-jackson</artifactId>
      <version>0.11.0</version>
      <scope>runtime</scope>
</dependency>

The Vonage SDK is dependant on jjwt v0.10.5, the method that your app is choking on however was introduced in v0.10.0 - when the arguments got flipped around. Maven can be a tad quirky when it comes to handling copies of a dependency. In this case, because you are referencing 0.9.1 of jjwt explicitly it's pulling in an incompatible version. If I had to take a shot in the dark, I'd guess that the reference to the non modular jjwt package comes ahead of the other dependencies - which is why it's being pulled in and not the others.

Regardless - just remove the reference the old jjwt package - that will resolve your issue.

like image 152
slorello Avatar answered Nov 15 '22 04:11

slorello