Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ subprojects { subproject ->
saajImplVersion = '1.3.23'
servletApiVersion = '3.1.0'
slf4jVersion = "1.7.6"
smackVersion = '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'
Expand Down Expand Up @@ -626,8 +626,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-tcp:$smackVersion"
testCompile "org.igniterealtime.smack:smack-extensions:$smackVersion"
testCompile "javax.mail:javax.mail-api:$javaxMailVersion"
testRuntime "com.sun.mail:mailapi:$javaxMailVersion"
}
Expand Down Expand Up @@ -657,14 +657,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") {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -35,6 +35,7 @@
import javax.jms.Session;

import org.hamcrest.Matchers;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Packet;
import org.junit.Test;
Expand Down Expand Up @@ -207,7 +208,7 @@ public void testInt2720EmailUriVariables() {
}

@Test
public void testInt2720XmppUriVariables() {
public void testInt2720XmppUriVariables() throws NotConnectedException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I see there is an issue with new Smack and old Spring WS.
Is Smack 4.0 compatible with a Smack 3.0? I mean can we have in the classpath both versions?
I'm not sure how quickly the Spring WS (2.3.0) with new Smack will be released so we should be carefull with the new Smack for SI and old one for WS, because we can't release our project with a milestone dependency.
Just in case: can we live with both Smacks in the CP?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would need some kind of isolation to have two different versions of the same library loaded (like OSGi). Not sure if this is true or possible in Spring. But even if you could do it, then there is also the API change from Smack 3 to 4. How should the user/JVM decide which version to load?

That's actually what I tried to explain in my JIRA comment: I don't know how the Spring project handles these situations, as it has many release lines, other stuff and sure some policies. All I can say is that the Smack API in spring-integration and spring-ws needs to be compatible. So it's either Smack 3 for both or Smack 4. How you achieve that is up to you.
BTW: I'm not sure if those inter-dependencies are a good design, as it causes situations like we have now, but hadn't time yet to look closer at it.


Mockito.doThrow(new WebServiceIOException("intentional")).when(this.xmppConnection).sendPacket(Mockito.any(Packet.class));

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -19,7 +19,9 @@
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;
Expand Down Expand Up @@ -92,7 +94,7 @@ public Class<? extends XMPPConnection> getObjectType() {

@Override
protected XMPPConnection createInstance() throws Exception {
this.connection = new XMPPConnection(this.connectionConfiguration);
this.connection = new XMPPTCPConnection(this.connectionConfiguration);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why TCP? Are there other connection variants?
I'm not familiar with this new Smack yet, so be patient to answer to such 'stupid' questions 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there are other variants e.g. XMPPBOSHConnection. XMPPTCPConnection is what you got in Smack 3 with the XMPPConnection.

return this.connection;
}

Expand All @@ -118,15 +120,19 @@ public void start() {
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);
}
}
}

public void stop() {
synchronized (this.lifecycleMonitor) {
if (this.isRunning()) {
this.connection.disconnect();
try {
this.connection.disconnect();
} catch (NotConnectedException e) {
// Ignore
}
this.running = false;
}
}
Expand Down Expand Up @@ -171,6 +177,16 @@ public void connectionClosedOnError(Exception e) {
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");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
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;
Expand Down Expand Up @@ -86,8 +87,12 @@ protected Map<String, Object> extractStandardHeaders(Message source) {
@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));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide a sample how target properties look in the org.jivesoftware.smack.packet.Message?
It's interest if we can get deal with that properties directly to avoid smack-extensions dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide a sample how target properties look in the org.jivesoftware.smack.packet.Message?

"target properties"?

It's interest if we can get deal with that properties directly to avoid smack-extensions dependency.

Which you shouldn't do. Don't roll your in code, simply use the provided one.

return headers;
}
Expand Down Expand Up @@ -129,7 +134,7 @@ protected void populateStandardHeaders(Map<String, Object> headers, Message targ

@Override
protected void populateUserDefinedHeader(String headerName, Object headerValue, Message target) {
target.setProperty(headerName, headerValue);
JivePropertiesManager.addProperty(target, headerName, headerValue);
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -22,11 +22,11 @@

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;
Expand Down Expand Up @@ -78,12 +78,8 @@ public void testInboundAdapter(){
}

@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);

Expand All @@ -96,8 +92,8 @@ public void testInboundAdapterUsageWithHeaderMapper() {
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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -117,7 +118,7 @@ public Object answer(InvocationOnMock invocation) {
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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -21,9 +21,6 @@
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;
Expand All @@ -37,25 +34,11 @@
*/
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());
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"));
Expand All @@ -78,8 +61,6 @@ public void testCompleteConfiguration() {
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"));
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -19,18 +19,17 @@
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;
Expand Down Expand Up @@ -114,16 +113,11 @@ public void testNoXmppConnection(){
}

@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
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;
Expand Down Expand Up @@ -138,11 +136,6 @@ public void testWithErrorChannel(){
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();
Expand Down
Loading