本文整理汇总了Java中com.netflix.zuul.context.RequestContext.set方法的典型用法代码示例。如果您正苦于以下问题:Java RequestContext.set方法的具体用法?Java RequestContext.set怎么用?Java RequestContext.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.netflix.zuul.context.RequestContext
的用法示例。
在下文中一共展示了RequestContext.set方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
public Object run() {
try {
RequestContext context = getCurrentContext();
InputStream in = (InputStream) context.get("requestEntity");
if (in == null) {
in = context.getRequest().getInputStream();
}
String body = StreamUtils.copyToString(in, Charset.forName("UTF-8"));
// body = "request body modified via set('requestEntity'): "+ body;
body = body.toUpperCase();
context.set("requestEntity", new ByteArrayInputStream(body.getBytes("UTF-8")));
}
catch (IOException e) {
rethrowRuntimeException(e);
}
return null;
}
示例2: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
// span is a child of one created in servlet-filter
Span span = tracer.buildSpan(ctx.getRequest().getMethod())
.withTag(Tags.COMPONENT.getKey(), COMPONENT_NAME)
.startManual();
tracer.inject(span.context(), Format.Builtin.HTTP_HEADERS,
new TextMapInjectAdapter(ctx.getZuulRequestHeaders()));
ctx.set(CONTEXT_SPAN_KEY, span);
return null;
}
示例3: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
String auth = request.getHeader("Authorization");
String accessToken = auth.split(" ")[1];
ctx.set("LimitAccess", Boolean.TRUE);
try {
Triple<Long, String, Long> clientTriple = databaseUserDetailService.loadClientByToken(accessToken);
String user = clientTriple.getMiddle();
Long intervalInMills = clientTriple.getLeft();
Long limits = clientTriple.getRight();
if (intervalInMills != null && intervalInMills != 0l && limits != null && limits != 0l) {
if (!access(user, intervalInMills, limits)) {
ctx.set("LimitAccess", Boolean.FALSE);
ctx.setSendZuulResponse(false);
ctx.setResponseStatusCode(HttpServletResponse.SC_BAD_REQUEST);
ctx.setResponseBody("The times of usage is limited");
}
}
} catch (Throwable e) {
}
return null;
}
示例4: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
RequestContext context = RequestContext.getCurrentContext();
HttpServletRequest request = context.getRequest();
logger.info("Send {} request to {}", request.getMethod(), request.getRequestURL().toString());
String accessToken = request.getParameter("access_token");
if (accessToken == null) {
logger.warn("Access token is empty");
/*
context.setSendZuulResponse(false);
context.setResponseStatusCode(401);
*/
RuntimeException e = new RuntimeException("An exception.");
context.set("error.status_code", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
context.set("error.exception", e);
throw e;
}
logger.info("Access ok");
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);
}
}
}
示例6: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
Throwable throwable = RequestContext.getCurrentContext().getThrowable();
log.error("this is a ErrorFilter : {}", throwable.getCause().getMessage());
ctx.set("error.status_code", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
ctx.set("error.exception", throwable.getCause());
return null;
}
示例7: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
RequestContext context = RequestContext.getCurrentContext();
Throwable throwable = context.getThrowable();
context.set("error.status_code", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
context.set("exception", throwable.getCause());
return null;
}