Habari Client libraries: on-line chat demo for Delphi launched

Habarisoft now provides an Open Message Queue (OpenMQ) server instance, which allows to run the Delphi Habari Chat example application (included in the demo download for Habari Client for OpenMQ) on-line, without the need for a local OpenMQ or GlassFish application server installation.

To use this OpenMQ message broker for your chat client message exchange, follow these steps:

  1. download, extract and launch the HabariChat executable
  2. in the Connection configuration screen, enter the server broker URL stomp://demo.habarisoft.com

Note: you can also use the URL stomp://habariwebcomponents.de which resolves to the same server. The client library will use the default port when omitted.

Illustrated step-by-step instructions

Step 1: Connection configuration

chat

Step 2: Enter a chat room name

ExampleTopic

Step 3: Enter your nickname

nick

Step 4: Send and receive messages

chatscreenNotes

  • To communicate with other chat users, make sure that all use the same chat room name
  • The chat application opens a STOMP connection on port 7672/TCP to the server, it will not work if your computer is behind a firewall
  • Please note that this demo service might be temporarily off-line, and its network connection speed is slower than with a broker service running in the local network

About Habari Client libraries for Delphi and Free Pascal

With Habari Client libraries, Delphi and Free Pascal developers can take advantage of message broker / message queue technology, which is distributed, loosely coupled, reliable and asynchronous, to build integrated systems, connecting clients using the peer-to-peer or the publish-subscribe communication model.

ScroogeXHTML RTF to (X)HTML converter: server deployment licenses included

28. December 2013 – Starting today, every single developer license of ScroogeXHTML now also includes two (2) server licenses for the deployment of server-side applications.
ScroogeXHTML is a converter library / component for Delphi and Free Pascal, which converts documents in Rich Text Format (RTF) to HTML and XHTML at high speed. Supported document types are: XHTML 1.0 Strict and Transitional, XHTML Basic 1.0, XHTML Mobile Profile 1.0 (a.k.a WAP 2.0), HTML 4.01 Strict and Transitional, and HTML5 (draft). The library is also available for the Java™ platform.

Single Developer License

The ScroogeXHTML Single Developer License allows one developer to create and distribute an unlimited number of single-user applications which use the library in compiled (binary) form.
The Single Developer License includes two (2) Server Licenses to run applications on the server side of client/server systems. For additional server-side installations, ScroogeXHTML Server Licenses are necessary (see below).

Server License

For applications which run on the server side of a client/server system, one ScroogeXHTML Server License is necessary per server.

Home page and demo download:

http://www.habarisoft.com/scroogexhtml_delphi.html

API documentation:
http://www.habarisoft.com/scroogexhtml/6.5/docs/api

“Getting started” documentation:
http://www.habarisoft.com/download/ScroogeXHTMLGettingStarted.pdf

Habari Client libraries – new features in first 2014 release (planned for Q1)

Transaction support for message receipt acknowledgement

Transactional sending of messages was already supported in all versions of Habari Client libraries. Some library versions1 now also support commit and roll back for the acknowledgement of received messages. When a transaction is rolled back or the connection is closed without a commit, messages which have been acknowledged after the transaction start will return to unacknowledged state.

  // receive in a transacted session
  Session := Connection.CreateSession(True, amClientAcknowledge);
  Queue := Session.CreateQueue(GetQueueName);
  Consumer := Session.CreateConsumer(Queue);
  Msg := Consumer.Receive(1000);

  // process the message
  ...

  // acknowledge the message
  Msg.Acknowledge;

  ...

  // in case of critical errors, roll back acknowledgements
  Session.Rollback;

Bug fixes and improvements

Bug fixes and improvements included in the next release (planned for Q1/2014):

  • Authentication with empty credentials (user / passcode) values fails
  • Support for encoded carriage return (“\r”) in STOMP 1.2 headers
  • Support for equal signs and colons in STOMP headers
  • Support for empty STOMP header values
  • Compiler errors with Free Pascal 2.7.1
  • Unit tests for wild-card destinations
  • Unit tests for queue browser

1Tested with Apache ActiveMQ 5.9.0, Apollo 1.6 and RabbitMQ 3.2.3

Habari Client Libraries for Delphi and Free Pascal – new releases

4. December 2013 – New versions of all Habari message broker client libraries are available. The new release of Habari Client libraries is mainly a maintenance release. The new library versions are:

  • Habari Client for ActiveMQ 3.6 (tested with ActiveMQ version 5.9.0)
  • Habari Client for Apollo 1.6 (tested with Apollo version 1.6)
  • Habari Client for HornetQ 2.2 (tested with HornetQ version 2.3.1)
  • Habari Client for OpenMQ 2.6 (tested with OpenMQ version 5.0.1)
  • Habari Client for RabbitMQ 1.8 (tested with RabbitMQ version 3.2.1)

