我尝试通过spring-social连接twitter,但我得到一个无法解决的奇怪异常。
正如我所想,Spring-social正确地添加到应用程序中。当用户应该被重定向到twitter auth页面时,我会在ConnectSupport.class
中获得异常:
private OAuthToken fetchRequestToken(NativeWebRequest request, MultiValueMap<String, String> requestParameters, OAuth1Operations oauthOperations) {
if (oauthOperations.getVersion() == OAuth1Version.CORE_10_REVISION_A) {
return oauthOperations.fetchRequestToken(callbackUrl(request), requestParameters);
}
return oauthOperations.fetchRequestToken(null, requestParameters);
}
堆栈追踪:
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://api.twitter.com/oauth/request_token": Connection refused; nested exception is java.net.ConnectException: Connection refused
[INFO] [talledLocalContainer] at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:524)
[INFO] [talledLocalContainer] at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:485)
[INFO] [talledLocalContainer] at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:436)
[INFO] [talledLocalContainer] at org.springframework.social.oauth1.OAuth1Template.exchangeForToken(OAuth1Template.java:187)
[INFO] [talledLocalContainer] at org.springframework.social.oauth1.OAuth1Template.fetchRequestToken(OAuth1Template.java:115)
[INFO] [talledLocalContainer] at org.springframework.social.connect.web.ConnectSupport.fetchRequestToken(ConnectSupport.java:212)
[INFO] [talledLocalContainer] at org.springframework.social.connect.web.ConnectSupport.buildOAuth1Url(ConnectSupport.java:199)
[INFO] [talledLocalContainer] at org.springframework.social.connect.web.ConnectSupport.buildOAuthUrl(ConnectSupport.java:126)
[INFO] [talledLocalContainer] at org.springframework.social.connect.web.ConnectController.connect(ConnectController.java:226)
[INFO] [talledLocalContainer] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[INFO] [talledLocalContainer] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[INFO] [talledLocalContainer] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[INFO] [talledLocalContainer] at java.lang.reflect.Method.invoke(Method.java:483)
[INFO] [talledLocalContainer] at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
[INFO] [talledLocalContainer] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
[INFO] [talledLocalContainer] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
[INFO] [talledLocalContainer] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
[INFO] [talledLocalContainer] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
[INFO] [talledLocalContainer] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
[INFO] [talledLocalContainer] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
[INFO] [talledLocalContainer] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
[INFO] [talledLocalContainer] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
[INFO] [talledLocalContainer] at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:855)
[INFO] [talledLocalContainer] at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
[INFO] [talledLocalContainer] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
[INFO] [talledLocalContainer] at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
[INFO] [talledLocalContainer] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
[INFO] [talledLocalContainer] at org.hippoecm.hst.container.HstFilter.doFilter(HstFilter.java:293)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
[INFO] [talledLocalContainer] at org.hippoecm.hst.container.XSSUrlFilter.doFilter(XSSUrlFilter.java:49)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
[INFO] [talledLocalContainer] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
[INFO] [talledLocalContainer] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
[INFO] [talledLocalContainer] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
[INFO] [talledLocalContainer] at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
[INFO] [talledLocalContainer] at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
[INFO] [talledLocalContainer] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
[INFO] [talledLocalContainer] at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
[INFO] [talledLocalContainer] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
[INFO] [talledLocalContainer] at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
[INFO] [talledLocalContainer] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
[INFO] [talledLocalContainer] at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
[INFO] [talledLocalContainer] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
[INFO] [talledLocalContainer] at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
[INFO] [talledLocalContainer] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
[INFO] [talledLocalContainer] at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
[INFO] [talledLocalContainer] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
[INFO] [talledLocalContainer] at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
[INFO] [talledLocalContainer] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
[INFO] [talledLocalContainer] at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
[INFO] [talledLocalContainer] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
[INFO] [talledLocalContainer] at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
[INFO] [talledLocalContainer] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
[INFO] [talledLocalContainer] at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
[INFO] [talledLocalContainer] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
[INFO] [talledLocalContainer] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
[INFO] [talledLocalContainer] at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
[INFO] [talledLocalContainer] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
[INFO] [talledLocalContainer] at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
[INFO] [talledLocalContainer] at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
[INFO] [talledLocalContainer] at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
[INFO] [talledLocalContainer] at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
[INFO] [talledLocalContainer] at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
[INFO] [talledLocalContainer] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
[INFO] [talledLocalContainer] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
[INFO] [talledLocalContainer] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
[INFO] [talledLocalContainer] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
[INFO] [talledLocalContainer] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
[INFO] [talledLocalContainer] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
[INFO] [talledLocalContainer] at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
[INFO] [talledLocalContainer] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
[INFO] [talledLocalContainer] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
[INFO] [talledLocalContainer] at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
[INFO] [talledLocalContainer] at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
[INFO] [talledLocalContainer] at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
[INFO] [talledLocalContainer] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[INFO] [talledLocalContainer] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[INFO] [talledLocalContainer] at java.lang.Thread.run(Thread.java:745)
[INFO] [talledLocalContainer] Caused by: java.net.ConnectException: Connection refused
[INFO] [talledLocalContainer] at java.net.PlainSocketImpl.socketConnect(Native Method)
[INFO] [talledLocalContainer] at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
[INFO] [talledLocalContainer] at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
[INFO] [talledLocalContainer] at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
[INFO] [talledLocalContainer] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
[INFO] [talledLocalContainer] at java.net.Socket.connect(Socket.java:589)
[INFO] [talledLocalContainer] at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:649)
[INFO] [talledLocalContainer] at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:524)
[INFO] [talledLocalContainer] at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:403)
[INFO] [talledLocalContainer] at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
[INFO] [talledLocalContainer] at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
[INFO] [talledLocalContainer] at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
[INFO] [talledLocalContainer] at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
[INFO] [talledLocalContainer] at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
[INFO] [talledLocalContainer] at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
[INFO] [talledLocalContainer] at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
[INFO] [talledLocalContainer] at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:88)
[INFO] [talledLocalContainer] at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:46)
[INFO] [talledLocalContainer] at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:49)
[INFO] [talledLocalContainer] at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:509)
[INFO] [talledLocalContainer] ... 89 more
此外,我还有一个应用程序使用spring-social,它基于spring-boot,并且所有“社交”操作都运行良好。
两种情况下的请求和其他参数都是相似的。
起初,我认为代理的问题,可能是这些应用程序中的不同代理配置,但它也很好。我可以向外国网络应用程序发送请求。
感谢您的帮助,我的想法已经结束了。