INT-3383: Update to Smack 4.0.0
JIRA: https://jira.spring.io/browse/INT-3383 The family of Message.(set|get)Properties methods has been factored out of Smack as an extra extension. Use JivePropertiesManager as replacement. It is no longer necessary to supress Smack path warnings. Delete custom smack-config.xml, as all it did was disabling certain (important) SASL mechanisms. Also remove the unit test that verified this. Some unit tests mock ChatManager and Chat for no reason, delete those lines. XMPPConnection.getHost() and .getPort() are only valid after the connection got established, due the fact that those information is often only available after a DNS SRV lookup was performed. Remove the lines in unit tests that verified their value. Remove the truststorePath example in documentation, since Smack 4.0 no longer provides support for providing a custom truststore. Instead ConnectionConfiguration in Smack 4.0 allows to set a custom SSLContext (which then again can provide a TrustManager that uses a custom truststore).
This commit is contained in:
committed by
Artem Bilan
parent
ca2ce6adac
commit
714db85681
15
build.gradle
15
build.gradle
@@ -107,7 +107,8 @@ subprojects { subproject ->
|
||||
saajImplVersion = '1.3.23'
|
||||
servletApiVersion = '3.1.0'
|
||||
slf4jVersion = "1.7.6"
|
||||
smackVersion = '3.2.1'
|
||||
smack3Version = '3.2.1'
|
||||
smackVersion = '4.0.0'
|
||||
springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '1.3.4.RELEASE'
|
||||
springDataMongoVersion = '1.5.0.RELEASE'
|
||||
springDataRedisVersion = '1.3.0.RELEASE'
|
||||
@@ -636,8 +637,8 @@ project('spring-integration-ws') {
|
||||
exclude group: 'org.springframework'
|
||||
}
|
||||
testCompile "javax.jms:jms-api:$jmsApiVersion"
|
||||
testCompile "org.igniterealtime.smack:smack:$smackVersion"
|
||||
testCompile "org.igniterealtime.smack:smackx:$smackVersion"
|
||||
testCompile "org.igniterealtime.smack:smack:$smack3Version"
|
||||
testCompile "org.igniterealtime.smack:smackx:$smack3Version"
|
||||
testCompile "javax.mail:javax.mail-api:$javaxMailVersion"
|
||||
testRuntime "com.sun.mail:mailapi:$javaxMailVersion"
|
||||
}
|
||||
@@ -667,14 +668,12 @@ project('spring-integration-xmpp') {
|
||||
dependencies {
|
||||
compile project(":spring-integration-core")
|
||||
compile("javax.activation:activation:$javaxActivationVersion", optional)
|
||||
compile "org.igniterealtime.smack:smack:$smackVersion"
|
||||
compile "org.igniterealtime.smack:smackx:$smackVersion"
|
||||
compile "org.igniterealtime.smack:smack-tcp:$smackVersion"
|
||||
compile "org.igniterealtime.smack:smack-resolver-javax:$smackVersion"
|
||||
compile "org.igniterealtime.smack:smack-extensions:$smackVersion"
|
||||
compile "org.springframework:spring-context-support:$springVersion"
|
||||
testCompile project(":spring-integration-stream")
|
||||
}
|
||||
|
||||
// suppress smack path warnings
|
||||
[compileJava,compileTestJava]*.options*.compilerArgs = ["${xLintArg},-path"]
|
||||
}
|
||||
|
||||
project("spring-integration-bom") {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -19,7 +19,9 @@ package org.springframework.integration.xmpp.config;
|
||||
import org.jivesoftware.smack.ConnectionConfiguration;
|
||||
import org.jivesoftware.smack.ConnectionListener;
|
||||
import org.jivesoftware.smack.Roster;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
import org.springframework.beans.factory.config.AbstractFactoryBean;
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
@@ -27,29 +29,31 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* This class configures an {@link org.jivesoftware.smack.XMPPConnection} object.
|
||||
* This class configures an {@link org.jivesoftware.smack.XMPPConnection} object.
|
||||
* This object is used for all scenarios to talk to a Smack server.
|
||||
*
|
||||
* @author Josh Long
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Florian Schmaus
|
||||
*
|
||||
* @see org.jivesoftware.smack.XMPPConnection
|
||||
* @since 2.0
|
||||
*/
|
||||
public class XmppConnectionFactoryBean extends AbstractFactoryBean<XMPPConnection> implements SmartLifecycle{
|
||||
|
||||
private final ConnectionConfiguration connectionConfiguration;
|
||||
|
||||
|
||||
private volatile String resource = null; // server will generate resource if not provided
|
||||
|
||||
|
||||
private volatile String user;
|
||||
|
||||
|
||||
private volatile String password;
|
||||
|
||||
|
||||
private volatile String subscriptionMode = "accept_all";
|
||||
|
||||
|
||||
private volatile XMPPConnection connection;
|
||||
|
||||
|
||||
private volatile boolean autoStartup = true;
|
||||
|
||||
private volatile int phase = Integer.MIN_VALUE;
|
||||
@@ -69,6 +73,10 @@ public class XmppConnectionFactoryBean extends AbstractFactoryBean<XMPPConnectio
|
||||
this.autoStartup = autoStartup;
|
||||
}
|
||||
|
||||
public void setPhase(int phase) {
|
||||
this.phase = phase;
|
||||
}
|
||||
|
||||
public void setSubscriptionMode(String subscriptionMode) {
|
||||
this.subscriptionMode = subscriptionMode;
|
||||
}
|
||||
@@ -80,11 +88,11 @@ public class XmppConnectionFactoryBean extends AbstractFactoryBean<XMPPConnectio
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
|
||||
public void setResource(String resource) {
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<? extends XMPPConnection> getObjectType() {
|
||||
return XMPPConnection.class;
|
||||
@@ -92,7 +100,7 @@ public class XmppConnectionFactoryBean extends AbstractFactoryBean<XMPPConnectio
|
||||
|
||||
@Override
|
||||
protected XMPPConnection createInstance() throws Exception {
|
||||
this.connection = new XMPPConnection(this.connectionConfiguration);
|
||||
this.connection = new XMPPTCPConnection(this.connectionConfiguration);
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
@@ -118,7 +126,8 @@ public class XmppConnectionFactoryBean extends AbstractFactoryBean<XMPPConnectio
|
||||
this.running = true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new BeanInitializationException("failed to connect to " + this.connectionConfiguration.getHost(), e);
|
||||
throw new BeanInitializationException("failed to connect to XMPP service for "
|
||||
+ this.connectionConfiguration.getServiceName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,7 +135,11 @@ public class XmppConnectionFactoryBean extends AbstractFactoryBean<XMPPConnectio
|
||||
public void stop() {
|
||||
synchronized (this.lifecycleMonitor) {
|
||||
if (this.isRunning()) {
|
||||
this.connection.disconnect();
|
||||
try {
|
||||
this.connection.disconnect();
|
||||
} catch (NotConnectedException e) {
|
||||
// Ignore
|
||||
}
|
||||
this.running = false;
|
||||
}
|
||||
}
|
||||
@@ -171,6 +184,16 @@ public class XmppConnectionFactoryBean extends AbstractFactoryBean<XMPPConnectio
|
||||
public void connectionClosed() {
|
||||
logger.debug("Connection closed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connected(XMPPConnection connection) {
|
||||
logger.debug("Connection connected");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void authenticated(XMPPConnection connection) {
|
||||
logger.debug("Connection authenticated");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -22,7 +22,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
|
||||
import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager;
|
||||
import org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension;
|
||||
import org.springframework.integration.mapping.AbstractHeaderMapper;
|
||||
import org.springframework.integration.xmpp.XmppHeaders;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -32,10 +33,12 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Florian Schmaus
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
public class DefaultXmppHeaderMapper extends AbstractHeaderMapper<Message> implements XmppHeaderMapper {
|
||||
|
||||
|
||||
private static final List<String> STANDARD_HEADER_NAMES = new ArrayList<String>();
|
||||
|
||||
static {
|
||||
@@ -49,17 +52,6 @@ public class DefaultXmppHeaderMapper extends AbstractHeaderMapper<Message> imple
|
||||
@Override
|
||||
protected Map<String, Object> extractStandardHeaders(Message source) {
|
||||
Map<String, Object> headers = new HashMap<String, Object>();
|
||||
/*Collection<PacketExtension> extensions = source.getExtensions();
|
||||
if (!CollectionUtils.isEmpty(extensions)) {
|
||||
for (PacketExtension extension : extensions) {
|
||||
String name = extension.getElementName();
|
||||
String namespace = extension.getNamespace();
|
||||
if (StringUtils.hasText(namespace)) {
|
||||
name = namespace + ":" + name;
|
||||
}
|
||||
headers.put(name, extension.toXML());
|
||||
}
|
||||
}*/
|
||||
String from = source.getFrom();
|
||||
if (StringUtils.hasText(from)) {
|
||||
headers.put(XmppHeaders.FROM, from);
|
||||
@@ -86,8 +78,12 @@ public class DefaultXmppHeaderMapper extends AbstractHeaderMapper<Message> imple
|
||||
@Override
|
||||
protected Map<String, Object> extractUserDefinedHeaders(Message source) {
|
||||
Map<String, Object> headers = new HashMap<String, Object>();
|
||||
for (String propertyName : source.getPropertyNames()) {
|
||||
headers.put(propertyName, source.getProperty(propertyName));
|
||||
JivePropertiesExtension jpe = (JivePropertiesExtension) source.getExtension(JivePropertiesExtension.NAMESPACE);
|
||||
if (jpe == null) {
|
||||
return headers;
|
||||
}
|
||||
for (String propertyName : jpe.getPropertyNames()) {
|
||||
headers.put(propertyName, JivePropertiesManager.getProperty(source, propertyName));
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
@@ -129,7 +125,7 @@ public class DefaultXmppHeaderMapper extends AbstractHeaderMapper<Message> imple
|
||||
|
||||
@Override
|
||||
protected void populateUserDefinedHeader(String headerName, Object headerValue, Message target) {
|
||||
target.setProperty(headerName, headerValue);
|
||||
JivePropertiesManager.addProperty(target, headerName, headerValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -145,4 +141,5 @@ public class DefaultXmppHeaderMapper extends AbstractHeaderMapper<Message> imple
|
||||
protected String getStandardHeaderPrefix() {
|
||||
return XmppHeaders.PREFIX;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- Smack configuration file. -->
|
||||
<smack>
|
||||
|
||||
<!-- Classes that will be loaded when Smack starts -->
|
||||
<startupClasses>
|
||||
<className>org.jivesoftware.smackx.ServiceDiscoveryManager</className>
|
||||
<className>org.jivesoftware.smack.PrivacyListManager</className>
|
||||
<className>org.jivesoftware.smackx.XHTMLManager</className>
|
||||
<className>org.jivesoftware.smackx.muc.MultiUserChat</className>
|
||||
<className>org.jivesoftware.smackx.filetransfer.FileTransferManager</className>
|
||||
<className>org.jivesoftware.smackx.LastActivityManager</className>
|
||||
<className>org.jivesoftware.smack.ReconnectionManager</className>
|
||||
<className>org.jivesoftware.smackx.commands.AdHocCommandManager</className>
|
||||
</startupClasses>
|
||||
|
||||
<!-- Paket reply timeout in milliseconds -->
|
||||
<packetReplyTimeout>5000</packetReplyTimeout>
|
||||
|
||||
<!-- Keep-alive interval in milleseconds -->
|
||||
<keepAliveInterval>30000</keepAliveInterval>
|
||||
|
||||
<mechName>PLAIN</mechName>
|
||||
</smack>
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -22,11 +22,11 @@ import static org.junit.Assert.assertSame;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.jivesoftware.smack.Chat;
|
||||
import org.jivesoftware.smack.ChatManager;
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
@@ -47,6 +47,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Mark Fisher
|
||||
* @author Gunnar Hillert
|
||||
* @author Florian Schmaus
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@@ -78,12 +79,8 @@ public class ChatMessageInboundChannelAdapterParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInboundAdapterUsageWithHeaderMapper() {
|
||||
public void testInboundAdapterUsageWithHeaderMapper() throws NotConnectedException {
|
||||
XMPPConnection xmppConnection = Mockito.mock(XMPPConnection.class);
|
||||
ChatManager chatManager = Mockito.mock(ChatManager.class);
|
||||
Mockito.when(xmppConnection.getChatManager()).thenReturn(chatManager);
|
||||
Chat chat = Mockito.mock(Chat.class);
|
||||
Mockito.when(chatManager.getThreadChat(Mockito.any(String.class))).thenReturn(chat);
|
||||
|
||||
ChatMessageListeningEndpoint adapter = context.getBean("xmppInboundAdapter", ChatMessageListeningEndpoint.class);
|
||||
|
||||
@@ -96,8 +93,8 @@ public class ChatMessageInboundChannelAdapterParserTests {
|
||||
Message message = new Message();
|
||||
message.setBody("hello");
|
||||
message.setTo("oleg");
|
||||
message.setProperty("foo", "foo");
|
||||
message.setProperty("bar", "bar");
|
||||
JivePropertiesManager.addProperty(message, "foo", "foo");
|
||||
JivePropertiesManager.addProperty(message, "bar", "bar");
|
||||
packetListener.processPacket(message);
|
||||
org.springframework.messaging.Message<?> siMessage = xmppInbound.receive(0);
|
||||
assertEquals("foo", siMessage.getHeaders().get("foo"));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.verify;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
@@ -53,6 +54,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
* @author Gunnar Hillert
|
||||
* @author Florian Schmaus
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@@ -117,7 +119,7 @@ public class ChatMessageOutboundChannelAdapterParserTests {
|
||||
Object[] args = invocation.getArguments();
|
||||
org.jivesoftware.smack.packet.Message xmppMessage = (org.jivesoftware.smack.packet.Message) args[0];
|
||||
assertEquals("oleg", xmppMessage.getTo());
|
||||
assertEquals("foobar", xmppMessage.getProperty("foobar"));
|
||||
assertEquals("foobar", JivePropertiesManager.getProperty(xmppMessage, "foobar"));
|
||||
return null;
|
||||
}})
|
||||
.when(connection).sendPacket(Mockito.any(org.jivesoftware.smack.packet.Message.class));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -21,9 +21,6 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -34,28 +31,16 @@ import org.springframework.integration.test.util.TestUtils;
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
* @author Gunnar Hillert
|
||||
* @author Florian Schmaus
|
||||
*/
|
||||
public class XmppConnectionParserTests {
|
||||
|
||||
@Test
|
||||
public void testSmackSasl() {
|
||||
/*
|
||||
* Possible SASL mechanisms
|
||||
* EXTERNAL, GSSAPI, DIGEST-MD5, CRAM-MD5, PLAIN, ANONYMOUS
|
||||
*/
|
||||
// values are set in META-INF/smack-config.xml
|
||||
List<String> saslMechNames = SmackConfiguration.getSaslMechs();
|
||||
assertEquals(2, saslMechNames.size());
|
||||
assertEquals("PLAIN", saslMechNames.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleConfiguration() {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("XmppConnectionParserTests-simple.xml", this.getClass());
|
||||
ApplicationContext ac =
|
||||
new ClassPathXmlApplicationContext("XmppConnectionParserTests-simple.xml", this.getClass());
|
||||
XMPPConnection connection = ac.getBean("connection", XMPPConnection.class);
|
||||
assertEquals("localhost", connection.getServiceName());
|
||||
assertEquals("localhost", connection.getHost());
|
||||
assertEquals(5222, connection.getPort());
|
||||
assertFalse(connection.isConnected());
|
||||
XmppConnectionFactoryBean xmppFb = ac.getBean("&connection", XmppConnectionFactoryBean.class);
|
||||
assertEquals("happy.user", TestUtils.getPropertyValue(xmppFb, "user"));
|
||||
@@ -69,17 +54,17 @@ public class XmppConnectionParserTests {
|
||||
|
||||
@Test
|
||||
public void testDefaultConnectionName() {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("XmppConnectionParserTests-simple.xml", this.getClass());
|
||||
ApplicationContext ac =
|
||||
new ClassPathXmlApplicationContext("XmppConnectionParserTests-simple.xml", this.getClass());
|
||||
assertTrue(ac.containsBean("xmppConnection"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompleteConfiguration() {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("XmppConnectionParserTests-complete.xml", this.getClass());
|
||||
ApplicationContext ac =
|
||||
new ClassPathXmlApplicationContext("XmppConnectionParserTests-complete.xml", this.getClass());
|
||||
XMPPConnection connection = ac.getBean("connection", XMPPConnection.class);
|
||||
assertEquals("foogle.com", connection.getServiceName());
|
||||
assertEquals("localhost", connection.getHost());
|
||||
assertEquals(6222, connection.getPort());
|
||||
assertFalse(connection.isConnected());
|
||||
XmppConnectionFactoryBean xmppFb = ac.getBean("&connection", XmppConnectionFactoryBean.class);
|
||||
assertEquals("happy.user", TestUtils.getPropertyValue(xmppFb, "user"));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -13,24 +13,24 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.xmpp.inbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jivesoftware.smack.Chat;
|
||||
import org.jivesoftware.smack.ChatManager;
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
@@ -49,6 +49,7 @@ import org.springframework.messaging.support.ErrorMessage;
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gunnar Hillert
|
||||
* @author Florian Schmaus
|
||||
*
|
||||
*/
|
||||
public class ChatMessageListeningEndpointTests {
|
||||
@@ -114,16 +115,11 @@ public class ChatMessageListeningEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithErrorChannel(){
|
||||
public void testWithErrorChannel() throws NotConnectedException{
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
XMPPConnection connection = mock(XMPPConnection.class);
|
||||
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, connection);
|
||||
|
||||
ChatManager cm = mock(ChatManager.class);
|
||||
when(connection.getChatManager()).thenReturn(cm);
|
||||
Chat chat = mock(Chat.class);
|
||||
when(cm.getThreadChat(Mockito.anyString())).thenReturn(chat);
|
||||
|
||||
ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint();
|
||||
|
||||
DirectChannel outChannel = new DirectChannel();
|
||||
|
||||
@@ -25,8 +25,6 @@ import static org.mockito.Mockito.when;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jivesoftware.smack.Chat;
|
||||
import org.jivesoftware.smack.ChatManager;
|
||||
import org.jivesoftware.smack.Roster;
|
||||
import org.jivesoftware.smack.RosterListener;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
@@ -138,11 +136,6 @@ public class PresenceListeningEndpointTests {
|
||||
XMPPConnection connection = mock(XMPPConnection.class);
|
||||
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, connection);
|
||||
|
||||
ChatManager cm = mock(ChatManager.class);
|
||||
when(connection.getChatManager()).thenReturn(cm);
|
||||
Chat chat = mock(Chat.class);
|
||||
when(cm.getThreadChat(Mockito.anyString())).thenReturn(chat);
|
||||
|
||||
PresenceListeningEndpoint endpoint = new PresenceListeningEndpoint();
|
||||
|
||||
DirectChannel outChannel = new DirectChannel();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -23,14 +23,14 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
|
||||
import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.integration.xmpp.XmppHeaders;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Florian Schmaus
|
||||
* @since 2.1
|
||||
*/
|
||||
public class DefaultXmppHeaderMapperTests {
|
||||
@@ -58,12 +58,12 @@ public class DefaultXmppHeaderMapperTests {
|
||||
assertEquals(Message.Type.headline, target.getType());
|
||||
|
||||
// user-defined headers not included by default
|
||||
assertNull(target.getProperty("userDefined1"));
|
||||
assertNull(target.getProperty("userDefined2"));
|
||||
assertNull(JivePropertiesManager.getProperty(target, "userDefined1"));
|
||||
assertNull(JivePropertiesManager.getProperty(target, "userDefined2"));
|
||||
|
||||
// transient headers should not be copied
|
||||
assertNull(target.getProperty("id"));
|
||||
assertNull(target.getProperty("timestamp"));
|
||||
assertNull(JivePropertiesManager.getProperty(target, "id"));
|
||||
assertNull(JivePropertiesManager.getProperty(target, "timestamp"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,15 +91,15 @@ public class DefaultXmppHeaderMapperTests {
|
||||
assertEquals(Message.Type.normal, target.getType());
|
||||
|
||||
// user-defined headers are included if in the list
|
||||
assertEquals("foo", target.getProperty("userDefined1"));
|
||||
assertEquals("bar", target.getProperty("userDefined2"));
|
||||
assertEquals("foo", JivePropertiesManager.getProperty(target, "userDefined1"));
|
||||
assertEquals("bar", JivePropertiesManager.getProperty(target, "userDefined2"));
|
||||
|
||||
// user-defined headers are not included if not in the list
|
||||
assertNull(target.getProperty("userDefined3"));
|
||||
assertNull(JivePropertiesManager.getProperty(target, "userDefined3"));
|
||||
|
||||
// transient headers should not be copied
|
||||
assertNull(target.getProperty("id"));
|
||||
assertNull(target.getProperty("timestamp"));
|
||||
assertNull(JivePropertiesManager.getProperty(target, "id"));
|
||||
assertNull(JivePropertiesManager.getProperty(target, "timestamp"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,8 +109,8 @@ public class DefaultXmppHeaderMapperTests {
|
||||
source.setFrom("test.from");
|
||||
source.setSubject("test.subject");
|
||||
source.setThread("test.thread");
|
||||
source.setProperty("userDefined1", "foo");
|
||||
source.setProperty("userDefined2", "bar");
|
||||
JivePropertiesManager.addProperty(source, "userDefined1", "foo");
|
||||
JivePropertiesManager.addProperty(source, "userDefined2", "bar");
|
||||
Map<String, Object> headers = mapper.toHeadersFromRequest(source);
|
||||
assertEquals("test.to", headers.get(XmppHeaders.TO));
|
||||
assertEquals("test.from", headers.get(XmppHeaders.FROM));
|
||||
@@ -129,8 +129,8 @@ public class DefaultXmppHeaderMapperTests {
|
||||
source.setFrom("test.from");
|
||||
source.setSubject("test.subject");
|
||||
source.setThread("test.thread");
|
||||
source.setProperty("userDefined1", "foo");
|
||||
source.setProperty("userDefined2", "bar");
|
||||
JivePropertiesManager.addProperty(source, "userDefined1", "foo");
|
||||
JivePropertiesManager.addProperty(source, "userDefined2", "bar");
|
||||
Map<String, Object> headers = mapper.toHeadersFromReply(source);
|
||||
assertNull(headers.get(XmppHeaders.TO));
|
||||
assertNull(headers.get(XmppHeaders.FROM));
|
||||
|
||||
@@ -205,7 +205,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/integration/xmpp
|
||||
<title>Advanced Configuration</title>
|
||||
|
||||
<para>
|
||||
Since Spring Integration XMPP support is based on the Smack 3.1 API (http://www.igniterealtime.org/downloads/index.jsp), it is important
|
||||
Since Spring Integration XMPP support is based on the Smack 4.0 API (http://www.igniterealtime.org/projects/smack/), it is important
|
||||
to know a few details related to more complex configuration of the XMPP Connection object.
|
||||
</para>
|
||||
<para>
|
||||
@@ -221,7 +221,6 @@ xsi:schemaLocation="http://www.springframework.org/schema/integration/xmpp
|
||||
<constructor-arg>
|
||||
<bean class="org.jivesoftware.smack.ConnectionConfiguration">
|
||||
<constructor-arg value="myServiceName"/>
|
||||
<property name="truststorePath" value="..."/>
|
||||
<property name="socketFactory" ref="..."/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
|
||||
Reference in New Issue
Block a user