Skip to content

Commit 32745b0

Browse files
committed
Add support for optional values from server's SOAP messages.
When AWS receives a SOAP message with a component xsi:nil="true" a xsd:null object was created but the deserialization was raising an exception as not founding the proper SOAP type. This has been fixed by returning a default value (0, 0.0, False or empty string) for the corresponding Ada variable/record. Add a corresponding regression test. For U122-023.
1 parent 85e92cf commit 32745b0

File tree

11 files changed

+453
-33
lines changed

11 files changed

+453
-33
lines changed

regtests/0103_soapcheck/test.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Parameter error in Call (R.V expected SOAP.Types.XSD_Integer, found SOAP.TYPES.XSD_STRING)
1+
Parameter error in Call (Integer expected, found SOAP.TYPES.XSD_STRING)
22
Parameter error in Print (Integer expected, found SOAP.TYPES.XSD_STRING)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
reuse_address true
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
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;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 "aws";
20+
21+
project Optional is
22+
for Source_Dirs use (".");
23+
for Main use ("optional.adb");
24+
end Optional;
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<definitions name="toptional"
3+
xmlns="http://schemas.xmlsoap.org/wsdl/"
4+
xmlns:w="http://schemas.xmlsoap.org/wsdl/"
5+
xmlns:ns1="http://nsoptional.org/xsd"
6+
xmlns:ns2="http://nsoptional.org/"
7+
xmlns:tns="http://tempuri.org/4s4c/1/3/wsdl/def/interopLab"
8+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
9+
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
10+
xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/"
11+
targetNamespace="http://tempuri.org/4s4c/1/3/wsdl/def/interopLab">
12+
13+
<types>
14+
<schema xmlns="http://www.w3.org/2001/XMLSchema"
15+
targetNamespace="http://nsoptional.org/xsd">
16+
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
17+
<complexType name="SOAPStruct">
18+
<all>
19+
<element name="varInt" type="int"/>
20+
<element name="varFloat" type="float"/>
21+
<element name="varString" type="string"/>
22+
</all>
23+
</complexType>
24+
</schema>
25+
</types>
26+
27+
<message name="echoStringRequest">
28+
<part name="inputString" type="xsd:string"/>
29+
</message>
30+
<message name="echoStringResponse">
31+
<part name="outputString" type="xsd:string"/>
32+
</message>
33+
34+
<message name="echoStructRequest">
35+
<part name="inputStruct" type="ns1:SOAPStruct"/>
36+
</message>
37+
<message name="echoStructResponse">
38+
<part name="outputStruct" type="ns1:SOAPStruct"/>
39+
</message>
40+
41+
<portType name="interopTestPortType">
42+
<operation name="echoString">
43+
<input message="tns:echoStringRequest"/>
44+
<output message="tns:echoStringResponse"/>
45+
</operation>
46+
47+
<operation name="echoStruct">
48+
<input message="tns:echoStructRequest"/>
49+
<output message="tns:echoStructResponse"/>
50+
</operation>
51+
</portType>
52+
53+
<binding name="interopTestBinding" type="tns:interopTestPortType">
54+
<soap:binding style="rpc"
55+
transport="http://schemas.xmlsoap.org/soap/http"/>
56+
<operation name="echoString">
57+
<soap:operation soapAction="http://nsoptional.org/#echoString"/>
58+
<input>
59+
<soap:body use="encoded"
60+
namespace="http://nsoptional.org/"
61+
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
62+
</input>
63+
<output>
64+
<soap:body use="encoded"
65+
namespace="http://nsoptional.org/"
66+
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
67+
</output>
68+
</operation>
69+
70+
<operation name="echoStruct">
71+
<soap:operation soapAction="http://nsoptional.org/"/>
72+
<input>
73+
<soap:body use="encoded"
74+
namespace="http://nsoptional.org/"
75+
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
76+
</input>
77+
<output>
78+
<soap:body use="encoded"
79+
namespace="http://nsoptional.org/"
80+
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
81+
</output>
82+
</operation>
83+
</binding>
84+
85+
<service name="toptional">
86+
<port name="interopTestPort" binding="tns:interopTestBinding">
87+
<soap:address location="http://localhost:9113"/>
88+
</port>
89+
</service>
90+
</definitions>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!xmlada DEAD
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
@ echoString
2+
Echo String
3+
This is the real value for the string!
4+
5+
@ echoStruct
6+
Echo Struct
7+
6
8+
6.60
9+
666
10+
11+
@ echoStruct
12+
<?xml version='1.0' encoding='UTF-8'?>
13+
<soapenv:Envelope soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenc="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">
14+
<soapenv:Body>
15+
<ns2:echoStruct xmlns:ns2="http://nsoptional.org/"
16+
xmlns:ns1="http://nsoptional.org/xsd">
17+
<ns1:inputStruct xsi:type="ns1:SOAPStruct">
18+
<varInt xsi:type="xsd:int">7</varInt>
19+
<varFloat xsi:type="xsd:float">7.00000E+00</varFloat>
20+
<varString xsi:type="xsd:string" xsi:nil="true"/>
21+
</ns1:inputStruct>
22+
</ns2:echoStruct>
23+
</soapenv:Body>
24+
</soapenv:Envelope>
25+
26+
<?xml version='1.0' encoding='UTF-8'?>
27+
<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">
28+
<soapenv:Body>
29+
<ns2:echoStructResponse xmlns:ns2="http://nsoptional.org/"
30+
xmlns:ns1="http://nsoptional.org/xsd">
31+
<ns1:outputStruct xsi:type="ns1:SOAPStruct">
32+
<varInt xsi:type="xsd:int">7</varInt>
33+
<varFloat xsi:type="xsd:float">7.00000E+00</varFloat>
34+
<varString xsi:type="xsd:string"></varString>
35+
</ns1:outputStruct>
36+
</ns2:echoStructResponse>
37+
</soapenv:Body>
38+
</soapenv:Envelope>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from test_support import *
2+
3+
exec_cmd('wsdl2aws', ['-q', '-f', '-doc', 'optional.wsdl'])
4+
build_and_run('optional');

0 commit comments

Comments
 (0)