|
| 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 | +-- SOAP/WSDL test |
| 20 | + |
| 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 | + |
| 31 | +with SOAP.Types; |
| 32 | +with SOAP.Utils; |
| 33 | + |
| 34 | +with R_Hello_Demo.Client; |
| 35 | +with R_Hello_Demo.Server; |
| 36 | +with R_Hello_Demo.Types; |
| 37 | + |
| 38 | +procedure WSDL_H2Hello is |
| 39 | + |
| 40 | + use Ada.Strings.Unbounded; |
| 41 | + use AWS; |
| 42 | + use R_Hello_Demo.Types; |
| 43 | + |
| 44 | + H_Server : Server.HTTP; |
| 45 | + CNF : Config.Object; |
| 46 | + |
| 47 | + procedure WSDL_Demo_Client is |
| 48 | + use Ada; |
| 49 | + R : Sayhello_Result; |
| 50 | + begin |
| 51 | + R := R_Hello_Demo.Client.sayHello (Firstname => "AWS"); |
| 52 | + Text_IO.Put_Line |
| 53 | + (To_String (R.Message) & SOAP.Types.Short'Image (R.Token)); |
| 54 | + end WSDL_Demo_Client; |
| 55 | + |
| 56 | + function sayHello (Firstname : String) return Sayhello_Result; |
| 57 | + |
| 58 | + ------------- |
| 59 | + -- SOAP_CB -- |
| 60 | + ------------- |
| 61 | + |
| 62 | + function SOAP_CB is new R_Hello_Demo.Server.sayHello_CB (sayHello); |
| 63 | + |
| 64 | + function SOAP_Wrapper is new SOAP.Utils.SOAP_Wrapper (SOAP_CB); |
| 65 | + |
| 66 | + -------- |
| 67 | + -- CB -- |
| 68 | + -------- |
| 69 | + |
| 70 | + function CB (Request : Status.Data) return Response.Data is |
| 71 | + SOAPAction : constant String := Status.SOAPAction (Request); |
| 72 | + begin |
| 73 | + if SOAPAction = "sayHello" then |
| 74 | + return SOAP_Wrapper (Request); |
| 75 | + else |
| 76 | + return Response.Build (MIME.Text_HTML, "<p>Not a SOAP request"); |
| 77 | + end if; |
| 78 | + end CB; |
| 79 | + |
| 80 | + -------------- |
| 81 | + -- sayHello -- |
| 82 | + -------------- |
| 83 | + |
| 84 | + function sayHello (Firstname : String) return Sayhello_Result is |
| 85 | + begin |
| 86 | + return |
| 87 | + (To_Unbounded_String |
| 88 | + ("Hello " & Firstname & " and welcome in H2!"), 12); |
| 89 | + end sayHello; |
| 90 | + |
| 91 | +begin |
| 92 | + Config.Set.Server_Name (CNF, "WSDL Hello demo"); |
| 93 | + Config.Set.Server_Host (CNF, "localhost"); |
| 94 | + Config.Set.Server_Port (CNF, R_Hello_Demo.Server.Port); |
| 95 | + Config.Set.HTTP2_Activated (CNF, True); |
| 96 | + |
| 97 | + Server.Start (H_Server, CB'Unrestricted_Access, CNF); |
| 98 | + |
| 99 | + if Net.IPv6_Available then |
| 100 | + -- Need to start second server on same port but on the different |
| 101 | + -- Protocol_Family because we do not know which family would client try |
| 102 | + -- to connect. |
| 103 | + |
| 104 | + if AWS.Server.Status.Is_IPv6 (H_Server) then |
| 105 | + Server.Add_Listening |
| 106 | + (H_Server, "localhost", R_Hello_Demo.Server.Port, Net.FAMILY_INET); |
| 107 | + else |
| 108 | + Server.Add_Listening |
| 109 | + (H_Server, "localhost", R_Hello_Demo.Server.Port, Net.FAMILY_INET6); |
| 110 | + end if; |
| 111 | + end if; |
| 112 | + |
| 113 | + WSDL_Demo_Client; |
| 114 | + |
| 115 | + Server.Shutdown (H_Server); |
| 116 | +end WSDL_H2Hello; |
0 commit comments