当前位置: 首页 > news >正文

深圳网站建设公司模板0基础学网站设计

深圳网站建设公司模板,0基础学网站设计,网站建设可行性报告,一个几个人做网站的几个故事电影黑名单配置 黑名单就是那些被禁止访问的URL创建自定义过滤器 BlackListUrlFilter,并配置黑名单地址列表blacklistUrl如果有其他需求,还可以实现自定义规则的过滤器来满足特定的过滤要求 /*** 黑名单过滤器** author canghe*/ Component public class B…

黑名单配置

  • 黑名单就是那些被禁止访问的URL
  • 创建自定义过滤器 BlackListUrlFilter,并配置黑名单地址列表blacklistUrl
  • 如果有其他需求,还可以实现自定义规则的过滤器来满足特定的过滤要求
/*** 黑名单过滤器** @author canghe*/
@Component
public class BlackListUrlFilter extends AbstractGatewayFilterFactory<BlackListUrlFilter.Config>
{@Overridepublic GatewayFilter apply(Config config){return (exchange, chain) -> {String url = exchange.getRequest().getURI().getPath();if (config.matchBlacklist(url)){return ServletUtils.webFluxResponseWriter(exchange.getResponse(), "请求地址不允许访问");}return chain.filter(exchange);};}public BlackListUrlFilter(){super(Config.class);}public static class Config{private List<String> blacklistUrl;private List<Pattern> blacklistUrlPattern = new ArrayList<>();public boolean matchBlacklist(String url){return !blacklistUrlPattern.isEmpty() && blacklistUrlPattern.stream().anyMatch(p -> p.matcher(url).find());}public List<String> getBlacklistUrl(){return blacklistUrl;}public void setBlacklistUrl(List<String> blacklistUrl){this.blacklistUrl = blacklistUrl;this.blacklistUrlPattern.clear();this.blacklistUrl.forEach(url -> {this.blacklistUrlPattern.add(Pattern.compile(url.replaceAll("\\*\\*", "(.*?)"), Pattern.CASE_INSENSITIVE));});}}}
  • 在Nacos的pmhub-gateway-dev.yml 中配置需要拉黑的请求路径

image.png

  • **拦截之后结果如下 : **

image.png

白名单配置

  • 白名单就是允许访问的地址。且无需登录就能访问
  • 比如登录、注册接口,以及其他的不需要网关做鉴权的接口
  • 在全局过滤器**AuthFilter**第一步就校验是否为白名单

