I have a problem about sending any request to a defined service through api gateway with the usage of bearer token coming from login.
After login, I tried to send a request to a defined service but I got this issue in JWTAuthenticationFilter of api gateway shown below.
java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter at io.jsonwebtoken.impl.Base64Codec.decode(Base64Codec.java:26) ~[jjwt-0.9.1.jar:0.9.1] at io.jsonwebtoken.impl.DefaultJwtParser.setSigningKey(DefaultJwtParser.java:151) ~[jjwt-0.9.1.jar:0.9.1] at com.microservice.apigateway.util.JwtUtils.validateJwtToken(JwtUtils.java:31) ~[classes/:na] at com.microservice.apigateway.filter.JwtAuthenticationFilter.filter(JwtAuthenticationFilter.java:55) ~[classes/:na] at org.springframework.cloud.gateway.filter.OrderedGatewayFilter.filter(OrderedGatewayFilter.java:44) ~[spring-cloud-gateway-server-3.1.4.jar:3.1.4] at org.springframework.cloud.gateway.handler.FilteringWebHandler$DefaultGatewayFilterChain.lambda$filter$0(FilteringWebHandler.java:117) ~[spring-cloud-gateway-server-3.1.4.jar:3.1.4] at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:44) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.Mono.subscribe(Mono.java:4455) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.subscribeNext(MonoIgnoreThen.java:263) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:51) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.Mono.subscribe(Mono.java:4455) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.subscribeNext(MonoIgnoreThen.java:263) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:51) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:157) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:74) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.MonoNext$NextSubscriber.onNext(MonoNext.java:82) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.innerNext(FluxConcatMap.java:282) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.FluxConcatMap$ConcatMapInner.onNext(FluxConcatMap.java:863) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:122) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:74) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1816) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:151) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:122) ~[reactor-core-3.4.23.jar:3.4.23] at reactor.core.publisher.MonoNext$NextSubscriber.onNext(MonoNext.java:82) ~[reactor-core-3.4.23.jar:3.4.23] java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter at io.jsonwebtoken.impl.Base64Codec.decode(Base64Codec.java:26) ~[jjwt-0.9.1.jar:0.9.1] at io.jsonwebtoken.impl.DefaultJwtParser.setSigningKey(DefaultJwtParser.java:151) ~[jjwt-0.9.1.jar:0.9.1] at com.microservice.apigateway.util.JwtUtils.validateJwtToken(JwtUtils.java:31) ~[classes/:na] at com.microservice.apigateway.filter.JwtAuthenticationFilter.filter(JwtAuthenticationFilter.java:55) Caused by: java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter
The exact location is in JWTUtils class with this line shown below.
Jwts.parser().setSigningKey(jwtSecret).parseClaimsJws(authToken);
How can I fix the issue?
Here is the repository : Link
Here is the screenshots : Link
Edited
After I added this dependency in pom.xml of api gateway shown below I got this issue. Here is the dependency
<dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.3.1</version> </dependency>
Here is the error:
java.lang.NullPointerException: Cannot invoke "io.jsonwebtoken.Claims.get(Object)" because "claims" is null at com.microservice.apigateway.filter.JwtAuthenticationFilter.filter(JwtAuthenticationFilter.java:66) ~[classes/:na]
Advertisement
Answer
After I revised some codes in JWTUTils in API Gateway, the issue disappeared.
Here is the solution
final String authorization = request.getHeaders().getOrEmpty("Authorization").get(0); final String token = authorization.replace("Bearer ", ""); jwtUtils.validateJwtToken(token);