INT-1222 moved the spring-integration-xmpp module from the sandbox to the trunk
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.springframework.integration.xmpp.config;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.MessageChannelTemplate;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.message.*;
|
||||
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Josh Long
|
||||
* @since 2.0
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class XmppHeaderEnricherParserTests {
|
||||
|
||||
@Value("#{input}")
|
||||
private DirectChannel input;
|
||||
|
||||
@Value("#{output}")
|
||||
private DirectChannel output;
|
||||
|
||||
@Test
|
||||
public void to() {
|
||||
MessageChannelTemplate messageChannelTemplate = new MessageChannelTemplate();
|
||||
|
||||
output.subscribe(new MessageHandler() {
|
||||
public void handleMessage(Message<?> message)
|
||||
throws MessageRejectedException, MessageHandlingException,
|
||||
MessageDeliveryException {
|
||||
for (String h : message.getHeaders().keySet())
|
||||
System.out.println(String.format("%s=%s (class: %s)", h, message.getHeaders().get(h), message.getHeaders().get(h).getClass().toString()));
|
||||
}
|
||||
});
|
||||
messageChannelTemplate.send(MessageBuilder.withPayload("foo").build(), input);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.xmpp.messages;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class ConsoleChatTests {
|
||||
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
Thread.sleep( 10 * 1000 );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.xmpp.messages;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Josh Long
|
||||
* @since 2.0
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class InboundXmppEndpointTests {
|
||||
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
Thread.sleep( 10 * 1000 );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.xmpp.messages;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Testing support for sending messages.
|
||||
*
|
||||
* @author Josh Long
|
||||
* @since 2.0
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class OutboundXmppEndpointTests {
|
||||
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
Thread.sleep(10 * 1000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.xmpp.messages;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Handle display of incoming XMPP messages to this user.
|
||||
*
|
||||
* @author Josh Long
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
@Component
|
||||
public class XmppMessageConsumer {
|
||||
|
||||
@ServiceActivator
|
||||
public void consume(Object input) throws Throwable {
|
||||
String text = null;
|
||||
if (input instanceof Message) {
|
||||
text = ((Message) input).getBody();
|
||||
}
|
||||
else if (input instanceof String) {
|
||||
text = (String) input;
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"expected either a Smack Message or a String, but received: " + input);
|
||||
}
|
||||
System.out.println("================================================================================");
|
||||
System.out.println("message: " + text);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.xmpp.messages;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.integration.xmpp.XmppHeaders;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Generates XMPP messages every 2s and forwards them on a channel which in turn publishes the message through XMPP.
|
||||
*
|
||||
* @author Josh Long
|
||||
* @since 2.0
|
||||
*/
|
||||
public class XmppMessageProducer implements MessageSource<String> {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(XmppMessageProducer.class);
|
||||
|
||||
private volatile int counter;
|
||||
private String recipient;
|
||||
|
||||
public void setRecipient(final String recipient) {
|
||||
this.recipient = recipient;
|
||||
}
|
||||
|
||||
public Message<String> receive() {
|
||||
try {
|
||||
if (counter > 10) {
|
||||
logger.debug("return null");
|
||||
return null;
|
||||
}
|
||||
counter += 1;
|
||||
Thread.sleep(1000 * 2);
|
||||
|
||||
String msg = "the current time is " + new Date();
|
||||
|
||||
logger.info("sending message to recipient " + recipient);
|
||||
|
||||
return MessageBuilder.withPayload(msg).setHeader(XmppHeaders.CHAT_TO_USER, recipient).build();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
logger.debug("exception thrown when trying to receive a message", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.springframework.integration.xmpp.presence;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* this class demonstrates that when I launch this and then manipulate the status of the
|
||||
* user using Pidgin, the updated state is immediately delivered to the Spring Integration bus.
|
||||
*
|
||||
* @author Josh Long
|
||||
* @since 2.0
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class InboundXmppRosterEventsEndpointTests {
|
||||
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
Thread.sleep( 60 * 1000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.springframework.integration.xmpp.presence;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.
|
||||
*
|
||||
*
|
||||
* @author Josh Long
|
||||
* @since 2.0
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class OutboundXmppRosterEventsEndpointTests {
|
||||
@Test
|
||||
public void testOutbound() throws Throwable {
|
||||
Thread.sleep( 60 * 1000);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.springframework.integration.xmpp.presence;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class will demonstrate using both inbound adapter types in a 1-2 punch of:
|
||||
* <UL>
|
||||
* <LI> notifying the bus of a user's sudden online availability using <xmpp:roster-event-inbound-channel-adapter></LI>
|
||||
* <LI> sending that user a message using the <xmpp:outbound-message-channel-adapter /></LI>
|
||||
* </UL>
|
||||
*
|
||||
* @author Josh Long
|
||||
* @since 2.0
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class PresenceMessageComboTests {
|
||||
|
||||
@Test
|
||||
public void run () throws Throwable {
|
||||
Thread.sleep( 60 * 1000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.springframework.integration.xmpp.presence;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageHeaders;
|
||||
import org.springframework.integration.xmpp.XmppHeaders;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class reacts to changes in {@link org.jivesoftware.smack.packet.Presence} objects for a given account.
|
||||
*
|
||||
* @author Josh Long
|
||||
* @since 2.0
|
||||
*/
|
||||
public class XmppRosterEventConsumer {
|
||||
|
||||
@ServiceActivator
|
||||
public void presenceChanged ( Message<?> presenceEventMsg ) throws Exception {
|
||||
System.out.println(StringUtils.repeat( "-" , 100));
|
||||
String whosePresence = (String)presenceEventMsg.getHeaders().get( XmppHeaders.PRESENCE_FROM);
|
||||
System.out.println( "entries affected: " + whosePresence);
|
||||
MessageHeaders messageHeaders = presenceEventMsg.getHeaders();
|
||||
for( String h : messageHeaders.keySet() )
|
||||
System.out.println( String.format( "%s = %s", h, messageHeaders.get(h)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.springframework.integration.xmpp.presence;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.message.*;
|
||||
import org.springframework.integration.xmpp.XmppHeaders;
|
||||
|
||||
|
||||
/**
|
||||
* This is used in {@link org.springframework.integration.xmpp.presence.OutboundXmppRosterEventsEndpointTests} to produce fake status / presence updates.
|
||||
*
|
||||
* @author Josh Long
|
||||
* @since 2.0
|
||||
*/
|
||||
public class XmppRosterEventProducer implements MessageSource<String> {
|
||||
public Message<String> receive() {
|
||||
try {
|
||||
Thread.sleep(1000 * 10);
|
||||
} catch (InterruptedException e) {
|
||||
// eat it
|
||||
}
|
||||
return (Math.random() > .5) ?
|
||||
MessageBuilder.withPayload(StringUtils.EMPTY).setHeader(XmppHeaders.PRESENCE_MODE, Presence.Mode.chat).setHeader(XmppHeaders.PRESENCE_TYPE, Presence.Type.available)
|
||||
.setHeader(XmppHeaders.PRESENCE_STATUS, "She Loves me").build() :
|
||||
MessageBuilder.withPayload(StringUtils.EMPTY).setHeader(XmppHeaders.PRESENCE_MODE, Presence.Mode.dnd).setHeader(XmppHeaders.PRESENCE_TYPE, Presence.Type.available)
|
||||
.setHeader(XmppHeaders.PRESENCE_STATUS, "She Loves me not").build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user