
     Time zone web application using two web services

The code in this folder demonstrates a very simple "web application"
that makes use of two simple "web services".

Here is a diagram of a web browser communicating with two web servers.
The first web server is executing a web application for the browser. That
web server is referred to as the "origin server". The second web server is
executing a web service for the browser. That web server is referred to as
a "cross-origin server". In this example, the cross-origin server is also
acting as a web service to the web application running on the origin server.



 browser.exe                    server.exe            java.exe                   server.exe            java.exe
 +---------+                   +---------+   pipe   +----------+                +---------+   pipe   +----------+
 |         |       http        | port    |--------->| stdin    |     http       | port    |--------->| stdin    |
 |         |<=================>| 8080    |<---------| stdout   |<==============>| 9090    |<---------| stdout   |
 |         |   tcp connection  |         |<---------| stderr   | tcp connection |         |<---------| stderr   |
 |         |                   |         |   pipe   |          |                |         |   pipe   |          |
 |         |<===\              +---------+          +----------+          /====>|         |          |          |
 +---------+    \\              origin   \          /                    //     +---------+          +----------+
      |          \\             server    \        /                    //       cross-   \          /
      |           \\                       \      /                    //        origin    \        /
      |            \\                      +------+                   //         server     \      /
   +-----+          \\                     |      |                  //                     +------+
   |     |           \\                    |      |                 //                      |      |
   |     |            \\                   +------+                //                       |      |
   +-----+             \\                   local                 //                        +------+
    local               \\                  file                 //                          local
    file                 \\                 system              //                           file
    system                \\                                   //                            system
                           \\                                 //
                            \\            http               //
                             \===============================/
                                     tcp connection



When the web server is asked to load the time zone app web page,

   http://localhost:8080/TimeZoneWebApp_v3/index.html

the browser sends to the web server an origin (or same-origin) HTTP
request like this.

GET  /TimeZoneWebApp_v3/index.html  HTTP/1.1
Host: localhost:8080

When the browser receives that HTML page, the browser sees that it must
request a JavaScript file, so the browser does another (origin) HTTP request,

GET  /TimeZoneWebApp_v3/index.js  HTTP/1.1
Host: localhost:8080

When the browser receives that JavaScript file, it executes the function
getTimeZoneList(), which is supposed to populate the HTML dropdown list
in the index.html page. The function getTimeZoneList() does an XMLHttpRequest
to the web service web server, which causes a cross-origin HTTP request to
the web service web server.

GET  /TimeZoneWebService_v3/TimeZoneList.class?GMT  HTTP/1.1
Host: localhost:9090

The web service web server will start an instance of the JVM and run the
TimeZoneList.class program which gets a list of time zones from the Java
runtime and writes the results to its standard output stream connected to
the web server. The web server then forwards the list, over the tcp-connection,
to the getTimeZoneList() function.

When the getTimeZoneList() function receives the response from the web service,
the function uses the response to fill the dropdown list in the index.html page.

NOTE: If the web service web server does not include an
     "Access-Control-Allow-Origin: *"
response header, then the browser will not allow the getTimeZoneList() function
to receive the results from the XMLHttpRequest. The XMLHttpRequest will be
executed, and the browser will receive the response from the XMLHttpRequest,
but the browser will not allow getTimeZoneList() to see the response (the
function will see a CORS error). Try commenting out the line of code in the
http server that sends that response header in the method doJavaCGI(). Then
use the browser's Dev-Tools to see that the call to getTimeZoneList() fails
with a CORS error.


When the user picks a time zone from the dropdown list and clicks on the
"Submit" button, that causes the browser to send to the (origin) web server
an HTTP request like this.

GET  /TimeZoneWebApp_v3/TimeZoneApp.class?timeZone=GMT  HTTP/1.1
Host: localhost:8080

The web server will start an instance of the JVM and run the TimeZoneApp.class
program which expects the name of a city in its standard input stream. The
TimeZoneApp.class program will take the name of the city and forward it to
the web server running the web service with an HTTP request like this.

GET  /TimeZoneWebService_v3/TimeZoneService.class?GMT  HTTP/1.1
Host: localhost:9090

That web server will start an instance of the JVM and run TimeZoneService.class.
The web server will write the name of the time zone to the stream connected to
the standard input stream of the JVM. The TimeZoneService.class program will take
the time zone name from its standard input stream and look up in Java's built-in
database of time zones. The result of the lookup will be written to the standard
output stream of the JVM. The web server will take that result and send it over
the tcp connection to the web application program which will use the web service's
result to finish its work.

The results from the web application program are sent over the JVM's standard
output stream to the (origin) web server. The web server sends those results
over the tcp connection to the browser as the response to the browser's HTTP
GET request. The browser displays those results as a web page.


To run this web application, copy the package folder
   TimeZoneWebApp_v3
into the root folder of the web server. Then compile and run the
web server that runs the web service programs. Then access this URL.

      http://localhost:8080/TimeZoneWebApp_v3/
