use of com.netflix.zuul.context.RequestContext in project fw-cloud-framework by liuweijw.
the class AccessFilter method run.
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
ctx.set("startTime", System.currentTimeMillis());
return null;
}
use of com.netflix.zuul.context.RequestContext in project spring-boot by Linda-Tan.
the class AccessFilter method run.
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
if (isIgnorePath(request.getRequestURI()))
return null;
String token = request.getHeader(jwtTokenHeader);
if (StringUtils.isBlank(token)) {
log.warn("access token is empty");
ctx.setSendZuulResponse(false);
ctx.setResponseStatusCode(401);
return null;
}
try {
// 校验token合法性
Jws<Claims> claimsJws = Jwts.parser().setSigningKey(RSAHelper.getBase64PublicKey(pubKeyPath)).parseClaimsJws(token);
Claims body = claimsJws.getBody();
UserInfo userInfo = new UserInfo();
userInfo.setId(body.getId());
userInfo.setName(body.getSubject());
log.info("parser token : {}", body);
} catch (Exception e) {
ctx.setResponseBody(JSON.toJSONString(new BaseResponse(ResponseCode.EX_OTHER_CODE, "Token error or Token is Expired!")));
log.error(e.getMessage());
}
return null;
}
use of com.netflix.zuul.context.RequestContext in project tutorials by eugenp.
the class CustomZuulFilter method run.
@Override
public Object run() {
final RequestContext ctx = RequestContext.getCurrentContext();
ctx.addZuulRequestHeader("Test", "TestSample");
return null;
}
use of com.netflix.zuul.context.RequestContext in project tutorials by eugenp.
the class SessionSavingZuulPreFilter method run.
@Override
public Object run() {
RequestContext context = RequestContext.getCurrentContext();
HttpSession httpSession = context.getRequest().getSession();
Session session = repository.getSession(httpSession.getId());
context.addZuulRequestHeader("Cookie", "SESSION=" + httpSession.getId());
log.info("ZuulPreFilter session proxy: {}", session.getId());
return null;
}
use of com.netflix.zuul.context.RequestContext in project tutorials by eugenp.
the class SwaggerBasePathRewritingFilterIntegrationTest method run_on_valid_response.
@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());
}
Aggregations