renaming components

This commit is contained in:
Mark Fisher
2010-11-13 11:49:58 -05:00
parent ad5adf3fbf
commit 22821d42d3
5 changed files with 44 additions and 38 deletions

View File

@@ -33,7 +33,7 @@ public class XmppRosterEventOutboundEndpointParser extends AbstractOutboundChann
@Override
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
"org.springframework.integration.xmpp.outbound.XmppRosterEventMessageSendingHandler");
"org.springframework.integration.xmpp.outbound.XmppPresenceSendingMessageHandler");
String connectionName = element.getAttribute("xmpp-connection");
builder.addConstructorArgReference(connectionName);
return builder.getBeanDefinition();

View File

@@ -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 org.jivesoftware.smack.Chat;
@@ -20,6 +21,7 @@ import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.integration.support.MessageBuilder;
@@ -34,9 +36,9 @@ import org.springframework.util.Assert;
* @author Josh Long
* @author Mark Fisher
* @author Oleg Zhurakousky
*
* @since 2.0
*/
public class XmppMessageDrivenEndpoint extends AbstractXmppConnectionAwareEndpoint {
public class XmppMessageDrivenEndpoint extends AbstractXmppConnectionAwareEndpoint {
private final MessagingTemplate messagingTemplate = new MessagingTemplate();
@@ -45,15 +47,17 @@ public class XmppMessageDrivenEndpoint extends AbstractXmppConnectionAwareEndpoi
private volatile boolean extractPayload = true;
private volatile PacketListener packetListener;
public XmppMessageDrivenEndpoint(){
super();
}
public XmppMessageDrivenEndpoint(XMPPConnection xmppConnection){
public XmppMessageDrivenEndpoint(XMPPConnection xmppConnection) {
super(xmppConnection);
}
/**
* @param requestChannel the channel on which the inbound message should be sent
*/
@@ -70,9 +74,24 @@ public class XmppMessageDrivenEndpoint extends AbstractXmppConnectionAwareEndpoi
this.extractPayload = extractPayload;
}
@Override
protected void onInit() throws Exception {
super.onInit();
this.messagingTemplate.setDefaultChannel(requestChannel);
this.messagingTemplate.afterPropertiesSet();
this.packetListener = new PacketListener() {
public void processPacket(final Packet packet) {
if (packet instanceof org.jivesoftware.smack.packet.Message) {
org.jivesoftware.smack.packet.Message xmppMessage = (org.jivesoftware.smack.packet.Message) packet;
forwardXmppMessage(xmppConnection.getChatManager().getThreadChat(xmppMessage.getThread()), xmppMessage);
}
}
};
}
@Override
protected void doStart() {
Assert.isTrue(this.initialized, this.getComponentName() + "#" + this.getComponentType() + " must be initialized");
Assert.isTrue(this.initialized, this.getComponentName() + " must be initialized");
xmppConnection.addPacketListener(this.packetListener, null);
}
@@ -81,25 +100,12 @@ public class XmppMessageDrivenEndpoint extends AbstractXmppConnectionAwareEndpoi
xmppConnection.removePacketListener(this.packetListener);
}
@Override
protected void onInit() throws Exception {
super.onInit();
this.messagingTemplate.setDefaultChannel(requestChannel);
this.messagingTemplate.afterPropertiesSet();
this.packetListener = new PacketListener() {
public void processPacket(final Packet packet) {
org.jivesoftware.smack.packet.Message message = (org.jivesoftware.smack.packet.Message) packet;
forwardXmppMessage(xmppConnection.getChatManager().getThreadChat(message.getThread()), message);
}
};
}
private void forwardXmppMessage(Chat chat, Message xmppMessage) {
Object payload = (this.extractPayload ? xmppMessage.getBody() : xmppMessage);
MessageBuilder<?> messageBuilder = MessageBuilder.withPayload(payload)
.setHeader(XmppHeaders.TYPE, xmppMessage.getType())
.setHeader(XmppHeaders.CHAT, chat);
messagingTemplate.send(requestChannel, messageBuilder.build());
this.messagingTemplate.send(requestChannel, messageBuilder.build());
}
}

View File

