ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com", 5222); config.setSASLAuthenticationEnabled(true); XMPPConnection xmpp = new XMPPConnection(config); try { SASLAuthentication.registerSASLMechanism("X-FACEBOOK-PLATFORM", SASLXFacebookPlatformMechanism.class); SASLAuthentication.supportSASLMechanism("X-FACEBOOK-PLATFORM", 0); xmpp.connect(); xmpp.login(apiKey + "|" + sessionKey, sessionSecret, "Application"); } catch (XMPPException e) { xmpp.disconnect(); e.printStackTrace(); }
public InputStream call() throws Exception { Packet streamInitiation = collector.nextResult( SmackConfiguration.getPacketReplyTimeout() * 2); if (streamInitiation == null) { throw new XMPPException("No response from remote client"); } StreamNegotiator negotiator = determineNegotiator(streamInitiation); return negotiator.negotiateIncomingStream(streamInitiation); } }
AccountManager accountManager=new AccountManager(connection); try { accountManager.createAccount("username", "password"); } catch (XMPPException e1) { Log.d(e1.getMessage(), e1); }
/** * Gets the account registration info from the server. * * @throws XMPPException if an error occurs. */ private synchronized void getRegistrationInfo() throws XMPPException { Registration reg = new Registration(); reg.setTo(connection.getServiceName()); PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class)); PacketCollector collector = connection.createPacketCollector(filter); connection.sendPacket(reg); IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Stop queuing results collector.cancel(); if (result == null) { throw new XMPPException("No response from server."); } else if (result.getType() == IQ.Type.ERROR) { throw new XMPPException(result.getError()); } else { info = (Registration)result; } } }
public String authenticateAnonymously() throws XMPPException { // Create the authentication packet we'll send to the server. Authentication auth = new Authentication(); PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(auth.getPacketID())); // Send the packet. connection.sendPacket(auth); // Wait up to a certain number of seconds for a response from the server. IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); if (response == null) { throw new XMPPException("Anonymous login failed."); } else if (response.getType() == IQ.Type.ERROR) { throw new XMPPException(response.getError()); } // We're done with the collector, so explicitly cancel it. collector.cancel(); if (response.getTo() != null) { return response.getTo(); } else { return connection.getServiceName() + "/" + ((Authentication) response).getResource(); } } }
/** * Deletes all offline messages of the user. * * @throws XMPPException If the user is not allowed to make this request or the server does * not support offline message retrieval. */ public void deleteMessages() throws XMPPException { OfflineMessageRequest request = new OfflineMessageRequest(); request.setPurge(true); // Filter packets looking for an answer from the server. PacketFilter responseFilter = new PacketIDFilter(request.getPacketID()); PacketCollector response = connection.createPacketCollector(responseFilter); // Send the deletion request to the server. connection.sendPacket(request); // Wait up to a certain number of seconds for a reply. IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Stop queuing results response.cancel(); if (answer == null) { throw new XMPPException("No response from server."); } else if (answer.getError() != null) { throw new XMPPException(answer.getError()); } } }
private void testLogin(){ ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com", 5222); config.setSASLAuthenticationEnabled(true); config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled); xmpp = new XMPPConnection(config); SASLAuthentication.registerSASLMechanism("X-FACEBOOK-PLATFORM",SASLXFacebookPlatformMechanism.class); SASLAuthentication.supportSASLMechanism("X-FACEBOOK-PLATFORM", 0); Log.i("XMPPClient", "Access token to " + mFacebook.getAccessToken()); Log.i("XMPPClient", "Access token to " + mFacebook.getAppId()); Log.i("XMPPClient", "Access token to " + mFacebook.getAccessToken()); try { xmpp.connect(); Log.i("XMPPClient", "Connected to " + xmpp.getHost()); } catch (XMPPException e1) { Log.i("XMPPClient", "Unable to " + xmpp.getHost()); e1.printStackTrace(); } try { xmpp.login(PreferenceConnector.APP_ID, mFacebook.getAccessToken()); getRoster(xmpp); } catch (XMPPException e) { e.printStackTrace(); } }
InputStream negotiateIncomingStream(Packet streamInitiation) throws XMPPException { Open openRequest = (Open) streamInitiation; if (openRequest.getType().equals(IQ.Type.ERROR)) { throw new XMPPException(openRequest.getError()); } PacketFilter dataFilter = new IBBMessageSidFilter(openRequest.getFrom(), openRequest.getSessionID()); PacketFilter closeFilter = new AndFilter(new PacketTypeFilter( IBBExtensions.Close.class), new FromMatchesFilter(openRequest .getFrom())); InputStream stream = new IBBInputStream(openRequest.getSessionID(), dataFilter, closeFilter); initInBandTransfer(openRequest); return stream; }
public static String[] getServiceFactoryNames(XMPPConnection connection) throws XMPPException { RequestServiceFactoriesIQ iq = new RequestServiceFactoriesIQ(); PacketCollector collector = connection .createPacketCollector(new PacketIDFilter(iq.getPacketID())); connection.sendPacket(iq); IQ result = (IQ) collector.nextResult(); if (result == null) { throw new XMPPException("No response from the server."); } if (result.getType() == IQ.Type.ERROR) { throw new XMPPException(result.getError()); } return ((ResultServiceFactoriesIQ) result).getServiceFactoryNames(); }
ConnectionConfiguration cc = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com"); XMPPConnection connection = new XMPPConnection(cc); try { connection.connect(); // You have to put this code before you login SASLAuthentication.supportSASLMechanism("PLAIN", 0); // You have to specify your gmail addres WITH @gmail.com at the end connection.login("some.account@gmail.com", "password", "resource"); // See if you are authenticated System.out.println(connection.isAuthenticated()); } catch (XMPPException e1) { e1.printStackTrace(); }
ConnectionConfiguration config = new ConnectionConfiguration(server, port); config.setCompressionEnabled(true); accountManager.createAccount(user, password); } catch (XMPPException e) { XMPPError error = e.getXMPPError(); if (error != null) { errorCode = error.getCode();
IQ iqPacket = createIQ(si.getPacketID(), si.getFrom(), si.getTo(), IQ.Type.ERROR); iqPacket.setError(error); connection.sendPacket(iqPacket); throw new XMPPException("No stream methods contained in packet.", error); IQ iqPacket = createIQ(si.getPacketID(), si.getFrom(), si.getTo(), IQ.Type.ERROR); iqPacket.setError(e.getXMPPError()); connection.sendPacket(iqPacket); throw e;
if (xmppAccount != null) { try { ConnectionConfiguration config = new ConnectionConfiguration(XmppConfig.getInstance().getHost(), XmppConfig.getInstance().getPort(), "Accounts"); return true; } catch (XMPPException e) { if (e.getXMPPError().getCode() == 409) { "XMPP account creation failed. Error: " + e.getLocalizedMessage(), e);
@Override protected synchronized void writeToXML(DataPacketExtension data) throws IOException { // create IQ stanza containing data packet IQ iq = new Data(data); iq.setTo(remoteJID); try { SyncPacketSend.getReply(connection, iq); } catch (XMPPException e) { // close session unless it is already closed if (!this.isClosed) { InBandBytestreamSession.this.close(); throw new IOException("Error while sending Data: " + e.getMessage()); } } }
/** * Cancels the SOCKS5 Bytestream request by sending an error to the initiator and building a * XMPP exception. * * @throws XMPPException XMPP exception containing the XMPP error */ private void cancelRequest() throws XMPPException { String errorMessage = "Could not establish socket with any provided host"; XMPPError error = new XMPPError(XMPPError.Condition.item_not_found, errorMessage); IQ errorIQ = IQ.createErrorResponse(this.bytestreamRequest, error); this.manager.getConnection().sendPacket(errorIQ); throw new XMPPException(errorMessage, error); }
try { rooster.createEntry("name", "user_id", null); } catch (XMPPException e) { e.printStackTrace(); }
private void connectUsingConfiguration(ConnectionConfiguration config) throws XMPPException { String host = config.getHost(); int port = config.getPort(); try { if (config.getSocketFactory() == null) { this.socket = new Socket(host, port); } else { this.socket = config.getSocketFactory().createSocket(host, port); } } catch (UnknownHostException uhe) { String errorMessage = "Could not connect to " + host + ":" + port + "."; throw new XMPPException(errorMessage, new XMPPError( XMPPError.Condition.remote_server_timeout, errorMessage), uhe); } catch (IOException ioe) { String errorMessage = "XMPPError connecting to " + host + ":" + port + "."; throw new XMPPException(errorMessage, new XMPPError( XMPPError.Condition.remote_server_error, errorMessage), ioe); } initConnection(); }
private class ConnectToXmpp extends AsyncTask<Void, Void, Void> { @Override protected Void doInBackground(Void... params) { ConnectionConfiguration config = new ConnectionConfiguration( server_host, SERVER_PORT); XMPPConnection m_connection = new XMPPConnection(config); try { SASLAuthentication.supportSASLMechanism("PLAIN"); config.setSASLAuthenticationEnabled(true); m_connection.connect(); Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual); } catch (XMPPException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(Void result) { } }
/** * This XMPPComponent method does not qualify for the component connection, it throws a exception. * * @throws XMPPException always. * */ public synchronized void login(String username, String password, String resource) throws XMPPException { throw new XMPPException("SASL Authentication does not exist in a component connection"); }
throw new XMPPException(streamHostsInfo.getError()); if (ex.getXMPPError() != null) { IQ errorPacket = super.createError(streamHostsInfo.getTo(), streamHostsInfo.getFrom(), streamHostsInfo.getPacketID(), ex.getXMPPError()); connection.sendPacket(errorPacket); throw new XMPPException("Error establishing input stream", e);