Smack problem

Hi everyone,

not sure if I´m at right place here, but despite that, I hope you can help me .

I try to make a little app that just connects jabber and sends a message. I downloaded Smack and linked it.

My code:

import java.sql.;
import javax.swing.
;
import java.awt.;
import java.awt.event.
;
import java.util.;
import org.jivesoftware.smack.
;
import org.jivesoftware.smack.packet.Message;

class Jabber{

public static void main(final String[] args) {

ConnectionConfiguration config = new ConnectionConfiguration("jabbim.cz", 5222); //got acc 3.14.TR@jabbim.cz - czech jabber server

config.setCompressionEnabled(true);
config.setSASLAuthenticationEnabled(true);

XMPPConnection connection = new XMPPConnection(config);

try{
System.out.println(“before connection”);
connection.connect();
connection.login(“3.14.TR”, “pass”, "3.14.TR@jabbim.cz/Smack");
System.out.println(“connected”);
}
catch(Exception a){
System.out.println(“connection error”);
return;
}

ChatManager chatmanager = connection.getChatManager();
Chat newChat = chatmanager.createChat("myFriend@jabbim.cz", new MessageListener() {
public void processMessage(Chat chat, Message message) {
System.out.println("Received message: " + message);
}
});

try {
newChat.sendMessage(“hoooooooooooj!”);
}
catch (XMPPException e) {
System.out.println(“Error Delivering block”);
}
connection.disconnect();

}

}

Compilation is always successful, but trying running program throws few exceptions:

before connection //means connection created, but not connected
java.lang.NullPointerException
at org.jivesoftware.smack.util.Base64.encodeBytes(Base64.java:636)
at org.jivesoftware.smack.sasl.SASLMechanism.challengeReceived(SASLMechanism.java: 152)
at org.jivesoftware.smack.SASLAuthentication.challengeReceived(SASLAuthentication. java:492)
at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:338)
at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:76)
connection error

can anyone help me please?

thanks a lot

petr bel

public static void main(final String[] args) {

ConnectionConfiguration config = new ConnectionConfiguration(“jabbim.cz”, 5222);
config.setCompressionEnabled(true);
config.setSASLAuthenticationEnabled(true);

XMPPConnection connection = new XMPPConnection(config);

try{
System.out.println(“before connection”);
connection.connect();
connection.login(“3.14.TR”, “cat8x8r1”, "3.14.TR@jabbim.cz/Smack");
System.out.println(“connected”);
}
catch(Exception a){
System.out.println(“connection error”);
return;
}

ChatManager chatmanager = connection.getChatManager();
Chat newChat = chatmanager.createChat("joyce@jabbim.cz", new MessageListener() {
public void processMessage(Chat chat, Message message) {
System.out.println("Received message: " + message);
}
});

try {
newChat.sendMessage(“hoooooooooooj!”);
}
catch (XMPPException e) {
System.out.println(“Error Delivering block”);
}
connection.disconnect();

}

config.setCompressionEnabled(true);
config.setSASLAuthenticationEnabled(true);

See the 2nd line? you enable SASL Authentication but you don’t specify the SASL Mechanism to implement on that authentication.

You need something before those lines like SASLAuthentication,registerMechanism(“Digest-Md5”,SASLDigestMd5Mechanism.class) ;

i dont know if it uses md5 its just a untch, what i do know is that you aren’t getting any response on the SASL challenge, thats why it reads null

even I added SASLAuthentication.supportSASLMechanism(“PLAIN”, 0); or DIGEST-MD5, nothing works, but, there are 2 exceptions available:

  1. when i use my normal pass, after connection it throws: “No response from the server”

  2. when i use hash(md5) of my pass: after conn it throws “SALS authentication failed using mechanism PLAIN” (or DIGEST-MD5) if ise it

I´ve read a lot of discussions about same problem, but there´s no solution anywhere.

Can you help?

thanx

thats weird… but since 2) says that the auth failed its better to use the hash of your pass because if it says that the auth failed it’s sure that it as encontered the server and connected. I think the DIGEST-MD5 implementation had an error try this fix:

http://community.igniterealtime.org/servlet/JiveServlet/download/200878-5114/MyS ASLDigestMD5Mechanism.java.zip

Unzip it to your project and then use this line:

SASLAuthentication.registerMechanism(“DIGEST-MD55”,MySASLDigestMd5Mechanism.clas s) ;

it worked for me when tryin to connect to facebook via digest-md5

i downloaded your zip, unzipped it, compiled into .class file, and than successfully imported into my file. Despite I have compilation error:

*Jabber.java:34: cannot find symbol
symbol : method registerMechanism(java.lang.String,java.lang.Class<sals.MySASLDigestMD5Mechanis m>)
location: class org.jivesoftware.smack.SASLAuthenticationSASLAuthentication.registerMechanis(“DIGEST-MD55”, MySASLDigestMD5Mechanism.class) ; *

Same as when i added nameofmypackge.yourclass.class, compiler isn´t able to find it or add it, maybe

I tried to remove “.class” but nothing happened. can you help please?