INT-1471 more polishing
This commit is contained in:
committed by
Chris Beams
parent
9d7be42db5
commit
c3aec2ae2d
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 2010 the original author or authors
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.twitter.config;
|
||||
|
||||
@@ -21,7 +21,11 @@ import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import static org.springframework.integration.twitter.config.TwitterNamespaceHandler.BASE_PACKAGE;
|
||||
|
||||
/**
|
||||
* Parser for 'twitter-connection' element
|
||||
* @author Josh Long
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ConnectionParser extends AbstractSingleBeanDefinitionParser {
|
||||
@Override
|
||||
protected String getBeanClassName(Element element) {
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010 the original author or authors
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.twitter.config;
|
||||
|
||||
import static org.springframework.integration.twitter.config.TwitterNamespaceHandler.BASE_PACKAGE;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import static org.springframework.integration.twitter.config.TwitterNamespaceHandler.BASE_PACKAGE;
|
||||
|
||||
/**
|
||||
* A parser for a {@link org.springframework.integration.twitter.inbound.InboundDirectMessageEndpoint} instance.
|
||||
* A parser for a 'inbound-dm-channel' element
|
||||
*
|
||||
* @author Josh Long
|
||||
* @since 2.0
|
||||
|
||||
@@ -24,9 +24,7 @@ import org.w3c.dom.Element;
|
||||
import static org.springframework.integration.twitter.config.TwitterNamespaceHandler.BASE_PACKAGE;
|
||||
|
||||
/**
|
||||
* a parser for the {@link org.springframework.integration.twitter.inbound.InboundMentionEndpoint} endpoint.
|
||||
* The parser exepcts an outbound channel and a reference to a connection, as typically factoried by a
|
||||
* {@link org.springframework.integration.twitter.config.ConnectionParser}
|
||||
* Parser for 'inbound-mention-channel-adapter' element
|
||||
*
|
||||
* @author Josh Long
|
||||
* @since 2.0
|
||||
|
||||
@@ -24,9 +24,8 @@ import org.w3c.dom.Element;
|
||||
import static org.springframework.integration.twitter.config.TwitterNamespaceHandler.BASE_PACKAGE;
|
||||
|
||||
/**
|
||||
* A parser for the {@link org.springframework.integration.twitter.inbound.InboundTimelineUpdateEndpoint} endpoint. The endpoint takes a channel and a reference to
|
||||
* the appropriate connection, typically factoried by {@link org.springframework.integration.twitter.config.ConnectionParser}
|
||||
*
|
||||
* A parser for InboundTimelineUpdateEndpoint endpoint.
|
||||
*
|
||||
* @author Josh Long
|
||||
* @since 2.0
|
||||
*/
|
||||
|
||||
@@ -25,8 +25,7 @@ import org.w3c.dom.Element;
|
||||
import static org.springframework.integration.twitter.config.TwitterNamespaceHandler.BASE_PACKAGE;
|
||||
|
||||
/**
|
||||
* a parser for a {@link org.springframework.integration.twitter.outbound.OutboundDirectMessageMessageHandler} instance.
|
||||
* The parser expects a reference to a Twitter connection, as typically factoried by a {@link org.springframework.integration.twitter.config.ConnectionParser}.
|
||||
* Parser for 'outbound-dm-channel-adapter' element
|
||||
*
|
||||
* @author Josh Long
|
||||
* @since 2.0
|
||||
|
||||
@@ -26,7 +26,7 @@ import static org.springframework.integration.twitter.config.TwitterNamespaceHan
|
||||
|
||||
/**
|
||||
*
|
||||
* this outbound adapter updates the twitter status for an account
|
||||
* Parsers for 'outbound-update-channel-adapter' element
|
||||
*
|
||||
* @author Josh Long
|
||||
* @since 2.0
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.integration.twitter.core;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Describes a direct-message in twitter. (Also known as a "DM").
|
||||
|
||||
@@ -47,7 +47,6 @@ class Twitter4jDecorator implements MethodInterceptor {
|
||||
/* (non-Javadoc)
|
||||
* @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
|
||||
*/
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
Class<?> twitter4jClass = twitterObject.getClass();
|
||||
Object[] args = invocation.getArguments();
|
||||
|
||||
@@ -22,12 +22,12 @@ import java.util.List;
|
||||
import org.springframework.integration.twitter.core.Status;
|
||||
import org.springframework.integration.twitter.core.TwitterFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Simple base class for the reply and timeline cases (as well as any other {@link twitter4j.Status} implementations of
|
||||
* {@link twitter4j.TwitterResponse}.
|
||||
*
|
||||
* @author Josh Long
|
||||
* @author Oleg ZHurakousky
|
||||
*/
|
||||
abstract public class AbstractInboundTwitterStatusEndpointSupport extends AbstractInboundTwitterEndpointSupport<Status> {
|
||||
|
||||
@@ -40,8 +40,6 @@ abstract public class AbstractInboundTwitterStatusEndpointSupport extends Abstra
|
||||
protected List<Status> fromTwitter4jStatuses(List<twitter4j.Status> stats) {
|
||||
List<Status> fwd = new ArrayList<Status>();
|
||||
for (twitter4j.Status s : stats) {
|
||||
// ProxyFactory factory = new ProxyFactory(Status.class, EmptyTargetSource.INSTANCE);
|
||||
// factory.addAdvice(new Twitter4jDecorator(s));
|
||||
fwd.add((Status) TwitterFactory.formTwitter4jMessage(s));
|
||||
}
|
||||
return fwd;
|
||||
|
||||
@@ -77,8 +77,6 @@ public class InboundDirectMessageEndpoint extends AbstractInboundTwitterEndpoint
|
||||
List<DirectMessage> dmsToFwd = new ArrayList<DirectMessage>();
|
||||
|
||||
for( twitter4j.DirectMessage dm : dms) {
|
||||
// ProxyFactory factory = new ProxyFactory(DirectMessage.class, EmptyTargetSource.INSTANCE);
|
||||
// factory.addAdvice(new Twitter4jDecorator(dm));
|
||||
dmsToFwd.add((DirectMessage) TwitterFactory.formTwitter4jMessage(dm));
|
||||
}
|
||||
forwardAll(dmsToFwd);
|
||||
|
||||
@@ -42,7 +42,6 @@ public class InboundMentionEndpoint extends AbstractInboundTwitterStatusEndpoint
|
||||
List<twitter4j.Status> stats = (!hasMarkedStatus())
|
||||
? twitter.getMentions()
|
||||
: twitter.getMentions(new Paging(sinceId));
|
||||
System.out.println("Polling. . . .");
|
||||
forwardAll( fromTwitter4jStatuses( stats));
|
||||
} catch (Exception e) {
|
||||
if (e instanceof RuntimeException){
|
||||
|
||||
@@ -41,14 +41,13 @@ public class OutboundDirectMessageMessageHandler extends AbstractOutboundTwitter
|
||||
Object payload = (String) message.getPayload();
|
||||
Assert.isInstanceOf(String.class, payload, "Only payload of type String is supported. If your payload " +
|
||||
"is not of type String you may want to introduce transformer");
|
||||
Object toUser = message.getHeaders().containsKey(TwitterHeaders.TWITTER_DM_TARGET_USER_ID) ?
|
||||
message.getHeaders().get(TwitterHeaders.TWITTER_DM_TARGET_USER_ID) :
|
||||
null;
|
||||
|
||||
Assert.notNull(toUser, "the header '" + TwitterHeaders.TWITTER_DM_TARGET_USER_ID + "' must be present");
|
||||
Assert.isTrue(message.getHeaders().containsKey(TwitterHeaders.TWITTER_DM_TARGET_USER_ID),
|
||||
"You must provide '" + TwitterHeaders.TWITTER_DM_TARGET_USER_ID + "' header");
|
||||
Object toUser = message.getHeaders().get(TwitterHeaders.TWITTER_DM_TARGET_USER_ID);
|
||||
|
||||
Assert.state(toUser instanceof String || toUser instanceof Integer,
|
||||
"the header '" + TwitterHeaders.TWITTER_DM_TARGET_USER_ID + "' must be either a String (a screenname) or an int (a user ID)");
|
||||
"the header '" + TwitterHeaders.TWITTER_DM_TARGET_USER_ID +
|
||||
"' must be either a String (a screenname) or an int (a user ID)");
|
||||
|
||||
if (toUser instanceof Integer) {
|
||||
this.twitter.sendDirectMessage((Integer) toUser, (String) payload);
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.integration.twitter.outbound;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.integration.mapping.OutboundMessageMapper;
|
||||
import org.springframework.integration.twitter.core.GeoLocation;
|
||||
import org.springframework.integration.twitter.core.TwitterHeaders;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -33,17 +34,6 @@ import twitter4j.StatusUpdate;
|
||||
* @since 2.0
|
||||
*/
|
||||
public class OutboundStatusUpdateMessageMapper implements OutboundMessageMapper<StatusUpdate> {
|
||||
// /**
|
||||
// * convenient, interface-oriented way of obtaining a reference to a {@link org.springframework.integration.twitter.core.twitter.Twitter4jGeoLocation}
|
||||
// *
|
||||
// * @param lat the latitude
|
||||
// * @param lon the longitude
|
||||
// * @return a {@link org.springframework.integration.twitter.core.GeoLocation} instance
|
||||
// */
|
||||
// public org.springframework.integration.twitter.core.GeoLocation fromLatitudeLongitudePair(double lat, double lon) {
|
||||
// return new Twitter4jGeoLocation(lat, lon);
|
||||
// }
|
||||
|
||||
/**
|
||||
* {@link StatusUpdate} instances are used to drive status updates.
|
||||
*
|
||||
@@ -79,16 +69,16 @@ public class OutboundStatusUpdateMessageMapper implements OutboundMessageMapper<
|
||||
|
||||
if (message.getHeaders().containsKey(TwitterHeaders.TWITTER_GEOLOCATION)) {
|
||||
|
||||
// org.springframework.integration.twitter.core.GeoLocation geoLocation = (org.springframework.integration.twitter.core.GeoLocation) message.getHeaders()
|
||||
// .get(TwitterHeaders.TWITTER_GEOLOCATION);
|
||||
// twitter4j.GeoLocation gl = null;
|
||||
//
|
||||
// if (geoLocation instanceof Twitter4jGeoLocation) {
|
||||
// gl = ((Twitter4jGeoLocation) geoLocation).getGeoLocation();
|
||||
// if (null != gl) {
|
||||
// statusUpdate.location(gl);
|
||||
// }
|
||||
// }
|
||||
org.springframework.integration.twitter.core.GeoLocation geoLocation = (org.springframework.integration.twitter.core.GeoLocation) message.getHeaders()
|
||||
.get(TwitterHeaders.TWITTER_GEOLOCATION);
|
||||
twitter4j.GeoLocation gl = null;
|
||||
|
||||
if (geoLocation instanceof GeoLocation) {
|
||||
gl = new twitter4j.GeoLocation(geoLocation.getLatitude(), geoLocation.getLongitude());
|
||||
if (null != gl) {
|
||||
statusUpdate.location(gl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (message.getHeaders()
|
||||
|
||||
@@ -1,21 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright 2010 the original author or authors
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<beans:beans
|
||||
xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
|
||||
@@ -1,21 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright 2010 the original author or authors
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<beans:beans
|
||||
xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
|
||||
Reference in New Issue
Block a user