当前位置: 首页>>代码示例>>Java>>正文


Java RequestContext.getRequest方法代码示例

本文整理汇总了Java中com.netflix.zuul.context.RequestContext.getRequest方法的典型用法代码示例。如果您正苦于以下问题:Java RequestContext.getRequest方法的具体用法?Java RequestContext.getRequest怎么用?Java RequestContext.getRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.netflix.zuul.context.RequestContext的用法示例。


在下文中一共展示了RequestContext.getRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();

    log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString()));

    Object accessToken = request.getParameter("accessToken");
    if(accessToken == null) {
        log.warn("access token is empty");
        ctx.setSendZuulResponse(false);
        ctx.setResponseBody("401");
        ctx.setResponseStatusCode(401);
        return null;
    }
    log.info("access token ok");
    return null;
}
 
开发者ID:DemoHubs,项目名称:hlxy-docker,代码行数:19,代码来源:AccessFilter.java

示例2: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
/**
 * filter 具体的逻辑
 */
@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();
    String uri = request.getRequestURI();
    if (uri.equals("/hi-service/upload") || uri.equals("/zuul/hi-service/upload")) {
        return ctx;
    }
    String token = request.getHeader("x-auth-token");
    if (StringUtils.isEmpty(token)) {
        ctx.setSendZuulResponse(false);
        ctx.setResponseStatusCode(401);
        ctx.setResponseBody("no token");
        return null;
    }
    if (!TOKEN_AUTH.equals(token)) {
        ctx.setSendZuulResponse(false);
        ctx.setResponseStatusCode(401);
        ctx.setResponseBody("token auth fail");
        return null;
    }
    ctx.addZuulRequestHeader("userInfo", "{\"name\":\"Tom\",\"age\":18}");
    return ctx;
}
 
开发者ID:yangdd1205,项目名称:spring-cloud-master,代码行数:28,代码来源:CustomAuthFilter.java

示例3: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
    public Object run() {
    	LOGGER.info("==============================================");
        RequestContext ctx = RequestContext.getCurrentContext();
        HttpServletRequest request = ctx.getRequest();
        LOGGER.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString()));
//        Object accessToken = request.getParameter("accessToken");
//        if(accessToken == null) {
//        	LOGGER.warn("access token is empty");
//            ctx.setSendZuulResponse(false);
//            ctx.setResponseStatusCode(401);
//            return null;
//        }
//        LOGGER.info("access token ok");
        String authString = request.getHeader("Authorization");
        LOGGER.info("authString: {}", authString);
        LOGGER.info("==============================================");
        return null;
    }
 
开发者ID:junneyang,项目名称:xxproject,代码行数:20,代码来源:AccessFilter.java

示例4: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
	RequestContext context = getCurrentRequestContext();
	HttpServletRequest request = context.getRequest();

       Long remainingLimit = null;
	for (RateLimitCheck rl : filterConfig.getRateLimitChecks()) {
		ConsumptionProbe probe = rl.rateLimit(request);
		if (probe != null) {
			if (probe.isConsumed()) {
				remainingLimit = getRemainingLimit(remainingLimit, probe);
			} else {
				context.setResponseStatusCode(HttpStatus.TOO_MANY_REQUESTS.value());
				context.setResponseBody(filterConfig.getHttpResponseBody());
				context.setSendZuulResponse(false);
				break;
			}
			if(filterConfig.getStrategy().equals(RateLimitConditionMatchingStrategy.FIRST)) {
				break;
			}
		}
	};

	return null;
}
 
开发者ID:MarcGiffing,项目名称:bucket4j-spring-boot-starter,代码行数:26,代码来源:ZuulRateLimitFilter.java

示例5: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
    RequestContext ctx= RequestContext.getCurrentContext();
    HttpServletRequest req=ctx.getRequest();
    String ipAddr=this.getIpAddr(req);
    logger.info("请求IP地址为:[{}]",ipAddr);
   //配置本地IP白名单,生产环境可放入数据库或者redis中
    List<String> ips=new ArrayList<String>();
    ips.add("0:0:0:0:0:0:0:1");
    ips.add("172.0.0.1");
    ips.add("10.17.30.1");


    if(!ips.contains(ipAddr)){
        logger.info("IP地址校验不通过!!!");
        ctx.setResponseStatusCode(401);
        ctx.setSendZuulResponse(false);
        ctx.setResponseBody("IpAddr is forbidden!");
    }else{
        logger.info("IP地址校验通过.");
    }
    return null;
}
 
开发者ID:gengkangkang,项目名称:springcloud,代码行数:24,代码来源:IPFilter.java

示例6: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
/**
 * 过滤器的具体逻辑。需要注意,这里我们通过ctx.setSendZuulResponse(false)令zuul过滤该请求,不对其进行路由,
 * 然后通过ctx.setResponseStatusCode(401)设置了其返回的错误码,当然我们也可以进一步优化我们的返回,
 * 比如,通过ctx.setResponseBody(body)对返回body内容进行编辑等。
 */
@Override
public Object run() {
	RequestContext ctx = RequestContext.getCurrentContext();
	HttpServletRequest request = ctx.getRequest();
	log.info(String.format("%s request to %s", request.getMethod(), request
			.getRequestURL().toString()));
	Object accessToken = request.getParameter("accessToken");
	if (accessToken == null) {
		log.warn("access token is empty");
		ctx.setSendZuulResponse(false);
		ctx.setResponseStatusCode(401);
		return null;
	}
	log.info("access token ok");
	return null;
}
 
开发者ID:hutou-workhouse,项目名称:miscroServiceHello,代码行数:22,代码来源:AccessFilter.java

示例7: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();

    System.out.println("post:" + String.format("%s %s request to %s", request.getMethod(), request.getHeader("Authorization"), request.getRequestURL().toString()));

    return null;
}
 
