Creating new user with Smack 2.1.0 and Jive Messanger 2.3.0

Hi,

I have installed new version of Smack and Jive messenger. Sometimes I have this type of exception:

org.xmlpull.v1.XmlPullParserException: start tag not allowed in epilog but got i (position: END_TAG seen …<i… @1:176)[/b]

at org.xmlpull.mxp1.MXParser.parseEpilog(MXParser.java:1588)

at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1393)

at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)

at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:352)

at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43)

at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:63)

It happens for a new users which I create with following code. But only sometimes. Sometimes it is without exception.

I used to use similar code with previous versions of Smack (2.0.0) and Jive Messanger (2.2.1) and it worked fine. No problem.

With new versions I had to change creating a new account within new connection.

Source code is there:

public void login(String serverUrl, int serverPort, String username, String password) throws ChatException {

// get connection to jabber server

try {

jabberConn = new XMPPConnection(serverUrl, serverPort);

}

catch (XMPPException e) {

throw new ChatException(“Cannot initialize connection with the jabber server.”, e);

}

// try to login

try {

jabberConn.login(username, password);

}

catch (XMPPException e) { // probably new user

// close old connection

if (jabberConn != null) {

jabberConn.close();

}

// try create new account for a new user

XMPPConnection newConn = null;

try {

newConn = new XMPPConnection(serverUrl, serverPort);

newConn.getAccountManager().createAccount(username, “test”);

}

catch (XMPPException innerE) {

throw new ChatException(“Cannot create new account on the jabber server.”, innerE);

}

finally {

newConn.close();

}

// try again login - there should be a new account

try {

jabberConn = new XMPPConnection(serverUrl, serverPort);

jabberConn.login(username, password);

}

catch (XMPPException innerE) {

if (jabberConn != null) {

jabberConn.close();

}

throw new ChatException(“Cannot login to the jabber server.”, innerE);

}

}

}

/code

Does anyone have similar problem? Or do you know what could be different in a newer versions?

Thanks,

Ondrej

Hey Ondrej,

Can you enable the Smack debugger and post the sent and received RAW packets? That info will help me better understand the path that the application is following.

Thanks,

– Gato

Hi Gato,

If I try to login as an user who exists, everything is ok.

Problem is if I try to login as a new user (new username and password). I can see three connection:

  1. Try to login - throws exception (SASL authentication failed) - it is ok (there is new user that is not in Jive messenger)

  2. Create new Account: …getAccountManager().createAccount()… - it is ok too

  3. Try login again…

There is problem: org.xmlpull.v1.XmlPullParserException: only whitespace content allowed before start tag and not t (position: START_DOCUMENT seen t… @1:1)

Sent:

/code

Received:

/code

I hope that it will help.

Regards,

Ondrej

Here is the code that works for me:

private XMPPConnection setConexionXmppServer(SubscriptionRequestPacketListener subscripcionListener, MensajesListener mensajesListener){

try{

XMPPConnection xmppCon = new XMPPConnection (this.host, this.port, this.service);

XMPPConnection.DEBUG_ENABLED = true;

roster.setDefaultSubscriptionMode(Roster.SUBSCRIPTION_MANUAL);// Setea como defecto la subscripción manual

xmppCon.addPacketListener(subscripcionListener, new PacketTypeFilter(Presence.class));

xmppCon.addPacketListener(mensajesListener, new PacketTypeFilter(Message.class));

return xmppCon;

}catch(XMPPException xmpp){

System.err.println("Catch setConnectionXmppServer(): XMPPException " + xmpp.toString() + “ConexionSmack.class” );

return null;

}

}[/code]

Here is the code that works for me:

// method for stablishing the connection with xmppserver

private XMPPConnection setConexionXmppServer(SubscriptionRequestPacketListener subscripcionListener, MensajesListener mensajesListener){

try{

XMPPConnection xmppCon = new XMPPConnection (this.host, this.port, this.service);

XMPPConnection.DEBUG_ENABLED = true;

roster.setDefaultSubscriptionMode(Roster.SUBSCRIPTION_MANUAL);// Setea como defecto la subscripción manual

xmppCon.addPacketListener(subscripcionListener, new PacketTypeFilter(Presence.class));

xmppCon.addPacketListener(mensajesListener, new PacketTypeFilter(Message.class));

return xmppCon;

}catch(XMPPException xmpp){

System.err.println("Catch setConnectionXmppServer(): XMPPException " + xmpp.toString() + “ConexionSmack.class” );

return null;

}

}[/code]

//method for login

private boolean autenticar(RosterChangesListener rosterListener){//primero intentamos logonear al usuario en jive, si falla creamos un nuevo usuario jive y volvemos a autenticar.

//crea una instancia del roster, despues de logonear con el servidor jive

if(xmppCon != null){

try{

xmppCon.login(usuario,clave);

xmppCon.sendPacket(new Presence(Presence.Type.AVAILABLE, “Se ha conectado”, 5, Presence.Mode.AVAILABLE));

roster = xmppCon.getRoster();//el roster se pide solo si el usuario está autenticado

roster.addRosterListener(rosterListener);

return true;

}catch(XMPPException xmpp){

System.err.println("Catch autenticar(): El usuario " + usuario + " no esiste en el Jive XMPPException " + xmpp.toString() );

return false;

}

}

else return false;

}[/code]

//method for a new user

private void crearNuevoUsuarioJive(){

try{//este código se ejecuta solo si el usuario no está registrado en jive, y solo 1 vez.

accountManager = this.xmppCon.getAccountManager();

accountManager.createAccount(this.usuario,this.clave);

}catch(XMPPException xmpp){

System.err.println(“Catch crearNuevoUsuarioJive(” + usuario + "):XMPPException " + xmpp.toString()+ “ConexionSmack.class” );

}

}[/code]

Hey Ondrej,

I was able to reproduce this problem though its frequency is very low. I think that the problem has been fixed. I had to change the JM code and did some logic clean up in Smack too. Try using the next nightly build of JM and also of Smack. Let me know how it goes.

Thanks,

– Gato