本文整理汇总了Java中com.netflix.zuul.context.RequestContext.getCurrentContext方法的典型用法代码示例。如果您正苦于以下问题:Java RequestContext.getCurrentContext方法的具体用法?Java RequestContext.getCurrentContext怎么用?Java RequestContext.getCurrentContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.netflix.zuul.context.RequestContext
的用法示例。
在下文中一共展示了RequestContext.getCurrentContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
try {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletResponse response = ctx.getResponse();
if (!rateLimiter.tryAcquire()) {
HttpStatus httpStatus = HttpStatus.TOO_MANY_REQUESTS;
response.setContentType(MediaType.TEXT_PLAIN_VALUE);
response.setStatus(httpStatus.value());
ctx.setResponseStatusCode(httpStatus.value());
ctx.setSendZuulResponse(false);
}
} catch (Exception e) {
ReflectionUtils.rethrowRuntimeException(e);
}
return null;
}
示例2: 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
示例3: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString()));
Object accessToken = request.getParameter("accessToken");
if(accessToken == null) {
log.warn("access token is empty");
ctx.setSendZuulResponse(false);
ctx.setResponseBody("401");
ctx.setResponseStatusCode(401);
return null;
}
log.info("access token ok");
return null;
}
示例4: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
log.info(String.format("%s >>> %s", request.getMethod(), request.getRequestURL().toString()));
Object accessToken = request.getParameter("token");
if (accessToken == null) {
log.warn("token is empty");
ctx.setSendZuulResponse(false);
ctx.setResponseStatusCode(401);
try {
ctx.getResponse().getWriter().write("token is empty");
} catch (Exception e) {
}
return null;
}
log.info("ok");
return null;
}
示例5: filter
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
private void filter() {
RequestContext context = RequestContext.getCurrentContext();
if (doesNotContainToken(context)) {
logger.warn("No token found in request header");
rejectRequest(context);
} else {
String token = token(context);
ResponseEntity<String> responseEntity = authenticationService.validate(token);
if (!responseEntity.getStatusCode().is2xxSuccessful()) {
logger.warn("Unauthorized token {} and request rejected", token);
rejectRequest(context);
} else {
logger.info("Token {} validated", token);
}
}
}
示例6: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
RequestContext context = RequestContext.getCurrentContext();
HttpSession session = RequestContext.getCurrentContext().getRequest().getSession(false);
if (session == null) {
return null;
}
AccessTokenRepresentation token = JSON.parse((String) session.getAttribute("token"), AccessTokenRepresentation.class);
if (token != null) {
context.addZuulRequestHeader("Authorization", "Bearer " + token.getAccessToken());
}
return null;
}
示例7: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
public Object run() {
RequestContext context = RequestContext.getCurrentContext();
HttpServletResponse servletResponse = context.getResponse();
servletResponse.addHeader("X-Foo",
UUID.randomUUID().toString());
return null;
}
示例8: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
// JwtUser jwtUser = (JwtUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//
// ObjectMapper mapper = new ObjectMapper();
// try {
// String json = mapper.writeValueAsString(jwtUser);
// ctx.addZuulRequestHeader("x-youbang-user", json);
// }
// catch (Exception ex){
// mylog.error(ex.getMessage());
// }
mylog.error("run zuul filter");
return null;
}
示例9: 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);
}
}
示例10: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
RequestContext requestContext = RequestContext.getCurrentContext();
try {
InputStream in = requestContext.getResponseDataStream();
StringBuffer result = new StringBuffer();
byte[] b = new byte[1024];
for (int n; (n = in.read(b)) != -1; ) {
result.append(new String(b, 0, n));
}
LOGGER.info("接口返回结果:{}", result.toString());
requestContext.setSendZuulResponse(true);
requestContext.setResponseStatusCode(200);
requestContext.setResponseBody(result.toString());
} catch (Exception e) {
LOGGER.error("解析返回值异常:{}", e);
}
return null;
}
示例11: shouldFilter
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public boolean shouldFilter() {
RequestContext ctx = RequestContext.getCurrentContext();
return ctx.getRequest().getRequestURI().endsWith("/api/login") &&
ctx.getResponseStatusCode() == 200 &&
ctx.getResponse().getHeader(SET_COOKIE) == null;
}
示例12: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
logger.info(String.format("send request %s failed.", request.getMethod(), request.getRequestURL().toString()));
return null;
}
示例13: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
PreRequestLogFilter.LOGGER.info(String.format("send %s request to %s", request.getMethod(), request.getRequestURL().toString()));
return null;
}
示例14: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
RequestContext context = RequestContext.getCurrentContext();
((SpanInScope) context.getRequest().getAttribute(SpanInScope.class.getName())).close();
clientHandler.handleReceive(context.getResponse(), null, tracer.currentSpan());
log.debug("Closed span {} for {}", tracer.currentSpan(), context.getRequest().getMethod());
return null;
}
示例15: run
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
_log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString()));
Object accessToken = request.getParameter("accessToken");
/*if(accessToken == null) {
log.warn("access token is empty");
ctx.setSendZuulResponse(false);
ctx.setResponseStatusCode(401);
return null;
}*/
return null;
}