本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}