<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Enavigo &#187; XMPP</title>
	<atom:link href="http://www.enavigo.com/tag/xmpp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.enavigo.com</link>
	<description>Take lemons, make lemonade or Jill and Yuval's Musings</description>
	<lastBuildDate>Fri, 20 Aug 2010 02:56:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Building an IM Bot with the Smack API. Avoid setting Roster Permissions</title>
		<link>http://www.enavigo.com/2008/11/23/building-an-im-bot-with-the-smack-api-avoid-setting-roster-permissions/</link>
		<comments>http://www.enavigo.com/2008/11/23/building-an-im-bot-with-the-smack-api-avoid-setting-roster-permissions/#comments</comments>
		<pubDate>Sun, 23 Nov 2008 19:19:40 +0000</pubDate>
		<dc:creator>yuval</dc:creator>
				<category><![CDATA[Commercials]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[WebSphere]]></category>
		<category><![CDATA[JSJaC]]></category>
		<category><![CDATA[Openfire]]></category>
		<category><![CDATA[PacketCollector]]></category>
		<category><![CDATA[PacketFilter]]></category>
		<category><![CDATA[Roster]]></category>
		<category><![CDATA[Smack]]></category>
		<category><![CDATA[XMPP]]></category>

		<guid isPermaLink="false">http://www.enavigo.com/?p=225</guid>
		<description><![CDATA[So I built what is an instant messaging bot using the Smack API and the Openfire XMPP server. Doing it is pretty simple of you read the documentation and Smack&#8217;s developer notes. The bot relies on a queue-like object that Smack gives you called a PacketCollector. All you need to do is log in to [...]]]></description>
			<content:encoded><![CDATA[<p>So I built what is an instant messaging bot using the <a href="http://www.igniterealtime.org/projects/smack/index.jsp">Smack API</a> and the <a href="http://www.igniterealtime.org/projects/openfire/index.jsp">Openfire XMPP</a> server. Doing it is pretty simple of you read the documentation and Smack&#8217;s developer notes. The bot relies on a queue-like object that Smack gives you called a <a href="http://www.igniterealtime.org/builds/smack/docs/latest/javadoc/org/jivesoftware/smack/PacketCollector.html">PacketCollector</a>. All you need to do is log in to the server, and let the packet collector wait for incoming messages. Clearly, you need to respond to the messages and use thread tools to do the waiting and all, but in general, the effort is relatively straightforward.<br />
<span id="more-225"></span><br />
One thing I noticed was that if you use a Smack-based IM client to send messages to Openfire, and on to the bot, the bot worked fine and received the messages. When I tried to send a message to the bot from a <a href="http://blog.jwchat.org/jsjac/">JSJaC-based client</a> (JavaScript <a href="http://xmpp.org">XMPP </a>library), the bot would not receive any messages. Even admin messages were not received by the bot, while the JSJaC client received them fine.</p>
<p>The culprit appeared to be the fact that I set the roster to accept all subscription requests. The roster, in plain English, is the buddy list. Subscriptions mean that as my buddy, you can see my status. My code looked like this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// set roster subscription mode</span>
Roster roster <span style="color: #339933;">=</span> conn1.<span style="color: #006633;">getRoster</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
roster.<span style="color: #006633;">setSubscriptionMode</span><span style="color: #009900;">&#40;</span>Roster.<span style="color: #006633;">SubscriptionMode</span>.<span style="color: #006633;">accept_all</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// wait for messages, accepting all of them</span>
PacketFilter pf <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PacketTypeFilter<span style="color: #009900;">&#40;</span>Message.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
PacketCollector pc <span style="color: #339933;">=</span> conn1.<span style="color: #006633;">createPacketCollector</span><span style="color: #009900;">&#40;</span>pf<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I found that if I used JSJaC I had to be logged-in to the server as a buddy of the bot for the bot to get the messages I sent it. On the other hand, when I removed these lines from my code, any message was received &#8212; which is what you want from a bot. So, if you do NOT set your roster subscription mode, you will be open to get all messages&#8230; </p>
<p>Weird.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.enavigo.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.enavigo.com/2008/11/23/building-an-im-bot-with-the-smack-api-avoid-setting-roster-permissions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Smack API: No clean way to discover if a multi-user chat room exists</title>
		<link>http://www.enavigo.com/2008/11/16/smack-api-no-clean-way-to-discover-if-a-multi-user-chat-room-exists/</link>
		<comments>http://www.enavigo.com/2008/11/16/smack-api-no-clean-way-to-discover-if-a-multi-user-chat-room-exists/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 05:25:02 +0000</pubDate>
		<dc:creator>yuval</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[existence]]></category>
		<category><![CDATA[MUC]]></category>
		<category><![CDATA[Multi-User Chat]]></category>
		<category><![CDATA[Smack]]></category>
		<category><![CDATA[XMPP]]></category>
		<category><![CDATA[XMPPException]]></category>

		<guid isPermaLink="false">http://www.enavigo.com/?p=220</guid>
		<description><![CDATA[Here&#8217;s another one to follow the previous two posts about Smack API and Multi-User Chat issues. Suppose you want to create a persistent room. Suppose you are not sure if that room already exists. In Smack, and I am not familiar of any other APIs, there is no non-exception-throwing way of doing this. Fundamentally, a [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s another one to follow the previous two posts about Smack API and Multi-User Chat issues.<br />
Suppose you want to create a persistent room. Suppose you are not sure if that room already exists. In Smack, and I am not familiar of any other APIs, there is no non-exception-throwing way of doing this. </p>
<p>Fundamentally, a room already exists is the situation where a room is already set up on the server with the same name as the one you wish to create.</p>
<p>The MultiUserChat object has a static <a href="http://www.igniterealtime.org/builds/smack/docs/latest/javadoc/org/jivesoftware/smackx/muc/MultiUserChat.html#getRoomInfo(org.jivesoftware.smack.XMPPConnection,%20java.lang.String)">getRoomInfo() method</a> which may have been the way to go. If the room does not exist, return null. Instead, if the room does not exist throws an <code>XMPPException</code>. Not sure what the error situation is here &#8211; I am just trying to find out if a room exists or not, but that causes an exception. </p>
<p>The flipside is on the creation end. If you try to create a room that already exists, an <code>XMPPException </code>will be thrown. This makes sense and is recoverable. Still, I am a fan of checking first instead of trying to do something only to encounter a bad situation. Not a biggie &#8211; just hope this spares someone the exploration and time. Not really documented, etc. </p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.enavigo.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.enavigo.com/2008/11/16/smack-api-no-clean-way-to-discover-if-a-multi-user-chat-room-exists/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Openfire/XMPP Multi-User Chat name is registered as all lower-case</title>
		<link>http://www.enavigo.com/2008/11/15/openfirexmpp-multi-user-chat-name-is-registered-as-all-lower-case/</link>
		<comments>http://www.enavigo.com/2008/11/15/openfirexmpp-multi-user-chat-name-is-registered-as-all-lower-case/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 04:11:22 +0000</pubDate>
		<dc:creator>yuval</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[lower-case]]></category>
		<category><![CDATA[Multi-User Chat]]></category>
		<category><![CDATA[Openfire]]></category>
		<category><![CDATA[Smack]]></category>
		<category><![CDATA[XMPP]]></category>

		<guid isPermaLink="false">http://www.enavigo.com/?p=219</guid>
		<description><![CDATA[Another observation regarding XMPP multi-user chat (aka chat-rooms) to follow on my previous entry. This one is also an odd one. It appears that Openfire uses all-lowercase names for multi-user chat rooms. So if your room&#8217;s name is &#8220;myRoom&#8221;, it will be saved as &#8220;myroom&#8221;. Could not find anything to require this in the XMPP [...]]]></description>
			<content:encoded><![CDATA[<p>Another observation regarding XMPP multi-user chat (aka chat-rooms) to follow on my <a href="http://www.enavigo.com/2008/11/15/openfiresmack-bug-unable-to-ask-multi-user-chat-who-the-admins-are/">previous entry</a>. This one is also an odd one.<br />
It appears that Openfire uses all-lowercase names for multi-user chat rooms. So if your room&#8217;s name is &#8220;myRoom&#8221;, it will be saved as &#8220;myroom&#8221;.</p>
<p>Could not find anything to require this in the <a href="http://www.xmpp.org/extensions/xep-0045.html">XMPP specifications for multi-user chat</a>.</p>
<p>Oddness.</p>
<p><strong>UPDATE:</strong><br />
This is apparently the way it is supposed to be according to the<a href="http://xmpp.org/extensions/xep-0106.html"> XMPP protocol</a> or as explained to me on the <a href="http://www.igniterealtime.org/community/message/182979#182979">Openfire dev boards</a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.enavigo.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.enavigo.com/2008/11/15/openfirexmpp-multi-user-chat-name-is-registered-as-all-lower-case/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Openfire/Smack bug? Unable to ask Multi-User Chat who the admins are</title>
		<link>http://www.enavigo.com/2008/11/15/openfiresmack-bug-unable-to-ask-multi-user-chat-who-the-admins-are/</link>
		<comments>http://www.enavigo.com/2008/11/15/openfiresmack-bug-unable-to-ask-multi-user-chat-who-the-admins-are/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 03:28:49 +0000</pubDate>
		<dc:creator>yuval</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[error 403]]></category>
		<category><![CDATA[IgniteRealtime]]></category>
		<category><![CDATA[MUC]]></category>
		<category><![CDATA[Multi-User Chat]]></category>
		<category><![CDATA[Openfire]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[Smack]]></category>
		<category><![CDATA[XMPP]]></category>

		<guid isPermaLink="false">http://www.enavigo.com/?p=218</guid>
		<description><![CDATA[I encountered two interesting points when working with the Openfire XMPP server and the Smack API, both from IgniteRealtime. After joining a Multi-User Chat (MUC) independently, without invite, I was forbidden (e.g. error 403) from finding out who the administrators or owners of the room were. I could not find anything about this in the [...]]]></description>
			<content:encoded><![CDATA[<p>I encountered two interesting points when working with the <a href="http://www.igniterealtime.org/projects/openfire/index.jsp">Openfire XMPP server</a> and the <a href="http://www.igniterealtime.org/projects/smack/index.jsp">Smack API</a>, both from <a href="http://www.igniterealtime.org/">IgniteRealtime</a>. </p>
<ol>
<li>After joining a Multi-User Chat (MUC) independently, without invite, I was forbidden (e.g. error 403) from finding out who the administrators or owners of the room were. I could not find anything about this in the <a href="http://www.igniterealtime.org/builds/smack/docs/latest/documentation/extensions/muc.html">documentation</a>.<br />
The workaround was not too bad: apparently the method <code>getOccupant(<full JID>) </full></code>allows you to get an <code>Occupant </code>object which does hold affiliation and can report admin rights.
</li>
<li>In some situations &#8211; not sure when yet &#8211; the owner of an MUC was able to grant another user admin status by just using his/her nickname, without using the full JID. That is<br />
<code>grantAdmin("nickname")</code> worked just as well as <code>grantAdmin("nickname@conference.server")</code>. Nonetheless, when trying to use the method getOccupant() as mentioned above, the full JID form worked while the nickname-only one failed.</li>
</ol>
<p>I am using Smack 3.0.4 and Openfire 3.5.2. Weird.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.enavigo.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.enavigo.com/2008/11/15/openfiresmack-bug-unable-to-ask-multi-user-chat-who-the-admins-are/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up JSJaC with Openfire 3.5.2</title>
		<link>http://www.enavigo.com/2008/10/14/setting-up-jsjac-with-openfire-352/</link>
		<comments>http://www.enavigo.com/2008/10/14/setting-up-jsjac-with-openfire-352/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 01:43:49 +0000</pubDate>
		<dc:creator>yuval</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Apache httpd]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSJaC]]></category>
		<category><![CDATA[mod_proxy]]></category>
		<category><![CDATA[Openfire]]></category>
		<category><![CDATA[XMPP]]></category>

		<guid isPermaLink="false">http://www.enavigo.com/?p=217</guid>
		<description><![CDATA[I am using Openfire, an XMPP (Jabber) server, to facilitate instant messaging in a closed system I am building. Part of my design had users rely on browsers as instant messaging (IM) clients. As Meebo showed, it can be done quite well and an open source JavaScript library, JSJaC, apparently provides this ability. JSJaC is [...]]]></description>
			<content:encoded><![CDATA[<p>I am using <a href="http://www.igniterealtime.org/projects/openfire/index.jsp" target="_blank">Openfire</a>, an <a title="The XMPP instant messaging protocol" href="http://xmpp.org" target="_blank">XMPP</a> (Jabber) server, to facilitate instant messaging in a closed system I am building. Part of my design had users rely on browsers as instant messaging (IM) clients. As <a href="http://www.meebo.com/" target="_blank">Meebo</a> showed, it can be done quite well and an open source JavaScript library, <a href="http://blog.jwchat.org/jsjac/" target="_blank">JSJaC</a>, apparently provides this ability. JSJaC is the backbone of a full-blown browser-based IM client called JWChat, but for me, the plumbing was what was necessary. </p>
<p>Only thing is that JSJaC is not the easiest to set up with Openfire. </p>
<p>JSJaC uses HTTP-binding, which according to <a href="http://en.wikipedia.org/wiki/Jabber">Wikipedia</a> allows for long-lasting HTTP requests instead of polling, which just periodically checks the server to see if there is a message waiting. To do that, JSJaC needs to connect to the server and that is done by accessing a somewhat tricky port, 7070 is the default in version 3.5.2. What&#8217;s tricky about it? Browsers do not like to let JavaScript access services using XMLHttpRequest, the lifeblood of AJAX, on URLs and ports unlike the one which the current URL relies on. This is normally solved using a proxy or a URL rewrite, which forward requests to the desired ports and pass back responses, all as if you used the &#8216;appropriate&#8217; ports. Luckily, Apache&#8217;s HTTPd has great modules that do just that. The instructions in JSJaC&#8217;s readme file recommended using a rewrite. That caused repeated 503 errors from Apache. Using its proxy did work for me. As usual, you spend time, read here and read there, and finally, you normally find a way to make it work. This how I did it.</p>
<ol>
<li>After downloading JSJaC, open jsjac.js. Change the line 

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> JSJACHBC_USE_BOSH_VER<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span></pre></div></div>

<p>to<br />
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> JSJACHBC_USE_BOSH_VER<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span></pre></div></div>

</li>
<li>To allow Apache HTTPd&#8217;s proxy to work, enable <code>proxy_module</code> and <code>proxy_http_module</code> in Apache HTTPd&#8217;s <code>httpd.conf</code> file</li>
<li>Add a virtual host that will map a certain URL to the proxy, and set up the proxy to point at the Openfire http-binding port:

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;virtualhost</span> 127.0.0.1:80<span style="color: #000000; font-weight: bold;">&gt;</span></span>
	DocumentRoot &quot;C:/www/root&quot;  <span style="color: #808080; font-style: italic;">&lt;!-- This is the document root for your server --&gt;</span>
	AddDefaultCharset UTF-8
	ProxyRequests On
	ProxyPass /http-bind/ http://127.0.0.1:7070/http-bind/ <span style="color: #808080; font-style: italic;">&lt;!-- This is where your Openfire server can be accessed --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/virtualhost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</li>
<li> To test this configuration, use JSJaC&#8217;s simpleclient.html, its sample client, to try and connect to the server. Make sure you add the following line

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">oArgs.<span style="color: #660066;">authtype</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'nonsasl'</span><span style="color: #339933;">;</span></pre></div></div>

<p>above</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">con.<span style="color: #660066;">connect</span><span style="color: #009900;">&#40;</span>oArgs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
<li>Start Apache HTTPd and open simpleclient.js</li>
<li>
simpleclient asks for 4 fields:</p>
<ul>
<li>The server&#8217;s base URL: This is the proxied URL, for example, http://127.0.0.1/http-bind/ (note the trailing slash) in my case.</li>
<li>Server name/domain: The domain Openfire was set up to use. In XMPP, if the server&#8217;s name is myserver, users will be known on it with IDs like joe@myserver</li>
<li>User name of existing user</li>
<li>The password for that user</li>
</ul>
</li>
<li>Connect!</li>
</ol>
<p>I highly recommend using <a href="https://addons.mozilla.org/en-US/firefox/addon/1843">Firebug </a>to ensure the request is sent properly and is being received properly from Openfire. Odd Firefox object initialization errors are due to the fact that an attempt is made to access a port JavaScript is not allowed to access.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.enavigo.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.enavigo.com/2008/10/14/setting-up-jsjac-with-openfire-352/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
