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
9 changes: 8 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ configure(allprojects) {

repositories {
maven { url 'http://repo.spring.io/libs-release' }
mavenCentral()
}

dependencies {
Expand Down Expand Up @@ -135,6 +136,10 @@ configure(subprojects) { subproject ->
archives sourcesJar
archives javadocJar
}

ext {
smackVersion = '4.0.0'
}
}

project('spring-xml') {
Expand Down Expand Up @@ -210,7 +215,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
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@

package org.springframework.ws.transport.xmpp;

import java.io.IOException;

import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
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.packet.Message;
import org.jivesoftware.smack.packet.Packet;

import org.springframework.ws.transport.support.AbstractStandaloneMessageReceiver;

/**
Expand Down Expand Up @@ -57,7 +60,7 @@ public void setConnection(XMPPConnection connection) {
}

@Override
protected void onActivate() throws XMPPException {
protected void onActivate() throws XMPPException, SmackException, IOException {
Copy link
Member

Choose a reason for hiding this comment

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

Can't SmackException and IOException be wrapped with XMPPException to avoid breaking changes for end-applications?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if it's possible but I don't think that this is a good idea because in Smack 4 XMPPExceptions are only for errors defined in a XMPP related protocol.

if (!connection.isConnected()) {
connection.connect();
}
Expand Down Expand Up @@ -88,7 +91,12 @@ protected void onShutdown() {
logger.info("Shutting down XMPP receiver [" + connection.getUser() + "]");
}
if (connection.isConnected()) {
connection.disconnect();
try {
connection.disconnect();
}
catch (NotConnectedException e) {
// Ignore
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import java.net.URISyntaxException;
import java.util.Iterator;

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

import org.springframework.util.Assert;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.transport.AbstractReceiverConnection;
Expand Down Expand Up @@ -139,6 +139,11 @@ protected OutputStream getResponseOutputStream() throws IOException {

@Override
protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
connection.sendPacket(responseMessage);
try {
connection.sendPacket(responseMessage);
}
catch (NotConnectedException e) {
throw new IOException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
import java.util.Iterator;

import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackException.NotConnectedException;
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.ThreadFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;

import org.springframework.util.Assert;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.transport.AbstractSenderConnection;
Expand Down Expand Up @@ -128,7 +128,12 @@ protected OutputStream getRequestOutputStream() throws IOException {
@Override
protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
requestMessage.setFrom(connection.getUser());
connection.sendPacket(requestMessage);
try {
connection.sendPacket(requestMessage);
}
catch (NotConnectedException e) {
throw new IOException(e);
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@

package org.springframework.ws.transport.xmpp.support;

import java.io.IOException;

import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;

import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
Expand Down Expand Up @@ -84,13 +88,13 @@ public void setResource(String resource) {
}

@Override
public void afterPropertiesSet() throws XMPPException {
public void afterPropertiesSet() throws XMPPException, SmackException, IOException {
Copy link
Member

Choose a reason for hiding this comment

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

I think here ti's OK do no wrap, because afterPropertiesSet() is a Spring Container API, not end-user

ConnectionConfiguration 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 @@ -102,7 +106,12 @@ public void afterPropertiesSet() throws XMPPException {

@Override
public void destroy() {
connection.disconnect();
try {
connection.disconnect();
}
catch (NotConnectedException e) {
// Ignore
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

import org.springframework.util.Assert;
import org.springframework.ws.transport.xmpp.XmppTransportConstants;

import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager;

/**
* Collection of utility methods to work with Mail transports.
Expand Down Expand Up @@ -62,17 +62,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
Expand Up @@ -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, SmackException, IOException {
factoryBean.afterPropertiesSet();
}

@Test(expected = IllegalArgumentException.class)
public void noUsername() throws XMPPException {
public void noUsername() throws XMPPException, SmackException, IOException {
factoryBean.setHost("jabber.org");
factoryBean.afterPropertiesSet();
}
Expand Down