twitter4j API -拒绝连接



我正在运行一个代码,让我的Webapp代表用户发布状态更新。代码在本地工作得很好,但当我把它放在Windows Server 2012 R2上时,我得到一个ConnectionException。

15-Sep-2015 18:40:59.128 SEVERE [http-apr-8080-exec-12] socialmedia.TwitterService.updateTwitterStatus null
 Connection refused: connect
Relevant discussions can be found on the Internet at:
    http://www.google.co.jp/search?q=2fc5b7cb or
    http://www.google.co.jp/search?q=0e20763e
TwitterException{exceptionCode=[2fc5b7cb-0e20763e 2fc5b7cb-0e207614], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=4.0.3}
    at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:178)
    at twitter4j.HttpClientBase.request(HttpClientBase.java:53)
    at twitter4j.HttpClientBase.post(HttpClientBase.java:82)
    at twitter4j.TwitterImpl.post(TwitterImpl.java:1598)
    at twitter4j.TwitterImpl.updateStatus(TwitterImpl.java:205)
    at de.materna.cmo.socialmedia.TwitterService.updateTwitterStatus(TwitterService.java:37)
    at de.materna.cmo.socialmedia.TwitterService$Proxy$_$$_WeldClientProxy.updateTwitterStatus(Unknown Source)
    at de.materna.cmo.campaignmanagment.CampaignService.deployTwitterContents(CampaignService.java:174)
    at de.materna.cmo.campaignmanagment.CampaignService.deployCampaignContents(CampaignService.java:167)
    at de.materna.cmo.campaignmanagment.CampaignService$Proxy$_$$_WeldClientProxy.deployCampaignContents(Unknown Source)
    at de.materna.cmo.controller.CampaignController.releaseCampaign(CampaignController.java:184)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:247)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267)
    at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
    at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:147)
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
    at javax.faces.component.UICommand.broadcast(UICommand.java:300)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:654)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2503)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2492)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient$1.run(Unknown Source)
    at sun.net.www.http.HttpClient$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.net.www.http.HttpClient.privilegedOpenServer(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
    at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:136)
    ... 50 more

属性配置如下

debug=true
oauth.consumerKey=CONSUMER_KEY
oauth.consumerSecret=CONSUMER_SECRET
oauth.accessToken=ACCESS_TOKEN
oauth.accessTokenSecret=ACCESS_TOKEN_SECRET
http.proxyHost=proxy
http.proxyPort=8080

代码:

@ApplicationScoped
public class TwitterService {
private Twitter twitter;
@Inject
private CmoTask task;
@PostConstruct
public void init() {
    twitter = TwitterFactory.getSingleton();
}
public void updateTwitterStatus(String status) {
    try {
        twitter.updateStatus(status);
    } catch (TwitterException ex) {
        Logger.getLogger(TwitterService.class.getName()).log(Level.SEVERE, null, ex);
    }
}

}

奇怪的是我让它运行了几个小时。我想这可能与我后来在本地更改配置有关,而twitter不允许你在不同的位置使用相同的配置。现在我做了一个更新,它又不起作用了。我试着注册一个不同的web应用程序,并在.properties文件中使用这些键。不工作。

  • 代理设置正确
  • 服务器上的防火墙已关闭

我错过了什么?

提前感谢!

连接错误实际上取决于对服务器的访问。请检查您是否能够从chrome或任何其他web浏览器访问https://api.twitter.com。

相关内容

  • 没有找到相关文章

最新更新