1.0.3 commit .
diff --git a/script/soul.sql b/script/soul.sql
index c767974..7768028 100644
--- a/script/soul.sql
+++ b/script/soul.sql
@@ -123,13 +123,13 @@
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*plugin*/
-INSERT INTO `soul`.`plugin` (`id`, `name`, `enabled`, `date_created`, `date_updated`) VALUES ('1', 'sign','0', '1', '2018-06-14 10:17:35', '2018-06-14 10:17:35');
-INSERT INTO `soul`.`plugin` (`id`, `name`, `enabled`, `date_created`, `date_updated`) VALUES ('2', 'waf', '0','0', '2018-06-23 10:26:30', '2018-06-13 15:43:10');
-INSERT INTO `soul`.`plugin` (`id`, `name`, `enabled`, `date_created`, `date_updated`) VALUES ('3', 'rewrite', '0','0', '2018-06-23 10:26:34', '2018-06-25 13:59:31');
-INSERT INTO `soul`.`plugin` (`id`, `name`, `enabled`, `date_created`, `date_updated`) VALUES ('4', 'rate_limiter','0', '0', '2018-06-23 10:26:37', '2018-06-13 15:34:48');
-INSERT INTO `soul`.`plugin` (`id`, `name`, `enabled`, `date_created`, `date_updated`) VALUES ('5', 'divide', '0','0', '2018-06-25 10:19:10', '2018-06-13 13:56:04');
-INSERT INTO `soul`.`plugin` (`id`, `name`, `enabled`, `date_created`, `date_updated`) VALUES ('6', 'dubbo','0', '1', '2018-06-23 10:26:41', '2018-06-11 10:11:47');
-INSERT INTO `soul`.`plugin` (`id`, `name`, `enabled`, `date_created`, `date_updated`) VALUES ('7', 'monitor', '0','0', '2018-06-25 13:47:57', '2018-06-25 13:47:57');
-INSERT INTO `soul`.`plugin` (`id`, `name`, `enabled`, `date_created`, `date_updated`) VALUES ('8', 'springCloud','0', '1', '2018-06-25 13:47:57', '2018-06-25 13:47:57');
+INSERT INTO `soul`.`plugin` (`id`, `name`,`role`, `enabled`, `date_created`, `date_updated`) VALUES ('1', 'sign','0', '0', '2018-06-14 10:17:35', '2018-06-14 10:17:35');
+INSERT INTO `soul`.`plugin` (`id`, `name`,`role`,`enabled`, `date_created`, `date_updated`) VALUES ('2', 'waf', '0','0', '2018-06-23 10:26:30', '2018-06-13 15:43:10');
+INSERT INTO `soul`.`plugin` (`id`, `name`,`role`, `enabled`, `date_created`, `date_updated`) VALUES ('3', 'rewrite', '0','0', '2018-06-23 10:26:34', '2018-06-25 13:59:31');
+INSERT INTO `soul`.`plugin` (`id`, `name`,`role`,`enabled`, `date_created`, `date_updated`) VALUES ('4', 'rate_limiter','0', '0', '2018-06-23 10:26:37', '2018-06-13 15:34:48');
+INSERT INTO `soul`.`plugin` (`id`, `name`,`role`, `enabled`, `date_created`, `date_updated`) VALUES ('5', 'divide', '0','1', '2018-06-25 10:19:10', '2018-06-13 13:56:04');
+INSERT INTO `soul`.`plugin` (`id`, `name`,`role`,`enabled`, `date_created`, `date_updated`) VALUES ('6', 'dubbo','0', '1', '2018-06-23 10:26:41', '2018-06-11 10:11:47');
+INSERT INTO `soul`.`plugin` (`id`, `name`,`role`,`enabled`, `date_created`, `date_updated`) VALUES ('7', 'monitor', '0','0', '2018-06-25 13:47:57', '2018-06-25 13:47:57');
+INSERT INTO `soul`.`plugin` (`id`, `name`,`role`, `enabled`, `date_created`, `date_updated`) VALUES ('8', 'springCloud','0', '1', '2018-06-25 13:47:57', '2018-06-25 13:47:57');
/**user**/
INSERT INTO `soul`.`dashboard_user` (`id`, `user_name`, `password`, `role`, `enabled`, `date_created`, `date_updated`) VALUES ('1', 'admin', '123456', '1', '1', '2018-06-23 15:12:22', '2018-06-23 15:12:23');
\ No newline at end of file
diff --git a/soul-extend-demo/src/main/java/org/dromara/soul/extend/demo/config/CustomConfiguration.java b/soul-extend-demo/src/main/java/org/dromara/soul/extend/demo/config/CustomConfiguration.java
index 239a870..20b47d7 100644
--- a/soul-extend-demo/src/main/java/org/dromara/soul/extend/demo/config/CustomConfiguration.java
+++ b/soul-extend-demo/src/main/java/org/dromara/soul/extend/demo/config/CustomConfiguration.java
@@ -18,9 +18,11 @@
package org.dromara.soul.extend.demo.config;
-import org.dromara.soul.extend.demo.extend.FunctionPlugin;
+import org.dromara.soul.extend.demo.custom.CustomPlugin;
+import org.dromara.soul.extend.demo.dubbo.CustomGenericParamServiceImpl;
import org.dromara.soul.web.cache.ZookeeperCacheManager;
import org.dromara.soul.web.plugin.SoulPlugin;
+import org.dromara.soul.web.plugin.dubbo.GenericParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -35,6 +37,11 @@
private final ZookeeperCacheManager zookeeperCacheManager;
+ /**
+ * Instantiates a new Custom configuration.
+ *
+ * @param zookeeperCacheManager the zookeeper cache manager
+ */
@Autowired(required = false)
public CustomConfiguration(final ZookeeperCacheManager zookeeperCacheManager) {
this.zookeeperCacheManager = zookeeperCacheManager;
@@ -43,10 +50,20 @@
/**
* init Custom function plugin.
*
- * @return SoulPlugin.
+ * @return SoulPlugin. soul plugin
*/
@Bean
public SoulPlugin functionPlugin() {
- return new FunctionPlugin(zookeeperCacheManager);
+ return new CustomPlugin(zookeeperCacheManager);
+ }
+
+ /**
+ * Generic param service generic param service.
+ *
+ * @return the generic param service
+ */
+ @Bean
+ public GenericParamService genericParamService() {
+ return new CustomGenericParamServiceImpl();
}
}
diff --git a/soul-extend-demo/src/main/java/org/dromara/soul/extend/demo/extend/FunctionPlugin.java b/soul-extend-demo/src/main/java/org/dromara/soul/extend/demo/custom/CustomPlugin.java
similarity index 66%
rename from soul-extend-demo/src/main/java/org/dromara/soul/extend/demo/extend/FunctionPlugin.java
rename to soul-extend-demo/src/main/java/org/dromara/soul/extend/demo/custom/CustomPlugin.java
index ae60893..74a2c16 100644
--- a/soul-extend-demo/src/main/java/org/dromara/soul/extend/demo/extend/FunctionPlugin.java
+++ b/soul-extend-demo/src/main/java/org/dromara/soul/extend/demo/custom/CustomPlugin.java
@@ -16,11 +16,13 @@
*
*/
-package org.dromara.soul.extend.demo.extend;
+package org.dromara.soul.extend.demo.custom;
import org.dromara.soul.common.dto.zk.RuleZkDTO;
import org.dromara.soul.common.dto.zk.SelectorZkDTO;
import org.dromara.soul.common.enums.PluginTypeEnum;
+import org.dromara.soul.common.utils.GsonUtils;
+import org.dromara.soul.extend.demo.entity.Test;
import org.dromara.soul.web.cache.ZookeeperCacheManager;
import org.dromara.soul.web.plugin.AbstractSoulPlugin;
import org.dromara.soul.web.plugin.SoulPluginChain;
@@ -37,19 +39,22 @@
*
* @author xiaoyu(Myth)
*/
-public class FunctionPlugin extends AbstractSoulPlugin {
+public class CustomPlugin extends AbstractSoulPlugin {
/**
* logger.
*/
- private static final Logger LOGGER = LoggerFactory.getLogger(FunctionPlugin.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(CustomPlugin.class);
- public FunctionPlugin(final ZookeeperCacheManager dataCacheManager) {
+ public CustomPlugin(final ZookeeperCacheManager dataCacheManager) {
super(dataCacheManager);
}
/**
* return plugin type.
+ * The type of plug-ins indicates their order at runtime
+ * The PluginTypeEnum.BEFORE is first
+ * The PluginTypeEnum.LAST is last.
*
* @return {@linkplain PluginTypeEnum}
*/
@@ -60,6 +65,7 @@
/**
* return plugin order .
+ * The same plugin he executes in the same order.
*
* @return int
*/
@@ -70,16 +76,20 @@
/**
* acquire plugin name.
+ * return you custom plugin name.
+ * It must be the same name as the plug-in you added in the admin background.
*
* @return plugin name.
*/
@Override
public String named() {
- return "waf";
+ return "test";
}
/**
* plugin is execute.
+ * Do I need to skip.
+ * if you need skip return true.
*
* @param exchange the current server exchange
* @return default false.
@@ -92,6 +102,26 @@
@Override
protected Mono<Void> doExecute(ServerWebExchange exchange, SoulPluginChain chain, SelectorZkDTO selector, RuleZkDTO rule) {
LOGGER.debug(".......... function plugin start..............");
+
+ /*
+ * Processing after your selector matches the rule.
+ * rule.getHandle() is you Customize the json string to be processed.
+ * for this example.
+ * Convert your custom json string pass to an entity class.
+ */
+ final String ruleHandle = rule.getHandle();
+
+ final Test test = GsonUtils.getInstance().fromJson(ruleHandle, Test.class);
+
+ /*
+ * Then do your own business processing.
+ * The last execution chain.execute(exchange).
+ * Let it continue on the chain until the end.
+ */
+
+ System.out.println(test.toString());
+
+
return chain.execute(exchange);
}
}
diff --git a/soul-extend-demo/src/main/java/org/dromara/soul/extend/demo/dubbo/CustomGenericParamServiceImpl.java b/soul-extend-demo/src/main/java/org/dromara/soul/extend/demo/dubbo/CustomGenericParamServiceImpl.java
new file mode 100644
index 0000000..b2f945d
--- /dev/null
+++ b/soul-extend-demo/src/main/java/org/dromara/soul/extend/demo/dubbo/CustomGenericParamServiceImpl.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.dromara.soul.extend.demo.dubbo;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+import org.dromara.soul.common.constant.DubboParamConstants;
+import org.dromara.soul.common.utils.GsonUtils;
+import org.dromara.soul.web.plugin.dubbo.GenericParamService;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The type Custom generic param service.
+ *
+ * @author xiaoyu(Myth)
+ */
+public class CustomGenericParamServiceImpl implements GenericParamService {
+
+ /**
+ * It parses itself based on the json string passed in by the body.
+ * Return dubbo GenericService Invoker need param
+ * see {@linkplain com.alibaba.dubbo.rpc.service.GenericService}
+ * @param paramMap the param map
+ * @return the left is parameter type. the right is Parameter Values.
+ */
+ @Override
+ public Pair<String[], Object[]> buildParameter(final Map<String, Object> paramMap) {
+ List<String> paramType = Lists.newArrayList();
+ List<Object> args = Lists.newArrayList();
+ if (paramMap.containsKey(DubboParamConstants.PARAM_CLASS)) {
+ List<String> clazz = GsonUtils.getInstance()
+ .fromList(paramMap.get(DubboParamConstants.PARAM_CLASS).toString(), String[].class);
+ paramType.addAll(clazz);
+ final Object classParams = paramMap.get(DubboParamConstants.CLASS_PARAMS);
+ args.addAll(GsonUtils.getInstance()
+ .fromJson(classParams.toString(), List.class));
+ }
+ return new ImmutablePair<>(paramType.toArray(new String[0]), args.toArray());
+ }
+}
diff --git a/soul-extend-demo/src/main/java/org/dromara/soul/extend/demo/entity/Test.java b/soul-extend-demo/src/main/java/org/dromara/soul/extend/demo/entity/Test.java
new file mode 100644
index 0000000..d63c130
--- /dev/null
+++ b/soul-extend-demo/src/main/java/org/dromara/soul/extend/demo/entity/Test.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.dromara.soul.extend.demo.entity;
+
+import lombok.Data;
+
+/**
+ * The type Test.
+ *
+ * @author xiaoyu(Myth)
+ */
+@Data
+public class Test {
+
+ private String id;
+
+ private String name;
+}