You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by GitBox <gi...@apache.org> on 2021/07/21 10:18:25 UTC

[GitHub] [incubator-shenyu] kevinw66 opened a new issue #1803: Jwt plugin throws JsonSyntaxException

kevinw66 opened a new issue #1803:
URL: https://github.com/apache/incubator-shenyu/issues/1803


   Jwt plugin read config `filterPath` as String value, the code is like below
   ```java
   Map<String, String> configMap = GsonUtils.getInstance().toObjectMap(pluginData.getConfig(), String.class);
   String secretKey = Optional.of(configMap.get(Constants.SECRET_KEY)).orElse("");
   String filterPath = Optional.of(configMap.get(Constants.FILTER_PATH)).orElse("");
   ```
   While sql script file is still use array as default value
   ```sql
   INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`, `enabled`, `date_created`, `date_updated`) VALUES ('19', 'jwt', 'authentication', 9, '{"secretKey":"key","filterPath":[]}', '0', '2021-05-24 17:58:37', '2021-05-25 15:38:04');
   ```
   This will cause JsonSyntaxException, full stack is like below
   ```
   com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 1 column 34 path $.
   	at com.google.gson.Gson.fromJson(Gson.java:899)
   	at com.google.gson.Gson.fromJson(Gson.java:852)
   	at com.google.gson.Gson.fromJson(Gson.java:801)
   	at org.apache.shenyu.common.utils.GsonUtils.toObjectMap(GsonUtils.java:219)
   	at org.apache.shenyu.plugin.jwt.handle.JwtPluginDataHandler.handlerPlugin(JwtPluginDataHandler.java:40)
   	at org.apache.shenyu.plugin.base.cache.CommonPluginDataSubscriber.lambda$null$1(CommonPluginDataSubscriber.java:123)
   	at java.util.Optional.ifPresent(Optional.java:159)
   	at org.apache.shenyu.plugin.base.cache.CommonPluginDataSubscriber.lambda$subscribeDataHandler$7(CommonPluginDataSubscriber.java:123)
   	at java.util.Optional.ifPresent(Optional.java:159)
   	at org.apache.shenyu.plugin.base.cache.CommonPluginDataSubscriber.subscribeDataHandler(CommonPluginDataSubscriber.java:118)
   	at org.apache.shenyu.plugin.base.cache.CommonPluginDataSubscriber.onSubscribe(CommonPluginDataSubscriber.java:50)
   	at java.util.ArrayList.forEach(ArrayList.java:1259)
   	at org.apache.shenyu.plugin.sync.data.websocket.handler.PluginDataHandler.doRefresh(PluginDataHandler.java:42)
   	at org.apache.shenyu.plugin.sync.data.websocket.handler.AbstractDataHandler.handle(AbstractDataHandler.java:68)
   	at org.apache.shenyu.plugin.sync.data.websocket.handler.WebsocketDataHandler.executor(WebsocketDataHandler.java:59)
   	at org.apache.shenyu.plugin.sync.data.websocket.client.ShenyuWebsocketClient.handleResult(ShenyuWebsocketClient.java:88)
   	at org.apache.shenyu.plugin.sync.data.websocket.client.ShenyuWebsocketClient.onMessage(ShenyuWebsocketClient.java:68)
   	at org.java_websocket.client.WebSocketClient.onWebsocketMessage(WebSocketClient.java:591)
   	at org.java_websocket.drafts.Draft_6455.processFrameText(Draft_6455.java:885)
   	at org.java_websocket.drafts.Draft_6455.processFrame(Draft_6455.java:819)
   	at org.java_websocket.WebSocketImpl.decodeFrames(WebSocketImpl.java:379)
   	at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:216)
   	at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:508)
   	at java.lang.Thread.run(Thread.java:748)
   ```
   
   
   Also `Optional.of()` will cause NullPointerException if the value is null, we should use `Optional.ofNullable()` instead.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-shenyu] dengliming closed issue #1803: Jwt plugin throws JsonSyntaxException

Posted by GitBox <gi...@apache.org>.
dengliming closed issue #1803:
URL: https://github.com/apache/incubator-shenyu/issues/1803


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org