AnsweredAssumed Answered

Connection closed with error ,Parser got END_DOCUMENT event

Question asked by chirag on May 21, 2015

Hi,

 

I am using smack 4.1.0 version to integrate chat feature in one of android application. I am able to connect server properly and send message. But after 2-3 mins, Connection is throwing below exception and closed itself. I have pasted my code below.

Code:

 

XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration
  .builder();
  configBuilder.setUsernameAndPassword("username",
  "password");
  configBuilder.setHost("host");
  configBuilder.setServiceName("servicename");
 configBuilder
  .setSecurityMode(ConnectionConfiguration.SecurityMode.ifpossible);
  final AbstractXMPPConnection conn1 = new XMPPTCPConnection(
  configBuilder.build());
  conn1.addAsyncStanzaListener(new StanzaListener() {
  @Override
  public void processPacket(Stanza stanza)
  throws NotConnectedException {
  Log.e("stanza", "stanza" + stanza.toXML());
  };
  }, new StanzaFilter() {
  public boolean accept(Stanza stanza) {
  return true;
  };
  });
  try {
  conn1.connect();
  conn1.addConnectionListener(new ConnectionListener() {
  @Override
  public void reconnectionSuccessful() {
  // TODO Auto-generated method stub
  Log.d("", "reconnectionSuccessful");
  }


  @Override
  public void reconnectionFailed(Exception arg0) {
  // TODO Auto-generated method stub
  Log.d("", "reconnectionFailed");


  }


  @Override
  public void reconnectingIn(int arg0) {
  // TODO Auto-generated method stub
  Log.d("", "reconnectingIn");
  }


  @Override
  public void connectionClosedOnError(Exception arg0) {
  // TODO Auto-generated method stub
  Log.d("", "connectionClosedOnError");
  try {
  conn1.connect();
  } catch (SmackException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  } catch (XMPPException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  }
  }


  @Override
  public void connectionClosed() {
  // TODO Auto-generated method stub
  Log.d("", "connectionClosed");
  }


  @Override
  public void connected(XMPPConnection arg0) {
  // TODO Auto-generated method stub
  Log.d("", "connected");


  }


  @Override
  public void authenticated(XMPPConnection arg0, boolean arg1) {
  // TODO Auto-generated method stub
  Log.d("", "authenticated");
  }
  });
  ProviderManager.addExtensionProvider("cid", "xmpp:cid",
  new EbbCidProvider());
  ProviderManager.addExtensionProvider("ebbuserid", "xmpp:ebbuserid",
  new EbbUserIdProvider());
  // Create a connection to the jabber.org server on a specific port.
  conn1.login();


  if (conn1.isConnected() && conn1.isAuthenticated()) {


  // user. We use an AndFilter to combine two other filters._
  StanzaFilter filter = new StanzaTypeFilter(Message.class);
  // Assume we've created an XMPPConnection name "connection".


  // First, register a packet collector using the filter we
  // created.


  // Normally, you'd do something with the collector, like wait
  // for new packets.


  // Next, create a packet listener. We use an anonymous inner
  // class for brevity.
  StanzaListener myListener = new StanzaListener() {


  @Override
  public void processPacket(Stanza stanza)
  throws NotConnectedException {
  Log.e("filter", "stanza" + stanza.toXML());
  Log.e("",
  "stanza extenstion"
  + ((CidExtenstion) stanza
  .getExtension("xmpp:cid")).cid);
  Log.e("",
  "stanza extenstion"
  + ((EbbUserIdExtenstion) stanza
  .getExtension("xmpp:ebbuserid")).ebbUserId);
  }


  };
  // Register the listener._
  conn1.addSyncStanzaListener(myListener, filter);
  conn1.sendStanza(new Presence(Presence.Type.available));
  Message message = new Message();
  message.setTo("test@xyz.com");
  message.setBody("test");
  message.setFrom(conn1.getUser());
  message.setType(Message.Type.chat);
  message.addExtension(new CidExtenstion("cid test"));
  message.addExtension(new EbbUserIdExtenstion("ebbuserId test"));
  conn1.sendStanzaWithResponseCallback(message,
  filter, myListener);


  }


  } catch (SASLErrorException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  } catch (SmackException e) {
  e.printStackTrace();
  } catch (IOException e) {
  e.printStackTrace();
  } catch (XMPPException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  }

 

Exception:

 

05-21 17:38:47.746: W/AbstractXMPPConnection(26316): Connection closed with error

05-21 17:38:47.746: W/AbstractXMPPConnection(26316): org.jivesoftware.smack.SmackException: Parser got END_DOCUMENT event. This could happen e.g. if the server closed the connection without sending a closing stream element

05-21 17:38:47.746: W/AbstractXMPPConnection(26316): at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPC onnection.java:1148)

05-21 17:38:47.746: W/AbstractXMPPConnection(26316): at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPCon nection.java:937)

05-21 17:38:47.746: W/AbstractXMPPConnection(26316): at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnecti on.java:952)

05-21 17:38:47.746: W/AbstractXMPPConnection(26316): at java.lang.Thread.run(Thread.java:818)

 

 

If anybody has already faced same issue and have some solution. Please guide me.

Outcomes