本文整理汇总了Java中com.netflix.zuul.context.RequestContext.get方法的典型用法代码示例。如果您正苦于以下问题:Java RequestContext.get方法的具体用法?Java RequestContext.get怎么用?Java RequestContext.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.netflix.zuul.context.RequestContext
的用法示例。
在下文中一共展示了RequestContext.get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: buildRequestBody
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
private void buildRequestBody(PactDslRequestWithPath pactRequest) throws IOException {
final RequestContext context = RequestContext.getCurrentContext();
String requestBody = null;
InputStream in = (InputStream) context.get("requestEntity");
if (in == null) {
in = context.getRequest().getInputStream();
}
if (in != null) {
String encoding = context.getRequest().getCharacterEncoding();
requestBody = StreamUtils.copyToString(in,
Charset.forName(encoding != null ? encoding : "UTF-8"));
}
if (requestBody != null && requestBody.length() > 0) {
pactRequest.body(requestBody);
}
}
示例3: 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 request wrapper: "+ body;
byte[] bytes = body.getBytes("UTF-8");
context.setRequest(new HttpServletRequestWrapper(getCurrentContext().getRequest()) {
@Override
public ServletInputStream getInputStream() throws IOException {
return new ServletInputStreamWrapper(bytes);
}
@Override
public int getContentLength() {
return bytes.length;
}
@Override
public long getContentLengthLong() {
return bytes.length;
}
});
}
catch (IOException e) {
rethrowRuntimeException(e);
}
return null;
}
示例4: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
Set<String> headers = (Set<String>) ctx.get("ignoredHeaders");
// We need our JWT tokens relayed to resource servers
headers.remove("authorization");
return null;
}
示例5: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
Set<String> headers = (Set<String>) ctx.get("ignoredHeaders");
// We need our JWT tokens relayed to resource servers
if (headers != null) {
headers.remove("authorization");
headers.remove("set-cookie");
headers.remove("cookie");
}
return null;
}
示例6: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
Object spanObject = ctx.get(TracePreZuulFilter.CONTEXT_SPAN_KEY);
if (spanObject instanceof Span) {
Span span = (Span) spanObject;
span.setTag(Tags.HTTP_STATUS.getKey(), ctx.getResponseStatusCode());
if (ctx.getThrowable() != null) {
onError(ctx.getThrowable(), span);
} else {
Object error = ctx.get("error.exception");
if (error instanceof Exception) {
onError((Exception) error, span);
}
}
if (ctx.getRouteHost() != null) {
span.setTag(ROUTE_HOST_TAG, ctx.getRouteHost().toString());
}
span.finish();
}
return null;
}