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


Java RequestContext.setRequest方法代码示例

本文整理汇总了Java中com.netflix.zuul.context.RequestContext.setRequest方法的典型用法代码示例。如果您正苦于以下问题:Java RequestContext.setRequest方法的具体用法?Java RequestContext.setRequest怎么用?Java RequestContext.setRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.netflix.zuul.context.RequestContext的用法示例。


在下文中一共展示了RequestContext.setRequest方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run_on_valid_response

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Test
public void run_on_valid_response() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/service1" + DEFAULT_URL);
    RequestContext context = RequestContext.getCurrentContext();
    context.setRequest(request);

    MockHttpServletResponse response = new MockHttpServletResponse();
    context.setResponseGZipped(false);
    context.setResponse(response);

    InputStream in = IOUtils.toInputStream("{\"basePath\":\"/\"}", StandardCharsets.UTF_8);
    context.setResponseDataStream(in);

    filter.run();

    assertEquals("UTF-8", response.getCharacterEncoding());
    assertEquals("{\"basePath\":\"/service1\"}", context.getResponseBody());
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:19,代码来源:SwaggerBasePathRewritingFilterTest.java

示例2: 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

示例3: should_execute_all_checks_when_using_RateLimitConditionMatchingStrategy_All

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Test
public void should_execute_all_checks_when_using_RateLimitConditionMatchingStrategy_All() {
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/url");
       RequestContext context = new RequestContext();
       context.setRequest(request);
       RequestContext.testSetCurrentContext(context);
       
       when(rateLimitCheck1.rateLimit(any())).thenReturn(consumptionProbe);
       when(rateLimitCheck2.rateLimit(any())).thenReturn(consumptionProbe);
       when(rateLimitCheck3.rateLimit(any())).thenReturn(consumptionProbe);
       
       configuration.setStrategy(RateLimitConditionMatchingStrategy.ALL);
       
       filter.run();
       
       verify(rateLimitCheck1, times(1)).rateLimit(any());
       verify(rateLimitCheck2, times(1)).rateLimit(any());
       verify(rateLimitCheck3, times(1)).rateLimit(any());
}
 
开发者ID:MarcGiffing,项目名称:bucket4j-spring-boot-starter,代码行数:20,代码来源:ZuulRateLimitFilterTest.java

示例4: should_execute_only_one_check_when_using_RateLimitConditionMatchingStrategy_FIRST

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Test
public void should_execute_only_one_check_when_using_RateLimitConditionMatchingStrategy_FIRST() {
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/url");
       RequestContext context = new RequestContext();
       context.setRequest(request);
       RequestContext.testSetCurrentContext(context);
       
       configuration.setStrategy(RateLimitConditionMatchingStrategy.FIRST);

       when(rateLimitCheck1.rateLimit(any())).thenReturn(consumptionProbe);
       
       filter.run();
       
       
       verify(rateLimitCheck1, times(1)).rateLimit(any());
       verify(rateLimitCheck2, times(0)).rateLimit(any());
       verify(rateLimitCheck3, times(0)).rateLimit(any());
}
 
开发者ID:MarcGiffing,项目名称:bucket4j-spring-boot-starter,代码行数:19,代码来源:ZuulRateLimitFilterTest.java

示例5: should_execute_only_one_check_when_using_RateLimitConditionMatchingStrategy_FIRST

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Test
public void should_execute_only_one_check_when_using_RateLimitConditionMatchingStrategy_FIRST() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/url");
       RequestContext context = new RequestContext();
       context.setRequest(request);
       RequestContext.testSetCurrentContext(context);
       
       configuration.setStrategy(RateLimitConditionMatchingStrategy.FIRST);

       when(rateLimitCheck1.rateLimit(any())).thenReturn(consumptionProbe);
       
       standaloneSetup(new TestController())
		.addFilters(filter).build()
		.perform(get(("/test")));
       
       
       verify(rateLimitCheck1, times(1)).rateLimit(any());
       verify(rateLimitCheck2, times(0)).rateLimit(any());
       verify(rateLimitCheck3, times(0)).rateLimit(any());
}
 
开发者ID:MarcGiffing,项目名称:bucket4j-spring-boot-starter,代码行数:21,代码来源:ServletRateLimitFilterTest.java

示例6: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
	RequestContext ctx = RequestContext.getCurrentContext();
	ctx.setSendZuulResponse(false);
	ctx.setRequest(encryptRequest(ctx.getRequest()));
	return null;
}
 
开发者ID:daflockinger,项目名称:poppynotes,代码行数:8,代码来源:InCommingNoteEncryptingFilter.java


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