powered by Jive Software

How to create custom stanza for retrieving chat history?

I am using smack library and want to retrieve the chat history from ejabberd . After some research I haven’t found any way to retrieve the chat history between person, but I have seen some where that in order to achieve this we need to implemet custom stanza . How can I implement this ? Any sample code will be highly appreciated


using below code you can add your custom tag in iq packet:

public class PacketExtensions implements PacketExtension {

public static String namespace = null;

public static String elementname = null;

private String Namespaces;

private String Element;


public String toXML() {

// TODO Auto-generated method stub

StringBuffer buf = new StringBuffer();

buf.append("<").append(getElementName()).append(" xmlns="").append(getNamespace()).append("">").append("</")


if (Namespaces != null) {

buf.append("<").append(Element).append(" xmlns="").append(Namespaces).append("">").append("</").append(Element)



return buf.toString();


public PacketExtensions() {


public static String getElementname() {

return elementname;


public void setElementname(String elementname) {

PacketExtensions.elementname = elementname;


public void setNamespace(String namespace) {

PacketExtensions.namespace = namespace;



public String getElementName() {

return elementname;



public String getNamespace() {

return PacketExtensions.namespace;


public String getFILE_NAME() {

return FILE_NAME;


public void setFILE_NAME(String fILE_NAME) {



public int getFILE_SIZE() {

return FILE_SIZE;


public void setFILE_SIZE(int fILE_SIZE) {



public String getMSG_URL() {

return MSG_URL;


public void setMSG_URL(String mSG_URL) {



public String getElement() {

return Element;


public void setElement(String element) {

Element = element;


public String getNamespaces() {

return Namespaces;


public void setNamespaces(String namespaces) {

Namespaces = namespaces;



now you need to add this in packet extension as

ExamplePacketExtension e = new ExamplePacketExtension();

e.setElementname(“youe element name”);

e.setNamespace(“youe namespace”);

add this e object in packet extension

send it to openfire server you will get addditional tag in openfire server.

now if you want to add aditional tag to youe side then use below code:

public class CustomIQProvider implements IQProvider {

public IQBuilder iq = new IQBuilder();

public Map<String, String> attribute = new HashMap<String, String>();

public String status;


public IQ parseIQ(XmlPullParser parser) throws Exception {

// Start parsing loop

outerloop: while (true) {

int eventType = parser.next();

switch (eventType) {

case XmlPullParser.START_TAG:

String elementName = parser.getName();

switch (elementName) {

case “elementname”:

status = parser.nextText();

attribute.put(“status”, status);




case XmlPullParser.END_TAG:

break outerloop;




return iq;



Will it work on ejabberd ?

don’t know about ejabberd but as you mentioned you are using smack and it will add your custom tag in iq packet and will read addtional tag from stanza on server side. i have used smack and openfire server and it is working fine but have not any idea about ejabbered.

Thanks, let me try your suggestion