Example of web service request/response over SOAP/HTTP [message #1700598] |
Sat, 04 July 2015 14:14 |
|
Our intention is to provide simple usage examples of Eclipse Titan for different areas; the code provided will not be of industrial robustness, focus is more on simplicity and readability. Tool-specific , non-standardized solutions such as test adapters (or test ports) and codecs will also be highlighted.
This posting, the first in the series , is dedicated to SOAP-based web services.
Although SOAP-based web services are losing ground in front of REST-based web services, they are still out there. An example of how to build a SOAP client capable of interrogating a web service , that is , sending a request and receivig/analyzing the answer is provided in the attachment.
This exemplifies several areas of Titan usage: a generic XML workflow, a SOAP example , an example for using the HTTP test port.
I have chosen a simple web service for converting between Celsius and Fahrenheit scales from http://www.w3schools.com/webservices/tempconvert.asmx.
The WSDL-file can be downloaded from http://www.w3schools.com/webservices/tempconvert.asmx?WSDL
(see Tempconvert.wsdl).
The messages used by the web service are described by the "schema" part of the WSDL. I have extracted this part into TempConvert.xsd.
The TTCN-3 counterpart can be generated with:
as a result , three files are generated:
xsd2ttcn TempConvert.xsd
Notify: Checking documents...
Notify: Parsing XML schema document `TempConvert.xsd'...
Notify: Generating TTCN-3 modules...
Notify: File 'http_www_w3schools_com_webservices.ttcn' was generated.
Notify: File 'UsefulTtcn3Types.ttcn' was generated.
Notify: File 'XSD.ttcn' was generated.
XSD.ttcn and UsefulTtcn3Types.ttcn contain automatically generated generic definitions, while http_www_w3schools_com_webservices.ttcn contains the TTCN-3 representation equivalent to the input schema, containing both TTCN-3 structures and encoding-decoding instructions for the codec.
These messages will have to be embedded into a SOAP envelope, consisting of a body and a header.
For completeness, I have attached a schema for SOAP ( SOAP.xsd) but this is too generic to be usable. A TTCN-3 file generated from it with xsd2ttcn will have to be amended for practical purposes. Instead , a proposed SOAP.ttcn is attached, which will cover most of the practical situations.
The SOAP body will carry one of the above protocol messages. A file named glue.ttcn connects the SOAP definitions to the protocol definitions.
As a result the encoding/decoding functions declared in SOAP.ttcn will work on both the SOAP sublayer and the protocol sublayer, with the slight disadvantage that the boundaries between the SOAP sublayer and the carried protocol are not distinct.
As an alternative, not detailed here, the content of the SOAP body can be declared as a generic XML string. In this case a two-step processing becomes necessarry: in sending direction for instance first the protocol message , then subsequently the assembled SOAP structure has to be XML-encoded.
For details on the XML workflow, XSD to TTCN-3 converter and encoding instructions please see the Titan referenceguide.
The dynamic part is contained in SOAP_demo.ttcn. Two test cases are described here : first a simple encoding-decoding test , then
an actual use of the webservice:
first an HTTP connect() is sent. after the reception of connect_response() , an HTTP request containing the SOAP-enveloped Fahrenheit-to-Celsius message is sent to the server; after the response is received, the connection is closed, HTTP 1.0 style (for HTTP 1.1, an open connection can serve several subsequent requests before being closed)
For details on HTTP port usage please see the documentation provided with the test port:
https://github.com/eclipse/titan.TestPorts.HTTPmsg
How to use the attached code:
Download and uncompress the code into a SOAP_demo directory.It is assumed that Titan is installed and working.
cd SOAP_demo/bin
../src/install.script
make
./SOAP SOAP.cfg
Check MyExample.log for execution details.
The Makefile was generated with the following parameters:
makefilegen -gs -e SOAP *.ttcn *.cc *.hh
If anyone has a specific request regarding a certain protocol or transport, please let me know.
Best regards
Elemer
|
|
|
Powered by
FUDForum. Page generated in 0.04035 seconds