1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.transport.xmpp.support;
18
19 import java.net.URI;
20 import java.net.URISyntaxException;
21 import java.util.Collections;
22 import java.util.Iterator;
23
24 import org.springframework.util.Assert;
25 import org.springframework.ws.transport.xmpp.XmppTransportConstants;
26
27 import org.jivesoftware.smack.packet.Message;
28
29
30
31
32
33
34
35 public abstract class XmppTransportUtils {
36
37 private XmppTransportUtils() {
38 }
39
40
41
42
43 public static URI toUri(Message requestMessage) throws URISyntaxException {
44 return new URI(XmppTransportConstants.XMPP_URI_SCHEME, requestMessage.getTo(), null);
45 }
46
47 public static String getTo(URI uri) {
48 return uri.getSchemeSpecificPart();
49 }
50
51 public static boolean hasError(Message message) {
52 return message != null && Message.Type.error.equals(message.getType());
53 }
54
55 public static String getErrorMessage(Message message) {
56 if (message == null || !Message.Type.error.equals(message.getType())) {
57 return null;
58 }
59 else {
60 return message.getBody();
61 }
62 }
63
64 public static void addHeader(Message message, String name, String value) {
65 message.setProperty(name, value);
66 }
67
68 public static Iterator<String> getHeaderNames(Message message) {
69 Assert.notNull(message, "'message' must not be null");
70 return message.getPropertyNames().iterator();
71 }
72
73 public static Iterator<String> getHeaders(Message message, String name) {
74 Assert.notNull(message, "'message' must not be null");
75 String value = message.getProperty(name).toString();
76 if (value != null) {
77 return Collections.singletonList(value).iterator();
78 }
79 else {
80 return Collections.<String>emptyList().iterator();
81 }
82 }
83
84 }