matreshka_league_21.0.0_0c8f4d47/examples/servlets/web_sockets/source/servlets-file.adb

 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
with Ada.Wide_Wide_Text_IO;
with Ada.Characters.Wide_Wide_Latin_1;

package body Servlets.File is

   function "+"
     (Text : Wide_Wide_String) return League.Strings.Universal_String
      renames League.Strings.To_Universal_String;

   ----------------------
   -- Get_Servlet_Info --
   ----------------------

   overriding function Get_Servlet_Info
     (Self : File_Servlet) return League.Strings.Universal_String
   is
      pragma Unreferenced (Self);
      Text : constant Wide_Wide_String :=
        "Hello servlet provides WebSocket upgrade responses";
   begin
      return +Text;
   end Get_Servlet_Info;

   ------------
   -- Do_Get --
   ------------

   overriding procedure Do_Get
     (Self     : in out File_Servlet;
      Request  :        Servlet.HTTP_Requests.HTTP_Servlet_Request'Class;
      Response : in out Servlet.HTTP_Responses.HTTP_Servlet_Response'Class)
   is
      Result : League.Strings.Universal_String;
      Input  : Ada.Wide_Wide_Text_IO.File_Type;
   begin
      Ada.Wide_Wide_Text_IO.Open
        (Input, Ada.Wide_Wide_Text_IO.In_File, "install/index.html");
      while not Ada.Wide_Wide_Text_IO.End_Of_File (Input) loop
         Result.Append (Ada.Wide_Wide_Text_IO.Get_Line (Input));
         Result.Append (Ada.Characters.Wide_Wide_Latin_1.LF);
      end loop;
      Ada.Wide_Wide_Text_IO.Close (Input);

      Response.Set_Status (Servlet.HTTP_Responses.OK);
      Response.Set_Content_Type (+"text/html");
      Response.Set_Character_Encoding (+"utf-8");

      Response.Get_Output_Stream.Write (Result);
   end Do_Get;

   -----------------
   -- Instantiate --
   -----------------

   overriding function Instantiate
     (Parameters : not null access Servlet.Generic_Servlets
        .Instantiation_Parameters'
        Class)
      return File_Servlet
   is
      pragma Unreferenced (Parameters);
   begin
      return (Servlet.HTTP_Servlets.HTTP_Servlet with null record);
   end Instantiate;

end Servlets.File;