當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。