Servlet API

Matreshka provides server-independent implementation of Servlet API. Web-application based on this module can be executed by Spikedog application server.

See examples of applications.

Initialization of application

When Spikedog loads application it lookups in loaded application's library for special symbol to resolve reference to object of application's initializer tagged type. This type should support Servlet.Container_Initializers.Servlet_Container_Initializer interface. Its On_Startup subprogram will be called after successful loading and initialization of application's dependencies. Application can do additional initialization in this subprogram (connect to database, for example) or create, register and configure listeners/servlets.

To provide this symbol application must instantiate Spikedog.Generic_Application_Initializer to application's initializer tagged type and link it in application's library. When you use GNAT tools you need to add instantiated package to the list of Library_Interfaces attribute of project file.

Here is example of application initializer tagged type:

with Servlet.Container_Initializers;
with Servlet.Contexts;

package Initializers is

   type Server_Initializer is limited
     new Servlet.Container_Initializers.Servlet_Container_Initializer
       with null record;

   overriding procedure On_Startup
    (Self    : in out Server_Initializer;
     Context : in out Servlet.Contexts.Servlet_Context'Class);

end Initializers;

and instantiation of Spikedog.Generic_Application_Initializer package:

with Spikedog.Generic_Application_Initializer;

with Initializers;

package Initializer is
  new Spikedog.Generic_Application_Initializer (Initializers.Server_Initializer);

Building application's library with GNAT

Application must be build as GNAT's standalone library. It is recommended to use project files to do this. Minimal project file will looks like:

with "matreshka/league.gpr";
with "matreshka/servlet.gpr";

library project Application is

   for Library_Name use "MyApplication";
   for Library_Kind use "dynamic";
   for Library_Dir use ".libs";
   for Library_Interface use ("Initializer", "My_Servlets", "My_Filters");

end Application;

It is important to list name of application initializer's instantiation package (if used), and names of all filters' and servlets' packages as library interface. This allows compiler to generate necessary elaboration code.

Prepare package to deploy application

Spikedog expects that all application's files are provided inside some directory. There are few predefined files and subdirectories and more subdirectories can be used by application to store application's resources.

Predefined subdirectories and files are

Path Kind Description
/ directory Root directory of application's resources which is available to clients and served by default servlet
/web.xml file Application deployment descriptor
/WEB-INF directory Root directory of private application's resources
/WEB-INF/lib directory Root directory of application's libraries
/WEB-INF/x86_64-linux directory Directory of application's library for Linux hosted on x86-64 machine
Last modified 2 years ago Last modified on Jan 24, 2015, 8:05:50 AM