当前位置: 首页>>代码示例>>Java>>正文


Java RequestContext.get方法代码示例

本文整理汇总了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;
}
 
开发者ID:spring-cloud-samples,项目名称:sample-zuul-filters,代码行数:18,代码来源:UppercaseRequestEntityFilter.java

示例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);
    }
}
 
开发者ID:ddebree,项目名称:pact-proxy,代码行数:18,代码来源:PactRecorderFilter.java

示例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;
}
 
开发者ID:spring-cloud-samples,项目名称:sample-zuul-filters,代码行数:33,代码来源:PrefixRequestEntityFilter.java

示例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;
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:11,代码来源:TokenRelayFilter.java

示例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;
}
 
开发者ID:xm-online,项目名称:xm-gate,代码行数:15,代码来源:TokenRelayFilter.java

示例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;
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-cloud,代码行数:28,代码来源:TracePostZuulFilter.java


注:本文中的com.netflix.zuul.context.RequestContext.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。