1 10 11 package org.mule.providers.xmpp; 12 13 import org.jivesoftware.smack.AccountManager; 14 import org.jivesoftware.smack.XMPPConnection; 15 import org.jivesoftware.smack.XMPPException; 16 import org.mule.providers.AbstractServiceEnabledConnector; 17 import org.mule.umo.endpoint.UMOEndpointURI; 18 19 26 public class XmppConnector extends AbstractServiceEnabledConnector 27 { 28 public static final String XMPP_PROPERTY_PREFIX = ""; 29 public static final String XMPP_SUBJECT = XMPP_PROPERTY_PREFIX + "subject"; 30 public static final String XMPP_THREAD = XMPP_PROPERTY_PREFIX + "thread"; 31 public static final String XMPP_TO = XMPP_PROPERTY_PREFIX + "to"; 32 public static final String XMPP_FROM = XMPP_PROPERTY_PREFIX + "from"; 33 public static final String XMPP_GROUP_CHAT = XMPP_PROPERTY_PREFIX + "groupChat"; 34 public static final String XMPP_NICKNAME = XMPP_PROPERTY_PREFIX + "nickname"; 35 36 public String getProtocol() 37 { 38 return "xmpp"; 39 } 40 41 public XMPPConnection createXmppConnection(UMOEndpointURI endpointURI) throws XMPPException 42 { 43 logger.info("Trying to find XMPP connection for uri: " + endpointURI); 44 XMPPConnection xmppConnection = null; 45 46 String username = endpointURI.getUsername(); 47 String hostname = endpointURI.getHost(); 48 String password = endpointURI.getPassword(); 49 String resource = (String )endpointURI.getParams().get("resource"); 50 51 if (endpointURI.getPort() != -1) 52 { 53 xmppConnection = new XMPPConnection(endpointURI.getHost(), endpointURI.getPort()); 54 } 55 else 56 { 57 xmppConnection = new XMPPConnection(endpointURI.getHost()); 58 } 59 60 if (!xmppConnection.isAuthenticated()) 61 { 62 try 64 { 65 AccountManager accManager = new AccountManager(xmppConnection); 66 accManager.createAccount(username, password); 67 } 68 catch (XMPPException ex) 69 { 70 logger.info("*** account (" + username + ") already exists ***"); 72 } 73 74 if (logger.isDebugEnabled()) 75 { 76 logger.debug("Logging in as: " + username); 77 logger.debug("pw is : " + password); 78 logger.debug("server : " + hostname); 79 logger.debug("resource : " + resource); 80 } 81 82 if (resource == null) 83 { 84 xmppConnection.login(username, password); 85 } 86 else 87 { 88 xmppConnection.login(username, password, resource); 89 } 90 } 91 else 92 { 93 if (logger.isDebugEnabled()) 94 logger.debug("Already authenticated on this connection, no need to log in again."); 95 } 96 return xmppConnection; 97 } 98 99 102 protected void doDispose() 103 { 104 } 106 107 public boolean isRemoteSyncEnabled() 108 { 109 return true; 110 } 111 } 112 | Popular Tags |