How to resolve error "java.lang.IllegalArgumentException: Can't initialize the configured debugger!" in smack

StackOverflow https://stackoverflow.com/questions/20563957

Question

I want to use smack api and gtalk server using for IM. My code works when I run it from local system.

    import java.io.Console;
    import java.util.Collection;
    import java.util.List;

    import javax.net.ssl.SSLSocketFactory;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.jivesoftware.smack.Chat;
    import org.jivesoftware.smackx.*;
    import org.jivesoftware.smack.ConnectionConfiguration;
    import org.jivesoftware.smack.MessageListener;
    import org.jivesoftware.smack.Roster;
    import org.jivesoftware.smack.RosterEntry;
    import org.jivesoftware.smack.XMPPConnection;
    import org.jivesoftware.smack.XMPPException;
    import org.jivesoftware.smack.packet.Message;
    import org.jivesoftware.smack.debugger.SmackDebugger;
    import org.jivesoftware.smack.filter.PacketFilter;
    import org.jivesoftware.smack.packet.Presence;


public class runcollectorAction extends Action implements MessageListener{

public static String username = "pqr";
public static String password ="mypwd";
XMPPConnection connection = new XMPPConnection("gmail.com");

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    XMPPConnection.DEBUG_ENABLED = true;
    System.out.println("okzzzz");
    String realtime=request.getParameter("collector");

    if(realtime!=null){
        boolean connectionStatus = connectToServer();
        displayUserList();
        if (connectionStatus){

            sendMessage(realtime,"abc@gmail.com");

        }

    System.out.println("Realtime  : "+ realtime);
    }
    return mapping.findForward("success");

}

public void sendMessage(String message, String to) throws   XMPPException
{
    System.out.println("Message is ... " + message);
    Chat chat = connection.getChatManager().createChat(to, this);
    chat.sendMessage(message);
}

@Override
public void processMessage(Chat chat, Message message) {
    // TODO Auto-generated method stub
    if ( message.getType() == Message.Type.chat){
        System.out.println(chat.getParticipant() + "says: " + message.getBody());

    }

}        

public boolean connectToServer() throws XMPPException{
    try {

        ConnectionConfiguration config = new ConnectionConfiguration("talk.google.com",5222,"gmail.com");

        config.setCompressionEnabled(true);
        //config.setSASLAuthenticationEnabled(false);
        connection = new XMPPConnection(config);

        connection.connect();
        Thread.sleep(31000);
        System.out.println("connected to ... " + connection.getHost() );

        connection.login(username, password);

        System.out.println("authenticated .... " + connection.isAuthenticated());

    }
    catch (Exception e){
        e.printStackTrace();
        System.out.println("Error occured while connecting to server");
    }
    return true;
    //return connection.isConnected();

}

/**
 * Function to display user list
 */
public void displayUserList()
{
Roster roster = connection.getRoster();
roster.setSubscriptionMode(Roster.SubscriptionMode.manual);
Collection<RosterEntry> entries = roster.getEntries();

System.out.println("\n\n" + entries.size() + " buddy(ies):");
for(RosterEntry r:entries)
    {
        System.out.println(r.getUser());
        Presence presence = roster.getPresence(r.getUser());
        System.out.println(r.getUser()+ " user is "+ presence.getMode());
    }
}
}

But when I push same code to server (live) using git without changing anything, it gives following errors.

java.lang.IllegalArgumentException: Can't initialize the configured debugger!
    at org.jivesoftware.smack.Connection.initDebugger(Connection.java:774)
    at org.jivesoftware.smack.XMPPConnection.initReaderAndWriter(XMPPConnection.java:679)
    at org.jivesoftware.smack.XMPPConnection.initConnection(XMPPConnection.java:543)
    at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection.java:527)
    at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:953)

Also it gives error that - "not connected to server"

How to resolve these errors??

Was it helpful?

Solution

This might be helpful to you.

Nsmack api is my class that is why I used its object. Only following statements are important in given code-

XMPPConnection.DEBUG_ENABLED = false;
config.setCompressionEnabled(true);
config.setSASLAuthenticationEnabled(false);


private void connectionInit() throws XMPPException, IOException {
    // TODO Auto-generated method stub
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("... in main function .......");
    XMPPConnection.DEBUG_ENABLED = false;
    mySmackObj = new NSmackAPI();
    boolean status = mySmackObj.connectTOGTalk();
    boolean initial_status = true;
    mySmackObj.displayUserList();
    System.out.println("-----");

    String talkTo=RunMTNew.customer+"web@"+server;
    System.out.println(talkTo);
    System.out.println("-----");
    System.out.println("All messages will be sent to " + talkTo);
    System.out.println("Enter your message in the console:");
    System.out.println("-----\n");
    mySmackObj.sendMessage("Hi..are you there", talkTo);
  try{
      while(!(smsg=br.readLine()).equals(null)){
          mySmackObj.sendMessage(smsg, talkTo);
      }
  }
  catch(Exception e){
      System.out.println("sending failed");
      e.printStackTrace();
  }

}

boolean connectTOGTalk() throws XMPPException{

    try {


        ConnectionConfiguration config = new ConnectionConfiguration(server, 5222, server);
        config.setCompressionEnabled(true);
        config.setSASLAuthenticationEnabled(false);
        connection = new XMPPConnection(config);
        connection.connect();
        System.out.println("Username is "+username);
        System.out.println("Connected to " + connection.getHost());
        connection.login(username,password);
        System.out.println(connection.isAuthenticated());
        }
    catch (Exception e) {
        e.printStackTrace();
    }
    if(connection.isConnected()){
        return true;
    }
    else {
        return false;
    }
}

OTHER TIPS

Adding this to my configuration fixed my issue

myConfig.setDebuggerEnabled(true);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top