1 of 29

Web Services Prerequisites

Jakub Klímek

2 of 29

Tools

Lectures and tutorials on XML and XML Schema in NPRG036 - Data Formats

3 of 29

Task 1 - ping

Use ping to determine the IP address for data.gov.cz using DNS

4 of 29

Task 1 - ping - solution

$ ping data.gov.cz

PING data.gov.cz (40.69.221.188) 32 bytes of data.

Alternatively, using nslookup

$ nslookup data.gov.cz

Server: UnKnown

Address: 2a03:a900:2000:5a6::1

Non-authoritative answer:

Name: data.gov.cz

Address: 185.17.214.226

5 of 29

Task 2 - telnet + HTTP

  1. Determine IP address of www.google.com����
  2. Use telnet to get the webpage
    1. telnet is a text based TCP communication tool
    2. syntax: telnet <IP> <port>
    3. after connection, you can write text according to the HTTP protocol
    4. Try HTTP/1.0 and HTTP/1.1

$ ping www.google.com

PING www.google.com (172.217.23.196) 56(84) bytes of data.

64 bytes from prg03s05-in-f196.1e100.net (172.217.23.196): icmp_seq=1 ttl=58 time=1.53 ms

6 of 29

Task 2 - PuTTY

If you are using PuTTY, use the “raw” connection:

7 of 29

Task 2 - telnet + HTTP - solution HTTP/1.0

$ telnet 172.217.23.196 80�Trying 172.217.23.196…�Connected to 172.217.23.196.�Escape character is '^]'.�GET / HTTP/1.0

You should get HTML content here. If you look closely, it will be in the language of your region, e.g. Czech.

8 of 29

Task 2 - telnet + HTTP - solution HTTP/1.1

$ telnet 172.217.23.196 80�Trying 172.217.23.196…�Connected to 172.217.23.196.�Escape character is '^]'.�GET / HTTP/1.1�Host: www.google.com

You should get HTML content here as well. In HTTP/1.1 you need to specify the Host: header, even though google is quite tolerant here.

9 of 29

Task 3 - telnet + HTTP + additional headers

Use telnet to get the spanish version of the google homepage.

10 of 29

Task 3 - telnet + HTTP + additional headers - solution

$ telnet 172.217.23.196 80

Trying 172.217.23.196...

Connected to 172.217.23.196.

Escape character is '^]'.

GET / HTTP/1.1

Host: www.google.com

Accept-Language: es

11 of 29

Task 4 - curl

Use curl to get the Google webpage

Use curl to get a spanish Google webpage

12 of 29

Task 4 - curl - solution

$ curl www.google.com

And if you want to see the communication:

$ curl -v www.google.com

Setting the header:

$ curl -v -H"Accept-Language: es" www.google.com

13 of 29

Task 5 - more content negotiation

Let’s have a resource identified by: https://data.gov.cz/zdroj/datové-sady/00006963/9b88bbed6f1effd48bd3e6b66232d8c9

  1. using telnet, try to get HTML representation of the resource
  2. using curl, get HTML representation of the resource
  3. using curl, get RDF representation of the resource
  4. using postman, get HTML representation of the resource
  5. using postman, get RDF representation of the resource

14 of 29

Task 5 - more content negotiation - solution - telnet 1�(no longer working)

$ telnet 185.17.214.226 80�Trying 185.17.214.226…�Connected to 185.17.214.226.�Escape character is '^]'.�GET /zdroj/datové-sady/00006963/9b88bbed6f1effd48bd3e6b66232d8c9 HTTP/1.1�Host: data.gov.cz��HTTP/1.1 301 Moved Permanently�Server: nginx�Date: Sat, 06 Feb 2021 09:15:35 GMT�Content-Type: text/html�Content-Length: 162�Connection: keep-alive�Location: https://data.gov.cz/zdroj/datové-sady/00006963/9b88bbed6f1effd48bd3e6b66232d8c9

15 of 29

Task 5 - more content negotiation - solution - telnet 2

$ telnet 185.17.214.226 443�Trying 185.17.214.226…�Connected to 185.17.214.226.�Escape character is '^]'.�GET /zdroj/datové-sady/00006963/9b88bbed6f1effd48bd3e6b66232d8c9 HTTP/1.1�Host: data.gov.cz��HTTP/1.1 400 Bad Request�Server: nginx�Date: Sat, 06 Feb 2021 09:17:06 GMT�Content-Type: text/html; charset=utf-8�Content-Length: 248�Connection: close��<html>�<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>�<body>�<center><h1>400 Bad Request</h1></center>�<center>The plain HTTP request was sent to HTTPS port</center>�<hr><center>nginx</center>�</body>�</html>�Connection closed by foreign host.

16 of 29

Task 5 - more content negotiation - solution - curl 1

$ curl -v https://data.gov.cz/zdroj/datové-sady/00006963/9b88bbed6f1effd48bd3e6b66232d8c9�$ curl -v -H"Accept: text/turtle" https://data.gov.cz/zdroj/datové-sady/00006963/9b88bbed6f1effd48bd3e6b66232d8c9�* Trying 185.17.214.226:443…�…�> GET /zdroj/datové-sady/00006963/9b88bbed6f1effd48bd3e6b66232d8c9 HTTP/2�> Host: data.gov.cz�> user-agent: curl/7.68.0�> accept: text/turtle�>�< HTTP/2 303�< server: nginx�< date: Sat, 06 Feb 2021 09:19:12 GMT�< content-type: text/html; charset=UTF-8�< content-length: 0�< location:�https://data.gov.cz/sparql?query=define%20sql%3Adescribe-mode%20%22CBD%22%20%20DESCRIBE%20%3Chttps%3A%2F%2Fdata.gov.cz%2Fzdroj%2Fdatové-sady%2F00006963%2F9b88bbed6f1effd48bd3e6b66232d8c9%3E&format=text%2Fturtle�< ...

