[jdev] Smack API and jabber.org
sumedha rubasinghe
sumedha.r at gmail.com
Thu Jan 8 20:42:27 CST 2009
Hi,
I have following code block & it works.
/sumedha
xmppConnection = new XMPPConnection(serverCredentials.getServerUrl());
try {
xmppConnection.connect();
} catch (XMPPException e) {
log.error("Failed to connect to server
:"+serverCredentials.getServerUrl(), e);
}
//Pause for a small time before trying to login.
//This prevents random ssl exception from Smack API
try {
Thread.sleep(100);
} catch (InterruptedException e5) {
log.debug("Sleep interrupted ",e5);
}
if(xmppConnection.isConnected()){
if(! xmppConnection.isAuthenticated()){
try {
xmppConnection.login(serverCredentials.getAccountName()+"@"+
serverCredentials.getServerUrl(),
serverCredentials.getPassword(),
serverCredentials.getResource(),
true);
} catch (XMPPException e) {
try {
log.error("Login failed for "
+serverCredentials.getAccountName()
+"@"+serverCredentials.getServerUrl()
+".Retrying in 2 secs",e);
Thread.sleep(2000);
xmppConnection.login(serverCredentials.getAccountName()+"@"+
serverCredentials.getServerUrl(),
serverCredentials.getPassword(),
serverCredentials.getResource(),
true);
} catch (InterruptedException e1) {
log.error("Sleep interrupted.",e1);
} catch (XMPPException e2) {
log.error("Login failed for : "+serverCredentials.getAccountName()
+"@"+serverCredentials.getServerUrl(),e2);
throw new AxisFault("Login failed for : "+serverCredentials.getAccountName()
+"@"+serverCredentials.getServerUrl());
}
}
//Listen for Message type packets from specified server url
//packetFilter = new AndFilter(new PacketTypeFilter(Message.class),
// new FromContainsFilter(serverCredentials.getServerUrl()));
packetFilter = new FromContainsFilter(serverCredentials.getServerUrl());
}
}
On Fri, Jan 9, 2009 at 3:00 AM, <jlist9 at gmail.com> wrote:
> Hello all,
>
> Has anyone tried using jivesoftware's Smack API to access
> jabber.org? I tried some sample code on their forum but I was
> getting an error. The same code (with the slight difference of
> using a full email address) works fine for talk.google.com.
>
> Or, has anyone tried any java XMPP library with success?
>
>
> The error:
>
> SASL authentication failed using mechanism PLAIN:
> at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:325)
> at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:395)
> at com.gn.xmpp.XmppTest.main(XmppTest.java:40)
>
> The sample code:
>
> ConnectionConfiguration cc = new ConnectionConfiguration("jabber.org", 5222, "jabber.org");
> XMPPConnection connection = new XMPPConnection(cc);
> try {
> connection.connect();
> SASLAuthentication.supportSASLMechanism("PLAIN", 0);
> connection.login("your.jabber", "password", "resource");
> System.out.println(connection.isAuthenticated());
> } catch (XMPPException e1) {
> e1.printStackTrace();
> }
>
> --
> Best regards,
> Jack
>
> _______________________________________________
> JDev mailing list
> FAQ: http://www.jabber.org/discussion-lists/jdev-faq
> Forum: http://www.jabberforum.org/forumdisplay.php?f=20
> Info: http://mail.jabber.org/mailman/listinfo/jdev
> Unsubscribe: JDev-unsubscribe at jabber.org
> _______________________________________________
>
More information about the JDev
mailing list