1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.transport.xmpp;
18
19 import java.io.IOException;
20 import java.net.URI;
21 import java.util.UUID;
22
23 import org.springframework.beans.factory.InitializingBean;
24 import org.springframework.util.Assert;
25 import org.springframework.ws.transport.WebServiceConnection;
26 import org.springframework.ws.transport.WebServiceMessageSender;
27 import org.springframework.ws.transport.xmpp.support.XmppTransportUtils;
28
29 import org.jivesoftware.smack.XMPPConnection;
30
31
32
33
34
35
36
37
38
39
40
41
42 public class XmppMessageSender implements WebServiceMessageSender, InitializingBean {
43
44
45 public static final long DEFAULT_RECEIVE_TIMEOUT = -1;
46
47
48 public static final String DEFAULT_MESSAGE_ENCODING = "UTF-8";
49
50 private long receiveTimeout = DEFAULT_RECEIVE_TIMEOUT;
51
52 private String messageEncoding = DEFAULT_MESSAGE_ENCODING;
53
54 private XMPPConnection connection;
55
56
57 public void setConnection(XMPPConnection connection) {
58 this.connection = connection;
59 }
60
61
62
63
64
65
66 public void setReceiveTimeout(long receiveTimeout) {
67 this.receiveTimeout = receiveTimeout;
68 }
69
70
71
72
73
74 public void setMessageEncoding(String messageEncoding) {
75 this.messageEncoding = messageEncoding;
76 }
77
78 public void afterPropertiesSet() throws Exception {
79 Assert.notNull(connection, "'connection' is required");
80 }
81
82 public WebServiceConnection createConnection(URI uri) throws IOException {
83 String to = XmppTransportUtils.getTo(uri);
84 String thread = createThread();
85 XmppSenderConnection connection = new XmppSenderConnection(this.connection, to, thread);
86 connection.setReceiveTimeout(receiveTimeout);
87 connection.setMessageEncoding(messageEncoding);
88 return connection;
89 }
90
91 public boolean supports(URI uri) {
92 return uri.getScheme().equals(XmppTransportConstants.XMPP_URI_SCHEME);
93 }
94
95 protected String createThread() {
96 return UUID.randomUUID().toString();
97 }
98 }