@RequestMapping(path = "/auth/checkToken", method = RequestMethod.GET)
public @ResponseBody Object checkToken(HttpServletRequest request) throws InvalidTokenException {
ClientUtils.checkValidToken(request, jedisPoolContainer.getJedisPool().getResource());
SuccessResult result = new SuccessResult();
return result;
}
public static boolean isValidToken(HttpServletRequest request, Jedis jedis) {
Token token = ClientUtils.getValidToken(request, jedis);
if (token != null)
return true;
return false;
}
public static void checkValidToken(HttpServletRequest request, Jedis jedis) throws InvalidTokenException {
logger.debug("ClientUtils.isValidToken(request, jedis): " + ClientUtils.isValidToken(request, jedis));
if (ClientUtils.isValidToken(request, jedis) == false)
throw new InvalidTokenException();
}
public static Token getValidToken(HttpServletRequest request, Jedis jedis) {
logger.debug("request.getHeader(TOKEN_HTTP_NAME): " + request.getHeader(TOKEN_HTTP_NAME));
if (request.getHeader(TOKEN_HTTP_NAME) == null)
return null;
if (request.getHeader(TOKEN_HTTP_NAME).length() != 32)
return null;
String rawTokenData = jedis.hget(JedisPoolContainer.TOKENS, request.getHeader(TOKEN_HTTP_NAME));
if (rawTokenData == null)
return null;
rawTokenData = rawTokenData.replace("\\", "");
Gson gson = new GsonBuilder().setDateFormat("yyyy-mm-dd HH:mm:ss").create();
Token token = gson.fromJson(rawTokenData, Token.class);
if (token.getIpAddress().equals(ClientUtils.getClientIpAddr(request)))
return token;
return null;
}
CorsFilter级别为:
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) servletResponse;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Methods", "PUT, POST, GET, HEAD, OPTIONS");
response.setHeader("Access-Control-Allow-Headers",
"Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, X-Token");
filterChain.doFilter(servletRequest, servletResponse);
}
当发送长度为零的“X-Token:”标题时,Spring不会返回任何响应。我用CTRL C阻止码头,然后Spring抛出这些异常:
[INFO] Stopped ServerConnector@30741e9b{HTTP/1.1,[http/1.1]}{0.0.0.0:8888}
[INFO] Destroying Spring FrameworkServlet 'mvc-dispatcher'
INFO (AbstractApplicationContext.java:987) Closing WebApplicationContext for namespace 'mvc-dispatcher-servlet': startup date [Wed Oct 18 21:54:38 EEST 2017]; parent: Root WebApplicationContext
[INFO] Closing Spring root WebApplicationContext
INFO (AbstractApplicationContext.java:987) Closing Root WebApplicationContext: startup date [Wed Oct 18 21:54:35 EEST 2017]; root of context hierarchy
[INFO] Stopped o.e.j.m.p.JettyWebAppContext@2f16c21f{/,file:///home/emir/workspacejava/SpringRestApi/src/main/webapp/,UNAVAILABLE}{file:///home/emir/workspacejava/SpringRestApi/src/main/webapp/}
[WARNING]
[WARNING]
[WARNING]
[WARNING]
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:816)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1684)
at com.nixarsoft.restapi.CorsFilter.doFilter(CorsFilter.java:31)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1667)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:581)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1121)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1055)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:118)
at org.eclipse.jetty.server.Server.handle(Server.java:515)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:291)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:238)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:57)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:191)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:126)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:170)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)
at org.springframework.web.method.ControllerAdviceBean.resolveBean(ControllerAdviceBean.java:146)
at org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.getExceptionHandlerMethod(ExceptionHandlerExceptionResolver.java:447)
at org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.doResolveHandlerMethodException(ExceptionHandlerExceptionResolver.java:362)
at org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver.doResolveException(AbstractHandlerMethodExceptionResolver.java:59)
at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:136)
at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1207)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1030)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
... 31 more
[WARNING]
[WARNING]
Caused by: java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:170)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)
at org.springframework.web.method.ControllerAdviceBean.resolveBean(ControllerAdviceBean.java:146)
at org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.getExceptionHandlerMethod(ExceptionHandlerExceptionResolver.java:447)
at org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.doResolveHandlerMethodException(ExceptionHandlerExceptionResolver.java:362)
at org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver.doResolveException(AbstractHandlerMethodExceptionResolver.java:59)
at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:136)
at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1207)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1030)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
... 31 more
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:816)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1684)
at com.nixarsoft.restapi.CorsFilter.doFilter(CorsFilter.java:31)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1667)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:581)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1121)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1055)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:118)
at org.eclipse.jetty.server.Server.handle(Server.java:515)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:291)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:238)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:57)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:191)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:126)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:170)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)
at org.springframework.web.method.ControllerAdviceBean.resolveBean(ControllerAdviceBean.java:146)
at org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.getExceptionHandlerMethod(ExceptionHandlerExceptionResolver.java:447)
at org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.doResolveHandlerMethodException(ExceptionHandlerExceptionResolver.java:362)
at org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver.doResolveException(AbstractHandlerMethodExceptionResolver.java:59)
at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:136)
at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1207)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1030)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
... 31 more
[INFO] Jetty server exiting.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 31:25 min
[INFO] Finished at: 2017-10-18T21:56:21+03:00
[INFO] Final Memory: 50M/684M
[INFO] ------------------------------------------------------------------------
emir@bugra:~/workspacejava/SpringRestApi$
GET-Request标头: 重新搜索后报头
如何通过Axios.js发送带有令牌的身份验证头?我试过几件事都没有成功,比如: 给出以下错误:
如何使用HTTP头发送HTTP请求?
有人能解释一下这个错误吗? 这是我的日志。
由于每次登录时都有大量文件下载,我正试图修复一个网络应用程序的性能。为此,我希望启用条件浏览器缓存,即,如果ETag发生变化,从服务器提供新的副本,否则使用浏览器缓存。 通过java过滤器从服务器发送的响应标头: 浏览器下次调用时,发送的请求标头为: 浏览器没有发送 If-None-Match 标头,因此用于验证 ETag 并发回 304 响应代码的服务器端代码失败,并且服务器始终将新副本发送到客
问题内容: 我有以下布局(实际上是空的): Activity类包含以下内容: 在移动设备上运行此命令时,出现以下错误: 无论是否有TextView我都尝试过,但错误仍然存在,对于这样的基本布局,我必须在根本上做错了。 有人对我如何将其加载而没有错误有任何想法吗? 问题答案: 因为你得到的错误是不相关的,那么它不涉及到你的键盘。 你得到的错误不是代码导致的;你可能正在具有Samsung Touc