Announcement Announcement Module
Collapse
No announcement yet.
What Happens inside the TwitterAPI or TwiterTemplate ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • What Happens inside the TwitterAPI or TwiterTemplate ?

    What happens exactly in this line of code:

    Code:
    TwitterApi twitterApi = new TwitterTemplate();
    Does the unauthenticated connection take place here? Is a new connection created for each call to 'new TwitterTemplate()' ?

    I am constantly getting connection timeout at random times, and I can't figure out the cause. My app uses one and only one call to 'new TwitterTemplate()' . Should I instantiate new TwitterApi object each time I want to make a new search call for example?
    Last edited by roise_r; Jun 19th, 2011, 10:59 AM.

  • #2
    Creating a TwitterTemplate using the default constructor gives you a Twitter ApiBinding you can use to invoke operations that do not require authorization, such as Twitter search. If you're getting timeouts, it's probably because Twitter itself is not responding. I'd be curious to see what the exact exception stack trace is you're getting, both against M3 and the latest build snapshot.

    Comment


    • #3
      This is what I get with 1.0.0.M3. Haven't tried with the latest snapshot.

      Code:
      Exception in thread "main" org.springframework.web.client.ResourceAccessException: I/O error: Connection timed out: connect; nested exception is java.net.ConnectException: Connection timed out: connect
      	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:453)
      	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:409)
      	at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:206)
      	at org.springframework.social.twitter.api.impl.SearchTemplate.search(SearchTemplate.java:65)
      	at org.springframework.social.twitter.api.impl.SearchTemplate.search(SearchTemplate.java:48)
      	at SearcherFactory.searchTwitter(SearcherFactory.java:138)
      	at SearchMain.main(SearchMain.java:19)
      Caused by: java.net.ConnectException: Connection timed out: connect
      	at java.net.PlainSocketImpl.socketConnect(Native Method)
      	at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
      	at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
      	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
      	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
      	at java.net.Socket.connect(Socket.java:529)
      	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:559)
      	at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141)
      	at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
      	at sun.net.http://www.http.HttpClient.openServe...lient.java:394)
      	at sun.net.http://www.http.HttpClient.openServe...lient.java:529)
      	at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:272)
      	at sun.net.http://www.protocol.https.HttpsClien...lient.java:329)
      	at sun.net.http://www.protocol.https.AbstractDe...ction.java:172)
      	at sun.net.http://www.protocol.http.HttpURLConn...ction.java:911)
      	at sun.net.http://www.protocol.https.AbstractDe...ction.java:158)
      	at sun.net.http://www.protocol.https.HttpsURLCo...nImpl.java:133)
      	at org.springframework.http.client.BufferingSimpleClientHttpRequest.executeInternal(BufferingSimpleClientHttpRequest.java:73)
      	at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:46)
      	at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:56)
      	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:438)
      	... 6 more
      I am wandering when does the connection takes place. Does the call to a TwitterTemplate constructor instantiate a new connection?? ... more specifically: what is the difference if I instantiate a new TwitterTemplate object and using an old one:

      TwitterApi ta = new TwitterTemplate();
      ta.searchOperations().search("query1");
      ta = new TwitterTemplate();
      ta.searchOperations().search("query2");

      vs.

      TwitterApi ta = new TwitterTemplate();
      ta.searchOperations().search("query1");
      ta.searchOperations().search("query2");

      Also, how do I dispose of an already established connection?

      Also, where can I get the TwitterApi source code?
      Last edited by roise_r; Jun 20th, 2011, 05:51 PM.

      Comment


      • #4
        The source code is here: http://github.com/SpringSource/spring-social-twitter.

        Would love to see the stack trace against the latest snapshot...

        Keith

        Comment


        • #5
          The ResourceAccessExceptions that I am getting are generated randomly and not very frequent at all, but they are still thrown sometimes even with the latest build. I just drop one iteration when that happens.

          Comment

          Working...
          X