@@ -23,28 +23,28 @@ import org.springframework.integration.xmpp.AbstractXmppConnectionAwareMessageHa
import org.springframework.util.Assert;
/**
* This class will facilitate publishing updated presence values for a given connection.
* MessageHandler that publishes updated Presence values for a given connection.
*
* @author Josh Long
* @author Oleg Zhurakousky
*
* @since 2.0
*/
public class XmppRosterEventMessageSendingHandler extends AbstractXmppConnectionAwareMessageHandler {
public XmppRosterEventMessageSendingHandler(){
public class XmppPresenceSendingMessageHandler extends AbstractXmppConnectionAwareMessageHandler {
public XmppPresenceSendingMessageHandler() {
super();
}
public XmppRosterEventMessageSendingHandler(XMPPConnection xmppConnection){
public XmppPresenceSendingMessageHandler(XMPPConnection xmppConnection) {
super(xmppConnection);
}
@Override
protected void handleMessageInternal(Message<?> message) throws Exception {
Assert.isTrue(this.initialized, this.getComponentName() + "#" + this.getComponentType() + " must be initialized");
Assert.isTrue(this.initialized, this.getComponentName() + " must be initialized");
Object payload = message.getPayload();
Assert.isInstanceOf(Presence.class, payload, "'payload' must be of type 'org.jivesoftware.smack.packet.Presence', was "
Assert.isInstanceOf(Presence.class, payload, "'payload' must be of type 'org.jivesoftware.smack.packet.Presence', was: "
+ payload.getClass().getName());
this.xmppConnection.sendPacket((Presence)payload);
}

View File

@@ -20,12 +20,12 @@ import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.integration.xmpp.outbound.XmppRosterEventMessageSendingHandler;
import org.springframework.integration.xmpp.outbound.XmppPresenceSendingMessageHandler;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Tests {@link XmppRosterEventMessageSendingHandler} to ensure that we are able to publish status.
* Tests {@link XmppPresenceSendingMessageHandler} to ensure that we are able to publish status.
*
* @author Josh Long
* @since 2.0

View File

@@ -26,7 +26,7 @@ import org.springframework.integration.MessageHandlingException;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.xmpp.XmppContextUtils;
import org.springframework.integration.xmpp.outbound.XmppRosterEventMessageSendingHandler;
import org.springframework.integration.xmpp.outbound.XmppPresenceSendingMessageHandler;
/**
* @author Oleg Zhurakousky
@@ -37,7 +37,7 @@ public class XmppRosterEventMessageSendingHandlerTests {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testPresencePayload(){
XmppRosterEventMessageSendingHandler handler = new XmppRosterEventMessageSendingHandler(mock(XMPPConnection.class));
XmppPresenceSendingMessageHandler handler = new XmppPresenceSendingMessageHandler(mock(XMPPConnection.class));
handler.afterPropertiesSet();
handler.handleMessage(new GenericMessage(mock(Presence.class)));
}
@@ -45,7 +45,7 @@ public class XmppRosterEventMessageSendingHandlerTests {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test(expected=MessageHandlingException.class)
public void testWrongPayload(){
XmppRosterEventMessageSendingHandler handler = new XmppRosterEventMessageSendingHandler(mock(XMPPConnection.class));
XmppPresenceSendingMessageHandler handler = new XmppPresenceSendingMessageHandler(mock(XMPPConnection.class));
handler.afterPropertiesSet();
handler.handleMessage(new GenericMessage(new Object()));
}
@@ -54,7 +54,7 @@ public class XmppRosterEventMessageSendingHandlerTests {
public void testWithImplicitXmppConnection(){
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, mock(XMPPConnection.class));
XmppRosterEventMessageSendingHandler handler = new XmppRosterEventMessageSendingHandler();
XmppPresenceSendingMessageHandler handler = new XmppPresenceSendingMessageHandler();
handler.setBeanFactory(bf);
handler.afterPropertiesSet();
assertNotNull(TestUtils.getPropertyValue(handler,"xmppConnection"));
@@ -62,7 +62,7 @@ public class XmppRosterEventMessageSendingHandlerTests {
@Test(expected=IllegalArgumentException.class)
public void testNoXmppConnection(){
XmppRosterEventMessageSendingHandler handler = new XmppRosterEventMessageSendingHandler();
XmppPresenceSendingMessageHandler handler = new XmppPresenceSendingMessageHandler();
handler.afterPropertiesSet();
}
}