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
@@ -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>
|
||||
Reference in New Issue
Block a user