过滤器部署及测试
首先要部署容器端过滤器,假设已经部署了ubsi.demo.hello微服务的localhost#7112容器还在运行,我们的部署步骤如下:
将过滤器发布到maven仓库
mvn clean deploy
创建过滤器的部署文件,比如 deploy.demo.filter.json:
{ "maven_url": "http://maven.aliyun.com/nexus/content/groups/public/", "maven_repo": [ { "url" : "https://maven.pkg.github.com/ubsi-home/release/", "user": "{your-github-account}", "password": "{your-github-Personal_Access_Token}" }, { "url" : "{your-maven-repository-url}", "user": "{your-maven-account}", "password": "{your-maven-password}" } ], "service_name": null, "service_class": "ubsi.demo.filter.Container", "jar_group": "ubsi.demo", "jar_artifact": "ubsi.demo.filter", "jar_version": "1.0", "resource_path": "", "config": null }
通过命令行部署工具进行部署:
> java -jar rewin.service.ubsi.repo-2.3.0-jar-with-dependencies.jar deploy.demo.filter.json 000.031 开始运行,读取部署文件 000.229 获取最新的JAR包 004.010 启动UBSI Consumer,开始部署 004.244 查找JAR包的依赖关系 006.103 检查目标容器:localhost#7112 009.759 ---------------- 009.775 部署ubsi.demo.filter : 1.0 009.790 上传ubsi.demo.filter-1.0.jar 009.806 注册ubsi.demo.filter-1.0.jar 009.853 上传资源文件: 无 009.853 添加过滤器ubsi.demo.filter.Container 009.884 设置配置参数: 无 009.884 ---------------- 009.884 启动过滤器ubsi.demo.filter.Container 009.900 部署结束,启动成功
```
容器端过滤器部署成功后,我们可以用Request命令行工具来访问一下服务接口。
先要设置consumer-filter,在当前目录下创建rewin.ubsi.consumer.json文件,内容如下:
```json { "filters": [ "ubsi.demo.filter.Consumer" ] }
然后执行Request命令:
`java -cp rewin.ubsi.core-2.3.0-jar-with-dependencies.jar;target\classes rewin.ubsi.cli.Request ubsi.demo.hello hello 测试员`
会得到如下输出结果:
before: 参数 "测试员" 被加密为 "e6b58be8af95e59198" after: 结果 "756273693a2068656c6c6f2c20e6b58be8af95e59198" 被解密为 "ubsi: hello, 测试员" "ubsi: hello, 测试员" ```