开发者ID:zyndev,项目名称:zyndev-spring-cloud,代码行数:10,代码来源:PostFilter.java

示例8: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();
    log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString()));
    Object accessToken = request.getParameter("accessToken");
    if (accessToken == null) {
        log.warn("access token is empty");
        ctx.setSendZuulResponse(false);
        ctx.setResponseStatusCode(401);
        return null;
    }
    log.info("access token ok");
    return null;
}
 
开发者ID:nellochen,项目名称:springboot-start,代码行数:16,代码来源:AccessFilter.java

示例9: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
    long requestId = COUNTER.incrementAndGet();
    try {
        RequestContext context = RequestContext.getCurrentContext();
        HttpServletRequest request = context.getRequest();

        String url = request.getRequestURL().toString();

        LOGGER.info("Request context: {}", context);
        LOGGER.info("Request {}: {} request to {}", requestId, request.getMethod(), url);

        PactDslRequestWithPath pactRequest = ConsumerPactBuilder
                .consumer(clientName)
                .hasPactWith(providerName)
                .uponReceiving("Request id " + requestId)
                    .path(url)
                    .method(request.getMethod());
        buildRequestBody(pactRequest);

        PactDslResponse pactResponse = pactRequest
                .willRespondWith()
                    .status(context.getResponseStatusCode());
        buildResponseBody(pactResponse);

        RequestResponsePact pact = pactResponse.toFragment().toPact();

        pactResultWriter.writePact(url, requestId, pact);
    } catch (IOException e) {
        rethrowRuntimeException(e);
    }

    return null;
}
 
开发者ID:ddebree,项目名称:pact-proxy,代码行数:35,代码来源:PactRecorderFilter.java

示例10: shouldFilter

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public boolean shouldFilter() {
	RequestContext currentContext = RequestContext.getCurrentContext();
	HttpServletRequest request = currentContext.getRequest();
	String requestURI = request.getRequestURI();
	return requestURI.matches(filterConfig.getUrl());
}
 
开发者ID:MarcGiffing,项目名称:bucket4j-spring-boot-starter,代码行数:8,代码来源:ServletRateLimitFilter.java

示例11: shouldFilter

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public boolean shouldFilter() {
	RequestContext ctx = RequestContext.getCurrentContext();
	boolean isRedirect = ctx.getResponseStatusCode() == 302;
	if (!isRedirect)
		return false;

	boolean hasCorrectLocation = false;

	List<Pair<String, String>> zuulResponseHeaders = ctx.getZuulResponseHeaders();
	for (Pair<String, String> zuulResponseHeader : zuulResponseHeaders) {
		if ("Location".equalsIgnoreCase(zuulResponseHeader.first())) {
			HttpServletRequest request = ctx.getRequest();
			String path = urlPathHelper.getPathWithinApplication(request);
			Route route = routeLocator.getMatchingRoute(path);
			UriComponents redirectTo = ServletUriComponentsBuilder
					.fromHttpUrl(zuulResponseHeader.second()).build();
			UriComponents routeLocation = ServletUriComponentsBuilder
					.fromHttpUrl(route.getLocation()).build();

			if (redirectTo.getHost().equalsIgnoreCase(routeLocation.getHost())
					&& redirectTo.getPort() == routeLocation.getPort()) {
				String toLocation = ServletUriComponentsBuilder
						.fromHttpUrl(zuulResponseHeader.second())
						.host(request.getServerName())
						.port(request.getServerPort())
						.replacePath(
								buildRoutePath(route, zuulResponseHeader.second()))
						.build().toUriString();

				ctx.put(REDIRECT_TO_URL, toLocation);
				hasCorrectLocation = true;
				break;
			}
		}
	}

	return hasCorrectLocation;
}
 
开发者ID:mthizo247,项目名称:spring-cloud-netflix-zuul-websocket,代码行数:40,代码来源:ProxyRedirectFilter.java

示例12: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();
    _log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString()));
    Object accessToken = request.getParameter("accessToken");
    /*if(accessToken == null) {
        log.warn("access token is empty");
        ctx.setSendZuulResponse(false);
        ctx.setResponseStatusCode(401);
        return null;
    }*/
    return null;
}
 
开发者ID:ywtnhm,项目名称:pay-xxpay-master,代码行数:15,代码来源:AccessFilter.java

示例13: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
public Object run() {
	RequestContext ctx = getCurrentContext();
	HttpServletRequest request = ctx.getRequest();
	// put the serviceId in `RequestContext`
	ctx.put("serviceId", request.getParameter("service"));
	return null;
}
 
开发者ID:spring-cloud-samples,项目名称:sample-zuul-filters,代码行数:8,代码来源:QueryParamServiceIdPreFilter.java

示例14: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();

    LOG.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString()));

    return null;
}
 
开发者ID:jonashackt,项目名称:cxf-spring-cloud-netflix-docker,代码行数:10,代码来源:LoggingFilter.java

示例15: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
public Object run() {
	RequestContext ctx = getCurrentContext();
	HttpServletRequest request = ctx.getRequest();
	// put the serviceId in `RequestContext`
	String port = request.getParameter("port");
	try {
		URL url = UriComponentsBuilder.fromUri(ctx.getRouteHost().toURI())
				.port(new Integer(port))
				.build().toUri().toURL();
		ctx.setRouteHost(url);
	} catch (Exception e) {
		ReflectionUtils.rethrowRuntimeException(e);
	}
	return null;
}
 
开发者ID:spring-cloud-samples,项目名称:sample-zuul-filters,代码行数:16,代码来源:QueryParamPortPreFilter.java


注:本文中的com.netflix.zuul.context.RequestContext.getRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。