So I just wrote some code to use JMS Queue to send a String message which is then used to back a Spring Integration channel, which is being listened on my an <int-twitter:outbound-channel-adapter> which references my TwitterTemplate bean and therefore sending the JMS Message should cause a status update to my account.
However, I am getting an error.
First a warning
"2012-03-17 18:55:29,575 [http-bio-8080-exec-1] WARN org.springframework.web.client.RestTemplate - POST request for "https://api.twitter.com/1/statuses/update.json" resulted in 401 (Unauthorized); invoking error handler"
Then the error, the stack trace has more, but nothing worth noting.
Here is my code and configurationCode:SEVERE: Servlet.service() for servlet [eventgate] in context with path [] threw exception [Request processing failed; nested exception is 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] with root cause 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) 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 com.perfectworldprogramming.eventgate.utils.TwitterService.sendTweet(TwitterService.java:58)
CodeCode:<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="vm://embedded?broker.persistent=false"/> </bean> <bean id="twitterQueue" class="org.apache.activemq.command.ActiveMQQueue"> <constructor-arg value="queue.twitter"/> </bean> <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> <property name="connectionFactory" ref="connectionFactory"/> <property name="defaultDestination" ref="twitterQueue"/> </bean> <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"/>
It looks correct to me, and in my .properties file with my Twitter credentials all seems fine, I even get true returned for twitterTemplate.isAuthorized();Code:@Transactional(propagation = Propagation.REQUIRES_NEW) public void sendTweet(TwitterMessage messageType, String... args) { String message = messages.get(messageType); message = MessageFormat.format(message, args) + Calendar.getInstance().toString(); if (message.length() > tweetSize) { message = message.substring(0, 139); } boolean testing = twitterTemplate.isAuthorized(); if (testing) { jmsTemplate.convertAndSend(message); } }
Any help would be appreciated.
Thanks
Mark


Reply With Quote