Skip to content
Merged
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
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;

Expand All @@ -34,6 +38,7 @@
*
* @author Gildas Cuisinier
* @author Arjen Poutsma
* @author Greg Turnquist
* @see org.springframework.ws.transport.xmpp.support.XmppConnectionFactoryBean
* @since 2.0
*/
Expand All @@ -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;

Expand All @@ -52,12 +57,12 @@ public XmppMessageReceiver() {
}

/** 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();
}
Expand All @@ -69,16 +74,16 @@ protected void onStart() {
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
protected void onStop() {
if (logger.isInfoEnabled()) {
logger.info("Stopping XMPP receiver [" + connection.getUser() + "]");
}
connection.removePacketListener(packetListener);
connection.removeAsyncStanzaListener(packetListener);
packetListener = null;
}

Expand All @@ -92,10 +97,10 @@ protected void onShutdown() {
}
}

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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -23,6 +23,7 @@
import java.net.URISyntaxException;
import java.util.Iterator;

import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Message;

Expand Down Expand Up @@ -140,6 +141,10 @@ protected OutputStream getResponseOutputStream() throws IOException {

@Override
protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
connection.sendPacket(responseMessage);
try {
connection.sendStanza(responseMessage);
} catch (SmackException.NotConnectedException e) {
throw new IOException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -24,13 +24,14 @@
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;
Expand Down Expand Up @@ -129,7 +130,11 @@ protected OutputStream getRequestOutputStream() throws IOException {
@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);
}
}

/*
Expand All @@ -138,10 +143,10 @@ protected void onSendAfterWrite(WebServiceMessage message) throws IOException {

@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;
}
Expand All @@ -151,9 +156,9 @@ else if (packet != null) {
}
}

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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -33,11 +36,11 @@
* @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;

Expand Down Expand Up @@ -84,13 +87,13 @@ public void setResource(String resource) {
}

@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);
Expand All @@ -106,13 +109,13 @@ public void destroy() {
}

@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
Expand All @@ -127,13 +130,20 @@ public boolean isSingleton() {
* @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();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -21,11 +21,12 @@
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.
*
Expand Down Expand Up @@ -62,17 +63,17 @@ public static String getErrorMessage(Message message) {
}

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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -30,12 +33,12 @@ public void createFactoryBean() {
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();
}
Expand Down