當前位置: 首頁>>代碼示例>>Java>>正文


Java RequestContext.setResponse方法代碼示例

本文整理匯總了Java中com.netflix.zuul.context.RequestContext.setResponse方法的典型用法代碼示例。如果您正苦於以下問題:Java RequestContext.setResponse方法的具體用法?Java RequestContext.setResponse怎麽用?Java RequestContext.setResponse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.netflix.zuul.context.RequestContext的用法示例。


在下文中一共展示了RequestContext.setResponse方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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包/類
@Override
public Object run() {
  logger.info("Moving cookies from byte stream to header");
  RequestContext ctx = RequestContext.getCurrentContext();

  String rawCookies = responseBodyOf(ctx);
  Map<String, String> cookies = jsonOf(ctx, rawCookies);

  HttpServletResponse response = ctx.getResponse();
  for (Map.Entry<String, String> entry : cookies.entrySet()) {
    Cookie cookie = new Cookie(entry.getKey(), entry.getValue());
    cookie.setPath("/");
    response.addCookie(cookie);
  }
  ctx.setResponse(response);
  ctx.setResponseBody("logged in");

  return null;
}
 
開發者ID:WillemJiang,項目名稱:acmeair,代碼行數:20,代碼來源:LoginCookieUpdateFilter.java


注:本文中的com.netflix.zuul.context.RequestContext.setResponse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。