當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。