renamed roster inbound endpoint to XmppRosterListeningEndpoint
This commit is contained in:
@@ -33,7 +33,7 @@ public class XmppRosterEventInboundEndpointParser extends AbstractSingleBeanDefi
|
||||
|
||||
@Override
|
||||
protected String getBeanClassName(Element element) {
|
||||
return "org.springframework.integration.xmpp.inbound.XmppRosterEventMessageDrivenEndpoint";
|
||||
return "org.springframework.integration.xmpp.inbound.XmppRosterListeningEndpoint";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.xmpp.inbound;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -25,6 +26,7 @@ import org.jivesoftware.smack.Roster;
|
||||
import org.jivesoftware.smack.RosterListener;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.MessageHandlingException;
|
||||
@@ -36,16 +38,16 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Describes an inbound endpoint that is able to login and then emit {@link Message}s when a
|
||||
* particular Presence event happens to the logged in users {@link Roster}
|
||||
* particular Presence event happens to the logged in user's {@link Roster}.
|
||||
* (e.g., logged in/out, changed status etc.)
|
||||
*
|
||||
* @author Josh Long
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0
|
||||
*/
|
||||
public class XmppRosterEventMessageDrivenEndpoint extends AbstractXmppConnectionAwareEndpoint {
|
||||
public class XmppRosterListeningEndpoint extends AbstractXmppConnectionAwareEndpoint {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(XmppRosterEventMessageDrivenEndpoint.class);
|
||||
private static final Log logger = LogFactory.getLog(XmppRosterListeningEndpoint.class);
|
||||
|
||||
private volatile MessageChannel requestChannel;
|
||||
|
||||
@@ -53,20 +55,23 @@ public class XmppRosterEventMessageDrivenEndpoint extends AbstractXmppConnection
|
||||
|
||||
private final EventForwardingRosterListener rosterListener = new EventForwardingRosterListener();
|
||||
|
||||
public XmppRosterEventMessageDrivenEndpoint(){
|
||||
|
||||
public XmppRosterListeningEndpoint() {
|
||||
super();
|
||||
}
|
||||
|
||||
public XmppRosterEventMessageDrivenEndpoint(XMPPConnection xmppConnection){
|
||||
public XmppRosterListeningEndpoint(XMPPConnection xmppConnection) {
|
||||
super(xmppConnection);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param requestChannel the channel on which the inbound message should be sent
|
||||
*/
|
||||
public void setRequestChannel(final MessageChannel requestChannel) {
|
||||
this.requestChannel = requestChannel;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void doStart() {
|
||||
Assert.isTrue(this.initialized, this.getComponentName() + "#" + this.getComponentType() + " must be initialized");
|
||||
@@ -86,49 +91,47 @@ public class XmppRosterEventMessageDrivenEndpoint extends AbstractXmppConnection
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever an event happens related to the {@link Roster}
|
||||
*
|
||||
* @param payload
|
||||
* Called whenever an event happens related to the {@link Roster}.
|
||||
*/
|
||||
private void forwardRosterEventMessage(Object payload) {
|
||||
private void forwardRosterEvent(Object event) {
|
||||
Message<?> message = null;
|
||||
try {
|
||||
message = MessageBuilder.withPayload(payload).build();
|
||||
messagingTemplate.send(requestChannel, message);
|
||||
message = MessageBuilder.withPayload(event).build();
|
||||
this.messagingTemplate.send(this.requestChannel, message);
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e instanceof MessagingException){
|
||||
throw (MessagingException)e;
|
||||
}
|
||||
else {
|
||||
throw new MessageHandlingException(message, "Failed to send message", e);
|
||||
}
|
||||
throw new MessageHandlingException(message, "Failed to send roster event message", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* RosterListener that subscribes to a given {@link Roster}s events
|
||||
* and forwards them to messaging bus
|
||||
* RosterListener that subscribes to a given {@link Roster}'s events
|
||||
* and forwards them to a message channel.
|
||||
*/
|
||||
class EventForwardingRosterListener implements RosterListener {
|
||||
private class EventForwardingRosterListener implements RosterListener {
|
||||
|
||||
public void entriesAdded(Collection<String> entries) {
|
||||
logger.debug("entries added: " + StringUtils.join(entries.iterator(), ","));
|
||||
forwardRosterEventMessage(entries);
|
||||
forwardRosterEvent(entries);
|
||||
}
|
||||
|
||||
public void entriesUpdated(Collection<String> entries) {
|
||||
logger.debug("entries updated: " + StringUtils.join(entries.iterator(), ","));
|
||||
forwardRosterEventMessage(entries);
|
||||
forwardRosterEvent(entries);
|
||||
}
|
||||
|
||||
public void entriesDeleted(Collection<String> entries) {
|
||||
logger.debug("entries deleted: " + StringUtils.join(entries.iterator(), ","));
|
||||
forwardRosterEventMessage(entries);
|
||||
forwardRosterEvent(entries);
|
||||
}
|
||||
|
||||
public void presenceChanged(Presence presence) {
|
||||
logger.debug("presence changed: " + ToStringBuilder.reflectionToString(presence));
|
||||
forwardRosterEventMessage(presence);
|
||||
forwardRosterEvent(presence);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,13 +41,13 @@ import org.springframework.integration.Message;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.xmpp.XmppContextUtils;
|
||||
import org.springframework.integration.xmpp.inbound.XmppRosterEventMessageDrivenEndpoint;
|
||||
import org.springframework.integration.xmpp.inbound.XmppRosterListeningEndpoint;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class XmppRosterEventMessageDrivenEndpointTests {
|
||||
public class XmppRosterListeningEndpointTests {
|
||||
|
||||
@Test
|
||||
public void testEndpointLifecycle(){
|
||||
@@ -69,7 +69,7 @@ public class XmppRosterEventMessageDrivenEndpointTests {
|
||||
return null;
|
||||
}
|
||||
}).when(roster).removeRosterListener(Mockito.any(RosterListener.class));
|
||||
XmppRosterEventMessageDrivenEndpoint rosterEndpoint = new XmppRosterEventMessageDrivenEndpoint(connection);
|
||||
XmppRosterListeningEndpoint rosterEndpoint = new XmppRosterListeningEndpoint(connection);
|
||||
rosterEndpoint.afterPropertiesSet();
|
||||
assertEquals(0, rosterSet.size());
|
||||
rosterEndpoint.start();
|
||||
@@ -80,7 +80,7 @@ public class XmppRosterEventMessageDrivenEndpointTests {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNonInitializedFailure(){
|
||||
XmppRosterEventMessageDrivenEndpoint rosterEndpoint = new XmppRosterEventMessageDrivenEndpoint(mock(XMPPConnection.class));
|
||||
XmppRosterListeningEndpoint rosterEndpoint = new XmppRosterListeningEndpoint(mock(XMPPConnection.class));
|
||||
rosterEndpoint.start();
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public class XmppRosterEventMessageDrivenEndpointTests {
|
||||
XMPPConnection connection = mock(XMPPConnection.class);
|
||||
Roster roster = mock(Roster.class);
|
||||
when(connection.getRoster()).thenReturn(roster);
|
||||
XmppRosterEventMessageDrivenEndpoint rosterEndpoint = new XmppRosterEventMessageDrivenEndpoint(connection);
|
||||
XmppRosterListeningEndpoint rosterEndpoint = new XmppRosterListeningEndpoint(connection);
|
||||
QueueChannel channel = new QueueChannel();
|
||||
rosterEndpoint.setRequestChannel(channel);
|
||||
rosterEndpoint.afterPropertiesSet();
|
||||
@@ -106,7 +106,7 @@ public class XmppRosterEventMessageDrivenEndpointTests {
|
||||
XMPPConnection connection = mock(XMPPConnection.class);
|
||||
Roster roster = mock(Roster.class);
|
||||
when(connection.getRoster()).thenReturn(roster);
|
||||
XmppRosterEventMessageDrivenEndpoint rosterEndpoint = new XmppRosterEventMessageDrivenEndpoint(connection);
|
||||
XmppRosterListeningEndpoint rosterEndpoint = new XmppRosterListeningEndpoint(connection);
|
||||
QueueChannel channel = new QueueChannel();
|
||||
rosterEndpoint.setRequestChannel(channel);
|
||||
rosterEndpoint.afterPropertiesSet();
|
||||
@@ -122,7 +122,7 @@ public class XmppRosterEventMessageDrivenEndpointTests {
|
||||
public void testWithImplicitXmppConnection(){
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, mock(XMPPConnection.class));
|
||||
XmppRosterEventMessageDrivenEndpoint endpoint = new XmppRosterEventMessageDrivenEndpoint();
|
||||
XmppRosterListeningEndpoint endpoint = new XmppRosterListeningEndpoint();
|
||||
endpoint.setBeanFactory(bf);
|
||||
endpoint.afterPropertiesSet();
|
||||
assertNotNull(TestUtils.getPropertyValue(endpoint,"xmppConnection"));
|
||||
@@ -130,7 +130,7 @@ public class XmppRosterEventMessageDrivenEndpointTests {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNoXmppConnection(){
|
||||
XmppRosterEventMessageDrivenEndpoint handler = new XmppRosterEventMessageDrivenEndpoint();
|
||||
XmppRosterListeningEndpoint handler = new XmppRosterListeningEndpoint();
|
||||
handler.afterPropertiesSet();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user