Setting up Openfire + BOSH + Strophe

The following post explains how to install an XMPP/Jabber server on a linux machine and how to use Strophe.js as the XMPP client. The following applications and packages were used:

  • Ubuntu Server 12.04
  • Apache 2
  • Openfire 3.8.1
  • Strophe 1.0.2

1.- Installing Openfire

Openfire is an IM server that uses XMPP protocol (Ejabberd is another server, but after playing around with both applications I found Openfire easier to setup). As a prerequisite, you must have OpenJDK in you machine. If you don’t have it, you can installed it running the following command:

sudo apt-get install openjdk-7-jre

Once OpenJDK is properly configured. You must download the Openfire and untar it with the following command:

tar -xvzf openfire_3_8_1.tar.gz

Then, move the files to /opt:

mv openfire /opt/

And finally, add a symbolic link for the daemon script to /etc/init.d so that you can start the daemon with a call to service:

ln -s /opt/openfire/bin/openfire /etc/init.d/

Openfire should be installed now. You can start the service with the following command:

service openfire start

If no errors were displayed, open the following URL in your browser:

http://localhost:9090

2.- Configuring Openfire

If everything went OK, you should see the following wizard:

Click ‘Continue’ and configure your domain and ports for administration (You can keep the defaults and use localhost as the domain name).

The next screen will ask you for the database configuration. You can use an external DB, but it is easier to use the built-in option (Embedded database):

User profiles can be stored in the server Database, LDAP or Clearspace. Keep the default option (Default):

Finally, enter the details for the admin account:

Restart the server:

service openfire stop service openfire start

Go back to http://localhost:9090 and you should see a login form (the username is “admin” and the password is the one that you set during the setup wizard).

3.- Testing Openfire

In order to test openfire, you must create a user id. To do this, log in to the administrative console, click Users and Create New User:

Once the user is created, you can test your Openfire server using an XMPP Client (Pidgin, Gajim, etc) and configuring the URL and port of your server. To configure Pidgin, click on  Accounts -> Add and select as protocol: XMPP.  the username is the one that was created in the previous step and the domain is locahost. Then, click on Advanced and make sure that “connection security” is set to “use encryption if available” and port is “5222”. If everything is OK, you should be able to connect:

4.- Configuring BOSH

BOSH stands for Bidirectional-streams Over Synchronous HTTP. Basically, it is used to transport XMPP stanzas over HTTP. So, if you are planning to use your server with an XMPP Web client, you must configure BOSH (or websockets..). In order to enable BOSH in Openfire, log in to the admin console and click on Server->Server Settings->HTTP Binding. Http-Bind should be configured with the following parameters:

 

Save the changes and run a test on Pidgin (Change your account settings: Modify Account -> Advanced. Connect port: 7070, Connect server: localhost).

 

5.- Connecting with Strophe.js

 

Strophe is an XMPP library for Javascript which allows you to connect from a Web browser to an XMPP server. Download the latest version of this library and unzip it in your workspace. This package contains a couple of examples that can be used as reference. In my case, I will use examples/basic.html. If you open it in your browser you should see the following form:

 

Before trying to connect. You must update the file examples/basic.js and change the BOSH URL as follows:

var BOSH_SERVICE = 'http://localhost:7070';

Now reload the page and try to connect using the username/password that was created previously. The following error might be displayed:

This error happens because you are trying to make a cross-domain request.  You could fix it using the crossdomain example found in the same folder or you could tweak your apache server.

6.- Enabling Proxy_Http in Apache 2

In order to fix the previous issue. You must set a proxy to redirect the “http-bind” request. To do that, you need to enable the proxy_http module in apache with the following command:

sudo a2enmod proxy_http

Then, you need to update the rules in your Site’s config file. You can update the “default” file found in /etc/apache2/sites-avaiable/ folder but its better to keep these changes in a separate file. So, create a new file under /etc/apache2/sites-available/ with the name ‘jabberserver’:

sudo nano jabberserver

And add the following rules:

<VirtualHost *:80>

DocumentRoot /var/www/jabber

ServerName jabber.local

#requests sent to /http-bind will be redirected to jabber.local:7070

ProxyPass /http-bind http://jabber.local:7070/http-bind/

ProxyPassReverse /http-bind http://jabber.local:7070/http-bind/

</VirtualHost>

DocumentRoot and ServerName are optional parameters. I decided to use them to have a different name for the XMPP server. If you do the same, remember to update your /etc/hosts file.

Restart your apache server (sudo service apache2 restart). And update the basic.js file one more time:

var BOSH_SERVICE = 'http://localhost/http-bind'

Go back to your browser and if you try to log in again you should see the following message:

Everything went fine this time. If you want to extend the Web client functionality, you might want to take a look at JQuery UI Chat box. or Penguin.