17 of 29

Task 5 - more content negotiation - solution - curl 2

$ curl -v -H"Accept: text/turtle" https://data.gov.cz/sparql?query=define%20sql%3Adescribe-mode%20%22CBD%22%20%20DESCRIBE%20%3Chttps%3A%2F%2Fdata.gov.cz%2Fzdroj%2Fdatové-sady%2F00006963%2F9b88bbed6f1effd48bd3e6b66232d8c9%3E&format=text%2Fturtle�…�> GET /sparql?query=define%20sql%3Adescribe-mode%20%22CBD%22%20%20DESCRIBE%20%3Chttps%3A%2F%2Fdata.gov.cz%2Fzdroj%2Fdatové-sady%2F2F00006963%2F9b88bbed6f1effd48bd3e6b66232d8c9%3E HTTP/2�> Host: data.gov.cz�> user-agent: curl/7.68.0�> accept: text/turtle�>�< HTTP/2 200�< server: nginx�< date: Sat, 06 Feb 2021 09:22:08 GMT�< content-type: text/turtle; charset=UTF-8�< …�<�@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .�@prefix ns1: <https://data.gov.cz/slovn\u00EDk/nkod/typ-datov\u00E9-sady-dle-zdroje/> .�<https://data.gov.cz/zdroj/datov\u00E9-sady/2F00006963/9b88bbed6f1effd48bd3e6b66232d8c9> rdf:type ns1:DcatLkodSparql .�...

18 of 29

Task 5 - more content negotiation - solution - curl 3

curl can do the “follow redirect” for us using the -L parameter

$ curl -v -L -H"Accept: text/turtle" https://data.gov.cz/zdroj/datové-sady/00006963/9b88bbed6f1effd48bd3e6b66232d8c9

19 of 29

Task 5 - postman

Graphical UI

try with application/ld+json

20 of 29

Task 5 - postman

Problem: why is the turtle representation empty here?

  • Postman encodes the IRI returned in the 303 redirect to URI (percent encoding)
  • The redirect leads to SPARQL query
  • In SPARQL, encoded URI and decoded IRI are different resources

21 of 29

Task 5 - postman

Postman allows you to export curl (and other) commands via the “code” button

22 of 29

Task 6 - observe HTTP communication in browser

Using your favorite web browser, GET a resource from the previous task and observe the HTTP communication

  • Methods
  • Headers
  • Response codes

Hint:

Usually, there is a “Developer console” with a “Network” tab

23 of 29

Task 7 - XML

Create a simple XML document with

  • 3 levels of nesting
  • 2 different attributes
  • 4 different elements
  • 2 different namespaces

Check well-formedness

e.g. https://www.xmlvalidation.com/

or xmllint on linux

24 of 29

Task 7 - example

<?xml version="1.0" encoding="UTF-8"?>

<catalog xmlns="https://example.org/catalog" xmlns:ext="https://example.org/extensions">

<title xml:lang="en">My catalog</title>

<title xml:lang="cs">Můj katalog</title>

<description xml:lang="en">This is my dummy catalog</description>

<description xml:lang="cs">Toto je můj falešný katalog</description>

<contact-point kind="email">

<ext:name xml:lang="en">John Doe</ext:name>

<ext:e-mail>mailto:john@doe.org</ext:e-mail>

</contact-point>

<datasets>

<dataset>

<title xml:lang="en">Bikesharing in Brno</title>

<title xml:lang="cs">Sdílení kol v Brně</title>

<distributions>

<distribution media-type="application/xml">

<downloadURL>http://brno.cz/myfile.xml</downloadURL>

</distribution>

<distribution>

<accessService>

<endpointURL>https://brno.cz/myAPI</endpointURL>

<title xml:lang="en">My API</title>

</accessService>

</distribution>

</distributions>

</dataset>

<dataset>

<title xml:lang="en">Bikesharing in Prague</title>

<title xml:lang="cs">Sdílení kol v Praze</title>

<distributions>

<distribution media-type="text/csv">

<title xml:lang="en">CSV</title>

<downloadURL>http://praha.eu/myfile.csv</downloadURL>

</distribution>

</distributions>

</dataset>

</datasets>

</catalog>

24

25 of 29

Task 8 - XPath

Download: https://goo.gl/P36GBg

Use e.g. http://xpather.com/ or Altova XMLSpy (free trial & enterprise version in lab on Windows)

  1. Select title of all contracts
  2. Select title of contract with id “c2“
  3. Select ids of contracts where the city of the subject is „Praha“

26 of 29

Task 9 - XML Schema

  1. Create an XSD describing public contracts. The document must contain at least one contract (create it in iterations)
    • Each contract has
      1. uri, publishedTime, publisher, contractData
    • Contract data involve
      • title, price, subject, and party
    • Subject and party have
      • name, id, and address
  2. Specify all the properties using elements
  3. Values should be of type xs:string
  4. Create both the schema and sample document and ensure validity

27 of 29

Homework

  1. design your own business process
  2. some steps will be later “mocked” as web services
  3. use BPMN to model the business process
    1. https://demo.bpmn.io/ or https://www.bizagi.com or similar tool
    2. see e.g. tutorials:
      1. BPMN Guide Quick Start by Bizagi BPM

28 of 29

Homework scope

Needs to be more detailed than this.

  1. Identify services
  2. Identify messages exchanged among services
    1. later, they will be realized as web services

Hospital

Reception

Investigation

Hospitalization

Surgery

Control

Economy

    • Material
    • Reports

Utility

    • Food
    • Sanitary
    • Accommodation

29 of 29

Homework scope: this seems sufficient