This release fixes several bugs and warnings. For a full list of changes please check the “Getting Started” documentation. More information, demo downloads, example code and the complete API reference are available on-line.

With Habari Client libraries, Delphi and Free Pascal developers can take advantage of message broker technology, which is distributed, loosely coupled, reliable and asynchronous, to build integrated systems, connecting clients using the peer-to-peer or the publish-and-subscribe communication model.

Habari Client Libraries

Habari Web Components 2.6 released

Habari Web Components is a web application framework for small to medium size HTTP services, based on the popular open source TCP/IP library for Delphi and Free Pascal, Internet Direct (Indy).

Changes in 2.6:

DataModule per session
New demo application which shows how a TDataModule instance can be stored in a session
Form based authentication
New example for HTML form based authentication
On-demand sessions
Helper method GetSession moved from class TdjWebComponentContextHandler to class TdjHandlerWrapper to make it more widely available
Statistics handler
Statistics handler demo class uses atomic (thread safe) variables
NCSA logging example
Improved NCSA logging handler example class

Stand-alone demo applications included in demo download: Kitchen sink, Flight Plan (jQuery mobile), Datamodule.

Online demo:  the “Kitchen Sink” online demo on http://www.habariwebcomponents.de/demo/index.html runs on a Ubuntu Linux system and shows many examples, which are also included in the demo download (Linux is not officially supported yet).

Save 40 €: the new price for the Single Developer License includes one year free updates, source code, a non-exclusive life-time license, free redistribution with your product and a 60 day money back guarantee.

Habari Web Components

How to use the RabbitMQ Web-Stomp Plugin with Delphi and Free Pascal

The RabbitMQ open source message broker includes a web-stomp plugin exposing the STOMP protocol over emulated HTML5 WebSockets. Web-Stomp examples are provided as a plugin which is included in the standard distribution and only needs to be enabled (this requires a broker restart).

For users of the Delphi and Free Pascal client library Habari Client for RabbitMQ, the echo demo, which shows how to use STOMP to do simple message broadcasting, had a small problem: while text sent from the Delphi / Free Pascal side correctly appeared in the browser chat window, text entered in the browser did not reach the Delphi / Free Pascal application.

The reason was a missing STOMP header, content-type. The STOMP specification states that in this case “the receiver SHOULD consider the body to be a binary blob”, and so the chat message will not be treated as a text message.

A change is planned in the RabbitMQ side which will cause the content-type:plain/text message frame to be present. Until its release, Delphi and Free Pascal can use a workaround and convert the binary message content to a string, using UTF8Decode or UTF8ToString.

Hint: the Habari Chat demo application can be used to try the web stomp plugin. Simply use ‘test’ as the chat room name.

aifegdbj

Open source message brokers: new releases

Apache ActiveMQ 5.9.0

This release addresses over 200 issues and introduces some significant improvements, for example: new hawtio web console, replicated leveldb message store, Runtime configuration. Read more …

RabbitMQ 3.2.0

This release introduced federated queues and features enhanced policies for aspects of the broker which previously required AMQP arguments. Clients can now obtain better feedback about authentication failures and broker alarm conditions. Read more …

OpenMQ 5.0

GlassFish Open MQ 5.0 is the worlds first JMS 2.0 compliant messaging project. Read more …

HornetQ 2.4.0.Beta1

This includes JMS 2.0, AMQP support and fixes. Read more …

Native Delphi and Free Pascal client libraries available!

The Habari Client library product line by Habarisoft uses the STOMP standard to communicate with message brokers. STOMP provides an interoperable wire format so that STOMP clients can communicate with any STOMP message broker to provide easy and widespread messaging interoperability among many languages, platforms and brokers.

Habari Web Components: TDatamodule per Session

This program for Habari Web Components demonstrates how the internal Indy HTTP server instance can be used to hold custom data objects in memory for the duration of a HTTP session. Update: the code and a compiled application is now included in the demo download.

It also shows how the datamodule instance can be removed automatically when its session ends.

When run, the demo application will display a list of names (populated with some example values) and a HTML form which allows to enter another name and send it to the server.

HTML page

For every client session, the server will create and use a separate instance of the datamodule. You can verify this with different browsers, or with private mode browser windows.

The executable and the project source are available at http://cc.embarcadero.com/Item/28784

The Datamodule class

