.. _High_level_services: .. highlight:: ada ******************* High level services ******************* Here you will find a description of high level services. These services are ready to use with AWS and can be used together with user's callbacks. Refer to the Ada spec for a complete API and usage description. .. _Directory_browser: Directory browser ================= .. index:: Directory browser This service will help building a Web directory browser. It has a lot of options to sort directory entries and is based on the templates interface :ref:`AWS.Templates`. This means that you can use the default directory template or provide your own. see :ref:`AWS.Services.Directory` for the complete specification and description of this service. .. _Dispatchers: Dispatchers =========== .. index:: Dispatchers In many AWS applications it is necessary to process the URI to give the right answer. This means that part of the application is a big **if/elsif** procedure. Also, in the standard callback it is not possible to have user data. Both of these restrictions are addressed with the Dispatcher facilities. Working with a dispatcher is quite easy: * Create a new dispatcher by inheriting from the service you want to build. * Register a set of action based on rules (strings or regular expressions depending on the service) .. _Callback_dispatcher: Callback dispatcher ------------------- .. index:: Dispatchers callback .. index:: Callback, dispatcher This is a wrapper around the standard callback procedure. It is needed to mix dispatcher based callback and access to procedure callback. Note that it is not in the `AWS.Services.Dispatchers` hierarchy but instead in `AWS.Dispatchers.Callback` because this is a basic service needed for the server itself. It is referenced here for documentation purposes but an AWS server can be built without using it. see :ref:`AWS.Dispatchers.Callback` for the complete specification. .. _Method_dispatcher: Method dispatcher ----------------- .. index:: Dispatchers method .. index:: method, dispatcher This is a dispatcher based on the request method. A different callback procedure can be registered for the supported request methods: GET, POST, PUT, HEAD. see :ref:`AWS.Services.Dispatchers.Method` for the complete specification. .. _URI_dispatcher: URI dispatcher -------------- .. index:: Dispatchers URI .. index:: URI, dispatcher This is a dispatcher based on the request resource. A different callback procedure can be registered for specific resources. The resource is described either by its full name (string) or a regular expression. see :ref:`AWS.Services.Dispatchers.URI` for the complete specification. .. _Virtual_host_dispatcher: Virtual host dispatcher ----------------------- .. index:: Dispatchers virtual host .. index:: virtual host, dispatcher This is a dispatcher based on the hostname. A different callback procedure can be registered for specific hostnames. This enables support for virtual hosting. The same computer can be registered into the DNS with different names. So all names point to the same machine. But in fact you want each name to be seen as a different Web server. This is called virtual hosting. This service will just do that, call different **callback** procedures or redirect to some **machine/port** based on the hostname in the client's request. see :ref:`AWS.Services.Dispatchers.Virtual_Host` for the complete specification. .. _Transient_pages_dispatcher: Transient pages dispatcher -------------------------- .. index:: Dispatchers Transient pages .. index:: transient pages, dispatcher This is a dispatcher that calls a user's callback and if the resource requested is not found (i.e. the user's callback returns status code 404) it checks if this resource is known as a transient page. see :ref:`Transient_Pages`. .. _Timer_dispatcher: Timer dispatcher ---------------- .. index:: Dispatchers Timer .. index:: timer, dispatcher A timer dispatcher can be used to call different callback routines depending on the current date and time. Such a dispatcher is composed of a set of activation `Period`s . When the current date and time is inside a `Period` the corresponding callback is called. A `Period` can eventually be repeated. Here are the different kinds of `Period`s supported by `AWS`: *Once* A unique period in time. The boundaries are fully described using a year, month, day, hour, minute and second. *Yearly* A period that repeats each year. The boundaries are described using a month, day, hour, minute and second. *Monthly* A period that repeats each month. The boundaries are described using a day, hour, minute and second. *Weekly* A period that repeats each week. The boundaries are described using a day name, hour, minute and second. *Daily* A period that repeats each day. The boundaries are described using an hour, minute and second. *Hourly* A period that repeats each hour. The boundaries are described using a minute and second. *Minutely* A period that repeats each minute. The boundaries are described using a second. .. _Linker_dispatcher: Linker dispatcher ----------------- .. index:: Dispatchers Linker .. index:: linker, dispatcher A dispatcher that can be used to chain two dispatchers. The response of the first dispatcher is returned except if it is a 404 (Not Found) error. In this case, the response of the second dispatcher is returned. .. _SOAP_dispatcher: SOAP dispatcher --------------- .. index:: Dispatchers SOAP .. index:: SOAP, dispatcher `AWS` also provides a `SOAP` specific dispatcher. This is a way to automatically route HTTP requests or `SOAP` requests to different callback routines. see :ref:`SOAP_helpers` for more information. see :ref:`SOAP.Dispatchers.Callback` for the complete specification. .. _Static_Page_server: Static Page server ================== .. index:: Static Page server .. index:: Simple Page server .. index:: Page server This service is a ready to use static page server callback. It is possible to use this service to build a simple static page server; this is as simple as:: with AWS.Server; with AWS.Services.Page_Server; procedure WPS is WS : AWS.Server.HTTP; begin AWS.Server.Start (WS, "Simple Page Server demo", Port => 8080, Callback => AWS.Services.Page_Server.Callback'Access, Max_Connection => 5); AWS.Server.Wait (AWS.Server.Q_Key_Pressed); AWS.Server.Shutdown (WS); end WPS; Build this program and execute it to serve `HTML` pages and images in the current directory. It is possible to activate the directory browsing facility of this simple page server. This is not activated by default. This feature is based on the directory browsing service see :ref:`Directory_browser`. Note that this service uses two template files: *aws_directory.thtml* The template page used for directory browsing. See see :ref:`AWS.Services.Directory` for a full description of this template usage. *404.thtml* The Web page returned if the requested page is not found. This is a template with a single tag variable named PAGE. It will be replaced by the ressource which was not found. Note that on Microsoft IE this page will be displayed only if the total page size is bigger than 512 bytes or it includes at least one image. see :ref:`AWS.Services.Page_Server` for the complete specification. .. _Transient_Pages: Transient Pages =============== .. index:: transient pages .. index:: pages, transient A transient page is a resource that has a certain life time on the server. After this time the resource will be released and will not be accessible anymore. Sometimes you want to reference, in a Web page, a resource that is built in memory by the server. This resource may or may not be requested by the client (by clicking on the corresponding link), in either case the page must be released after a certain amount of time to free the associated memory. This is exactly what the transient pages high level service does automatically. Each transient page must be registered into the service, then a specific routine named `Get_URI` can be used to create a unique `URI` on this server. see :ref:`AWS.Services.Transient_Pages`. A transient pages dispatcher can be used to build a server supporting transient pages. see :ref:`Transient_pages_dispatcher`. .. _Split_pages: Split pages =========== .. index:: split pages .. index:: pages, split It not not very convenient to send back a Web page with a large table. In such a case it is better to split the table into chunks (20 lines or so) and to send only the first page. This first page reference the next pages and can also contain an index of all the pages. The `AWS`'s split page feature can automatically do this for you. Given template `Translate_Table` or `Translate_Set` and the max line per page it returns the first page and creates a set of transient pages for all other pages. A set of template tags are used to reference the previous and next page and also to build the page index. There are different ways to split a set of pages and ready-to-use splitters are available: *Alpha* Split into (at most) 28 pages, one for empty fields, one for all fields that start with a digit, and one for each different initial letter. see :ref:`AWS.Services.Split_Pages.Alpha`. *Alpha.Bounded* Same as the alpha splitter, but pages larger than a Max_Per_Page value are further split. A secondary index is generated that gives the various pages for a given letter. see :ref:`AWS.Services.Split_Pages.Alpha.Bounded`. *Uniform* Split into pages of length Max_Per_Page (except the last one). This corresponds to the default service in the Split_Pages package. see :ref:`AWS.Services.Split_Pages.Uniform`. *Uniform.Alpha* Same as the uniform splitter, but additionally builds an alphabetical secondary index from a key field. see :ref:`AWS.Services.Split_Pages.Uniform.Alpha`. *Uniform.Overlapping* Same as the uniform splitter, but pages (except the first one) repeat Overlap lines from the previous page in addition to the Max_Per_Page lines. see :ref:`AWS.Services.Split_Pages.Uniform.Overlapping`. Using the spliter abstract interface it is possible to build a customized splitter algorithm. see :ref:`AWS.Services.Split_Pages`. .. _Download_Manager: Download Manager ================ .. index:: Download Manager A server that needs to handle lot of large downloads can run out of connections to answer the standard Web pages. One solution is to increase the number of simultaneous connections, but this is not really efficient as a task is created for each connection and does not ensure that all the connections will be used for the downloads anyway. The download manager can be used for that, and provides the following feature: * use a single task for all downloads * can be configured to limit the number of simultaneous connections * downloads past this limit are queued * send messages to the client with the position in the waiting line * send messages to the client when the download is about to start The server must be configured to use dispatchers (standard callbacks are not supported, note that it is possible to create a dispatcher for standard callbacks. see :ref:`AWS.Dispatchers.Callback`). To start the download manager you need to pass the main server dispatcher object. The start routine will return a new dispatcher, linked with the download server specific dispatcher, that must be used to start the standard Web server. See the comments in see :ref:`AWS.Services.Download`. To queue a download request in the download manager you just need to create a stream object (can be any kind of stream, see `AWS.Resources.Streams.*`) for the resource to download. The download manager needs two templates files: *aws_download_manager_waiting.thtml* This template is used for sending a message to the client when the request is on the waiting line. The tags defined in this template file are: *NAME* the name of the resource to download (the filename), this is the default filename used for the client side save dialog. *RES_URI* the URI used to access the resource. *POSITION* the position in the waiting line (not counting the clients being currently served). *aws_download_manager_start.thtml* This template is used for sending a message to the client when the download is about to start (the request is out of the waiting line). The tags defined in this template file are: *NAME* as above *RES_URI* as above .. highlight:: xml It is important to note that those templates must be reloaded periodically. The best way to do that in the context of an `HTML` document is to use a meta-tag. For example to refresh the page every two seconds:: The templates could look like: *aws_download_manager_waiting.thtml* :: Download Manager - waiting

Waiting for downloading @_NAME_@

Position in the waiting line @_POSITION_@ *aws_download_manager_start.thtml* :: Download Manager - waiting

Waiting for downloading @_NAME_@

The download will start in a moment .. _Web_Elements: Web Elements ============ .. index:: Web Elements `AWS` provides some components to help in creating nice looking Web interfaces. It is possible to browse these Web Elements using the `web_elements` demo. Just launch this Web application from the demos directory and turn your Web browser to `http://localhost:2400 `_. Currently `AWS` provides: * Notebooks (based on CSS) * CSS Menu * Rounded boxes * Ajax All of them are based on templates that can be easily reused in other applications. The first three are best described by the Web Elements demos as they are 100% design. The `Ajax` one is a bit more complex, we will present its use in the following section. .. _Installation: Installation ------------ .. index:: we_icons .. index:: we_js To ease integration we have used the following design: * Sub-directories found in the `AWS`'s web_elements directory are self contained. The content must be copied into the project. Note that the icons and javascripts directories contain the icons and javascripts code shared by all web elements and must also be copied, see below. * Each graphic elements (icons) is referenced in the templates with the alias `/we_icons/`. So users must provide the right alias ("`/we_icons/`") in the Web server. * Each JavaScripts code is referenced in the templates with the alias `/we_js/