[CmdletBinding()]
Param([switch]$ManageTomcat,
[String]$TomcatHome = "\apache-tomcat-9.0.0.M19"
)


#Measure-Command { Invoke-WebRequest -URI http://localhost:8080/sbms/semantics/types/type }  Select-Object TotalSeconds


Function Request($url) {
  #"Sending..." + [System.DateTime]::Now
  $start = [System.DateTime]::Now
  $r = Invoke-WebRequest -URI $url | Select-Object StatusCode, Content
  $end = [System.DateTime]::Now.Subtract($start) #| Select-Object TotalSeconds
  $dur = $end.TotalSeconds
  $dur.ToString() + ";" + $r.StatusCode + ";" + $r.Content.Length + ";" + $url
  
}

if($ManageTomcat) {
  If($env:JAVA_HOME -eq $null -or $env:JAVA_HOME -eq "") {
    "JAVA_HOME is not set - set the environment variable correctly to run Apache Tomcat"
    return;
  }
  $env:CATALINA_HOME=$TomcatHome
  & $TomcatHome\bin\startup.bat
  Pause

}

"duration;statusCode;contentLength;request"

Request http://localhost:8080/sbms/semantics/types/type

Request http://localhost:8080/sbms/semantics/types/type

if($ManageTomcat) {
  Pause
  & $TomcatHome\bin\shutdown.bat
}