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

1

6

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) ~[?:?]

Slaw answered 16/2, 2021 at 9:22 Comment(1)
Please post your entire POM file, this issue is most likely a prior dependency in your POM file pulling in an outdated version of jjwt.Rouvin
R
5

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.

Rouvin answered 1/3, 2021 at 21:59 Comment(2)
I removed that jjwt dependency but still I am getting the same error.Slaw
Validate that it really is out of your dependency tree - check to see what version of jjwt is being pulled in - I was able to recreate your error by adding the jjwt dependency ahead of the vonage dependency, and was able to fix it by removing it, Something in your dependency tree has a hard dependency on a pre 0.10.5 version of jjwtRouvin

© 2022 - 2024 — McMap. All rights reserved.