Skip to content

Commit cceba68

Browse files
committed
SWS-428 - XMPP support
1 parent b983fa4 commit cceba68

File tree

18 files changed

+1052
-21
lines changed

18 files changed

+1052
-21
lines changed

core/src/main/java/org/springframework/ws/transport/support/WebServiceMessageReceiverObjectSupport.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006 the original author or authors.
2+
* Copyright 2005-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,9 +18,6 @@
1818

1919
import java.net.URISyntaxException;
2020

21-
import org.apache.commons.logging.Log;
22-
import org.apache.commons.logging.LogFactory;
23-
2421
import org.springframework.beans.factory.InitializingBean;
2522
import org.springframework.util.Assert;
2623
import org.springframework.ws.FaultAwareWebServiceMessage;
@@ -37,6 +34,9 @@
3734
import org.springframework.ws.transport.context.TransportContext;
3835
import org.springframework.ws.transport.context.TransportContextHolder;
3936

37+
import org.apache.commons.logging.Log;
38+
import org.apache.commons.logging.LogFactory;
39+
4040
/**
4141
* Convenience base class for server-side transport objects. Contains a {@link WebServiceMessageFactory}, and has
4242
* methods for handling incoming {@link WebServiceConnection}s.
@@ -111,7 +111,7 @@ protected final void handleConnection(WebServiceConnection connection, WebServic
111111
private void logUri(WebServiceConnection connection) {
112112
if (logger.isDebugEnabled()) {
113113
try {
114-
logger.debug("Accepting incoming [" + connection + "] to [" + connection.getUri() + "]");
114+
logger.debug("Accepting incoming [" + connection + "] at [" + connection.getUri() + "]");
115115
}
116116
catch (URISyntaxException e) {
117117
// ignore

parent/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,11 @@
634634
<artifactId>activemq-core</artifactId>
635635
<version>4.1.1</version>
636636
</dependency>
637+
<dependency>
638+
<groupId>jivesoftware</groupId>
639+
<artifactId>smack</artifactId>
640+
<version>3.1.0</version>
641+
</dependency>
637642
<!-- Logging dependencies -->
638643
<dependency>
639644
<groupId>commons-logging</groupId>

src/docbkx/client.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,47 @@
182182
<property name="defaultUri" value="mailto:[email protected]?subject=SOAP%20Test"/>
183183
</bean>
184184
185+
</beans>]]></programlisting>
186+
</para>
187+
</section>
188+
<section>
189+
<title>XMPP transport</title>
190+
<para>
191+
Spring Web Services 2.0 introduced an XMPP (Jabber) transport, which can be used to send and
192+
receive web service messages via XMPP. The client-side XMPP
193+
functionality is contained in the <classname>XmppMessageSender</classname> class.
194+
This class creates an XMPP message from the request
195+
<interfacename>WebServiceMessage</interfacename>, and sends it via XMPP. It then listens for a
196+
response message to arrive.
197+
</para>
198+
<para>
199+
To use the <classname>XmppMessageSender</classname>, set the <property>defaultUri</property> or
200+
<parameter>uri</parameter> parameter to a <literal>xmpp</literal> URI, for example
201+
<uri>xmpp:[email protected]</uri>. The sender also requires an
202+
<classname>XMPPConnection</classname> to work, which can be conveniently created using the
203+
<classname>org.springframework.ws.transport.xmpp.support.XmppConnectionFactoryBean</classname>.
204+
</para>
205+
<para>
206+
The following example shows how to use the xmpp transport:<programlisting><![CDATA[<beans>
207+
208+
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
209+
210+
<bean id="connection" class="org.springframework.ws.transport.xmpp.support.XmppConnectionFactoryBean">
211+
<property name="host" value="jabber.org"/>
212+
<property name="username" value="username"/>
213+
<property name="password" value="password"/>
214+
</bean>
215+
216+
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
217+
<constructor-arg ref="messageFactory"/>
218+
<property name="messageSender">
219+
<bean class="org.springframework.ws.transport.xmpp.XmppMessageSender">
220+
<property name="connection" ref="connection"/>
221+
</bean>
222+
</property>
223+
<property name="defaultUri" value="xmpp:[email protected]"/>
224+
</bean>
225+
185226
</beans>]]></programlisting>
186227
</para>
187228
</section>

src/docbkx/server.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,50 @@
523523
<ulink url="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/remoting/support/SimpleHttpServerFactoryBean.html">Javadoc</ulink>.
524524
</para>
525525
</section>
526+
<section>
527+
<title>XMPP transport</title>
528+
<para>
529+
Finally, Spring Web Services 2.0 introduced support for XMPP, otherwise known as Jabber. The support
530+
is based on the <ulink url="http://www.igniterealtime.org/projects/smack/index.jsp">Smack</ulink>
531+
library.
532+
</para>
533+
<para>
534+
Spring Web Services support for XMPP is very similar to the other transports: there is a a
535+
<classname>XmppMessageSender</classname> for the <classname>WebServiceTemplate</classname> and
536+
and a <classname>XmppMessageReceiver</classname> to use with the
537+
<classname>MessageDispatcher</classname>.
538+
</para>
539+
<para>The following example shows how to set up the server-side XMPP components:
540+
<programlisting><![CDATA[<beans>
541+
542+
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
543+
544+
<bean id="connection" class="org.springframework.ws.transport.xmpp.support.XmppConnectionFactoryBean">
545+
<property name="host" value="jabber.org"/>
546+
<property name="username" value="username"/>
547+
<property name="password" value="password"/>
548+
</bean>
549+
550+
<bean id="messagingReceiver" class="org.springframework.ws.transport.xmpp.XmppMessageReceiver">
551+
<property name="messageFactory" ref="messageFactory"/>
552+
<property name="connection" ref="connection"/>
553+
<property name="messageReceiver" ref="messageDispatcher"/>
554+
</bean>
555+
556+
<bean id="messageDispatcher" class="org.springframework.ws.soap.server.SoapMessageDispatcher">
557+
<property name="endpointMappings">
558+
<bean
559+
class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
560+
<property name="defaultEndpoint">
561+
<bean class="com.example.MyEndpoint"/>
562+
</property>
563+
</bean>
564+
</property>
565+
</bean>
566+
567+
</beans>]]></programlisting>
568+
</para>
569+
</section>
526570
</section>
527571
<section>
528572
<title>Endpoints</title>

support/pom.xml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,6 @@
1111
<packaging>jar</packaging>
1212
<name>Spring WS Support</name>
1313
<description>Spring Web Services Support package.</description>
14-
<!--
15-
<repositories>
16-
<repository>
17-
<id>spring-ext</id>
18-
<name>Spring External Dependencies Repository</name>
19-
<url>https://springframework.svn.sourceforge.net/svnroot/springframework/repos/repo-ext/</url>
20-
</repository>
21-
<repository>
22-
<id>java.net-maven-2</id>
23-
<name>Java.net Repository for Maven</name>
24-
<url>http://download.java.net/maven/2/</url>
25-
</repository>
26-
</repositories>
27-
-->
2814
<profiles>
2915
<profile>
3016
<id>jdk15</id>
@@ -103,6 +89,10 @@
10389
<artifactId>mail</artifactId>
10490
<optional>true</optional>
10591
</dependency>
92+
<dependency>
93+
<groupId>jivesoftware</groupId>
94+
<artifactId>smack</artifactId>
95+
</dependency>
10696
<!-- Other dependencies -->
10797
<dependency>
10898
<groupId>org.apache.activemq</groupId>

support/src/main/java/org/springframework/ws/transport/jms/JmsSenderConnection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ protected void onReceiveBeforeRead() throws IOException {
257257
}
258258
else if (message != null) {
259259
throw new IllegalArgumentException(
260-
"Wrong message type: [" + message.getClass() + "]. Only BytesMessages can be handled.");
260+
"Wrong message type: [" + message.getClass() + "]. " +
261+
"Only BytesMessages or TextMessages can be handled.");
261262
}
262263
}
263264
catch (JMSException ex) {

support/src/main/java/org/springframework/ws/transport/mail/MailMessageReceiver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class MailMessageReceiver extends AbstractAsyncStandaloneMessageReceiver
6666

6767
private MonitoringStrategy monitoringStrategy;
6868

69-
/** Sets the from address to use when sending reponse messages. */
69+
/** Sets the from address to use when sending response messages. */
7070
public void setFrom(String from) throws AddressException {
7171
this.from = new InternetAddress(from);
7272
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2005-2010 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ws.transport.xmpp;
18+
19+
import java.io.ByteArrayInputStream;
20+
import java.io.FilterInputStream;
21+
import java.io.IOException;
22+
import java.io.InputStream;
23+
24+
import org.springframework.util.Assert;
25+
26+
import org.jivesoftware.smack.packet.Message;
27+
28+
/**
29+
* Input stream that wraps a {@link Message}.
30+
*
31+
* @author Gildas Cuisinier
32+
* @author Arjen Poutsma
33+
* @since 2.0
34+
*/
35+
class MessageInputStream extends FilterInputStream {
36+
37+
MessageInputStream(Message message, String encoding) throws IOException {
38+
super(createInputStream(message, encoding));
39+
}
40+
41+
private static InputStream createInputStream(Message message, String encoding) throws IOException {
42+
Assert.notNull(message, "'message' must not be null");
43+
Assert.notNull(encoding, "'encoding' must not be null");
44+
String text = message.getBody();
45+
byte[] contents = text != null ? text.getBytes(encoding) : new byte[0];
46+
return new ByteArrayInputStream(contents);
47+
}
48+
49+
50+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2005-2010 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ws.transport.xmpp;
18+
19+
import java.io.ByteArrayOutputStream;
20+
import java.io.FilterOutputStream;
21+
import java.io.IOException;
22+
23+
import org.springframework.util.Assert;
24+
25+
import org.jivesoftware.smack.packet.Message;
26+
27+
/**
28+
* Output stream that wraps a {@link Message}.
29+
*
30+
* @author Gildas Cuisinier
31+
* @author Arjen Poutsma
32+
* @since 2.0
33+
*/
34+
class MessageOutputStream extends FilterOutputStream {
35+
36+
private final Message message;
37+
38+
private final String encoding;
39+
40+
MessageOutputStream(Message message, String encoding) {
41+
super(new ByteArrayOutputStream());
42+
Assert.notNull(message, "'message' must not be null");
43+
Assert.notNull(encoding, "'encoding' must not be null");
44+
this.message = message;
45+
this.encoding = encoding;
46+
}
47+
48+
@Override
49+
public void flush() throws IOException {
50+
super.flush();
51+
ByteArrayOutputStream bos = (ByteArrayOutputStream) out;
52+
String text = new String(bos.toByteArray(), encoding);
53+
message.setBody(text);
54+
}
55+
}

0 commit comments

Comments
 (0)