The Datamodule in this example acts as a container for people names stored in a TStrings object. This people list is accessible as a property with public visibility.

unit DemoDataMod;

  ...

  TDemoDataModule = class(TDataModule)
    procedure DataModuleCreate(Sender: TObject);
    procedure DataModuleDestroy(Sender: TObject);
  private
    FPeople: TStrings;
  public
    property People: TStrings read FPeople;
  end;

TDemoDataModule.DataModuleCreate creates an instance of TStringList, assigns it to the internal FPeople field, and adds some example data.
TDemoDataModule.DataModuleDestroy frees the TStringList instance. (Note that the datamodule has to be destroyed also when its owning session ends, this will be shown in the next section).

procedure TDemoDataModule.DataModuleCreate(Sender: TObject);
begin
  FPeople := TStringlist.Create;

  People.Add('Alice');
  People.Add('Bob');
  People.Add('Homer');
end;

procedure TDemoDataModule.DataModuleDestroy(Sender: TObject);
begin
  People.Free;
end;

The Web Component class

The Web Component interface uses the handlers for HTTP GET and POST requests, to route them to our own “catch-all” handler OnHandleRequest. This handler will process both the initial GET request (when the client navigates to the page) and all POST requests when the client submits the HTML form.

unit DataFormCmp;

  ...

  TDataFormPage = class(TdjWebComponent)
  private
    procedure OnHandleRequest(Request: TIdHTTPRequestInfo;
      Response: TIdHTTPResponseInfo);
  public
    procedure OnGet(Request: TIdHTTPRequestInfo; Response:
      TIdHTTPResponseInfo); override;
    procedure OnPost(Request: TIdHTTPRequestInfo; Response:
      TIdHTTPResponseInfo); override;
  end;

  ...

procedure TDataFormPage.OnGet(Request: TIdHTTPRequestInfo;
  Response: TIdHTTPResponseInfo);
begin
  OnHandleRequest(Request, Response);
end;

procedure TDataFormPage.OnPost(Request: TIdHTTPRequestInfo;
  Response: TIdHTTPResponseInfo);
begin
  OnHandleRequest(Request, Response);
end;

In OnHandleRequest, the datamodule either will be created and stored in the session if it does not exist or it will be retrieved from the session:

procedure TDataFormPage.OnHandleRequest(Request:
  TIdHTTPRequestInfo; Response: TIdHTTPResponseInfo);
const
  KEY = 'datamodule';
var
  Pos: Integer;
  DM: TDemoDataModule;
  Tmp: string;
  S: string;
begin
  Request.Session.Lock;
  try
    Pos := Request.Session.Content.IndexOf(KEY);
    if Pos <> -1 then
    begin
    DM := TDemoDataModule(Request.Session.Content.Objects[Pos]);
    end
    else
    begin
      WriteLn(Format('Create datamodule for session %s',
       [Request.Session.SessionID]));
      DM := TDemoDataModule.Create(nil);
      Request.Session.Content.AddObject(KEY, DM);
    end;
  finally
    Request.Session.Unlock;
  end;

If it is a POST request, the value of the input field will be extracted and added to the people list:

  if Request.CommandType = hcPOST then
  begin
    S := Utf8ToString(RawByteString(
           Request.Params.Values['textfield1']));
    if S <> '' then
    begin
      DM.People.Add(S);
    end;
  end;

We have all that is needed to build the HTML response now:

  • a reference to the datamodule instance which belongs to this session
  • the name which has been POSTed from the client is in the people list

Finally, the OnHandleRequest handler creates the HTML response. The names stored in the people list will be added to the HTML code (followed by the HTML form code, which is not shown here but included in the source code).

  Tmp := '<!DOCTYPE html>'

   ... // add HTML page code ...

  for S in DM.People do
  begin
    Tmp := Tmp + '  <p>' + S + '</p>' + #10;
  end;

  ... // more HTML page code ...

  Response.ContentText := Tmp;
  Response.ContentType := 'text/html';
  Response.CharSet := 'utf-8';

Housekeeping

In a server application, memory leaks would lead to out of memory errors sooner or later. Our code has to free the datamodule instance when the session ends. The Habari Web Component framework is build on top of Indy, so we can use the OnSessionEnd event of the internal TIdHTTPServer instance to do this. In the example project, we custom subclass of TdjHTTPConnector to add a handler for the OnSessionEnd event, and to set the session timeout to a lower value than the default.

program DataModuleDemo;

  ...

  TCleanUpConnector = class(TdjHTTPConnector)
  private
    procedure DoSessionCleanUp(Sender: TIdHTTPSession);
  public
    constructor Create(const Handler: IHandler); override;
  end;