```java // 跳过不需要验证的路径 if (StringUtils.matches(url, ignoreWhite.getWhites())) { return chain.filter(exchange); } ``` ![image.png](https://img-blog.csdnimg.cn/img_convert/039bd801d452b9b721ff2d031f1c0812.png)
  • **在 ****ignore**中设置 **whites**,表示允许匿名访问

image.png

统计接口调用耗时

  • 在全局过滤器处理完其他操作之后再记录时间
  • 全局过滤器: 1.白名单过滤 2.Token鉴权 3.设置用户信息到请求 4. 接口调用耗时

image.png

  • 计算接口调用总耗时

return chain.filter(exchange).then(Mono.fromRunnable(()->{Long beginVisitTime = exchange.getAttribute(BEGIN_VISIT_TIME);if (beginVisitTime != null){log.info("访问接口主机: " + exchange.getRequest().getURI().getHost());log.info("访问接口端口: " + exchange.getRequest().getURI().getPort());log.info("访问接口URL: " + exchange.getRequest().getURI().getPath());log.info("访问接口URL参数: " + exchange.getRequest().getURI().getRawQuery());log.info("访问接口时长: " + (System.currentTimeMillis() - beginVisitTime) + "ms");log.info("我是美丽分割线: ###################################################");System.out.println();}
}));
  • 感觉还是自带的计时工具好用一些, 不过不支持异步
/*** 统计耗时工具类, 这个只支持同步的耗时打印,不支持异步的场景** @author YiHui* @date 2023/11/10*/
public class StopWatchUtil {private StopWatch stopWatch;private StopWatchUtil(String task) {stopWatch = task == null ? new StopWatch() : new StopWatch(task);}/*** 初始化** @param task* @return*/public static StopWatchUtil init(String... task) {return new StopWatchUtil(task.length > 0 ? task[0] : null);}/*** 同步耗时计时** @param task 任务名* @param call 执行业务逻辑* @param <T>  返回类型* @return 返回结果*/public <T> T record(String task, Callable<T> call) {stopWatch.start(task);try {return call.call();} catch (Exception e) {throw new RuntimeException(e);} finally {stopWatch.stop();}}/*** 同步耗时计时** @param task 任务名* @param run  执行业务逻辑*/public void record(String task, Runnable run) {stopWatch.start(task);try {run.run();} finally {stopWatch.stop();}}/*** 计时信息输出** @return*/public String prettyPrint() {return stopWatch.prettyPrint();}
}
  • 下面是一个使用**StopWatchUtil**的例子
  • 先初始化**StopWatchUtil stopWatchUtil = StopWatchUtil.init("图片上传");**
  • 再stopWatchUtil.record(“流转字节”, () -> StreamUtils.copyToByteArray(finalInput));
  • 最后**log.info("图片上传耗时: {}", stopWatchUtil.prettyPrint());**
@Overridepublic String upload(InputStream input, String fileType) {// 记录耗时分布StopWatchUtil stopWatchUtil = StopWatchUtil.init("图片上传");try {if (fileType == null) {// 根据魔数判断文件类型InputStream finalInput = input;byte[] bytes = stopWatchUtil.record("流转字节", () -> StreamUtils.copyToByteArray(finalInput));input = new ByteArrayInputStream(bytes);fileType = getFileType((ByteArrayInputStream) input, fileType);}String path = imageProperties.getAbsTmpPath() + imageProperties.getWebImgPath();String fileName = genTmpFileName();InputStream finalInput = input;String finalFileType = fileType;FileWriteUtil.FileInfo file = stopWatchUtil.record("存储", () -> FileWriteUtil.saveFileByStream(finalInput, path, fileName, finalFileType));return imageProperties.buildImgUrl(imageProperties.getWebImgPath() + file.getFilename() + "." + file.getFileType());} catch (Exception e) {log.error("Parse img from httpRequest to BufferedImage error! e:", e);throw ExceptionUtil.of(StatusEnum.UPLOAD_PIC_FAILED);} finally {log.info("图片上传耗时: {}", stopWatchUtil.prettyPrint());}}
http://www.yayakq.cn/news/621457/

相关文章:

  • 怎么查看网站的ftp软件应用商店下载免费
  • 全球网站流量排名100小红书seo是什么意思
  • 深圳制作网站主页杭州网站维护公司
  • 全国做网站的百度搜索推广怎么做
  • 襄阳网站建设找下拉哥科技凡客诚品创始人
  • 高端网吧电脑配置重庆网站搜索引擎seo
  • 公司百度网站怎么做泉州软件开发制作
  • 用asp做的一个网站实例源代码陕西网站建设培训
  • 濮阳网站网站建设做单位网站的公司吗
  • 珠海网站建设工程短链接生成接口
  • 天津手机网站公司网站建设交接清单
  • wordpress手机菜单导航seo自动点击排名
  • 竞价网站策划网站开发的毕业设计题目
  • 如何做网站的登录注册北海网站优化
  • 网站建设_免费视频怎样修改网站标题
  • 电商网站开发数据库设计开发板是什么
  • 厦门市app开发网站建设公司wordpress 英文转中文
  • 营销形网站dw做的网站怎么去掉
  • 如何自己买域做网站网站运营是做什么的
  • 唐山培训网站建设优改网logo设计免费官网入口
  • 网站建设文字教程网站建设预算和维护
  • 单本小说网站网站备案查询不到说明啥
  • 音乐网站开发案例安徽工业大学两学一做网站
  • 衡水建设企业网站免费申请网站空间
  • asp在网站开发中起什么作用wordpress 移动主题
  • 那个网站做logo兼职我是做网站的 怎么才能提高业绩
  • 做网站和推广找哪家好平顶山做网站推广
  • 网站建设代码问卷调查泉州自主建站模板
  • 做微信的网站有哪些功能网站设计尺寸
  • 网站建设服务8网站建设的工作人员