当我尝试访问zuul下游的api时遇到异常。下游服务配置有Spring Security,Spring Session和Hazel Cast
请找到堆栈跟踪:
feign.FeignException:状态500读取TokenValidationProxy#validateToken(String);内容: {“ timestamp”:“ 2019-05-29T09:10:09.252 + 0000”,“状态”:500,“错误”:“内部服务器错误”,“消息”:“ java.lang.ClassNotFoundException:org.springframework。 session.hazelcast.SessionUpdateEntryProcessor“,”路径“:” / validateToken“} 在feign.FeignException.errorStatus(FeignException.java:62) 在feign.codec.ErrorDecoder $ Default.decode(ErrorDecoder.java:91) 在feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:138) 在feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76) 在feign.ReflectiveFeign $ FeignInvocationHandler.invoke(ReflectiveFeign.java:103) 在com.sun.proxy。$ Proxy139.validateToken(未知来源) 在com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:117) 在com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:193) 在com.netflix.zuul.FilterProcessor.runFilters(FilterProcessor.java:157) 在com.netflix.zuul.FilterProcessor.preRoute(FilterProcessor.java:133) 在com.netflix.zuul.ZuulRunner.preRoute(ZuulRunner.java:105) 在com.netflix.zuul.http.ZuulServlet.preRoute(ZuulServlet.java:125) 在com.netflix.zuul.http.ZuulServlet.service(ZuulServlet.java:74) 在org.springframework.web.servlet.mvc.ServletWrappingController.handleRequestInternal(ServletWrappingController.java:165) 在org.springframework.cloud.netflix.zuul.web.ZuulController.handleRequest(ZuulController.java:44) 在org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:52) 在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) 在org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) 在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974) 在org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:866) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:635) 在org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:742) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:158) 在org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:126) 在org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:111) 在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:90) 在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) 在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109) 在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) 在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.springframework.cloud.sleuth.instrument.web.ExceptionLoggingFilter.doFilter(ExceptionLoggingFilter.java:48) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在brave.servlet.TracingFilter.doFilter(TracingFilter.java:86) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) 在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) 在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) 在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496) 在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) 在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) 在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) 在org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) 在org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) 在org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:790) 在org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1468) 在org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624) 在org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) 在java.lang.Thread.run(Thread.java:748)
虚假客户端,以调用下游服务:
@FeignClient(“某些服务名称” +“ / validateToken”) 公共接口TokenValidationProxy {
@GetMapping(value = "", headers = "x-auth-token")
public void validateToken(@RequestHeader("x-auth-token") String token);
}
Zuul过滤器,在这里我从zuul调用下游服务以验证令牌:
公共类TokenValidationFilter扩展了ZuulFilter { 私有静态Logger日志= LoggerFactory.getLogger(TokenValidationFilter.class);
@Autowired
private TokenValidationProxy tokenValidationProxy;
@Override
public String filterType() {
return "pre";
}
@Override
public int filterOrder() {
return 1;
}
@Override
public boolean shouldFilter() {
return true;
}
@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()));
if(! request.getRequestURL().toString().endsWith("/login")) {
try {
System.out.println(request.getHeader("x-auth-token"));
tokenValidationProxy.validateToken(request.getHeader("x-auth-token"));
return null;
} catch(Exception e) {
e.printStackTrace();
try {
ctx.getResponse().sendError(401,"your token is invalid");
} catch (IOException e1) {
e1.printStackTrace();
}
}
}