{ TCleanUpConnector }

constructor TCleanUpConnector.Create(const Handler: IHandler);
begin
  inherited;

  HTTPServer.OnSessionEnd := DoSessionCleanUp;

  // 20 sec to demonstrate seesion cleanup
  HTTPServer.SessionTimeOut := 20000;
end;

procedure TCleanUpConnector.DoSessionCleanUp(Sender:
  TIdHTTPSession);
const
  KEY = 'datamodule';
var
  Pos: Integer;
begin
  Pos := Sender.Content.IndexOf(KEY);

  if (Pos <> -1) and Assigned(Sender.Content.Objects[Pos]) then
  begin
    WriteLn(Format('Destroy datamodule for session %s',
      [Sender.SessionID]));
    Sender.Content.Objects[Pos].Free;
  end
end;

Is it 100% thread safe?

Not yet: the People property of the datamodule is not protected against concurrent modificationss by different threads. This can cause problems when the client opens multiple connection to the server in the same session, and two connections read or write the People property.

Putting it all together

This excerpt of the demo project shows how the Web Component and the custom HTTP connector are wired in the Habari Web Components framework.

procedure Demo;
var
  Server: TdjServer;
  Connector: TdjHTTPConnector;
  Context: TdjWebAppContext;
begin
  Server := TdjServer.Create(8080);
  try
    Context := TdjWebAppContext.Create('demo', True);
    Context.Add(TDataFormPage, '/dataform.html');
    Server.Add(Context);

    Connector := TCleanUpConnector.Create(Server.Handler);

    Connector.Host := '127.0.0.1';
    Connector.Port := 8080;

    Server.AddConnector(Connector);

    SetShutdownHook(Server);

    Server.Start;

    // launch default web browser and navigate to dataform.html
    ShellExecute(0, 'open',
      'http://127.0.0.1:8080/demo/dataform.html', '', '', 0);
    WriteLn('Hit any key to terminate.');
    ReadLn;

  finally
    Server.Free;
  end;
end;

Server running

Habari Web Components 2.5 released

Habari Web Components is a web application framework for small to medium size HTTP services, based on the popular open source TCP/IP library for Delphi and Free Pascal, Internet Direct (Indy).

Changes in 2.5:

Free Pascal
Improved support for Free Pascal mixed compiler modes, the -Mdelphi compiler switch is no longer required.
Documentation
Additional documentation for unit tests and UTF-8 usage with Free Pascal, for the TdjStatisticsHandler class, and expected exceptions in unit tests.
Bootstrap
Upgraded example web pages to Bootstrap 3.0, jQuery to 1.10.2 and jQuery mobile to 1.3.2.
NCSA logger
NCSA logger example class can be used on Linux. Milliseconds have been removed from the output to follow the standard.
Demo
Minor fixes and improvements in the demo applications (for details please see the Getting Started documentation).

Stand-alone demo applications included in demo download: Kitchen sink, Flight Plan (jQuery mobile), Captcha.

Online demo:  the “Kitchen Sink” online demo on http://www.habariwebcomponents.de/demo/index.html runs on a Ubuntu Linux system and shows many examples, which are also included in the demo download (note that Linux is not officially supported yet).

Save 40 €: the new price for the Single Developer License includes one year free updates, source code, a non-exclusive life-time license, free redistribution with your product and a 60 day money back guarantee.

Habari Web Components

Habari Client Libraries for Delphi and Free Pascal – new releases

New versions of all Habari message broker client libraries is available. The new release of Habari Client libraries introduces new features, including improved Free Pascal support:

  • New: Remote Procedure Call (RPC) demo program
  • New: Heart-beating tests using built-in STOMP server
  • New: Connection parameter “subscribe.receipt” to request and verify broker confirmations for subscriptions
  • New: Connection pool example implementation with demo project
  • New: Tested with Free Pascal 2.6.2
  • New: Tested with Indy 10.6
  • New: Support for mixed compiler modes with Free Pascal
  • Improved: ESynapseError exceptions will be re-raised from Receive operations

With Habari Client libraries, Delphi and Free Pascal developers can take advantage of message broker technology, which is distributed, loosely coupled, reliable and asynchronous, to build integrated systems, connecting clients using the peer-to-peer or the publish-and-subscribe communication model.

Habari Client libraries provide access to enterprise quality messaging solutions. Supported message brokers include Apache ActiveMQ, Apollo, HornetQ, Open MQ, and RabbitMQ.

Habari Client Libraries