• 大小: 1.58MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-16
  • 语言: 其他
  • 标签: springcloud  

资源简介

springcloud_教程 springcloud_教程 https://blog.csdn.net/hellozpc/article/details/83692496 https://blog.csdn.net/hellozpc/article/details/83692496

资源截图

代码片段和文件信息

package com.zpc.gateway.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 *  网关过滤器
 *  加入到Spring容器
 * @author Evan
 */
@Component
public class UserLoginZuulFilter extends ZuulFilter {

    @Override
    public boolean shouldFilter() {
        return true; // 该过滤器需要执行
    }

    @Override
    public object run() { //编写业务逻辑
        RequestContext requestContext = RequestContext.getCurrentContext();
        HttpServletRequest request = requestContext.getRequest();
        String token = request.getParameter(“token“);
        if(StringUtils.isEmpty(token)){
            requestContext.setSendZuulResponse(false); // 过滤该请求,不对其进行路由
            requestContext.setResponseStatusCode(401); // 设置响应状态码
            requestContext.setResponseBody(“ token is empty!!“); // 设置响应状态码
            return null;
        }
        return null;
    }

    @Override
    public String filterType() {
        return “pre“; // 设置过滤器类型为:pre
    }

    @Override
    public int filterOrder() {
        return 0;// 设置执行顺序为0
    }

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-11-08 22:36  microservice-api-gateway\
     目录           0  2018-11-08 23:56  microservice-api-gateway\.idea\
     文件         778  2018-11-04 16:05  microservice-api-gateway\.idea\compiler.xml
     文件         256  2018-11-04 16:05  microservice-api-gateway\.idea\encodings.xml
     目录           0  2018-11-04 15:57  microservice-api-gateway\.idea\inspectionProfiles\
     文件         418  2018-11-04 15:57  microservice-api-gateway\.idea\inspectionProfiles\Project_Default.xml
     目录           0  2018-11-08 22:36  microservice-api-gateway\.idea\libraries\
     文件         462  2018-11-04 16:32  microservice-api-gateway\.idea\libraries\Maven__antlr_antlr_2_7_7.xml
     文件         514  2018-11-04 16:32  microservice-api-gateway\.idea\libraries\Maven__aopalliance_aopalliance_1_0.xml
     文件         568  2018-11-04 16:05  microservice-api-gateway\.idea\libraries\Maven__ch_qos_logback_logback_classic_1_2_3.xml
     文件         547  2018-11-04 16:05  microservice-api-gateway\.idea\libraries\Maven__ch_qos_logback_logback_core_1_2_3.xml
     文件         543  2018-11-04 16:05  microservice-api-gateway\.idea\libraries\Maven__commons_codec_commons_codec_1_11.xml
     文件         616  2018-11-04 16:05  microservice-api-gateway\.idea\libraries\Maven__commons_collections_commons_collections_3_2_2.xml
     文件         624  2018-11-04 16:05  microservice-api-gateway\.idea\libraries\Maven__commons_configuration_commons_configuration_1_8.xml
     文件         503  2018-11-04 16:08  microservice-api-gateway\.idea\libraries\Maven__commons_io_commons_io_2_4.xml
     文件         547  2018-11-04 16:32  microservice-api-gateway\.idea\libraries\Maven__commons_jxpath_commons_jxpath_1_3.xml
     文件         525  2018-11-04 16:05  microservice-api-gateway\.idea\libraries\Maven__commons_lang_commons_lang_2_6.xml
     文件         522  2018-11-04 16:05  microservice-api-gateway\.idea\libraries\Maven__com_fasterxml_classmate_1_3_4.xml
     文件         644  2018-11-04 16:05  microservice-api-gateway\.idea\libraries\Maven__com_fasterxml_jackson_core_jackson_annotations_2_9_0.xml
     文件         595  2018-11-04 16:05  microservice-api-gateway\.idea\libraries\Maven__com_fasterxml_jackson_core_jackson_core_2_9_7.xml
     文件         623  2018-11-04 16:05  microservice-api-gateway\.idea\libraries\Maven__com_fasterxml_jackson_core_jackson_databind_2_9_7.xml
     文件         674  2018-11-04 16:05  microservice-api-gateway\.idea\libraries\Maven__com_fasterxml_jackson_datatype_jackson_datatype_jdk8_2_9_7.xml
     文件         688  2018-11-04 16:05  microservice-api-gateway\.idea\libraries\Maven__com_fasterxml_jackson_datatype_jackson_datatype_jsr310_2_9_7.xml
     文件         701  2018-11-04 16:08  microservice-api-gateway\.idea\libraries\Maven__com_fasterxml_jackson_module_jackson_module_afterburner_2_9_7.xml
     文件         729  2018-11-04 16:05  microservice-api-gateway\.idea\libraries\Maven__com_fasterxml_jackson_module_jackson_module_parameter_names_2_9_7.xml
     文件         605  2018-11-04 16:32  microservice-api-gateway\.idea\libraries\Maven__com_github_andrewoma_dexx_dexx_collections_0_2.xml
     文件         581  2018-11-04 16:32  microservice-api-gateway\.idea\libraries\Maven__com_github_vlsi_compactmap_compactmap_1_2_1.xml
     文件         545  2018-11-04 16:05  microservice-api-gateway\.idea\libraries\Maven__com_google_code_findbugs_jsr305_3_0_1.xml
     文件         515  2018-11-04 16:32  microservice-api-gateway\.idea\libraries\Maven__com_google_code_gson_gson_2_8_5.xml
     文件         499  2018-11-08 22:36  microservice-api-gateway\.idea\libraries\Maven__com_google_guava_guava_20_0.xml
     文件         510  2018-11-04 16:32  microservice-api-gateway\.idea\libraries\Maven__com_google_inject_guice_4_1_0.xml
............此处省略2705个文件信息

评论

共有 条评论