Oh and my hosting plan gives me access to a Ruby web server but not a Java web server.
I kept the code independent of any particular web framework, so you will need to write a
short handler for HTTP requests that is responsible for forwarding the requests to the
module and taking responses back from it. Here is the one I use for Rails:
As you can see. Its pretty short.
require 'rexml/document'
require 'xmpphttpbind'
class RhbController < ApplicationController
# Handles HTTP Bind requests
def bind
begin
xmpp_response = XMPP::HTTPBind::parse request.raw_post
logger.debug 'Response: ' + xmpp_response
render :xml => xmpp_response
rescue XMPP::HTTPBind::RHBNotFoundException => bre
logger.debug bre.inspect
render_text '', '404 - Not Found'
rescue XMPP::HTTPBind::RHBForbiddenException => bre
logger.debug bre.inspect
render_text '', '403 - Forbidden'
rescue Exception => e
logger.debug e.inspect + "\n" + e.backtrace.join("\n")
render_text '', '400 - Bad Request'
end
end
end
This version correctly implements polling behaviour. If you want to force the client to poll you should set REQUESTS to 0 in xmpphttpbind.rb.
xmpphttpbind uses the xmpp4r gem which is available on rubyforge. This is the command I used
to install it:
Because of the way that XEP-0124 works you will have to make sure that your Ruby web server
can handle more than one simultaneous connection. I use Apache+FastCGI+Rails on my production
server and Apache+SCGI+Rails on my development server. I got bit by this on my
development server. I had to edit
gem install xmpp4r http://rubyforge.org/frs/download.php/14264/xmpp4r-0.3.gem
config/scgi.yaml to include a :maxconns: line, specifically:
:maxconns: 8
The HTTP Jabber client I use is JWChat. You should install
this on the same web site as xmpphttpbind. I put it in public/jwchat. If you're using
Apache+Rails remember to edit your .htaccess file to serve jwchat up directly rather then send
requests for http://yoursite/jwchat to Rails. You also need to edit the jwchat/config.js file
to tell it where the client should send its HTTP requests - i.e. to the controller above.
There is an example config.js file in subversion too.