我可以在回调中从用户那里获得授权“代码”,授予我的网络应用程序访问 Google 日历的权限。但是,当我尝试使用以下方法获取访问令牌和刷新令牌时,我总是在以下代码块中的以下行中收到“java.net.SocketTimeoutException:连接超时”异常:
googleTokenResponse = googleAuthorizationCodeTokenRequest.execute();
令人沮丧的是,我可以在 vFabric tc Server 上运行的 Grails Web 应用程序中获取访问令牌和刷新令牌,但是我必须编写一个在 JBoss EAP 6 上运行的 Java EE Web 应用程序,这就是我得到的地方超时异常。
这是我用来获取访问令牌和刷新令牌的方法:
String accessToken = "";
String refreshToken = "";
GoogleTokenResponse googleTokenResponse = null;
try {
GoogleAuthorizationCodeTokenRequest googleAuthorizationCodeTokenRequest = new GoogleAuthorizationCodeTokenRequest(new NetHttpTransport(), new JacksonFactory(), myClientId, myClientSecret, code, myRedirectURI);
log.info("getTokensUsingGoogleAPI() :: googleAuthorizationCodeTokenRequest = " + googleAuthorizationCodeTokenRequest);
googleTokenResponse = googleAuthorizationCodeTokenRequest.execute();
} catch (TokenResponseException e) {
...
}
if (googleTokenResponse != null) {
accessToken = googleTokenResponse.getAccessToken();
if (accessToken != null) {
googleAuthenticationForCalendarId.setAccessToken(accessToken);
log.info("getTokensUsingGoogleAPI() :: accessToken = " + accessToken);
}
refreshToken = googleTokenResponse.getRefreshToken();
if (refreshToken != null) {
log.info("getTokensUsingGoogleAPI() :: refreshToken = " + refreshToken);
googleAuthenticationForCalendarId.setRefreshToken(refreshToken);
}
} else {
log.severe("getTokensUsingGoogleAPI() :: googleTokenResponse == null. Try again!!!");
}
这是一个例外:
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) java.net.SocketTimeoutException: connect timed out
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:337)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at java.net.Socket.connect(Socket.java:579)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:607)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at sun.net.www.http.HttpClient.openServer(HttpClient.java:483)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:278)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:335)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:928)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1087)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:84)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:991)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:299)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest.execute(GoogleAuthorizationCodeTokenRequest.java:175)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at au.edu.nsw.det.corpcomm.calendar.rest.GoogleAuthenticationResourceRESTService.getTokensUsingGoogleAPI(GoogleAuthenticationResourceRESTService.java:167)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at au.edu.nsw.det.corpcomm.calendar.rest.GoogleAuthenticationResourceRESTService.getValuesFromCallback(GoogleAuthenticationResourceRESTService.java:90)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at java.lang.reflect.Method.invoke(Method.java:601)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:374)
12:39:06,292 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:129)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:137)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.jpa.interceptor.SFSBInvocationInterceptor.processInvocation(SFSBInvocationInterceptor.java:58)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ejb3.component.stateful.StatefulSessionSynchronizationInterceptor.processInvocation(StatefulSessionSynchronizationInterceptor.java:156)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:74)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ejb3.component.stateful.StatefulComponentInstanceInterceptor.processInvocation(StatefulComponentInstanceInterceptor.java:67)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:227)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:303)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:189)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:42)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:32)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:176)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ejb3.component.stateful.StatefulComponentIdInterceptor.processInvocation(StatefulComponentIdInterceptor.java:52)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at au.edu.nsw.det.corpcomm.calendar.rest.GoogleAuthenticationResourceRESTService$$$view39.getValuesFromCallback(Unknown Source)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at java.lang.reflect.Method.invoke(Method.java:601)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:525)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:679)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:931)
12:39:06,308 ERROR [stderr] (http-/0.0.0.0:8080-4) at java.lang.Thread.run(Thread.java:722)
我做了很多测试都没有成功。
我做了很多搜索,但在https://groups.google.com/forum/?fromgroups=#!search/GoogleAuthorizationCodeTokenRequest $20connect$20timed$20out/oauth2-dev/OXo- Y5jBo3w/j8YiZ0_FwEoJ 但这并没有给出任何实际的解决方案。
任何帮助将不胜感激。