Welcome to my unobtrusive blog!
By default I blog in english but there is also german content.

Ada Webserver AWS Hello World Example on Debian 4.0 Etch and Ubuntu 8.10

December 4th, 2008 Posted in english

Hi, I wanted to experiment with the Ada Webserver called “AWS” and I faced several small problems that prevented me from running even a simple “hello world” example but with the help of the mailing list (archive) I could solve my problems and I want to share it with you.

The easiest way to get AWS up and running is to use Debian or Ubuntu Server and there may be other distributions out there that work fine as well but these two I did my testing on. I just can tell you that the setup under Microsoft Windows is cumbersome. Really, don’t waste too much time with it.

For Debian 4.0 “Etch” and Ubuntu 8.10 install the following packages with apt-get:

  • gnat
  • libaws-dev

I personally prefer Ubuntu 8.10 Server on my local test machine because Ubuntu provides newer versions of both packages. But the install process is the same…

If you are using Ubuntu Server 8.10 this will install the following packages:

binutils, gcc-4.3, gnat, gnat-4.3, gnat-4.3-base, libc6-dev, libgnat-4.3, libgnatprj4.3, libgnatvsn4.3, libgomp1, linux-libc-dev, libasis2007, libaws-bin, libaws-dev, libaws-doc, libaws2.5, libldap2-dev, libtemplates-parser-dev, libtemplates-parser11, libxmlada-dev, libxmlada3, zlib1g-dev

Create the following directories in your home or wherever you want:

  • awstest
    • obj

In the directory “awstest” create the file “default.gpr” with the following content:

with "aws";
 
     project default is
 
        for Main use ("helloworld.adb");
 
        for Source_Dirs use (".");
 
        for Object_Dir use "obj";
 
	package Linker is
  		for Default_Switches ("Ada") use ("-laws");
	end Linker;
 
     end default;

Now in the same directory create the file “hello_world.adb” with the following content:

with AWS.Response;
with AWS.Server;
with AWS.Status;
 
procedure HELLOWORLD is
   WS : AWS.Server.HTTP;
   function HW_CB (Request : in AWS.Status.Data)
                   return AWS.Response.Data
   is
      URI : constant String := AWS.Status.URI (Request);
   begin
      if URI = "/hello" then
         return AWS.Response.Build ("text/html", "<p>Hello world !");
      else
         return AWS.Response.Build ("text/html", "<p>Hum...");
      end if;
   end HW_CB;
begin
   AWS.Server.Start
     (WS, "Hello World", Port => 1234, Callback => HW_CB'Unrestricted_Access);
   delay 60.0;
end HELLOWORLD;

Now compile this app with: “gnatmake -Pdefault.gpr” and you should see something like this:

gnatmake -Pdefault.gpr
aws.gpr:40:35: warning: unknown unit "aws.os_lib"
gcc-4.3 -c -I- -gnatA /home/andreas/awstest/helloworld.adb
gnatbind -shared -I- -x /home/andreas/awstest/obj/helloworld.ali
gnatlink /home/andreas/awstest/obj/helloworld.ali -shared-libgcc -laws -L/usr/lib -laws -L/usr/lib -ltemplates_parser -o /home/andreas/awstest/obj/helloworld

This will give you an executable binary in directory “obj” with the name “helloworld” so let’s try executing it.
-> ./obj/helloworld

You can then access this httpd at “http://localhost:1234″ but hurry, you only got 60 seconds to try it. The normal “/” request will give you “hum…” and the request to “/hello” will give you “Hello World !”.

One last hint: for Debian 4.0 you need the “package linker…” part in your project file because the compiler in debian 4.0 is not aware of “library project files” that “aws.gpr” in “/usr/share/ada/adainclude” is. Thanks to Ludovic Brenta for that piece of information.

However, this was a rather basic example and you may get more ideas while browsing the documentation at https://libre.adacore.com/aws/aws-gpl-2.3.0.html and https://libre.adacore.com/aws/templates_parser-gpl-2.3.0.html.

It’s “finnish” but not the end :P…

follow comments via rss

Post a Comment