66 responses to “Setting up Openfire + BOSH + Strophe

  • hiren

    when i configure httpbind .. localhost:7070/http-bind there is shown error 404 not found file 😦 can u plz help me

  • hiren prajapati

    i am not use apache server … is there necessary apache server i dont think so

  • hiren prajapati

    for localhost:5222 .. it’s requesting but server cant response ..
    see following scenario

    i download the openfire server and set up the for admin console
    then in server setting :-> httpbind option i see the port number 7070

    then i type http://localhost:7070
    then it will see like
    Openfire HTTP Binding Service

    but when i wrote http://localhost:7070/http-bind or http://localhost:7070/httpbind

    then it will seen like following
    HTTP ERROR: 404
    Problem accessing /http-bind/. Reason:
    Not Found

    I am not used the apache server … i am asp.net devloper ..

    so have any idea sir ?

    • Oscar

      HTTP binding service is working. But you won’t be able to test it from the browser. Try with an IM client like pidgin. About the other issue, why do you want to access localhost:7070/http-bind ? it is not needed, the HTTP protocol is already linked to port 7070 (localhost:7070). If you want to access the service in a different way (like localhost/http-bind), then you need a proxy. I am using Apache for this task, but you should be able to do the same with IIS. This kind of setting is useful if you are planning to access openfire from the client side (because you won’t be allowed to do cross domain request), but if you are planning to access the server from the backend, then localhost:7070 or localhost:5222 should work fine.

      About port 5222 taking too much time, try disabling HTTP binding.

  • hiren prajapati

    hey when i tried with http://localhost:5222/
    server response as
    it take too much time

  • hiren

    hey thanq you it is sucessfully done uo to step 5 .. can you know how to Enabling Proxy_Http in iis server ?

  • hiren prajapati

    hey i got like following sender request and revicer response
    RECV : itz quite differet from your image is it well going ?
    Strophe is connecting.
    SENT:
    RECV: Openfire HTTP Binding Service Openfire HTTP Binding Service

  • hiren prajapati

    hey i got like following sender request and revicer response
    RECV : itz quite differet from your image is it well going ?

    Strophe is connecting.

    “SENT:
    RECV: Openfire HTTP Binding Service Openfire HTTP Binding Service

      • Stefan

        Hi. Great post.
        I got the same problem.

        I get the following response:

        Openfire HTTP Binding Service
        Openfire HTTP Binding Service

        This response is repeating on forever. There is never a login done or anything like in your example. I followed your above approach completely…

        Do you have any suggestions?

      • Oscar

        Did you try it with an IM client? The best way to check that your OF server is working, is trying to connect using an IM client (Pidgin, Gajim, etc). If it does, but the connection is failing when you are trying to connect from a Web page, then you might want to check the browser’s console. Most of the time the error is related to a cross domain request.

  • hiren prajapati

    my simple code for connection …
    there is connection status iz alwayz 1 means connectiong
    not connected status 5 😦
    code iz as following
    function callbackstatus(status) {
    alert(status);
    if (status === Strophe.Status.CONNECTED) {
    alert(‘status connected’);
    }
    }
    function xmppconnection() {
    var conn = new Strophe.Connection(“http://localhost:7070/”);
    var jabberid = document.getElementById(‘txtUsername’).value;
    var passowrd = document.getElementById(‘txtPassword’).value;
    conn.connect(jabberid, passowrd,);

  • hiren prajapati

    my simple code for connection …
    there is connection status iz alwayz 1 means connectiong
    not connected status 5 😦
    code iz as following

    window.onload = function () {
    };

    function callbackstatus(status) {
    alert(status);
    if (status === Strophe.Status.CONNECTED) {
    alert(‘status connected’);
    }
    }
    function xmppconnection() {
    var conn = new Strophe.Connection(“http://localhost:7070/”);
    var jabberid = document.getElementById(‘txtUsername’).value;
    var passowrd = document.getElementById(‘txtPassword’).value;
    conn.connect(jabberid, passowrd, callbackstatus);
    }

    • Oscar

      You wont be able to do it that way. You are not allowed to make requests to a different domain and localhost:7070 falls into this category. Take a look at the browser’s console and you should see the error. That is why the proxy is being used. JS sends the request to locahost/httpbind and the server redirects it to localhost:7070.

  • hiren prajapati

    is it necessary used apache server for proxy … is it happen in visual studio ?

  • hiren

    how to Execute the sudo a2enmod proxy_http commands to enable proxy support in your Apache web server ? where i wrote this command ?

  • hiren prajapati

    hey thanq u from bottom heart , finally it’s working sucessfully 😀

  • Subhan Zaidi

    I did all the steps but in the end i got two errors. There are the errors

    POST http://localhost/http-bind 500 (Server Error) strophe.js:2554
    sendFunc strophe.js:2554
    Strophe.Connection._processRequest strophe.js:2566
    Strophe.Connection._onIdle strophe.js:3572
    POST http://localhost/http-bind 500 (Server Error) strophe.js:2554
    sendFunc strophe.js:2554
    Strophe.Connection._processRequest strophe.js:2566
    Strophe.Connection._throttledRequestHandler strophe.js:2607
    Strophe.Connection._onRequestStateChange.

    Please help me that how can i resolve these issues ?
    Thanks

  • hiren

    BRO AGAIN NEED YOUR HELP , I AM FAILED TO IMPORT MY MS SQL DATABASE IN OPENFIRE SERVER.
    CAN YOU PROVIDE ME EASY INSTALLATION

  • hiren

    stefan which server u used apache or iis server ??
    if you use apache then flush all text in httpd configuaration and paste the following lines
    ———————————————————————
    #
    # This is the main Apache HTTP server configuration file. It contains the
    # configuration directives that give the server its instructions.
    # See for detailed information.
    # In particular, see
    #
    # for a discussion of each configuration directive.
    #
    # Do NOT simply read the instructions in here without understanding
    # what they do. They’re here only as hints or reminders. If you are unsure
    # consult the online docs. You have been warned.
    #
    # Configuration and logfile names: If the filenames you specify for many
    # of the server’s control files begin with “/” (or “drive:/” for Win32), the
    # server will use that explicit path. If the filenames do *not* begin
    # with “/”, the value of ServerRoot is prepended — so “logs/foo.log”
    # with ServerRoot set to “C:/Program Files/Apache Software Foundation/Apache2.2” will be interpreted by the
    # server as “C:/Program Files/Apache Software Foundation/Apache2.2/logs/foo.log”.
    #
    # NOTE: Where filenames are specified, you must use forward slashes
    # instead of backslashes (e.g., “c:/apache” instead of “c:\apache”).
    # If a drive letter is omitted, the drive on which Apache.exe is located
    # will be used by default. It is recommended that you always supply
    # an explicit drive letter in absolute paths to avoid confusion.

    #
    # ServerRoot: The top of the directory tree under which the server’s
    # configuration, error, and log files are kept.
    #
    # Do not add a slash at the end of the directory path. If you point
    # ServerRoot at a non-local disk, be sure to point the LockFile directive
    # at a local disk. If you wish to share the same ServerRoot for multiple
    # httpd daemons, you will need to change at least LockFile and PidFile.
    #
    ServerRoot “c:/wamp/bin/apache/apache2.2.17”

    #
    # Listen: Allows you to bind Apache to specific IP addresses and/or
    # ports, instead of the default. See also the
    # directive.
    #
    # Change this to Listen on specific IP addresses as shown below to
    # prevent Apache from glomming onto all bound IP addresses.
    #
    #Listen 12.34.56.78:80
    Listen 80

    #
    # Dynamic Shared Object (DSO) Support
    #
    # To be able to use the functionality of a module which was built as a DSO you
    # have to place corresponding `LoadModule’ lines at this location so the
    # directives contained in it are actually available _before_ they are used.
    # Statically compiled modules (those listed by `httpd -l’) do not need
    # to be loaded here.
    #
    # Example:
    # LoadModule foo_module modules/mod_foo.so
    #
    LoadModule actions_module modules/mod_actions.so
    LoadModule alias_module modules/mod_alias.so
    LoadModule asis_module modules/mod_asis.so
    LoadModule auth_basic_module modules/mod_auth_basic.so
    #LoadModule auth_digest_module modules/mod_auth_digest.so
    #LoadModule authn_alias_module modules/mod_authn_alias.so
    #LoadModule authn_anon_module modules/mod_authn_anon.so
    #LoadModule authn_dbd_module modules/mod_authn_dbd.so
    #LoadModule authn_dbm_module modules/mod_authn_dbm.so
    LoadModule authn_default_module modules/mod_authn_default.so
    LoadModule authn_file_module modules/mod_authn_file.so
    #LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
    #LoadModule authz_dbm_module modules/mod_authz_dbm.so
    LoadModule authz_default_module modules/mod_authz_default.so
    LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
    LoadModule authz_host_module modules/mod_authz_host.so
    #LoadModule authz_owner_module modules/mod_authz_owner.so
    LoadModule authz_user_module modules/mod_authz_user.so
    LoadModule autoindex_module modules/mod_autoindex.so
    #LoadModule cache_module modules/mod_cache.so
    #LoadModule cern_meta_module modules/mod_cern_meta.so
    LoadModule cgi_module modules/mod_cgi.so
    #LoadModule charset_lite_module modules/mod_charset_lite.so
    #LoadModule dav_module modules/mod_dav.so
    #LoadModule dav_fs_module modules/mod_dav_fs.so
    #LoadModule dav_lock_module modules/mod_dav_lock.so
    #LoadModule dbd_module modules/mod_dbd.so
    #LoadModule deflate_module modules/mod_deflate.so
    LoadModule dir_module modules/mod_dir.so
    #LoadModule disk_cache_module modules/mod_disk_cache.so
    #LoadModule dumpio_module modules/mod_dumpio.so
    LoadModule env_module modules/mod_env.so
    #LoadModule expires_module modules/mod_expires.so
    #LoadModule ext_filter_module modules/mod_ext_filter.so
    #LoadModule file_cache_module modules/mod_file_cache.so
    #LoadModule filter_module modules/mod_filter.so
    #LoadModule headers_module modules/mod_headers.so
    #LoadModule ident_module modules/mod_ident.so
    #LoadModule imagemap_module modules/mod_imagemap.so
    LoadModule include_module modules/mod_include.so
    #LoadModule info_module modules/mod_info.so
    LoadModule isapi_module modules/mod_isapi.so
    #LoadModule ldap_module modules/mod_ldap.so
    #LoadModule logio_module modules/mod_logio.so
    LoadModule log_config_module modules/mod_log_config.so
    #LoadModule log_forensic_module modules/mod_log_forensic.so
    #LoadModule mem_cache_module modules/mod_mem_cache.so
    LoadModule mime_module modules/mod_mime.so
    #LoadModule mime_magic_module modules/mod_mime_magic.so
    LoadModule negotiation_module modules/mod_negotiation.so
    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
    #LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
    #LoadModule proxy_connect_module modules/mod_proxy_connect.so
    #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
    LoadModule proxy_http_module modules/mod_proxy_http.so
    #LoadModule rewrite_module modules/mod_rewrite.so
    LoadModule setenvif_module modules/mod_setenvif.so
    #LoadModule speling_module modules/mod_speling.so
    #LoadModule ssl_module modules/mod_ssl.so
    #LoadModule status_module modules/mod_status.so
    #LoadModule substitute_module modules/mod_substitute.so
    #LoadModule unique_id_module modules/mod_unique_id.so
    #LoadModule userdir_module modules/mod_userdir.so
    #LoadModule usertrack_module modules/mod_usertrack.so
    #LoadModule version_module modules/mod_version.so
    #LoadModule vhost_alias_module modules/mod_vhost_alias.so
    LoadModule php5_module “c:/wamp/bin/php/php5.3.5/php5apache2_2.dll”

    #
    # If you wish httpd to run as a different user or group, you must run
    # httpd as root initially and it will switch.
    #
    # User/Group: The name (or #number) of the user/group to run httpd as.
    # It is usually good practice to create a dedicated user and group for
    # running httpd, as with most system services.
    #
    User daemon
    Group daemon

    # ‘Main’ server configuration
    #
    # The directives in this section set up the values used by the ‘main’
    # server, which responds to any requests that aren’t handled by a
    # definition. These values also provide defaults for
    # any containers you may define later in the file.
    #
    # All of these directives may appear inside containers,
    # in which case these default settings will be overridden for the
    # virtual host being defined.
    #

    #
    # ServerAdmin: Your address, where problems with the server should be
    # e-mailed. This address appears on some server-generated pages, such
    # as error documents. e.g. admin@your-domain.com
    #
    ServerAdmin admin@localhost

    #
    # ServerName gives the name and port that the server uses to identify itself.
    # This can often be determined automatically, but we recommend you specify
    # it explicitly to prevent problems during startup.
    #
    # If your host doesn’t have a registered DNS name, enter its IP address here.
    #
    ServerName localhost:80

    #
    # DocumentRoot: The directory out of which you will serve your
    # documents. By default, all requests are taken from this directory, but
    # symbolic links and aliases may be used to point to other locations.
    #
    DocumentRoot “c:/wamp/www/”

    #
    # Each directory to which Apache has access can be configured with respect
    # to which services and features are allowed and/or disabled in that
    # directory (and its subdirectories).
    #
    # First, we configure the “default” to be a very restrictive set of
    # features.
    #

    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all

    #
    # Note that from this point forward you must specifically allow
    # particular features to be enabled – so if something’s not working as
    # you might expect, make sure that you have specifically enabled it
    # below.
    #

    #
    # This should be changed to whatever you set DocumentRoot to.
    #

    #
    # Possible values for the Options directive are “None”, “All”,
    # or any combination of:
    # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that “MultiViews” must be named *explicitly* — “Options All”
    # doesn’t give it to you.
    #
    # The Options directive is both complicated and important. Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be “All”, “None”, or any combination of the keywords:
    # Options FileInfo AuthConfig Limit
    #
    AllowOverride all

    #
    # Controls who can get stuff from this server.
    #

    # onlineoffline tag – don’t remove
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1

    #
    # DirectoryIndex: sets the file that Apache will serve if a directory
    # is requested.
    #

    DirectoryIndex index.php index.php3 index.html index.htm

    #
    # The following lines prevent .htaccess and .htpasswd files from being
    # viewed by Web clients.
    #

    Order allow,deny
    Deny from all
    Satisfy All

    #
    # ErrorLog: The location of the error log file.
    # If you do not specify an ErrorLog directive within a
    # container, error messages relating to that virtual host will be
    # logged here. If you *do* define an error logfile for a
    # container, that host’s errors will be logged there and not here.
    #
    ErrorLog “c:/wamp/logs/apache_error.log”

    #
    # LogLevel: Control the number of messages logged to the error_log.
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    #
    LogLevel warn

    #
    # The following directives define some format nicknames for use with
    # a CustomLog directive (see below).
    #
    LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”” combined
    LogFormat “%h %l %u %t \”%r\” %>s %b” common

    # You need to enable mod_logio.c to use %I and %O
    LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\” %I %O” combinedio

    #
    # The location and format of the access logfile (Common Logfile Format).
    # If you do not define any access logfiles within a
    # container, they will be logged here. Contrariwise, if you *do*
    # define per- access logfiles, transactions will be
    # logged therein and *not* in this file.
    #
    CustomLog “c:/wamp/logs/access.log” common

    #
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    #CustomLog “logs/access.log” combined

    #
    # Redirect: Allows you to tell clients about documents that used to
    # exist in your server’s namespace, but do not anymore. The client
    # will make a new request for the document at its new location.
    # Example:
    # Redirect permanent /foo http://localhost/bar

    #
    # Alias: Maps web paths into filesystem paths and is used to
    # access content that does not live under the DocumentRoot.
    # Example:
    # Alias /webpath /full/filesystem/path
    #
    # If you include a trailing / on /webpath then the server will
    # require it to be present in the URL. You will also likely
    # need to provide a section to allow access to
    # the filesystem path.

    #
    # ScriptAlias: This controls which directories contain server scripts.
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the target directory are treated as applications and
    # run by the server when requested rather than as documents sent to the
    # client. The same rules about trailing “/” apply to ScriptAlias
    # directives as to Alias.
    #
    ScriptAlias /cgi-bin/ “cgi-bin/”

    #
    # ScriptSock: On threaded servers, designate the path to the UNIX
    # socket used to communicate with the CGI daemon of mod_cgid.
    #
    #Scriptsock logs/cgisock

    #
    # “C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin” should be changed to whatever your ScriptAliased
    # CGI directory exists, if you have that configured.
    #

    AllowOverride None
    Options None
    Order allow,deny
    Allow from all

    #
    # DefaultType: the default MIME type the server will use for a document
    # if it cannot otherwise determine one, such as from filename extensions.
    # If your server contains mostly text or HTML documents, “text/plain” is
    # a good value. If most of your content is binary, such as applications
    # or images, you may want to use “application/octet-stream” instead to
    # keep browsers from trying to display binary files as though they are
    # text.
    #
    DefaultType text/plain

    #
    # TypesConfig points to the file containing the list of mappings from
    # filename extension to MIME-type.
    #
    TypesConfig conf/mime.types

    #
    # AddType allows you to add to or override the MIME configuration
    # file specified in TypesConfig for specific file types.
    #
    #AddType application/x-gzip .tgz
    #
    # AddEncoding allows you to have certain browsers uncompress
    # information on the fly. Note: Not all browsers support this.
    #
    #AddEncoding x-compress .Z
    #AddEncoding x-gzip .gz .tgz
    #
    # If the AddEncoding directives above are commented-out, then you
    # probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php .php3

    #
    # AddHandler allows you to map certain file extensions to “handlers”:
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action directive (see below)
    #
    # To use CGI scripts outside of ScriptAliased directories:
    # (You will also need to add “ExecCGI” to the “Options” directive.)
    #
    #AddHandler cgi-script .cgi

    # For type maps (negotiated resources):
    #AddHandler type-map var

    #
    # Filters allow you to process content before it is sent to the client.
    #
    # To parse .shtml files for server-side includes (SSI):
    # (You will also need to add “Includes” to the “Options” directive.)
    #
    #AddType text/html .shtml
    #AddOutputFilter INCLUDES .shtml

    #
    # The mod_mime_magic module allows the server to use various hints from the
    # contents of the file itself to determine its type. The MIMEMagicFile
    # directive tells the module where the hint definitions are located.
    #
    #MIMEMagicFile conf/magic

    #
    # Customizable error responses come in three flavors:
    # 1) plain text 2) local redirects 3) external redirects
    #
    # Some examples:
    #ErrorDocument 500 “The server made a boo boo.”
    #ErrorDocument 404 /missing.html
    #ErrorDocument 404 “/cgi-bin/missing_handler.pl”
    #ErrorDocument 402 http://localhost/subscription_info.html
    #

    #
    # EnableMMAP and EnableSendfile: On systems that support it,
    # memory-mapping or the sendfile syscall is used to deliver
    # files. This usually improves server performance, but must
    # be turned off when serving from networked-mounted
    # filesystems or if support for these functions is otherwise
    # broken on your system.
    #
    #EnableMMAP off
    #EnableSendfile off

    # Supplemental configuration
    #
    # The configuration files in the conf/extra/ directory can be
    # included to add extra features or to modify the default configuration of
    # the server, or you may simply copy their contents here and change as
    # necessary.

    # Server-pool management (MPM specific)
    #Include conf/extra/httpd-mpm.conf

    # Multi-language error messages
    #Include conf/extra/httpd-multilang-errordoc.conf

    # Fancy directory listings
    Include conf/extra/httpd-autoindex.conf

    # Language settings
    #Include conf/extra/httpd-languages.conf

    # User home directories
    #Include conf/extra/httpd-userdir.conf

    # Real-time info on requests and configuration
    #Include conf/extra/httpd-info.conf

    # Virtual hosts
    #Include conf/extra/httpd-vhosts.conf

    # Local access to the Apache HTTP Server Manual
    #Include conf/extra/httpd-manual.conf

    # Distributed authoring and versioning (WebDAV)
    #Include conf/extra/httpd-dav.conf

    # Various default settings
    #Include conf/extra/httpd-default.conf

    # Secure (SSL/TLS) connections
    #Include conf/extra/httpd-ssl.conf
    #
    # Note: The following must must be present to support
    # starting without SSL on platforms with no /dev/random equivalent
    # but a statically compiled-in mod_ssl.
    #
    ————————-

    SSLRandomSeed startup builtin
    SSLRandomSeed connect builtin

    Include “c:/wamp/alias/*”

    ProxyPass /http-bind http://localhost:7070/http-bind/
    ProxyPassReverse /http-bind http://localhost:7070/http-bind/

  • hiren prajapati

    visit my blog related the xmpp protocol
    http://xmppprotocol.blogspot.in/

  • sulochana

    hi every one good article. using this article i could establish the chat session in windows buy failed in linux.

    in linux box i got below error.

    Strophe is connecting.
    SENT:
    RECV: DIGEST-MD5PLAINANONYMOUSCRAM-MD5zlib
    SENT:
    SENT:
    SENT:

    i am getting first response and second request is failing. what could be wrong in this.

    can you please suggest me.

    • Oscar

      I don’t think that is an error. You might want to try these solutions first:
      http://stackoverflow.com/questions/12020254/how-to-avoid-notices-in-my-page-php

      • sulochana

        thanks for you quick reply . but that(avoid notices) is not my problem. i am getting 500 server error in browser when strophe request for second query.
        POST http://192.238.58.91/http-bind 500 (Server Error) strophe.js:2554
        Strophe.Connection._processRequest.sendFunc strophe.js:2554
        Strophe.Connection._processRequest strophe.js:2566
        Strophe.Connection._throttledRequestHandler strophe.js:2607
        Strophe.Connection._onRequestStateChange strophe.js:2709
        event.returnValue is deprecated. Please use the standard event.preventDefault() instead. jquery.min.js:3
        POST http://192.238.58.91/http-bind 500 (Server Error) strophe.js:2554
        Strophe.Connection._processRequest.sendFunc strophe.js:2554
        Strophe.Connection._processRequest strophe.js:2566
        Strophe.Connection._onIdle strophe.js:3572
        POST http://192.238.58.91/http-bind 500 (Server Error) strophe.js:2554
        Strophe.Connection._processRequest.sendFunc strophe.js:2554
        Strophe.Connection._processRequest strophe.js:2566
        Strophe.Connection._throttledRequestHandler strophe.js:2607
        Strophe.Connection._onRequestStateChange strophe.js:2709

        what could be the problem. there is no error log on httpd side.

        need help me in this.

      • Oscar

        Have you tested your server using a Jabber client (i.e Pidgin, Gajim, etc)? This is just to find out if the error comes from the server or the front-end. Also, did you add the proxy on apache?

  • sulocahna

    i am testing with strophe.js basic example. yes i have added the proxy on apache.
    i have added below line in httpd.conf file
    ProxyRequests Off
    ProxyPass /http-bind http://localhost:7070/http-bind/
    ProxyPassReverse /http-bind http://localhost:7070/http-bind/
    #ProxyPass /http-binds http://localhost:7443/http-bind/
    #ProxyPassReverse /http-binds http://localhost:7443/http-bind/

  • sulocahna

    working now. i restarted the openfire. then started working.:)

  • Hendra

    hi, its a great tutorial, i really appreciate it, because i need this to create my web chat application with openfire and PHP.

    i’ve been following your step, but i got stuck and following error when the last step in inspect element console tab..

    XMLHttpRequest cannot load http://localhost:7070/http-bind. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:90’ is therefore not allowed access.

    i’ve paste “ProxyPass /http-bind http://localhost:7070/http-bind/
    ProxyPassReverse /http-bind http://localhost:7070/http-bind/” below httpd.conf file..

    i’m using xampp, windows 32bit anyway, really appreciate your help.. thanks

  • Hendra

    oh i’ve test it with spark, openfire chat application and work smoothly.. but not on my web development.. 😦

  • Hendra

    ah thank for the fast response.. 🙂

    i’ve try to change basic.js to
    var BOSH_SERVICE = ‘http://localhost:90/http-bind’
    in inspect it show me error : POST http://localhost:90/http-bind 404 (Not Found).

    i think i lost the 6th step, when config the proxy reverse..

    i’m using apache and windows server, the step i’ve done are :

    open comment for
    “LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_http_module modules/mod_proxy_http.so” to httpd.conf file in apache,

    and add the
    “ProxyRequests Off
    ProxyPass /xmpp-httpbind http://127.0.0.1:7070/http-bind/
    ProxyPassReverse /xmpp-httpbind http://127.0.0.1:7070/http-bind/
    in httpd.conf too..

    am i wrong?
    thanks..

  • hiren prajapati

    hey do you know what is requirement for develop cloud telephony application like twilio ?

  • Bradley

    Can you do a post for this but just for real time data? Just say you are using this instead of ajax to poll the server and update the page…

    • Oscar

      Do you mean websockets? If that is the case, you could give it a try to this plugin:
      http://community.igniterealtime.org/blogs/ignite/2011/09/15/websockets-connection-manager-for-openfire

      But keep in mind that Strophe does not support websockets (however there is a plugin for that). You could test the websocket support with openfire’s chat chrome extension:
      http://community.igniterealtime.org/blogs/ignite/2011/09/18/openfire-chat-chrome-extension

      I haven’t tried this approach, but I will give it a shot and post my results.

      • Bradley

        I would like web sockets but I understand that not all browsers support it yet. I meant using bosh-strophe for real time updates not related to chat, but for real time page updates without refreshing the page. For example, how facebook comments and notifications show up after entered by other users.

      • Oscar

        Thats true, butt you might want to consider to support websockets and long polling. Specially if you are only using it for real time updates. Bosh is great when you want to send structured data (like XMPP), but it has some drawbacks like the header info that is sent back and forth.
        There are a couple of projects out there that support websockets and long polling. For example NodeJS & socket.io, but it all depends on what technology you are using on your backend.
        If you want to stick to BOSH, then this book might be useful:
        Professional XMPP Programming with JavaScript and jQuery

        It describes XMPP and provides nice examples like a chat app, collaborative text editor, tic-tac-toe, etc.

  • Puneet

    Great stuff Oscar! I have the Openfire-3.9.1 installed in remote server. I have my web application installed in Tomcat server. I make the BOSH_SERVICE = ‘http://localhost:7070’; and run crossdomain example you mentioned and get the same response for every credentials – right or wrong. The response is different from you mentioned. The response I get is same always:

    trophe is connecting.
    SENT:
    RECV: Openfire HTTP Binding Service Openfire HTTP Binding Service
    SENT:
    RECV: Openfire HTTP Binding Service Openfire HTTP Binding Service
    SENT:
    RECV: Openfire HTTP Binding Service Openfire HTTP Binding Service
    SENT:
    RECV: Openfire HTTP Binding Service Openfire HTTP Binding Service

    • Oscar

      are you getting any error in your browser’s console? Also, test your server using an IM client (like pidigin) to make sure that the error is coming from the backend and not from your JS.

  • Puneet

    and i deploy my client war in Tomcat…How to enable websocket for Tomcat? Thanks in advance!

  • vishal gajera

    i referred your blog this is nicely helped me.
    now i want to establish https:localhost:443/http-bind/

    but eventually i can’t able to achieve this…!!! May be i am novice for this..!!

    can you help me to accomplished it…!!

    Thanking you.

    • Oscar

      If you are using https I am assming that you already configured the certificates, virtual hosts, etc. If that is the case, then maybe you need to configure OpenFire to use SSL (port 7443) and the redirect will be done to that port instead 7070.

      • vishal j gajera

        no i haven’t any idea about any certificate configured & virtual host.
        I just want my connection should be secure i mean as i aware about this somewhat like with help of SSL/TLS connection.
        so that in openfire current user’s session comes like secure with LOCK icon.

        so can you describe all steps which i have to followed from the scratch.

        Thanking you for listen my curios feeling.

      • Oscar

        This walkthough should be helpful

        http://www.vanemery.com/Linux/Apache/apache-SSL.html

        I believe openfire should be working without further changes once your web server is setup as HTTPS.

  • vishal j gajera

    hello every one,
    some days passes obviously my sophisticated requirement increase…

    i am looking for binding Resource using strophe.js because at server side specially i would like to say at open fire when user connects then in session tab it’s looking with online user but it’s resource column i got anonymous name like a42dbb4b,
    but i see when i connect using spark web client at that time it’s named into resource column Spark 2.6.3 .
    so can i also setup my own name in resource column….??? so that specially i can fix my problem i.e. duplicate entity exist at the same time.

    Thanking you for listen me.

  • Steve

    Great post Oscar.

    I am writing a simple chat client (using strophe) which connects to my Openfire server. Strophe works successfully with BOSH, but for some reason cannot connect using websockets.

    I have installed the latest version (websockets-0.0.0.6) of “WebSockets Plugin” plugin for OpenFire, using the default path “ws”. My client url is ws://my-server:7070/ws.

    I get the following error in my browser console: WebSocket connection to ‘ws://localhost:7070/ws’ failed: Error during WebSocket handshake: Unexpected response code: 302

    I look at other related post (stackoverflow.com/questions/22983302/strophe-failed-to-connect-openfire-by-websocket) but have not been successful.

    Has anyone come across this problem before?

    Any help would really be appreciated.

    Thanks in advance.

    • vishal j gajera

      as i worked on it then i just followed some step at server side , i mean server(Openfire) configuration for establish BOSH integration with strophe.js and that is responsible to manage all web socket related task. so nothing to worry about websocket.
      hope you diagnosis your issues with keep in mind with my hint. may be i had establish as per my requirement.
      hope I helped you at some what level thanx.

      • Steve

        thanks for the response Vishal. Did you use your own client to connect to openfire, or did you use sparkweb (or another of the provided plugins)? I can connect when using sparkweb, and spark, however my own client doesnt connect to ws. I noticed that the url that is used spark is different to the one suggested in the openfire websocket plugin.

        e.g. sparkweb uses:
        ws://server-name:7070/ws/server?username=testuser&password=123&resource=sparkweb’

        The plugin states that you should use:
        ws://server-name:7070/ws/

        Thanks

  • Nikul

    Hi!
    Thanks for great tutorial. I am creating web chat module but facing issue of http-bind bad request in my windows 7 pc. I am using WAMP on port 81 and installed latest openfire.
    Can you tell me how can i configure bosh service url like http://localhost:81/http-bind/ or http://localhost:7070/http-bind/
    so that it can work with strophe.js.

    Please help me on this as i am stuck for many days.
    Waiting for your reply.

    Thanks

  • vishal j gajera

    hey steve,
    I used my own client to connect openfire however spark/pidgin and so on. clients also available to used.
    but some how i used my own client for fulfill my own requirement.

    and i used url that is likewise :
    “http://serverAddress:7070/http-bind/”
    i.e. “http://192.168.1.2:7070/http-bind/”;

    so enjoy with your dreams……. for more query always welcome.

  • vishal j gajera

    hey Nikul ,
    I thinks my response to steve is become fruitful to you.
    hope your query solved out by it.
    Thanx.

    • Steve

      Hi Vishal, this hasn’t solved the problem unfortunately. Did you do any further configuration to your apache server to enable websockets? Also, what changes did you make to openfire. I installed the websocket plugin on Openfire (and followed the instruction in the plugin readme). I can get sparkweb (and other clients to work) but they use a completely different url to the one suggested in the plugin. I have left a query about this on openfire forum, but as yet nobody has replied.

      Thanks again for your help,
      Steve

      • vishal j gajera

        hey steve ,
        it’s necessary for you use Apache…!!!!
        May be U sucked on me..!! bt think abt it…!!!

      • vishal j gajera

        just for clarification i remind you that as per my knowledge and RnD that openfire inbuild use JT server.

  • Mark Tetrode

    Saved my day! Thanks for the good documentation

  • vishal gajera

    hello every one
    i hope all is well and great.

    well i am served by some blocker that is related to strophe.js

    let me describe it,

    i am trying achieve re-login functionality, specially in that case when network goes off and again come back in a very few time.

    so that user cannot get bad experience on my webchat.

    i am trying to achieve it by

    connection.attach(JID, SID, RID, callback); method of strophe.js

    but it is almost i achieve but after attached it automaticallity ended my session from server side so that at client side user logged out often when network off.

    please guess what’s wrong i am doing??? or any suggestion i want.

    please kindly report your extreme effort which appreciate me…..!!!

    Thanking you.

  • Minh Lộc (@minhloc_2011mk)

    Hi!
    Thanks for great tut. I’m have test with pidgin to try connect BOSH, however it’s response “Server close the connection”. Also i tried to test on step 5 via browser then im get the errors “XMLHttpRequest cannot load http://localhost:7070/http-bind. The request was redirected to ‘http://localhost:7070/http-bind/’, which is disallowed for cross-origin requests that require preflight.”. I’m installed openfire on windows and using wamp server, so what should i do ?.
    Waiting for your reply.

Leave a reply to hiren prajapati Cancel reply