Sunday, July 6, 2014

Release 0.2.0 - Create an XMPP Core Library, MUC support and more...

Welcome to another blog post! It's been a long time since my last post and since the last version there have been two major refactorings which are now finished. There are also new features like Multi-User Chat support which have reached a status where they can be considered complete. Reason enough to release version 0.2.0! Let's have a look at the important changes.

Refactoring 1: Create an XMPP Core Library

The first refactoring I am talking about is that Babbler has emerged into two modules: An "xmpp-core" module which mainly consists of mappings between Java classes and XMPP and an "xmpp-client" module for XMPP client functionality, which implements "real" business logic for clients.

The reason for this separation is simple: I wanted to have an "xmpp-core" module, which could serve client and server implementations alike, at least theoretically.

Its purpose is comparable to Tinder, but it's much cleaner, more complete and doesn't have the "jivesoftware stamp" attached to it. Besides mapping to XMPP stanzas and extensions it also provides a few utility methods and classes, e.g. for generating the verification string for Entity Capabilities.

If interest arose, it could now be easily provided as own library, similarly to Tinder.

What you can do with it now is that you can generate XMPP-style XML in an easy way using standard JAXB:

Writer writer = new StringWriter();

XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newFactory().createXMLStreamWriter(writer);
XMLStreamWriter xmppStreamWriter = XmppUtils.createXmppStreamWriter(xmlStreamWriter, true);

JAXBContext jaxbContext = JAXBContext.newInstance(Message.class, Sent.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);

Message forwardedMessage = new Message(Jid.valueOf(""), Message.Type.CHAT, "Hi!!");

Message message = new Message(Jid.valueOf(""));
message.getExtensions().add(new Sent(new Forwarded(forwardedMessage)));

marshaller.marshal(message, xmppStreamWriter);


Which would output the following:

<message to="">
    <sent xmlns="urn:xmpp:carbons:2">
        <forwarded xmlns="urn:xmpp:forward:0">
            <message xmlns="jabber:client" to="" type="chat">

Cool, isn't it? Especially, that it sets the correct namespace for the inner message, but doesn't set it for the outer message (since it's the default namespace there).

Refactoring 2: XmppSession Instead of Connection

The second major refactoring was the concept of using an "XmppSession" instead of a "Connection". The session can have multiple connection methods which are tried during establishing the XMPP session. If connecting with TCP fails for some reason, the session can try alternative connection methods such as BOSH as fallback.

I've illustrated this approach here:

New Features

Besides these major refactorings, there were other changes in form of new features, improvements and more documentation.

One of the major addition is the Multi-User Chat support. In my last blog post, I've also announced support for Real-Time Text would find its way into 0.2.0, but unfortunately it's not yet finished.

You can find the changelog and documentation on the project site.


That's it for now, I hope you like it. If you have something to say, just leave a comment!