|
| 1 | +------------------------------------------------------------------------------ |
| 2 | +-- Ada Web Server -- |
| 3 | +-- -- |
| 4 | +-- Copyright (C) 2021, AdaCore -- |
| 5 | +-- -- |
| 6 | +-- This is free software; you can redistribute it and/or modify it -- |
| 7 | +-- under terms of the GNU General Public License as published by the -- |
| 8 | +-- Free Software Foundation; either version 3, or (at your option) any -- |
| 9 | +-- later version. This software is distributed in the hope that it will -- |
| 10 | +-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty -- |
| 11 | +-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- |
| 12 | +-- General Public License for more details. -- |
| 13 | +-- -- |
| 14 | +-- You should have received a copy of the GNU General Public License -- |
| 15 | +-- distributed with this software; see file COPYING3. If not, go -- |
| 16 | +-- to http://www.gnu.org/licenses for a complete copy of the license. -- |
| 17 | +------------------------------------------------------------------------------ |
| 18 | + |
| 19 | +with Ada.Calendar; |
| 20 | +with Ada.Integer_Text_IO; |
| 21 | +with Ada.Strings.Unbounded; |
| 22 | +with Ada.Text_IO; |
| 23 | + |
| 24 | +with AWS.Config.Set; |
| 25 | +with AWS.MIME; |
| 26 | +with AWS.Net; |
| 27 | +with AWS.Response; |
| 28 | +with AWS.Server.Status; |
| 29 | +with AWS.Status; |
| 30 | +with AWS.Translator; |
| 31 | +with SOAP.Client; |
| 32 | +with SOAP.Message.Payload; |
| 33 | +with SOAP.Message.Response; |
| 34 | +with SOAP.Message.XML; |
| 35 | + |
| 36 | +with Toptional.Client; |
| 37 | +with Toptional.Server; |
| 38 | +with Toptional.Types; |
| 39 | + |
| 40 | +procedure Optional is |
| 41 | + |
| 42 | + use Ada; |
| 43 | + use Ada.Strings.Unbounded; |
| 44 | + use AWS; |
| 45 | + |
| 46 | + use Toptional.Types; |
| 47 | + |
| 48 | + H_Server : Server.HTTP; |
| 49 | + |
| 50 | + function "+" (Str : String) return Unbounded_String |
| 51 | + renames To_Unbounded_String; |
| 52 | + |
| 53 | + package FIO is new Text_IO.Float_IO (Float); |
| 54 | + |
| 55 | + ------------ |
| 56 | + -- Output -- |
| 57 | + ------------ |
| 58 | + |
| 59 | + procedure Output (S : SOAPStruct_Type) is |
| 60 | + begin |
| 61 | + Integer_Text_IO.Put (S.varInt); Text_IO.New_Line; |
| 62 | + FIO.Put (S.VarFloat, Exp => 0, Aft => 2); Text_IO.New_Line; |
| 63 | + Text_IO.Put_Line (To_String (S.varString)); |
| 64 | + end Output; |
| 65 | + |
| 66 | + --------------------- |
| 67 | + -- T_echoString_CB -- |
| 68 | + --------------------- |
| 69 | + |
| 70 | + function T_echoString_CB (inputString : String) return String is |
| 71 | + begin |
| 72 | + return inputString; |
| 73 | + end T_echoString_CB; |
| 74 | + |
| 75 | + function echoString_CB is |
| 76 | + new Toptional.Server.echoString_CB (T_echoString_CB); |
| 77 | + |
| 78 | + ------------------ |
| 79 | + -- T_echoString -- |
| 80 | + ------------------ |
| 81 | + |
| 82 | + procedure T_echoString is |
| 83 | + Res : constant String := Toptional.Client.echoString |
| 84 | + ("This is the real value for the string!"); |
| 85 | + begin |
| 86 | + Text_IO.Put_Line ("Echo String"); |
| 87 | + |
| 88 | + Text_IO.Put_Line (Res); |
| 89 | + Text_IO.New_Line; |
| 90 | + end T_echoString; |
| 91 | + |
| 92 | + --------------------- |
| 93 | + -- T_echoStruct_CB -- |
| 94 | + --------------------- |
| 95 | + |
| 96 | + function T_echoStruct_CB |
| 97 | + (inputStruct : SOAPStruct_Type) |
| 98 | + return echoStruct_Result is |
| 99 | + begin |
| 100 | + return inputStruct; |
| 101 | + end T_echoStruct_CB; |
| 102 | + |
| 103 | + function echoStruct_CB is |
| 104 | + new Toptional.Server.echoStruct_CB (T_echoStruct_CB); |
| 105 | + |
| 106 | + ------------------ |
| 107 | + -- T_echoStruct -- |
| 108 | + ------------------ |
| 109 | + |
| 110 | + procedure T_echoStruct is |
| 111 | + Struct : constant SOAPStruct_Type := (6, 6.6, +"666"); |
| 112 | + Res : constant echoStruct_Result := |
| 113 | + Toptional.Client.echoStruct (Struct); |
| 114 | + begin |
| 115 | + Text_IO.Put_Line ("Echo Struct"); |
| 116 | + Output (Res); |
| 117 | + Text_IO.New_Line; |
| 118 | + end T_echoStruct; |
| 119 | + |
| 120 | + -------- |
| 121 | + -- CB -- |
| 122 | + -------- |
| 123 | + |
| 124 | + function CB (Request : Status.Data) return Response.Data is |
| 125 | + SOAPAction : constant String := Status.SOAPAction (Request); |
| 126 | + P_Str : aliased constant String := AWS.Status.Payload (Request); |
| 127 | + Payload : constant SOAP.Message.Payload.Object := |
| 128 | + SOAP.Message.XML.Load_Payload |
| 129 | + (P_Str, Schema => Toptional.Schema); |
| 130 | + Proc : constant String := |
| 131 | + SOAP.Message.Payload.Procedure_Name (Payload); |
| 132 | + begin |
| 133 | + Text_IO.Put_Line ("@ " & Proc); |
| 134 | + |
| 135 | + if Proc = "echoString" then |
| 136 | + return echoString_CB (SOAPAction, Payload, Request); |
| 137 | + |
| 138 | + elsif Proc = "echoStruct" then |
| 139 | + return echoStruct_CB (SOAPAction, Payload, Request); |
| 140 | + |
| 141 | + else |
| 142 | + return Response.Build |
| 143 | + (MIME.Text_HTML, "Not a SOAP request, Proc=" & Proc); |
| 144 | + end if; |
| 145 | + end CB; |
| 146 | + |
| 147 | + CNF : Config.Object := Config.Get_Current; |
| 148 | + |
| 149 | +begin |
| 150 | + Config.Set.Server_Name (CNF, "WSDL Optional Server"); |
| 151 | + Config.Set.Server_Host (CNF, "localhost"); |
| 152 | + Config.Set.Server_Port (CNF, Toptional.Server.Port); |
| 153 | + Config.Set.Protocol_Family (CNF, "FAMILY_INET"); |
| 154 | + |
| 155 | + Server.Start (H_Server, CB'Unrestricted_Access, CNF); |
| 156 | + |
| 157 | + if Net.IPv6_Available then |
| 158 | + Server.Add_Listening |
| 159 | + (H_Server, "localhost", Toptional.Server.Port, Net.FAMILY_INET6); |
| 160 | + end if; |
| 161 | + |
| 162 | + T_echoString; |
| 163 | + T_echoStruct; |
| 164 | + |
| 165 | + -- Now check struct with a xsi:nil (optional value) |
| 166 | + |
| 167 | + declare |
| 168 | + N : constant String := String'(1 => ASCII.CR) & ASCII.LF; |
| 169 | + Mes : aliased constant String := |
| 170 | + "<?xml version='1.0' encoding='UTF-8'?>" & N |
| 171 | + & "<soapenv:Envelope soapenv:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:soap-enc=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">" & N |
| 172 | + & "<soapenv:Body>" & N |
| 173 | + & "<ns2:echoStruct xmlns:ns2=""http://nsoptional.org/""" |
| 174 | + & " xmlns:ns1=""http://nsoptional.org/xsd"">" & N |
| 175 | + & "<ns1:inputStruct xsi:type=""ns1:SOAPStruct"">" |
| 176 | + & "<ns1:varInt xsi:type=""xsd:int"">7</ns1:varInt>" |
| 177 | + & "<ns1:varFloat xsi:type=""xsd:float"">7.0</ns1:varFloat>" |
| 178 | + & "<ns1:varString xsi:type=""xsd:string"" xsi:nil=""true""/>" |
| 179 | + & "</ns1:inputStruct>" |
| 180 | + & "</ns2:echoStruct>" & N |
| 181 | + & "</soapenv:Body>" & N |
| 182 | + & "</soapenv:Envelope>"; |
| 183 | + Pl : constant SOAP.Message.Payload.Object := |
| 184 | + SOAP.Message.XML.Load_Payload (Mes); |
| 185 | + R : constant SOAP.Message.Response.Object'Class := |
| 186 | + SOAP.Client.Call |
| 187 | + (URL => AWS.Server.Status.Local_URL (H_Server), |
| 188 | + P => Pl, |
| 189 | + SOAPAction => "http://nsoptional.org/"); |
| 190 | + begin |
| 191 | + Text_IO.Put_Line (SOAP.Message.XML.Image (Pl)); |
| 192 | + Text_IO.Put_Line (SOAP.Message.XML.Image (R)); |
| 193 | + end; |
| 194 | + |
| 195 | + Server.Shutdown (H_Server); |
| 196 | +end Optional; |
0 commit comments