1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.providers.xmpp; |
12 | |
|
13 | |
import org.mule.providers.AbstractConnector; |
14 | |
import org.mule.umo.UMOException; |
15 | |
import org.mule.umo.endpoint.UMOEndpointURI; |
16 | |
import org.mule.umo.lifecycle.InitialisationException; |
17 | |
|
18 | |
import org.jivesoftware.smack.AccountManager; |
19 | |
import org.jivesoftware.smack.XMPPConnection; |
20 | |
import org.jivesoftware.smack.XMPPException; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | 0 | public class XmppConnector extends AbstractConnector |
26 | |
{ |
27 | |
public static final String XMPP_PROPERTY_PREFIX = ""; |
28 | |
public static final String XMPP_SUBJECT = XMPP_PROPERTY_PREFIX + "subject"; |
29 | |
public static final String XMPP_THREAD = XMPP_PROPERTY_PREFIX + "thread"; |
30 | |
public static final String XMPP_TO = XMPP_PROPERTY_PREFIX + "to"; |
31 | |
public static final String XMPP_FROM = XMPP_PROPERTY_PREFIX + "from"; |
32 | |
public static final String XMPP_GROUP_CHAT = XMPP_PROPERTY_PREFIX + "groupChat"; |
33 | |
public static final String XMPP_NICKNAME = XMPP_PROPERTY_PREFIX + "nickname"; |
34 | |
|
35 | |
|
36 | |
protected void doInitialise() throws InitialisationException |
37 | |
{ |
38 | |
|
39 | 0 | } |
40 | |
|
41 | |
protected void doDispose() |
42 | |
{ |
43 | |
|
44 | 0 | } |
45 | |
|
46 | |
protected void doConnect() throws Exception |
47 | |
{ |
48 | |
|
49 | 0 | } |
50 | |
|
51 | |
protected void doDisconnect() throws Exception |
52 | |
{ |
53 | |
|
54 | 0 | } |
55 | |
|
56 | |
protected void doStart() throws UMOException |
57 | |
{ |
58 | |
|
59 | 0 | } |
60 | |
|
61 | |
protected void doStop() throws UMOException |
62 | |
{ |
63 | |
|
64 | 0 | } |
65 | |
|
66 | |
public String getProtocol() |
67 | |
{ |
68 | 0 | return "xmpp"; |
69 | |
} |
70 | |
|
71 | |
public XMPPConnection createXmppConnection(UMOEndpointURI endpointURI) throws XMPPException |
72 | |
{ |
73 | 0 | logger.info("Trying to find XMPP connection for uri: " + endpointURI); |
74 | 0 | XMPPConnection xmppConnection = null; |
75 | |
|
76 | 0 | String username = endpointURI.getUsername(); |
77 | 0 | String hostname = endpointURI.getHost(); |
78 | 0 | String password = endpointURI.getPassword(); |
79 | 0 | String resource = (String)endpointURI.getParams().get("resource"); |
80 | |
|
81 | 0 | if (endpointURI.getPort() != -1) |
82 | |
{ |
83 | 0 | xmppConnection = new XMPPConnection(endpointURI.getHost(), endpointURI.getPort()); |
84 | |
} |
85 | |
else |
86 | |
{ |
87 | 0 | xmppConnection = new XMPPConnection(endpointURI.getHost()); |
88 | |
} |
89 | |
|
90 | 0 | if (!xmppConnection.isAuthenticated()) |
91 | |
{ |
92 | |
|
93 | |
try |
94 | |
{ |
95 | 0 | AccountManager accManager = new AccountManager(xmppConnection); |
96 | 0 | accManager.createAccount(username, password); |
97 | |
} |
98 | 0 | catch (XMPPException ex) |
99 | |
{ |
100 | |
|
101 | 0 | logger.info("*** account (" + username + ") already exists ***"); |
102 | 0 | } |
103 | |
|
104 | 0 | if (logger.isDebugEnabled()) |
105 | |
{ |
106 | 0 | logger.debug("Logging in as: " + username); |
107 | 0 | logger.debug("pw is : " + password); |
108 | 0 | logger.debug("server : " + hostname); |
109 | 0 | logger.debug("resource : " + resource); |
110 | |
} |
111 | |
|
112 | 0 | if (resource == null) |
113 | |
{ |
114 | 0 | xmppConnection.login(username, password); |
115 | |
} |
116 | |
else |
117 | |
{ |
118 | 0 | xmppConnection.login(username, password, resource); |
119 | |
} |
120 | |
} |
121 | |
else |
122 | |
{ |
123 | 0 | if (logger.isDebugEnabled()) |
124 | 0 | logger.debug("Already authenticated on this connection, no need to log in again."); |
125 | |
} |
126 | 0 | return xmppConnection; |
127 | |
} |
128 | |
|
129 | |
public boolean isRemoteSyncEnabled() |
130 | |
{ |
131 | 0 | return true; |
132 | |
} |
133 | |
} |