1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
------------------------------------------------------------------------------
-- Ada Web Server --
-- --
-- Copyright (C) 2004 --
-- ACT-Europe --
-- --
-- This library is free software; you can redistribute it and/or modify --
-- it under the terms of the GNU General Public License as published by --
-- the Free Software Foundation; either version 2 of the License, or (at --
-- your option) any later version. --
-- --
-- This library is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public License --
-- along with this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
-- --
------------------------------------------------------------------------------
-- ~ MAIN [STD]
-- Test hotplug feature
with Ada.Exceptions;
with Ada.Text_IO;
with AWS.Client.Hotplug;
with AWS.Messages;
with AWS.Response;
with AWS.Server.Hotplug;
with AWS.Utils;
with Hotplug_Pack;
with Get_Free_Port;
procedure Test_Hotplug is
use Ada;
use AWS;
Filter : constant String := "/H.*";
task Hotplug_Server is
entry Start;
entry Started;
entry Stop;
end Hotplug_Server;
procedure Request (URI : in String);
-- Request URI resource to main server, output result
Hotplug_Port : Natural := 1235;
Main_Port : Natural := 8236;
Com_Port : Natural := 2222;
--------------------
-- Hotplug_Server --
--------------------
task body Hotplug_Server is
use type Messages.Status_Code;
WS : Server.HTTP;
R : Response.Data;
begin
accept Start;
Server.Start
(WS, "Hotplug",
Admin_URI => "/Admin-Page",
Port => Hotplug_Port,
Max_Connection => 3,
Callback => Hotplug_Pack.Hotplug'Access);
R := Client.Hotplug.Register
("hp_test", Hotplug_Pack.Password,
"http://localhost:" & Utils.Image (Com_Port),
Filter, "http://localhost:" & Utils.Image (Hotplug_Port));
if Response.Status_Code (R) = Messages.S200 then
Text_IO.Put_Line ("Register OK");
else
Text_IO.Put_Line
("Register Error : " & Response.Message_Body (R));
raise Constraint_Error;
end if;
accept Started;
accept Stop do
R := AWS.Client.Hotplug.Unregister
("hp_test", Hotplug_Pack.Password,
"http://localhost:" & Utils.Image (Com_Port), Filter);
if Response.Status_Code (R) = Messages.S200 then
Text_IO.Put_Line ("Unregister OK");
else
Text_IO.Put_Line
("Unregister Error : " & Response.Message_Body (R));
end if;
Server.Shutdown (WS);
end Stop;
exception
when E : others =>
Text_IO.Put_Line
("Hotplug task " & Ada.Exceptions.Exception_Information (E));
Server.Shutdown (WS);
end Hotplug_Server;
-------------
-- Request --
-------------
procedure Request (URI : in String) is
R : Response.Data;
begin
R := Client.Get
("http://localhost:" & Utils.Image (Main_Port) & "/" & URI);
Text_IO.Put_Line ("Response: " & Response.Message_Body (R));
end Request;
begin
Text_IO.Put_Line ("Starting main server...");
Get_Free_Port (Hotplug_Port);
Get_Free_Port (Main_Port);
Get_Free_Port (Com_Port);
-- Write access file
declare
F : Text_IO.File_Type;
begin
Text_IO.Create (F, Text_IO.Out_File, "hotplug_access.ini");
Text_IO.Put_Line
(F, "hp_test:5c7d7628067d4336484330968b6a7d01:localhost:"
& Utils.Image (Hotplug_Port));
Text_IO.Close (F);
end;
Server.Start
(Hotplug_Pack.Main_Server, "Main",
Admin_URI => "/Admin-Page",
Port => Main_Port,
Max_Connection => 3,
Callback => Hotplug_Pack.Main'Access);
Server.Hotplug.Activate
(Hotplug_Pack.Main_Server'Access, Com_Port, "hotplug_access.ini");
-- Send some requests
Request ("MkHuoi");
Request ("toto");
Request ("Hotplug");
-- Start hotplug now
Hotplug_Server.Start;
Hotplug_Server.Started;
Request ("MkHuoi");
Request ("toto");
Request ("Hotplug");
Text_IO.Put_Line ("Stop hotplug server");
Hotplug_Server.Stop;
Text_IO.Put_Line ("Shutdown hotplug server support");
AWS.Server.Hotplug.Shutdown;
Text_IO.Put_Line ("Shutdown main server");
Server.Shutdown (Hotplug_Pack.Main_Server);
exception
when E : others =>
Text_IO.Put_Line
("Main task " & Ada.Exceptions.Exception_Information (E));
AWS.Server.Hotplug.Shutdown;
Server.Shutdown (Hotplug_Pack.Main_Server);
end Test_Hotplug;
|