本文整理汇总了Java中com.netflix.zuul.context.RequestContext.getResponse方法的典型用法代码示例。如果您正苦于以下问题:Java RequestContext.getResponse方法的具体用法?Java RequestContext.getResponse怎么用?Java RequestContext.getResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.netflix.zuul.context.RequestContext
的用法示例。
在下文中一共展示了RequestContext.getResponse方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
try {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletResponse response = ctx.getResponse();
if (!rateLimiter.tryAcquire()) {
HttpStatus httpStatus = HttpStatus.TOO_MANY_REQUESTS;
response.setContentType(MediaType.TEXT_PLAIN_VALUE);
response.setStatus(httpStatus.value());
ctx.setResponseStatusCode(httpStatus.value());
ctx.setSendZuulResponse(false);
}
} catch (Exception e) {
ReflectionUtils.rethrowRuntimeException(e);
}
return null;
}
示例2: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
try {
RequestContext currentContext = RequestContext.getCurrentContext();
HttpServletResponse response = currentContext.getResponse();
if (!rateLimiter.tryAcquire()) {
response.setContentType(MediaType.TEXT_PLAIN_VALUE);
response.setStatus(this.tooManyRequests.value());
response.getWriter().append(this.tooManyRequests.getReasonPhrase());
currentContext.setSendZuulResponse(false);
throw new ZuulException(this.tooManyRequests.getReasonPhrase(),
this.tooManyRequests.value(),
this.tooManyRequests.getReasonPhrase());
}
} catch (Exception e) {
ReflectionUtils.rethrowRuntimeException(e);
}
return null;
}
示例3: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
logger.info("Moving cookies from byte stream to header");
RequestContext ctx = RequestContext.getCurrentContext();
String rawCookies = responseBodyOf(ctx);
Map<String, String> cookies = jsonOf(ctx, rawCookies);
HttpServletResponse response = ctx.getResponse();
for (Map.Entry<String, String> entry : cookies.entrySet()) {
Cookie cookie = new Cookie(entry.getKey(), entry.getValue());
cookie.setPath("/");
response.addCookie(cookie);
}
ctx.setResponse(response);
ctx.setResponseBody("logged in");
return null;
}
示例4: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
public Object run() {
RequestContext context = RequestContext.getCurrentContext();
HttpServletResponse servletResponse = context.getResponse();
servletResponse.addHeader("X-Foo",
UUID.randomUUID().toString());
return null;
}
示例5: doFieldMappingRun
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
private void doFieldMappingRun() {
ZuulRouteDto route = this.loadRoute();
Map<String, String> fieldMap = route.getMappingField();
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
HttpServletResponse response = ctx.getResponse();
Map<String, String> valueMap = Maps.newHashMap();
for (Map.Entry<String, String> entry : fieldMap.entrySet()) {
String sourceFieldName = entry.getKey();
String targetFieldName = entry.getValue();
String fieldValue = request.getParameter(sourceFieldName);
valueMap.put(targetFieldName, fieldValue);
}
if (valueMap.isEmpty()) {
ctx.set("error.status_code", 400);
ctx.set("error.message", "param can not be empty");
} else {
try {
String result = remoteComponent.callRemoteService(route.getServiceName(), route.getGroup(),
route.getVersion(), route.getMethod(), valueMap);
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("application/json; charset=UTF-8");
response.getWriter().print(result);
} catch (Throwable e) {
ctx.set("error.status_code", 500);
ctx.set("error.message", e.getMessage());
ctx.set("error.exception", e);
}
}
}