SWS-885 Upgrade to Smack 4.1.5
This commit is contained in:
@@ -15,6 +15,7 @@ configure(allprojects) {
|
||||
ext.springVersion = "4.0.9.RELEASE"
|
||||
ext.springSecurityVersion = "3.2.7.RELEASE"
|
||||
ext.axiomVersion = "1.2.15"
|
||||
ext.smackVersion = "4.1.5"
|
||||
|
||||
apply plugin: "java"
|
||||
|
||||
@@ -218,7 +219,9 @@ project('spring-ws-support') {
|
||||
provided("javax.jms:jms-api:1.1-rev-1")
|
||||
provided("javax.mail:javax.mail-api:1.4.7")
|
||||
provided("com.sun.mail:javax.mail:1.4.7")
|
||||
optional("org.igniterealtime.smack:smack:3.2.1")
|
||||
optional("org.igniterealtime.smack:smack-tcp:$smackVersion")
|
||||
optional("org.igniterealtime.smack:smack-resolver-javax:$smackVersion")
|
||||
optional("org.igniterealtime.smack:smack-extensions:$smackVersion")
|
||||
testCompile("commons-httpclient:commons-httpclient:3.1")
|
||||
testRuntime("org.apache.activemq:activemq-core:4.1.2") {
|
||||
exclude group:'org.apache.geronimo.specs', module:'geronimo-jms_1.1_spec'
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,4 +1,4 @@
|
||||
#Tue Dec 15 10:03:30 CST 2015
|
||||
#Wed Jan 20 16:03:00 CST 2016
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005-2014 the original author or authors.
|
||||
* Copyright 2005-2016 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.
|
||||
@@ -16,13 +16,17 @@
|
||||
|
||||
package org.springframework.ws.transport.xmpp;
|
||||
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.StanzaListener;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
import org.jivesoftware.smack.filter.StanzaFilter;
|
||||
import org.jivesoftware.smack.filter.StanzaTypeFilter;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
||||
|
||||
import org.springframework.ws.transport.support.AbstractStandaloneMessageReceiver;
|
||||
|
||||
@@ -34,6 +38,7 @@ import org.springframework.ws.transport.support.AbstractStandaloneMessageReceive
|
||||
*
|
||||
* @author Gildas Cuisinier
|
||||
* @author Arjen Poutsma
|
||||
* @author Greg Turnquist
|
||||
* @see org.springframework.ws.transport.xmpp.support.XmppConnectionFactoryBean
|
||||
* @since 2.0
|
||||
*/
|
||||
@@ -42,7 +47,7 @@ public class XmppMessageReceiver extends AbstractStandaloneMessageReceiver {
|
||||
/** Default encoding used to read from and write to {@link org.jivesoftware.smack.packet.Message} messages. */
|
||||
public static final String DEFAULT_MESSAGE_ENCODING = "UTF-8";
|
||||
|
||||
private XMPPConnection connection;
|
||||
private XMPPTCPConnection connection;
|
||||
|
||||
private WebServicePacketListener packetListener;
|
||||
|
||||
@@ -52,12 +57,12 @@ public class XmppMessageReceiver extends AbstractStandaloneMessageReceiver {
|
||||
}
|
||||
|
||||
/** Sets the {@code XMPPConnection} to use. Setting this property is required. */
|
||||
public void setConnection(XMPPConnection connection) {
|
||||
public void setConnection(XMPPTCPConnection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivate() throws XMPPException {
|
||||
protected void onActivate() throws XMPPException, IOException, SmackException {
|
||||
if (!connection.isConnected()) {
|
||||
connection.connect();
|
||||
}
|
||||
@@ -69,8 +74,8 @@ public class XmppMessageReceiver extends AbstractStandaloneMessageReceiver {
|
||||
logger.info("Starting XMPP receiver [" + connection.getUser() + "]");
|
||||
}
|
||||
packetListener = new WebServicePacketListener();
|
||||
PacketFilter packetFilter = new PacketTypeFilter(Message.class);
|
||||
connection.addPacketListener(packetListener, packetFilter);
|
||||
StanzaFilter packetFilter = new StanzaTypeFilter(Message.class);
|
||||
connection.addAsyncStanzaListener(packetListener, packetFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,7 +83,7 @@ public class XmppMessageReceiver extends AbstractStandaloneMessageReceiver {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Stopping XMPP receiver [" + connection.getUser() + "]");
|
||||
}
|
||||
connection.removePacketListener(packetListener);
|
||||
connection.removeAsyncStanzaListener(packetListener);
|
||||
packetListener = null;
|
||||
}
|
||||
|
||||
@@ -92,10 +97,10 @@ public class XmppMessageReceiver extends AbstractStandaloneMessageReceiver {
|
||||
}
|
||||
}
|
||||
|
||||
private class WebServicePacketListener implements PacketListener {
|
||||
private class WebServicePacketListener implements StanzaListener {
|
||||
|
||||
@Override
|
||||
public void processPacket(Packet packet) {
|
||||
public void processPacket(Stanza packet) {
|
||||
logger.info("Received " + packet);
|
||||
if (packet instanceof Message) {
|
||||
Message message = (Message) packet;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005-2014 the original author or authors.
|
||||
* Copyright 2005-2016 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,6 +23,7 @@ import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
|
||||
@@ -140,6 +141,10 @@ public class XmppReceiverConnection extends AbstractReceiverConnection {
|
||||
|
||||
@Override
|
||||
protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
|
||||
connection.sendPacket(responseMessage);
|
||||
try {
|
||||
connection.sendStanza(responseMessage);
|
||||
} catch (SmackException.NotConnectedException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005-2014 the original author or authors.
|
||||
* Copyright 2005-2016 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,13 +24,14 @@ import java.net.URISyntaxException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.jivesoftware.smack.PacketCollector;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.filter.AndFilter;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
import org.jivesoftware.smack.filter.StanzaFilter;
|
||||
import org.jivesoftware.smack.filter.StanzaTypeFilter;
|
||||
import org.jivesoftware.smack.filter.ThreadFilter;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
@@ -129,7 +130,11 @@ public class XmppSenderConnection extends AbstractSenderConnection {
|
||||
@Override
|
||||
protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
|
||||
requestMessage.setFrom(connection.getUser());
|
||||
connection.sendPacket(requestMessage);
|
||||
try {
|
||||
connection.sendStanza(requestMessage);
|
||||
} catch (SmackException.NotConnectedException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -138,10 +143,10 @@ public class XmppSenderConnection extends AbstractSenderConnection {
|
||||
|
||||
@Override
|
||||
protected void onReceiveBeforeRead() throws IOException {
|
||||
PacketFilter packetFilter = createPacketFilter();
|
||||
StanzaFilter packetFilter = createPacketFilter();
|
||||
|
||||
PacketCollector collector = connection.createPacketCollector(packetFilter);
|
||||
Packet packet = receiveTimeout >= 0 ? collector.nextResult(receiveTimeout) : collector.nextResult();
|
||||
Stanza packet = receiveTimeout >= 0 ? collector.nextResult(receiveTimeout) : collector.nextResult();
|
||||
if (packet instanceof Message) {
|
||||
responseMessage = (Message) packet;
|
||||
}
|
||||
@@ -151,9 +156,9 @@ public class XmppSenderConnection extends AbstractSenderConnection {
|
||||
}
|
||||
}
|
||||
|
||||
private PacketFilter createPacketFilter() {
|
||||
private StanzaFilter createPacketFilter() {
|
||||
AndFilter andFilter = new AndFilter();
|
||||
andFilter.addFilter(new PacketTypeFilter(Message.class));
|
||||
andFilter.addFilter(new StanzaTypeFilter(Message.class));
|
||||
andFilter.addFilter(new ThreadFilter(requestMessage.getThread()));
|
||||
return andFilter;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005-2014 the original author or authors.
|
||||
* Copyright 2005-2016 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.
|
||||
@@ -16,9 +16,12 @@
|
||||
|
||||
package org.springframework.ws.transport.xmpp.support;
|
||||
|
||||
import org.jivesoftware.smack.ConnectionConfiguration;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
@@ -33,11 +36,11 @@ import org.springframework.util.StringUtils;
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public class XmppConnectionFactoryBean implements FactoryBean<XMPPConnection>, InitializingBean, DisposableBean {
|
||||
public class XmppConnectionFactoryBean implements FactoryBean<XMPPTCPConnection>, InitializingBean, DisposableBean {
|
||||
|
||||
private static final int DEFAULT_PORT = 5222;
|
||||
|
||||
private XMPPConnection connection;
|
||||
private XMPPTCPConnection connection;
|
||||
|
||||
private String host;
|
||||
|
||||
@@ -84,13 +87,13 @@ public class XmppConnectionFactoryBean implements FactoryBean<XMPPConnection>, I
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws XMPPException {
|
||||
ConnectionConfiguration configuration = createConnectionConfiguration(host, port, serviceName);
|
||||
public void afterPropertiesSet() throws XMPPException, IOException, SmackException {
|
||||
XMPPTCPConnectionConfiguration configuration = createConnectionConfiguration(host, port, serviceName);
|
||||
Assert.notNull(configuration, "'configuration' must not be null");
|
||||
Assert.hasText(username, "'username' must not be empty");
|
||||
Assert.hasText(password, "'password' must not be empty");
|
||||
|
||||
connection = new XMPPConnection(configuration);
|
||||
connection = new XMPPTCPConnection(configuration);
|
||||
connection.connect();
|
||||
if (StringUtils.hasText(resource)) {
|
||||
connection.login(username, password, resource);
|
||||
@@ -106,13 +109,13 @@ public class XmppConnectionFactoryBean implements FactoryBean<XMPPConnection>, I
|
||||
}
|
||||
|
||||
@Override
|
||||
public XMPPConnection getObject() {
|
||||
public XMPPTCPConnection getObject() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<XMPPConnection> getObjectType() {
|
||||
return XMPPConnection.class;
|
||||
public Class<XMPPTCPConnection> getObjectType() {
|
||||
return XMPPTCPConnection.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -127,13 +130,20 @@ public class XmppConnectionFactoryBean implements FactoryBean<XMPPConnection>, I
|
||||
* @param port the port to connect to
|
||||
* @param serviceName the name of the service to connect to. May be {@code null}
|
||||
*/
|
||||
protected ConnectionConfiguration createConnectionConfiguration(String host, int port, String serviceName) {
|
||||
protected XMPPTCPConnectionConfiguration createConnectionConfiguration(String host, int port, String serviceName) {
|
||||
Assert.hasText(host, "'host' must not be empty");
|
||||
if (StringUtils.hasText(serviceName)) {
|
||||
return new ConnectionConfiguration(host, port, serviceName);
|
||||
return XMPPTCPConnectionConfiguration.builder()
|
||||
.setHost(host)
|
||||
.setPort(port)
|
||||
.setServiceName(serviceName)
|
||||
.build();
|
||||
}
|
||||
else {
|
||||
return new ConnectionConfiguration(host, port);
|
||||
return XMPPTCPConnectionConfiguration.builder()
|
||||
.setHost(host)
|
||||
.setPort(port)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
* Copyright 2005-2016 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,11 +21,12 @@ import java.net.URISyntaxException;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.transport.xmpp.XmppTransportConstants;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
|
||||
/**
|
||||
* Collection of utility methods to work with Mail transports.
|
||||
*
|
||||
@@ -62,17 +63,17 @@ public abstract class XmppTransportUtils {
|
||||
}
|
||||
|
||||
public static void addHeader(Message message, String name, String value) {
|
||||
message.setProperty(name, value);
|
||||
JivePropertiesManager.addProperty(message, name, value);
|
||||
}
|
||||
|
||||
public static Iterator<String> getHeaderNames(Message message) {
|
||||
Assert.notNull(message, "'message' must not be null");
|
||||
return message.getPropertyNames().iterator();
|
||||
return JivePropertiesManager.getPropertiesNames(message).iterator();
|
||||
}
|
||||
|
||||
public static Iterator<String> getHeaders(Message message, String name) {
|
||||
Assert.notNull(message, "'message' must not be null");
|
||||
String value = message.getProperty(name).toString();
|
||||
String value = JivePropertiesManager.getProperty(message, name).toString();
|
||||
if (value != null) {
|
||||
return Collections.singletonList(value).iterator();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
* Copyright 2005-2016 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.
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.springframework.ws.transport.xmpp.support;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -30,12 +33,12 @@ public class XmppConnectionFactoryBeanTest {
|
||||
factoryBean = new XmppConnectionFactoryBean();
|
||||
}
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void noHost() throws XMPPException {
|
||||
public void noHost() throws XMPPException, IOException, SmackException {
|
||||
factoryBean.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void noUsername() throws XMPPException {
|
||||
public void noUsername() throws XMPPException, IOException, SmackException {
|
||||
factoryBean.setHost("jabber.org");
|
||||
factoryBean.afterPropertiesSet();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user