INT-1554 removed Presence headers, Inbound/Outboound Message Mapper, fixed schema and tests
This commit is contained in:
@@ -404,6 +404,7 @@ project('spring-integration-xmpp') {
|
||||
compile "jivesoftware:smackx:3.1.0"
|
||||
compile "org.springframework:spring-context-support:$springVersion"
|
||||
testCompile project(":spring-integration-test")
|
||||
testCompile project(":spring-integration-stream")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,13 @@
|
||||
package org.springframework.integration.xmpp;
|
||||
|
||||
import org.springframework.integration.MessageHeaders;
|
||||
|
||||
|
||||
/**
|
||||
* Used as keys for {@link org.springframework.integration.Message} objects
|
||||
* that handle XMPP events.
|
||||
*
|
||||
* @author Mario Gray
|
||||
* @author Josh Long
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0
|
||||
*/
|
||||
public class XmppHeaders {
|
||||
@@ -37,17 +36,4 @@ public class XmppHeaders {
|
||||
public static final String CHAT_THREAD_ID = PREFIX + "threadId";
|
||||
|
||||
public static final String TYPE = PREFIX + "type";
|
||||
|
||||
public static final String PRESENCE = PREFIX + "presence";
|
||||
|
||||
public static final String PRESENCE_LANGUAGE = PRESENCE + "language";
|
||||
|
||||
public static final String PRESENCE_PRIORITY = PRESENCE + "priority";
|
||||
|
||||
public static final String PRESENCE_MODE = PRESENCE + "mode";
|
||||
|
||||
public static final String PRESENCE_STATUS = PRESENCE + "status";
|
||||
|
||||
public static final String PRESENCE_FROM = PRESENCE + "from";
|
||||
|
||||
}
|
||||
|
||||
@@ -15,12 +15,13 @@
|
||||
*/
|
||||
package org.springframework.integration.xmpp.config;
|
||||
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.springframework.integration.config.xml.HeaderEnricherParserSupport;
|
||||
import org.springframework.integration.xmpp.XmppHeaders;
|
||||
|
||||
/**
|
||||
* Parser for 'xmpp:header-enricher' element
|
||||
* @author Josh Long
|
||||
* @author Oleg ZHurakousky
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
@@ -32,10 +33,5 @@ public class XmppHeaderEnricherParser extends HeaderEnricherParserSupport {
|
||||
this.addElementToHeaderMapping("message-to", XmppHeaders.CHAT_TO_USER);
|
||||
this.addElementToHeaderMapping("message-thread-id", XmppHeaders.CHAT_THREAD_ID);
|
||||
|
||||
// presence headers
|
||||
this.addElementToHeaderMapping("presence-mode", XmppHeaders.PRESENCE_MODE, Presence.Mode.class);
|
||||
this.addElementToHeaderMapping("presence-from", XmppHeaders.PRESENCE_FROM);
|
||||
this.addElementToHeaderMapping("presence-status", XmppHeaders.PRESENCE_STATUS);
|
||||
this.addElementToHeaderMapping("presence-priority", XmppHeaders.PRESENCE_PRIORITY, Integer.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser;
|
||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
@@ -36,7 +35,6 @@ public class XmppRosterEventOutboundEndpointParser extends AbstractOutboundChann
|
||||
"org.springframework.integration.xmpp.presence.XmppRosterEventMessageSendingHandler");
|
||||
String connectionName = element.getAttribute("xmpp-connection");
|
||||
builder.addConstructorArgReference(connectionName);
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-mapper");
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
/*
|
||||
* 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.presence;
|
||||
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageHeaders;
|
||||
import org.springframework.integration.mapping.MessageMappingException;
|
||||
import org.springframework.integration.mapping.OutboundMessageMapper;
|
||||
import org.springframework.integration.xmpp.XmppHeaders;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of the strategy interface {@link OutboundMessageMapper}
|
||||
* which maps {@link Presence} to {@link Message}
|
||||
*
|
||||
* @author Josh Long
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0
|
||||
*/
|
||||
public class XmppPresenceMessageMapper implements OutboundMessageMapper<Presence> {
|
||||
|
||||
// /**
|
||||
// * Builds {@link Message} with payload of {@link Presence} while also
|
||||
// * setting Presence attributes as {@link MessageHeaders}
|
||||
// *
|
||||
// * @param presence the presence object
|
||||
// * @return the Message
|
||||
// * @throws Exception thrown if conversion should fail
|
||||
// */
|
||||
// @SuppressWarnings("unchecked")
|
||||
// public Message<Presence> toMessage(Presence presence) throws Exception {
|
||||
// MessageBuilder<?> presenceMessageBuilder = MessageBuilder.withPayload(presence);
|
||||
// presenceMessageBuilder.setHeader(XmppHeaders.PRESENCE_PRIORITY, presence.getPriority());
|
||||
// presenceMessageBuilder.setHeader(XmppHeaders.PRESENCE_STATUS, presence.getStatus());
|
||||
// presenceMessageBuilder.setHeader(XmppHeaders.PRESENCE_MODE, presence.getMode());
|
||||
// presenceMessageBuilder.setHeader(XmppHeaders.PRESENCE_FROM, presence.getFrom());
|
||||
//
|
||||
// return (Message<Presence>) presenceMessageBuilder.build();
|
||||
// }
|
||||
|
||||
/**
|
||||
* Builds a {@link Presence} object from the inbound Message headers, if possible.
|
||||
*
|
||||
* @param message the Message whose headers and payload willl b
|
||||
* @return the presence object as constructed from the {@link org.springframework.integration.Message} object
|
||||
* @throws Exception if there is a problem
|
||||
*/
|
||||
public Presence fromMessage(Message<?> message) throws Exception {
|
||||
Object payload = message.getPayload();
|
||||
if (payload instanceof Presence) {
|
||||
return (Presence) payload;
|
||||
}
|
||||
else if (payload instanceof Presence.Type) {
|
||||
Presence.Type presenceType = (Presence.Type) payload;
|
||||
MessageHeaders messageHeaders = message.getHeaders();
|
||||
|
||||
Integer priority = (Integer) messageHeaders.get(XmppHeaders.PRESENCE_PRIORITY);
|
||||
String status = (String) messageHeaders.get(XmppHeaders.PRESENCE_STATUS);
|
||||
String language = (String) messageHeaders.get(XmppHeaders.PRESENCE_LANGUAGE);
|
||||
String from = (String) messageHeaders.get(XmppHeaders.PRESENCE_FROM);
|
||||
|
||||
Object modeObj = messageHeaders.get(XmppHeaders.PRESENCE_MODE);
|
||||
Presence.Mode mode = null;
|
||||
|
||||
if (modeObj != null){
|
||||
if (modeObj instanceof String) {
|
||||
mode = Presence.Mode.valueOf((String) modeObj);
|
||||
}
|
||||
else if (modeObj instanceof Presence.Mode) {
|
||||
mode = (Presence.Mode) modeObj;
|
||||
}
|
||||
else {
|
||||
throw new MessageMappingException("Unsupported type for Presence mode. Only" +
|
||||
" String or Presence.Mode is allowed, but was: " + modeObj.getClass().getName());
|
||||
}
|
||||
}
|
||||
return this.factoryPresence(from, status, priority, presenceType, mode, language);
|
||||
}
|
||||
else {
|
||||
throw new MessageMappingException("Unsupported Payload type. " +
|
||||
"The only supported payload type is org.jivesoftware.smack.packet.Presence: " + payload.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
private Presence factoryPresence(String from, String status, Integer priority,
|
||||
Presence.Type type, Presence.Mode mode, String language) {
|
||||
if (null == type) {
|
||||
type = Presence.Type.available;
|
||||
}
|
||||
|
||||
Presence presence = new Presence(type);
|
||||
|
||||
if (null != priority) {
|
||||
presence.setPriority(priority);
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(status)) {
|
||||
presence.setStatus(status);
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(from)) {
|
||||
presence.setFrom(from);
|
||||
}
|
||||
|
||||
if (null != mode) {
|
||||
presence.setMode(mode);
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(language)) {
|
||||
presence.setLanguage(language);
|
||||
}
|
||||
|
||||
return presence;
|
||||
}
|
||||
}
|
||||
@@ -36,34 +36,18 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class XmppRosterEventMessageSendingHandler extends AbstractMessageHandler {
|
||||
|
||||
private OutboundMessageMapper<Presence> messageMapper;
|
||||
|
||||
private final XMPPConnection xmppConnection;
|
||||
|
||||
public XmppRosterEventMessageSendingHandler(XMPPConnection xmppConnection){
|
||||
Assert.notNull(xmppConnection, "'xmppConnection' must not be null");
|
||||
this.xmppConnection = xmppConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* the MessageMapper is responsible for converting outbound Messages into status updates of type
|
||||
* {@link org.jivesoftware.smack.packet.Presence}
|
||||
*
|
||||
* @param messageMapper mapper for the message into a {@link Presence} instance
|
||||
*/
|
||||
public void setMessageMapper(OutboundMessageMapper<Presence> messageMapper) {
|
||||
this.messageMapper = messageMapper;
|
||||
}
|
||||
|
||||
protected void onInit() throws Exception {
|
||||
if (this.messageMapper == null) {
|
||||
this.messageMapper = new XmppPresenceMessageMapper();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMessageInternal(Message<?> message) throws Exception {
|
||||
Presence presence = this.messageMapper.fromMessage(message);
|
||||
this.xmppConnection.sendPacket(presence);
|
||||
Object payload = message.getPayload();
|
||||
Assert.isInstanceOf(Presence.class, payload, "'payload' must be of type 'org.jivesoftware.smack.packet.Presence', was "
|
||||
+ payload.getClass().getName());
|
||||
this.xmppConnection.sendPacket((Presence)payload);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,15 +57,6 @@
|
||||
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="message-mapper" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.integration.mapping.OutboundMessageMapper"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="channel" use="required" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
@@ -191,15 +182,8 @@
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="transformerType">
|
||||
<xsd:choice minOccurs="1" maxOccurs="unbounded">
|
||||
|
||||
|
||||
<xsd:element name="message-to" type="headerType"/>
|
||||
<xsd:element name="message-thread-id" type="headerType"/>
|
||||
<xsd:element name="presence-from" type="headerType"/>
|
||||
<xsd:element name="presence-mode" type="headerType"/>
|
||||
<xsd:element name="presence-type" type="headerType"/>
|
||||
<xsd:element name="presence-status" type="headerType"/>
|
||||
<xsd:element name="presence-priority" type="headerType"/>
|
||||
</xsd:choice>
|
||||
<xsd:attribute name="default-overwrite">
|
||||
<xsd:annotation>
|
||||
|
||||
@@ -17,11 +17,7 @@
|
||||
<channel id="output"/>
|
||||
|
||||
<xmpp:header-enricher input-channel="input" output-channel="output">
|
||||
<xmpp:presence-from value="test@example.org"/>
|
||||
<xmpp:presence-mode value="available"/>
|
||||
<xmpp:message-to value="test1@example.org"/>
|
||||
<xmpp:presence-type value="unavailable"/>
|
||||
<xmpp:message-to value="test1@example.org"/>
|
||||
</xmpp:header-enricher>
|
||||
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -16,19 +16,25 @@
|
||||
|
||||
package org.springframework.integration.xmpp.config;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageDeliveryException;
|
||||
import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.integration.MessageRejectedException;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.core.MessagingTemplate;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.xmpp.XmppHeaders;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -41,27 +47,30 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class XmppHeaderEnricherParserTests {
|
||||
|
||||
|
||||
private static final Log logger = LogFactory.getLog(XmppHeaderEnricherParserTests.class);
|
||||
|
||||
@Value("#{input}")
|
||||
private DirectChannel input;
|
||||
|
||||
@Value("#{output}")
|
||||
private DirectChannel output;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void to() {
|
||||
MessagingTemplate messagingTemplate = new MessagingTemplate();
|
||||
output.subscribe(new MessageHandler() {
|
||||
public void handleMessage(Message<?> message)
|
||||
throws MessageRejectedException, MessageHandlingException,
|
||||
MessageDeliveryException {
|
||||
for (String h : message.getHeaders().keySet())
|
||||
logger.debug(String.format("%s=%s (class: %s)", h, message.getHeaders().get(h), message.getHeaders().get(h).getClass().toString()));
|
||||
MessageHandler handler = mock(MessageHandler.class);
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Message message = (Message) invocation.getArguments()[0];
|
||||
String chatToUser = (String) message.getHeaders().get(XmppHeaders.CHAT_TO_USER);
|
||||
assertNotNull(chatToUser);
|
||||
assertEquals("test1@example.org", chatToUser);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}).when(handler).handleMessage(Mockito.any(Message.class));
|
||||
output.subscribe(handler);
|
||||
messagingTemplate.send(input, MessageBuilder.withPayload("foo").build());
|
||||
verify(handler, times(1)).handleMessage(Mockito.any(Message.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,12 +26,7 @@
|
||||
|
||||
<int-xmpp:roster-event-outbound-channel-adapter id="eventOutboundRosterAdapter"
|
||||
xmpp-connection="testConnection"
|
||||
channel="eventChannel"
|
||||
message-mapper="mockMappper"/>
|
||||
channel="eventChannel"/>
|
||||
|
||||
<bean id="mockMappper" class="org.mockito.Mockito" factory-method="mock">
|
||||
<constructor-arg value="org.springframework.integration.mapping.OutboundMessageMapper"/>
|
||||
</bean>
|
||||
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.integration.xmpp.config;
|
||||
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -24,10 +22,6 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.endpoint.PollingConsumer;
|
||||
import org.springframework.integration.mapping.OutboundMessageMapper;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.xmpp.presence.XmppPresenceMessageMapper;
|
||||
import org.springframework.integration.xmpp.presence.XmppRosterEventMessageSendingHandler;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
@@ -42,29 +36,12 @@ public class XmppRosterEventOutboundChannelAdapterParserTests {
|
||||
Object pollingConsumer = ac.getBean("pollingOutboundRosterAdapter");
|
||||
assertTrue(pollingConsumer instanceof PollingConsumer);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testRosterEventOutboundChannelAdapterParserDefaultMapper(){
|
||||
ApplicationContext ac =
|
||||
new ClassPathXmlApplicationContext("XmppRosterEventOutboundChannelAdapterParserTests-context.xml", this.getClass());
|
||||
Object pollingConsumer = ac.getBean("pollingOutboundRosterAdapter");
|
||||
XmppRosterEventMessageSendingHandler handler =
|
||||
TestUtils.getPropertyValue(pollingConsumer, "handler", XmppRosterEventMessageSendingHandler.class);
|
||||
OutboundMessageMapper mapper = TestUtils.getPropertyValue(handler, "messageMapper", OutboundMessageMapper.class);
|
||||
assertNotNull(mapper);
|
||||
assertTrue(mapper instanceof XmppPresenceMessageMapper);
|
||||
}
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testRosterEventOutboundChannelAdapterParserCustomMapperEventDriven(){
|
||||
public void testRosterEventOutboundChannelAdapterParserEventConsumer(){
|
||||
ApplicationContext ac =
|
||||
new ClassPathXmlApplicationContext("XmppRosterEventOutboundChannelAdapterParserTests-context.xml", this.getClass());
|
||||
Object eventConsumer = ac.getBean("eventOutboundRosterAdapter");
|
||||
assertTrue(eventConsumer instanceof EventDrivenConsumer);
|
||||
XmppRosterEventMessageSendingHandler handler =
|
||||
TestUtils.getPropertyValue(eventConsumer, "handler", XmppRosterEventMessageSendingHandler.class);
|
||||
OutboundMessageMapper mapper = TestUtils.getPropertyValue(handler, "messageMapper", OutboundMessageMapper.class);
|
||||
assertNotNull(mapper);
|
||||
assertFalse(mapper instanceof XmppPresenceMessageMapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,33 +8,33 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-3.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/xmpp http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp.xsd
|
||||
http://www.springframework.org/schema/integration/xmpp http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp-2.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
|
||||
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
|
||||
http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd">
|
||||
|
||||
|
||||
<beans:bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:ignoreUnresolvablePlaceholders="false">
|
||||
<beans:bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<beans:property name="location" value="classpath:test.properties"/>
|
||||
</beans:bean>
|
||||
|
||||
<xmpp:xmpp-connection
|
||||
id="testConnection"
|
||||
user="${user.2.login}"
|
||||
password="${user.2.password}"
|
||||
host="${user.2.host}"
|
||||
port="${user.2.port}"
|
||||
resource="${user.2.resource}"
|
||||
service-name="${user.2.service}"
|
||||
/>
|
||||
user="${user.1.login}"
|
||||
password="${user.1.password}"
|
||||
host="${user.1.host}"
|
||||
service-name="${user.1.service}"/>
|
||||
|
||||
<console:stdout-channel-adapter id="stdout" append-newline="true"/>
|
||||
<console:stdin-channel-adapter id="stdin"/>
|
||||
|
||||
<header-enricher input-channel="stdin" output-channel="messagesToSend">
|
||||
<header name="#{T(org.springframework.integration.xmpp.XmppHeaders).CHAT_TO_USER}" value="${user.1.login}"/>
|
||||
</header-enricher>
|
||||
|
||||
<console:stdin-channel-adapter id="stdin">
|
||||
<poller fixed-rate="1000"/>
|
||||
</console:stdin-channel-adapter>
|
||||
|
||||
<xmpp:header-enricher input-channel="stdin" output-channel="messagesToSend">
|
||||
<xmpp:message-to value="${user.2.login}"/>
|
||||
</xmpp:header-enricher>
|
||||
|
||||
<xmpp:message-inbound-channel-adapter channel="stdout" xmpp-connection="testConnection"/>
|
||||
|
||||
@@ -42,9 +42,4 @@
|
||||
|
||||
<xmpp:message-outbound-channel-adapter channel="messagesToSend" xmpp-connection="testConnection"/>
|
||||
|
||||
<poller default="true">
|
||||
<interval-trigger interval="1" time-unit="SECONDS"/>
|
||||
</poller>
|
||||
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ConsoleChatTests {
|
||||
@Test
|
||||
@Ignore
|
||||
public void run() throws Exception {
|
||||
Thread.sleep(10 * 1000);
|
||||
Thread.sleep(10 * 1000 * 1000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,13 +33,13 @@ 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)));
|
||||
}
|
||||
// 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)));
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,17 +35,18 @@ import org.springframework.integration.xmpp.XmppHeaders;
|
||||
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("available").setHeader(
|
||||
XmppHeaders.PRESENCE_MODE, Presence.Mode.chat)
|
||||
.setHeader(XmppHeaders.PRESENCE_STATUS, "She Loves me").build()
|
||||
: MessageBuilder.withPayload(StringUtils.EMPTY).setHeader(XmppHeaders.PRESENCE_MODE, Presence.Mode.dnd)
|
||||
.setHeader(XmppHeaders.PRESENCE_STATUS, "She Loves me not").build();
|
||||
// try {
|
||||
// Thread.sleep(1000 * 10);
|
||||
// }
|
||||
// catch (InterruptedException e) {
|
||||
// // eat it
|
||||
// }
|
||||
// return (Math.random() > .5) ? MessageBuilder.withPayload("available").setHeader(
|
||||
// XmppHeaders.PRESENCE_MODE, Presence.Mode.chat)
|
||||
// .setHeader(XmppHeaders.PRESENCE_STATUS, "She Loves me").build()
|
||||
// : MessageBuilder.withPayload(StringUtils.EMPTY).setHeader(XmppHeaders.PRESENCE_MODE, Presence.Mode.dnd)
|
||||
// .setHeader(XmppHeaders.PRESENCE_STATUS, "She Loves me not").build();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.junit.Test;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.mapping.MessageMappingException;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.xmpp.XmppHeaders;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
@@ -34,61 +33,61 @@ public class XmppPresenceMessageMapperTests {
|
||||
|
||||
@Test
|
||||
public void testFromMessageWithPayloadPresence() throws Exception{
|
||||
Presence presence = new Presence(Type.available, "Hello", 1, Mode.chat);
|
||||
Message<?> message = MessageBuilder.withPayload(presence).build();
|
||||
XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
Presence mappedPresence = mapper.fromMessage(message);
|
||||
assertEquals(Mode.chat, mappedPresence.getMode());
|
||||
assertEquals(Type.available, mappedPresence.getType());
|
||||
assertEquals("Hello", mappedPresence.getStatus());
|
||||
assertEquals(1, mappedPresence.getPriority());
|
||||
// Presence presence = new Presence(Type.available, "Hello", 1, Mode.chat);
|
||||
// Message<?> message = MessageBuilder.withPayload(presence).build();
|
||||
// XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
// Presence mappedPresence = mapper.fromMessage(message);
|
||||
// assertEquals(Mode.chat, mappedPresence.getMode());
|
||||
// assertEquals(Type.available, mappedPresence.getType());
|
||||
// assertEquals("Hello", mappedPresence.getStatus());
|
||||
// assertEquals(1, mappedPresence.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromMessageWithPayloadPresenceType() throws Exception{
|
||||
Message<?> message = MessageBuilder.withPayload(Type.available)
|
||||
.setHeader(XmppHeaders.PRESENCE_FROM, "oleg")
|
||||
.setHeader(XmppHeaders.PRESENCE_MODE, Mode.chat)
|
||||
.setHeader(XmppHeaders.PRESENCE_STATUS, "hello")
|
||||
.setHeader(XmppHeaders.PRESENCE_PRIORITY, 1)
|
||||
.build();
|
||||
XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
Presence mappedPresence = mapper.fromMessage(message);
|
||||
assertEquals(Mode.chat, mappedPresence.getMode());
|
||||
assertEquals(Type.available, mappedPresence.getType());
|
||||
assertEquals("hello", mappedPresence.getStatus());
|
||||
assertEquals(1, mappedPresence.getPriority());
|
||||
}
|
||||
@Test
|
||||
public void testFromMessageWithPayloadPresenceTypeAndStringModeType() throws Exception{
|
||||
Message<?> message = MessageBuilder.withPayload(Type.available)
|
||||
.setHeader(XmppHeaders.PRESENCE_FROM, "oleg")
|
||||
.setHeader(XmppHeaders.PRESENCE_MODE, "chat")
|
||||
.setHeader(XmppHeaders.PRESENCE_STATUS, "hello")
|
||||
.setHeader(XmppHeaders.PRESENCE_PRIORITY, 1)
|
||||
.build();
|
||||
XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
Presence mappedPresence = mapper.fromMessage(message);
|
||||
assertEquals(Mode.chat, mappedPresence.getMode());
|
||||
assertEquals(Type.available, mappedPresence.getType());
|
||||
assertEquals("hello", mappedPresence.getStatus());
|
||||
assertEquals(1, mappedPresence.getPriority());
|
||||
}
|
||||
// @Test
|
||||
// public void testFromMessageWithPayloadPresenceType() throws Exception{
|
||||
// Message<?> message = MessageBuilder.withPayload(Type.available)
|
||||
// .setHeader(XmppHeaders.PRESENCE_FROM, "oleg")
|
||||
// .setHeader(XmppHeaders.PRESENCE_MODE, Mode.chat)
|
||||
// .setHeader(XmppHeaders.PRESENCE_STATUS, "hello")
|
||||
// .setHeader(XmppHeaders.PRESENCE_PRIORITY, 1)
|
||||
// .build();
|
||||
// XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
// Presence mappedPresence = mapper.fromMessage(message);
|
||||
// assertEquals(Mode.chat, mappedPresence.getMode());
|
||||
// assertEquals(Type.available, mappedPresence.getType());
|
||||
// assertEquals("hello", mappedPresence.getStatus());
|
||||
// assertEquals(1, mappedPresence.getPriority());
|
||||
// }
|
||||
// @Test
|
||||
// public void testFromMessageWithPayloadPresenceTypeAndStringModeType() throws Exception{
|
||||
// Message<?> message = MessageBuilder.withPayload(Type.available)
|
||||
// .setHeader(XmppHeaders.PRESENCE_FROM, "oleg")
|
||||
// .setHeader(XmppHeaders.PRESENCE_MODE, "chat")
|
||||
// .setHeader(XmppHeaders.PRESENCE_STATUS, "hello")
|
||||
// .setHeader(XmppHeaders.PRESENCE_PRIORITY, 1)
|
||||
// .build();
|
||||
// XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
// Presence mappedPresence = mapper.fromMessage(message);
|
||||
// assertEquals(Mode.chat, mappedPresence.getMode());
|
||||
// assertEquals(Type.available, mappedPresence.getType());
|
||||
// assertEquals("hello", mappedPresence.getStatus());
|
||||
// assertEquals(1, mappedPresence.getPriority());
|
||||
// }
|
||||
|
||||
@Test(expected=MessageMappingException.class)
|
||||
public void testFromMessageWithPayloadPresenceTypeUnsupportedMode() throws Exception{
|
||||
|
||||
Message<?> message = MessageBuilder.withPayload(Type.available)
|
||||
.setHeader(XmppHeaders.PRESENCE_MODE, 1)
|
||||
.build();
|
||||
XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
mapper.fromMessage(message);
|
||||
}
|
||||
// @Test(expected=MessageMappingException.class)
|
||||
// public void testFromMessageWithPayloadPresenceTypeUnsupportedMode() throws Exception{
|
||||
//
|
||||
// Message<?> message = MessageBuilder.withPayload(Type.available)
|
||||
// .setHeader(XmppHeaders.PRESENCE_MODE, 1)
|
||||
// .build();
|
||||
// XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
// mapper.fromMessage(message);
|
||||
// }
|
||||
|
||||
@Test(expected=MessageMappingException.class)
|
||||
public void testFromMessageWithUnsupportedPayload() throws Exception{
|
||||
Message<?> message = MessageBuilder.withPayload("hello").build();
|
||||
XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
mapper.fromMessage(message);
|
||||
}
|
||||
// @Test(expected=MessageMappingException.class)
|
||||
// public void testFromMessageWithUnsupportedPayload() throws Exception{
|
||||
// Message<?> message = MessageBuilder.withPayload("hello").build();
|
||||
// XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
// mapper.fromMessage(message);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,24 +1,6 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# to be able to run these tests, put this file on your desktop and configure as appropriate
|
||||
user.1.login=user@gmail.com
|
||||
user.2.login=user1@gmail.com
|
||||
|
||||
user.1.login=user2@gmail.com
|
||||
user.1.password=password
|
||||
user.1.host=talk.google.com
|
||||
user.1.service=gmail.com
|
||||
#user.1.sasl.mechanism=PLAIN
|
||||
#user.1.sasl.index=0
|
||||
#user.1.resource=resource
|
||||
#user.1.port=5222
|
||||
user.1.service=gmail.com
|
||||
Reference in New Issue
Block a user