GH-2071: Upgrade to S-WS-3.0 and Smack-4.2.1
Fixes: spring-projects/spring-integration#2071 * Clean up `build.gradle` for redundant excludes * Add `javax.mail` dependency to WS module to avoid WARN about missed providers * Refactoring for the XMPP module according changes in the latest Smack * Polishing for the `BackToBackAdapterTests` to avoid extra wait for `null` on the channel and some race conditions when client is closed during by the `stop()` during publishing Polishing `UriVariableTests` according the latest S-WS B-S Revert excludes removal
This commit is contained in:
committed by
Gary Russell
parent
1f88e2de7b
commit
bc4337ffa8
@@ -39,8 +39,9 @@ import org.springframework.util.StringUtils;
|
||||
* @author Artem Bilan
|
||||
* @author Philipp Etschel
|
||||
*
|
||||
* @see XMPPTCPConnection
|
||||
* @since 2.0
|
||||
*
|
||||
* @see XMPPTCPConnection
|
||||
*/
|
||||
public class XmppConnectionFactoryBean extends AbstractFactoryBean<XMPPConnection> implements SmartLifecycle {
|
||||
|
||||
@@ -140,14 +141,19 @@ public class XmppConnectionFactoryBean extends AbstractFactoryBean<XMPPConnectio
|
||||
XMPPTCPConnectionConfiguration.Builder builder =
|
||||
XMPPTCPConnectionConfiguration.builder()
|
||||
.setHost(this.host)
|
||||
.setPort(this.port)
|
||||
.setResource(this.resource)
|
||||
.setUsernameAndPassword(this.user, this.password)
|
||||
.setServiceName(this.serviceName);
|
||||
.setPort(this.port);
|
||||
|
||||
if (!StringUtils.hasText(this.serviceName) && StringUtils.hasText(this.user)) {
|
||||
if (StringUtils.hasText(this.resource)) {
|
||||
builder.setResource(this.resource);
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(this.serviceName)) {
|
||||
builder.setUsernameAndPassword(this.user, this.password)
|
||||
.setXmppDomain(this.serviceName);
|
||||
}
|
||||
else {
|
||||
builder.setUsernameAndPassword(XmppStringUtils.parseLocalpart(this.user), this.password)
|
||||
.setServiceName(XmppStringUtils.parseDomain(this.user));
|
||||
.setXmppDomain(this.user);
|
||||
}
|
||||
|
||||
connectionConfiguration = builder.build();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -41,6 +41,7 @@ import org.springframework.util.Assert;
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ChatMessageListeningEndpoint extends AbstractXmppConnectionAwareEndpoint {
|
||||
@@ -121,7 +122,7 @@ public class ChatMessageListeningEndpoint extends AbstractXmppConnectionAwareEnd
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processPacket(final Stanza packet) {
|
||||
public void processStanza(Stanza packet) {
|
||||
if (packet instanceof org.jivesoftware.smack.packet.Message) {
|
||||
org.jivesoftware.smack.packet.Message xmppMessage = (org.jivesoftware.smack.packet.Message) packet;
|
||||
Map<String, ?> mappedHeaders = ChatMessageListeningEndpoint.this.headerMapper.toHeadersFromRequest(xmppMessage);
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.jivesoftware.smack.roster.Roster;
|
||||
import org.jivesoftware.smack.roster.RosterListener;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
import org.springframework.integration.xmpp.core.AbstractXmppConnectionAwareEndpoint;
|
||||
import org.springframework.messaging.Message;
|
||||
@@ -90,21 +91,21 @@ public class PresenceListeningEndpoint extends AbstractXmppConnectionAwareEndpoi
|
||||
}
|
||||
|
||||
@Override
|
||||
public void entriesAdded(Collection<String> entries) {
|
||||
public void entriesAdded(Collection<Jid> entries) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("entries added: " + StringUtils.collectionToCommaDelimitedString(entries));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void entriesUpdated(Collection<String> entries) {
|
||||
public void entriesUpdated(Collection<Jid> entries) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("entries updated: " + StringUtils.collectionToCommaDelimitedString(entries));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void entriesDeleted(Collection<String> entries) {
|
||||
public void entriesDeleted(Collection<Jid> entries) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("entries deleted: " + StringUtils.collectionToCommaDelimitedString(entries));
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
import org.springframework.integration.xmpp.XmppHeaders;
|
||||
@@ -93,7 +94,7 @@ public class ChatMessageSendingMessageHandler extends AbstractXmppConnectionAwar
|
||||
else {
|
||||
String to = message.getHeaders().get(XmppHeaders.TO, String.class);
|
||||
Assert.state(StringUtils.hasText(to), "The '" + XmppHeaders.TO + "' header must not be null");
|
||||
xmppMessage = new org.jivesoftware.smack.packet.Message(to);
|
||||
xmppMessage = new org.jivesoftware.smack.packet.Message(JidCreate.from(to));
|
||||
|
||||
if (payload instanceof ExtensionElement) {
|
||||
xmppMessage.addExtension((ExtensionElement) payload);
|
||||
|
||||
@@ -24,6 +24,9 @@ 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.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
import org.springframework.integration.mapping.AbstractHeaderMapper;
|
||||
import org.springframework.integration.xmpp.XmppHeaders;
|
||||
@@ -36,12 +39,13 @@ import org.springframework.util.StringUtils;
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Florian Schmaus
|
||||
* @author Stephane Nicoll
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
public class DefaultXmppHeaderMapper extends AbstractHeaderMapper<Message> implements XmppHeaderMapper {
|
||||
|
||||
private static final List<String> STANDARD_HEADER_NAMES = new ArrayList<String>();
|
||||
private static final List<String> STANDARD_HEADER_NAMES = new ArrayList<>();
|
||||
|
||||
static {
|
||||
STANDARD_HEADER_NAMES.add(XmppHeaders.FROM);
|
||||
@@ -57,10 +61,10 @@ public class DefaultXmppHeaderMapper extends AbstractHeaderMapper<Message> imple
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> extractStandardHeaders(Message source) {
|
||||
Map<String, Object> headers = new HashMap<String, Object>();
|
||||
String from = source.getFrom();
|
||||
if (StringUtils.hasText(from)) {
|
||||
headers.put(XmppHeaders.FROM, from);
|
||||
Map<String, Object> headers = new HashMap<>();
|
||||
Jid from = source.getFrom();
|
||||
if (from != null) {
|
||||
headers.put(XmppHeaders.FROM, from.toString());
|
||||
}
|
||||
String subject = source.getSubject();
|
||||
if (StringUtils.hasText(subject)) {
|
||||
@@ -70,9 +74,9 @@ public class DefaultXmppHeaderMapper extends AbstractHeaderMapper<Message> imple
|
||||
if (StringUtils.hasText(thread)) {
|
||||
headers.put(XmppHeaders.THREAD, thread);
|
||||
}
|
||||
String to = source.getTo();
|
||||
if (StringUtils.hasText(to)) {
|
||||
headers.put(XmppHeaders.TO, to);
|
||||
Jid to = source.getTo();
|
||||
if (to != null) {
|
||||
headers.put(XmppHeaders.TO, to.toString());
|
||||
}
|
||||
Message.Type type = source.getType();
|
||||
if (type != null) {
|
||||
@@ -83,7 +87,7 @@ public class DefaultXmppHeaderMapper extends AbstractHeaderMapper<Message> imple
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> extractUserDefinedHeaders(Message source) {
|
||||
Map<String, Object> headers = new HashMap<String, Object>();
|
||||
Map<String, Object> headers = new HashMap<>();
|
||||
JivePropertiesExtension jpe = (JivePropertiesExtension) source.getExtension(JivePropertiesExtension.NAMESPACE);
|
||||
if (jpe == null) {
|
||||
return headers;
|
||||
@@ -102,12 +106,24 @@ public class DefaultXmppHeaderMapper extends AbstractHeaderMapper<Message> imple
|
||||
}
|
||||
String to = getHeaderIfAvailable(headers, XmppHeaders.TO, String.class);
|
||||
if (StringUtils.hasText(to)) {
|
||||
target.setTo(to);
|
||||
try {
|
||||
target.setTo(JidCreate.from(to));
|
||||
}
|
||||
catch (XmppStringprepException e) {
|
||||
throw new IllegalStateException("Cannot parse 'xmpp_to' header value", e);
|
||||
}
|
||||
}
|
||||
|
||||
String from = getHeaderIfAvailable(headers, XmppHeaders.FROM, String.class);
|
||||
if (StringUtils.hasText(from)) {
|
||||
target.setFrom(from);
|
||||
try {
|
||||
target.setFrom(JidCreate.from(from));
|
||||
}
|
||||
catch (XmppStringprepException e) {
|
||||
throw new IllegalStateException("Cannot parse 'xmpp_from' header value", e);
|
||||
}
|
||||
}
|
||||
|
||||
String subject = getHeaderIfAvailable(headers, XmppHeaders.SUBJECT, String.class);
|
||||
if (StringUtils.hasText(subject)) {
|
||||
target.setSubject(subject);
|
||||
|
||||
Reference in New Issue
Block a user