Results 1 to 4 of 4

Thread: Spring Social with Spring Integration

  1. #1
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default Spring Social with Spring Integration

    So I am using Spring Integration's Twitter module and I am trying to post to Twitter, but it isn't working and might be related to oauth. Here is the exception that I receive

    Code:
    org.springframework.integration.MessagingException: failed to handle incoming JMS Message
    	at org.springframework.integration.jms.SubscribableJmsChannel$DispatchingMessageListener.onMessage(SubscribableJmsChannel.java:123)
    	at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:561)
    	at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:499)
    	at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:467)
    	at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325)
    	at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263)
    	at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1059)
    	at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1051)
    	at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:948)
    	at java.lang.Thread.run(Thread.java:680)
    Caused by: org.springframework.integration.MessageHandlingException: error occurred in message handler [org.springframework.integration.twitter.outbound.StatusUpdatingMessageHandler#0]
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:79)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:114)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:101)
    	at org.springframework.integration.jms.SubscribableJmsChannel$DispatchingMessageListener.onMessage(SubscribableJmsChannel.java:116)
    	... 9 more
    Caused by: org.springframework.web.client.ResourceAccessException: I/O error: cannot retry due to server authentication, in streaming mode; nested exception is java.net.HttpRetryException: cannot retry due to server authentication, in streaming mode
    	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:453)
    	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:415)
    	at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:294)
    	at org.springframework.social.twitter.api.impl.TimelineTemplate.updateStatus(TimelineTemplate.java:236)
    	at org.springframework.social.twitter.api.impl.TimelineTemplate.updateStatus(TimelineTemplate.java:224)
    	at org.springframework.integration.twitter.outbound.StatusUpdatingMessageHandler.handleMessageInternal(StatusUpdatingMessageHandler.java:57)
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)
    	... 12 more
    Caused by: java.net.HttpRetryException: cannot retry due to server authentication, in streaming mode
    	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1257)
    	at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)
    	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:318)
    	at org.springframework.http.client.SimpleClientHttpResponse.getStatusCode(SimpleClientHttpResponse.java:48)
    	at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:46)
    	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:439)
    	... 18 more
    In my pom I have Spring-integration-twitter as a dependency but not spring social jars. Also in the SI documentation for how to set it up, there is very little to do, and no direct beans from Spring Social like the Controller classes. Do I need them? Is this what is causing my exception to post a new status?

    This is my SI configuration. I activate it through sending a JMS message to a Queue.

    Code:
    <bean id="twitterTemplate" class="org.springframework.social.twitter.api.impl.TwitterTemplate">
        	<constructor-arg value="${twitter.oauth.consumerKey}"/>
        	<constructor-arg value="${twitter.oauth.consumerSecret}"/>
        	<constructor-arg value="${twitter.oauth.accessToken}"/>
        	<constructor-arg value="${twitter.oauth.accessTokenSecret}"/>
        </bean>
        
        <int-twitter:outbound-channel-adapter
          		twitter-template="twitterTemplate"
          		channel="twitterChannel"/>
    
        <int-jms:channel id="twitterChannel" queue-name="queue.twitter"/>
    So I use the Spring Social template, since I am a web app that is acting as a client to Twitter. I have the token strings in a .properties file and they are a match to what I generated at Twitter.

    Thanks

    Mark

  2. #2
    Join Date
    Aug 2004
    Posts
    1,099

    Default

    First, can you (in a JUnit test or main() method) construct an instance of TwitterTemplate with the key/secret/token/secret you are given and make it work? My guess is that it won't work and you'll likely get the same exception...but it's worth trying.

    Based on the exception, it sounds like it's encountering an HTTP 3xx code and trying to follow the value in the Location: header...but it can't because following that would require authentication which it doesn't have for the new URL. I can think of no reason why doing an updateStatus() would result in such a response, but could there be some sort of proxy in between you and Twitter that's intercepting the request and doing such a redirection?

    I'm also curious: Where did you get your access token and secret? These are usually gathered in the course of the OAuth connection flow and aren't known at configuration time...so it seems odd to me that you have configured them in your Spring configuration. I suppose, however, that if your TwitterTemplate is always intended to target the same user account on Twitter then there's no problem with wiring them in like that.
    Craig Walls
    Spring Social Project Lead

  3. #3
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    I got my token and stuff from Twitter dev.twitter.com.

    But the problem was twitter. They gave me keys that only allowed read access and every time I tried to change it to read/write I would get a twitter is over capacity error. The UI would show then as read/write but if I logged out and logged back into dev.twitter.com it would revert back to read only.

    So last night I clicked their button to regenerate the keys and when it did it also changed to read/write and I have now successfully Tweeted from my app through my own twitter account. I haven't set up my web app to tweet on actual users accounts yet, but that I will add later. The tweets from my app don't have to come from the users twitter account really anyway. I tweet about events and user so put hashtags on the event name and @ if the user puts their twitter account name into their account details.

    Thanks for replying C.

    Mark

  4. #4
    Join Date
    Aug 2004
    Posts
    1,099

    Default

    I see...so the access token/secret are the ones that Twitter gives you for *your* Twitter account (or at least the account that was used to create the app in the first place. Got it.

    Sounds like you've got it sorted out. Unfortunate that Twitter was flaking out when you tried to change it to read/write.
    Craig Walls
    Spring Social Project Lead

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •