我看到一些TwitterClient会话过期,导致异常。从最好的我可以告诉twitter oAuth会话不会过期所以我想知道可能导致这个问题的原因是什么?我正在使用memcache存储用户会话,因为我们的网站可以扩展到许多实例,这可能会影响到这个问题,但我在转移到memcache之前就看到了这种行为,所以我相信这可能来自其他东西。
理想情况下,我正在寻找可能导致这种情况的想法,所以我可以解决它,但在短期内,如果有人能告诉我如何拦截此异常并处理它以便我的用户没有看到,我将不胜感激错误屏幕。
我正在使用play 2.3.3和play-pac4j 1.6
ERROR o.p.oauth.client.BaseOAuth10Client: Token request expired
ERROR play: Cannot invoke the action, eventually got an error: org.pac4j.oauth.client.exception.OAuthCredentialsException: Token request expired
ERROR application:
! @6lhge4dme - Internal server error, for (GET) [/league/callback?client_name=TwitterClient&oauth_token=tgk8pilQpkwlgt5kU01ieK1lgMO33Vv0&oauth_verifier=DhE9aFaVxsbSWmm7SN34IrNHR3gcixbe] ->
play.api.Application$$anon$1: Execution exception[[OAuthCredentialsException: Token request expired]]
at play.api.Application$class.handleError(Application.scala:296) ~[com.typesafe.play.play_2.10-2.3.5.jar:2.3.5]
at play.core.server.servlet.DefaultWarApplication.handleError(Play2Server.scala:118) [com.github.play2war.play2-war-core-common_2.10-1.3-beta2.jar:1.3-beta2]
at play.core.server.servlet.Play2GenericServletRequestHandler$$anonfun$1$$anonfun$applyOrElse$7.apply(RequestHandler.scala:376) [com.github.play2war.play2-war-core-common_2.10-1.3-beta2.jar:1.3-beta2]
at play.core.server.servlet.Play2GenericServletRequestHandler$$anonfun$1$$anonfun$applyOrElse$7.apply(RequestHandler.scala:376) [com.github.play2war.play2-war-core-commo...
...n_2.10-1.3-beta2.jar: 1.3-beta2]
...n_2.10-1.3-beta2.jar: at scala.Option.fold(Option.scala:157) [org.scala-lang.scala-library-2.10.4.jar:na]
...n_2.10-1.3-beta2.jar: at play.core.server.servlet.Play2GenericServletRequestHandler$$anonfun$1.applyOrElse(RequestHandler.scala:375) [com.github.play2war.play2-war-core-common_2.10-1.3-beta2.jar:1.3-beta2]
...n_2.10-1.3-beta2.jar: at play.core.server.servlet.Play2GenericServletRequestHandler$$anonfun$1.applyOrElse(RequestHandler.scala:372) [com.github.play2war.play2-war-core-common_2.10-1.3-beta2.jar:1.3-beta2]
...n_2.10-1.3-beta2.jar: at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:344) [org.scala-lang.scala-library-2.10.4.jar:na]
...n_2.10-1.3-beta2.jar: at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:343) [org.scala-lang.scala-library-2.10.4.jar:na]
...n_2.10-1.3-beta2.jar: at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [org.scala-lang.scala-library-2.10.4.jar:na]
...n_2.10-1.3-beta2.jar: at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:46) [com.typesafe.play.play-iteratees_2.10-2.3.5.jar:2.3.5...
...: ]
...: at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40) [org.scala-lang.scala-library-2.10.4.jar:na]
...: at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248) [org.scala-lang.scala-library-2.10.4.jar:na]
...: at scala.concurrent.Promise$class.complete(Promise.scala:55) [org.scala-lang.scala-library-2.10.4.jar:na]
...: at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:153) [org.scala-lang.scala-library-2.10.4.jar:na]
...: at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:23) [org.scala-lang.scala-library-2.10.4.jar:na]
...: at play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:40) [com.typesafe.play.play_2.10-2.3.5.jar:2.3.5]
...: at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:41) [com.typesafe.akka.akka-actor_2.10-2.3.4.jar:na]
...: at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:393) [com.typesafe.akka.akka-...
...actor_2.10-2.3.4.jar: na]
...actor_2.10-2.3.4.jar: at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [org.scala-lang.scala-library-2.10.4.jar:na]
...actor_2.10-2.3.4.jar: at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [org.scala-lang.scala-library-2.10.4.jar:na]
...actor_2.10-2.3.4.jar: at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [org.scala-lang.scala-library-2.10.4.jar:na]
...actor_2.10-2.3.4.jar: at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [org.scala-lang.scala-library-2.10.4.jar:na]
...actor_2.10-2.3.4.jar: Caused by: org.pac4j.oauth.client.exception.OAuthCredentialsException: Token request expired
...actor_2.10-2.3.4.jar: at org.pac4j.oauth.client.BaseOAuth10Client.getAccessToken(BaseOAuth10Client.java:100) ~[org.pac4j.pac4j-oauth-1.6.0.jar:na]
...actor_2.10-2.3.4.jar: at org.pac4j.oauth.client.BaseOAuthClient.retrieveUserProfile(BaseOAuthClient.java:166) ~[org.pac4j.pac4j-oauth-1.6.0.jar:na]
...actor_2.10-2.3.4.jar: at org.pac4j.oauth.client.BaseOAuthClient.retrieveUserProfile(BaseOAuthClient.java:45) ~[org.pa...
...c4j.pac4j-oauth-1.6.0.jar: na]
...c4j.pac4j-oauth-1.6.0.jar: at org.pac4j.core.client.BaseClient.getUserProfile(BaseClient.java:231) ~[org.pac4j.pac4j-core-1.6.0.jar:na]
...c4j.pac4j-oauth-1.6.0.jar: at org.pac4j.play.CallbackController$1.apply(CallbackController.java:95) ~[org.pac4j.play-pac4j_java-1.3.0.jar:na]
...c4j.pac4j-oauth-1.6.0.jar: at org.pac4j.play.CallbackController$1.apply(CallbackController.java:69) ~[org.pac4j.play-pac4j_java-1.3.0.jar:na]
...c4j.pac4j-oauth-1.6.0.jar: at play.core.j.FPromiseHelper$$anonfun$promise$2.apply(FPromiseHelper.scala:36) ~[com.typesafe.play.play_2.10-2.3.5.jar:2.3.5]
...c4j.pac4j-oauth-1.6.0.jar: at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) [org.scala-lang.scala-library-2.10.4.jar:na]
...c4j.pac4j-oauth-1.6.0.jar: at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) [org.scala-lang.scala-library-2.10.4.jar:na]
...c4j.pac4j-oauth-1.6.0.jar: ... 7 common frames omitted
答案 0 :(得分:0)
我找到了一个问题的答案,如何拦截例外情况,但我仍然不太确定导致这种情况的原因,因为虽然它出现在我的日志中但我还没有能够重现它我经常更喜欢。
拦截异常就像覆盖Global.java中的onError()方法一样简单并处理异常
@Override
public Promise<Result> onError(RequestHeader req, Throwable t) {
//Check for session timeout for Twitter Clients and log them out if something is wrong.
if(t instanceof OAuthCredentialsException){
Logger.warn("[LiveError] OAuthException: Loguser out.",t);
//Attempt to log user out and go to logging page
return Promise.<Result>pure(org.pac4j.play.CallbackController.logoutAndRedirect());
}
Logger.warn("[LiveError] Encountered an unexpected error,",t);
return Promise.<Result>pure(internalServerError(views.html.league.error.render("Sorry, we have an error! "+t.getMessage())));
}
以下是我得到答案的参考资料:https://groups.google.com/d/msg/pac4j-users/cy9sZw3KJnQ/L0T7nv0M7QEJ