/usr/lib/tcltk/tclws2.3.8/ServerSide.tcl is in tclws 2.3.8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 | ###############################################################################
## ##
## Copyright (c) 2006-2013, Gerald W. Lester ##
## Copyright (c) 2008, Georgios Petasis ##
## Copyright (c) 2006, Visiprise Software, Inc ##
## Copyright (c) 2006, Colin McCormack ##
## Copyright (c) 2006, Rolf Ade ##
## Copyright (c) 2001-2006, Pat Thoyts ##
## All rights reserved. ##
## ##
## Redistribution and use in source and binary forms, with or without ##
## modification, are permitted provided that the following conditions ##
## are met: ##
## ##
## * Redistributions of source code must retain the above copyright ##
## notice, this list of conditions and the following disclaimer. ##
## * Redistributions in binary form must reproduce the above ##
## copyright notice, this list of conditions and the following ##
## disclaimer in the documentation and/or other materials provided ##
## with the distribution. ##
## * Neither the name of the Visiprise Software, Inc nor the names ##
## of its contributors may be used to endorse or promote products ##
## derived from this software without specific prior written ##
## permission. ##
## ##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ##
## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ##
## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ##
## FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ##
## COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ##
## INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, ##
## BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; ##
## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ##
## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ##
## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ##
## ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ##
## POSSIBILITY OF SUCH DAMAGE. ##
## ##
###############################################################################
package require Tcl 8.4
package require WS::Utils 2.3.7 ; # provides dict
package require html
package require log
package require tdom
package provide WS::Server 2.3.7
namespace eval ::WS::Server {
array set ::WS::Server::serviceArr {}
set ::WS::Server::procInfo {}
set ::WS::Server::mode {}
}
###########################################################################
#
# Public Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PUBLIC<<
#
# Procedure Name : ::WS::Server::Service
#
# Description : Declare a Web Service, the following URLs will exist
# /service/<ServiceName>
# Displays an HTML page describing the service
# /service/<ServiceName>/wsdl
# Returns a WSDL describing the service
# /service/<ServiceName>/op
# Invoke an operation
#
# Arguments : this procedure uses position independent arguments, they are:
# -host - The host name for this service.
# Defaults to "ip:port" in embedded mode,
# and to "localhost" otherwise.
# -description - The HTML description for this service
# -service - The service name (this will also be used for
# the Tcl namespace of the procedures that implement
# the operations.
# -premonitor - This is a command prefix to be called before
# an operation is called. The following arguments are
# added to the command prefix:
# PRE serviceName operationName operArgList
# -postmonitor - This is a command prefix to be called after
# an operation is called. The following arguments are
# added to the command prefix:
# POST serviceName operationName OK|ERROR results
# -inheaders - List of input header types.
# -outheaders - List of output header types.
# -intransform - Inbound (request) transform procedure.
# -outtransform - Outbound (reply) transform procedure.
# -checkheader - Command prefix to check headers.
# If the call is not to be allowed, this command
# should raise an error.
# The signature of the command must be:
# cmd \
# service \
# operation \
# caller_ipaddr \
# http_header_list \
# soap_header_list
# -mode - Mode that service is running in. Must be one of:
# tclhttpd -- running inside of tclhttpd or an
# environment that supplies a
# compatible Url_PrefixInstall
# and Httpd_ReturnData commands
# embedded -- using the ::WS::Embedded package
# aolserver -- using the ::WS::AolServer package
# wub -- using the ::WS::Wub package
# wibble -- running inside of wibble
# rivet -- running inside Apache Rivet (mod_rivet)
# channel -- use a channel pair, WSDL is return if no XML
# otherwise an operation is called
# -ports - List of ports. Only valid for embedded and channel mode
# For chanel mode. Defaults to {stdin stdout}
# NOTE -- a call should be to
# ::WS::Channel::Start to process data
# For embedded mode. Default: 80
# NOTE -- a call should be to
# ::WS::Embedded::Listen
# for each port in this
# list prior to this call
# -prefix - Path prefix used for the namespace and endpoint
# Defaults to "/service/" plus the service name
# -traceEnabled - Boolean to enable/disable trace being passed back in exception
# Defaults to "Y"
# -docFormat - Format of the documentation for operations ("text" or "html").
# Defaults to "text"
# -stylesheet - The CSS stylesheet URL used in the HTML documentation
#
#
# Returns : Nothing
#
# Side-Effects : None
#
# Exception Conditions :
# MISSREQARG -- Missing required arguments
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PUBLIC<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Server::Service {args} {
variable serviceArr
variable procInfo
variable mode
::log::log debug "Defining Service as $args"
array set defaults {
-description {}
-checkheader {::WS::Server::ok}
-inheaders {}
-outheaders {}
-intransform {}
-outtransform {}
-htmlhead {TclHttpd Based Web Services}
-author {}
-description {}
-mode {tclhttpd}
-ports {80}
-traceEnabled {Y}
-docFormat {text}
-stylesheet {}
}
array set defaults $args
if {[string equal $defaults(-mode) channel]} {
set defaults(-ports) {stdin stdout}
array set defaults $args
}
set requiredList {-service}
set missingList {}
foreach opt $requiredList {
if {![info exists defaults($opt)]} {
lappend missingList $opt
}
}
if {[llength $missingList]} {
return \
-code error \
-errorcode [list WSSERVER MISSREQARG $missingList] \
"Missing required arguments '[join $missingList {,}]'"
}
set service $defaults(-service)
if {![info exists defaults(-prefix)]} {
set defaults(-prefix) /service/$service
}
# find default host
if {![info exists defaults(-host)]} {
switch -exact -- $defaults(-mode) {
embedded {
set me [socket -server garbage_word -myaddr [info hostname] 0]
set defaults(-host) [lindex [fconfigure $me -sockname] 0]
close $me
if {0 !=[llength $defaults(-ports)] && 80 != [lindex $defaults(-ports) 0]} {
append defaults(-host) ":[lindex $defaults(-ports) 0]"
}
}
default {
set defaults(-host) localhost
}
}
}
set defaults(-uri) $service
namespace eval ::$service {}
set serviceArr($service) [array get defaults]
if {![dict exists $procInfo $service operationList]} {
dict set procInfo $service operationList {}
}
set mode $defaults(-mode)
##
## Install wsdl doc
##
interp alias {} ::WS::Server::generateInfo_${service} \
{} ::WS::Server::generateInfo ${service}
::log::log debug "Installing Generate info for $service at $defaults(-prefix)"
switch -exact -- $mode {
embedded {
package require WS::Embeded 2.1.3
foreach port $defaults(-ports) {
::WS::Embeded::AddHandler $port $defaults(-prefix) ::WS::Server::generateInfo_${service}
}
}
tclhttpd {
::Url_PrefixInstall $defaults(-prefix) ::WS::Server::generateInfo_${service} \
-thread 0
}
wub {
package require WS::Wub
}
aolserver {
package require WS::AOLserver
}
rivet {
package require Rivet
}
wibble {
##
## Define zone handler - get code from andy
##
proc ::wibble::webservice {state} {
dict with state options {}
switch -exact -- $suffix {
"" - \
/ {
::WS::Server::generateInfo $name 0 response
sendresponse $response
} /op {
::WS::Server::callOperation $name 0 [dict get $state request] response
sendresponse $response
} /wsdl {
::WS::Server::generateWsdl $name 0 response
sendresponse $response
}
default {
## Do nothing
}
}
}
if {[package present Wibble] eq "0.1"} {
proc ::WS::Wibble::ReturnData {responseDictVar type text status} {
upvar 1 $responseDictVar responseDict
dict set responseDict header content-type $type
dict set responseDict content $text
dict set responseDict status $status
}
} else {
proc ::WS::Wibble::ReturnData {responseDictVar type text status} {
upvar 1 $responseDictVar responseDict
dict set responseDict header content-type "" $type
dict set responseDict content $text
dict set responseDict status $status
}
}
::wibble::handle $defaults(-prefix) webservice name $service
}
default {
return \
-code error \
-errorcode [list WSSERVER UNSUPMODE $mode] \
"-mode '$mode' not supported"
}
}
##
## Install wsdl
##
interp alias {} ::WS::Server::generateWsdl_${service} \
{} ::WS::Server::generateWsdl ${service}
::log::log debug "Installing GenerateWsdl info for $service at $defaults(-prefix)/wsdl"
switch -exact -- $mode {
embedded {
foreach port $defaults(-ports) {
::WS::Embeded::AddHandler $port $defaults(-prefix)/wsdl ::WS::Server::generateWsdl_${service}
}
}
channel {
package require WS::Channel
::WS::Channel::AddHandler $defaults(-ports) {} ::WS::Server::generateWsdl_${service}
}
tclhttpd {
::Url_PrefixInstall $defaults(-prefix)/wsdl ::WS::Server::generateWsdl_${service} \
-thread 0
}
default {
## Do nothing
}
}
##
## Install operations
##
interp alias {} ::WS::Server::callOperation_${service} \
{} ::WS::Server::callOperation ${service}
::log::log debug "Installing callOperation info for $service at $defaults(-prefix)/op"
switch -exact -- $mode {
embedded {
foreach port $defaults(-ports) {
::WS::Embeded::AddHandler $port $defaults(-prefix)/op ::WS::Server::callOperation_${service}
}
}
channel {
package require WS::Channel
::WS::Channel::AddHandler $defaults(-ports) {op} ::WS::Server::callOperation_${service}
}
tclhttpd {
::Url_PrefixInstall $defaults(-prefix)/op ::WS::Server::callOperation_${service} \
-thread 1
}
default {
## Do nothing
}
}
return;
}
###########################################################################
#
# Public Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PUBLIC<<
#
# Procedure Name : ::WS::Server::ServiceProc
#
# Description : Register an operation for a service and declare the procedure to handle
# the operations.
#
# Arguments :
# ServiceName -- Name of the service this operation is for
# NameInfo -- List of three elements:
# 1) OperationName -- the name of the operation
# 2) ReturnType -- the type of the procedure return,
# this can be a simple or complex type
# 3) Description -- description of the return method
# Arglist -- List of argument definitions,
# each list element must be of the form:
# 1) ArgumentName -- the name of the argument
# 2) ArgumentTypeInfo -- A list of:
# {type typeName comment commentString}
# typeName can be any simple or defined type.
# commentString is a quoted string describing the field.
# Documentation -- HTML describing what this operation does
# Body -- The tcl code to be called when the operation is invoked. . This
# code should return a dictionary with <OperationName>Result as a
# key and the operation's result as the value.
#
# Returns : Nothing
#
# Side-Effects :
# A procedure named "<ServiceName>::<OperationName>" defined
# A type name with the name <OperationName>Result is defined.
#
# Exception Conditions : None
#
# Pre-requisite Conditions : ::WS::Server::Server must have been called for the ServiceName
#
# Original Author : Gerald W. Lester
#
#>>END PUBLIC<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Server::ServiceProc {service nameInfo arglist documentation body} {
variable procInfo
set name [lindex $nameInfo 0]
::log::log debug "Defining operation $name for $service"
set argOrder {}
::log::log debug "\targs are {$arglist}"
foreach {arg data} $arglist {
lappend argOrder $arg
}
if {![dict exists $procInfo $service op$name argList]} {
set tmpList [dict get $procInfo $service operationList]
lappend tmpList $name
dict set procInfo $service operationList $tmpList
}
dict set procInfo $service op$name argList $arglist
dict set procInfo $service op$name argOrder $argOrder
dict set procInfo $service op$name docs $documentation
dict set procInfo $service op$name returnInfo [lindex $nameInfo 1]
set typeInfo [dict get $procInfo $service op$name returnInfo]
::WS::Utils::ServiceTypeDef Server $service ${name}Results [list ${name}Result $typeInfo]
::WS::Utils::ServiceTypeDef Server $service ${name}Request $arglist
set tclArgList {}
foreach {arg typeinfo} $arglist {
lappend tclArgList [lindex $arg 0]
}
proc ::${service}::${name} $tclArgList $body
}
###########################################################################
#
# Private Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PRIVATE<<
#
# Procedure Name : ::WS::Server::GetWsdl
#
# Description : Generates a WSDL for a registered service.
#
# Arguments :
# serviceName - The name of the service
# urlPrefix - (optional) Prefix to use for location; defaults to http://<host>
#
# Returns :
# XML for the WSDL
#
# Side-Effects : None
#
# Exception Conditions :
# WS SERVER UNKSERV - Unknown service name
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PRIVATE<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
# 2 12/12/2009 W.Kocjan Support for services over SSL in Tclhttpd
#
#
###########################################################################
proc ::WS::Server::GetWsdl {serviceName {urlPrefix ""}} {
variable serviceArr
variable procInfo
array set serviceData $serviceArr($serviceName)
set operList [lsort -dictionary [dict get $procInfo $serviceName operationList]]
::log::log debug "Generating WSDL for $serviceName"
if {![info exists serviceArr($serviceName)]} {
set msg "Unknown service '$serviceName'"
::return \
-code error \
-errorCode [list WS SERVER UNKSERV $serviceName] \
$msg
}
set msg {}
set reply [::dom createDocument wsdl:definitions]
$reply documentElement definition
$definition setAttribute \
xmlns:wsdl "http://schemas.xmlsoap.org/wsdl/" \
xmlns:http "http://schemas.xmlsoap.org/wsdl/http/" \
xmlns:mime "http://schemas.xmlsoap.org/wsdl/mime/" \
xmlns:xs "http://www.w3.org/2001/XMLSchema" \
xmlns:soap "http://schemas.xmlsoap.org/wsdl/soap/" \
xmlns:soapenc "http://schemas.xmlsoap.org/soap/encoding/" \
xmlns:${serviceName} "http://$serviceData(-host)$serviceData(-prefix)" \
targetNamespace "http://$serviceData(-host)$serviceData(-prefix)"
foreach topLevel {types} {
$definition appendChild [$reply createElement wsdl:$topLevel $topLevel]
}
##
## Messages
##
## Operations
foreach oper $operList {
$definition appendChild [$reply createElement wsdl:message input]
$input setAttribute name ${oper}In
$input appendChild [$reply createElement wsdl:part part]
$part setAttribute \
name parameters \
element ${serviceName}:${oper}Request
$definition appendChild [$reply createElement wsdl:message output]
$output setAttribute name ${oper}Out
$output appendChild [$reply createElement wsdl:part part]
$part setAttribute \
name parameters \
element ${serviceName}:${oper}Results
}
## Input headers
foreach headerType $serviceData(-inheaders) {
$definition appendChild [$reply createElement wsdl:message header]
$header setAttribute name $headerType
$header appendChild [$reply createElement wsdl:part part]
$part setAttribute \
name parameters \
element ${serviceName}:${headerType}
}
## Output headers
foreach headerType $serviceData(-outheaders) {
$definition appendChild [$reply createElement wsdl:message header]
$header setAttribute name $headerType
$header appendChild [$reply createElement wsdl:part part]
$part setAttribute \
name parameters \
element ${serviceName}:${headerType}
}
##
## Add the rest of the toplevels in
##
foreach topLevel {portType binding service} {
$definition appendChild [$reply createElement wsdl:$topLevel $topLevel]
}
##
## Service
##
$service setAttribute name $serviceName
$service appendChild [$reply createElement wsdl:documentation documentation]
$documentation appendChild [$reply createTextNode $serviceData(-description)]
$service appendChild [$reply createElement wsdl:port port]
$port setAttribute \
name ${serviceName}Soap \
binding ${serviceName}:${serviceName}Soap
$port appendChild [$reply createElement soap:address address]
if {$urlPrefix == ""} {
set urlPrefix "http://$serviceData(-host)"
}
$address setAttribute \
location "$urlPrefix$serviceData(-prefix)/op"
##
## Bindings
##
$binding setAttribute \
name ${serviceName}Soap \
type ${serviceName}:${serviceName}Soap
$binding appendChild [$reply createElement soap:binding b2]
$b2 setAttribute\
style document \
transport "http://schemas.xmlsoap.org/soap/http"
foreach oper $operList {
$binding appendChild [$reply createElement wsdl:operation operNode]
$operNode setAttribute name $oper
$operNode appendChild [$reply createElement soap:operation o2]
$o2 setAttribute \
soapAction $serviceName:$oper \
style document
## Input message
$operNode appendChild [$reply createElement wsdl:input input]
$input appendChild [$reply createElement soap:body tmp]
$tmp setAttribute use literal
foreach headerType $serviceData(-inheaders) {
$operNode appendChild [$reply createElement wsdl:header header]
$header appendChild [$reply createElement soap:header tmp]
$tmp setAttribute \
use literal \
message ${serviceName}:${headerType} \
part $headerType
}
## Output message
$operNode appendChild [$reply createElement wsdl:output output]
$output appendChild [$reply createElement soap:body tmp]
$tmp setAttribute use literal
foreach headerType $serviceData(-outheaders) {
$operNode appendChild [$reply createElement wsdl:header header]
$header appendChild [$reply createElement soap:header tmp]
$tmp setAttribute \
use literal \
message ${serviceName}:${headerType} \
part $headerType
}
}
##
## Ports
##
$portType setAttribute name ${serviceName}Soap
foreach oper $operList {
$portType appendChild [$reply createElement wsdl:operation operNode]
$operNode setAttribute name $oper
$operNode appendChild [$reply createElement wsdl:input input]
$input setAttribute message ${serviceName}:${oper}In
$operNode appendChild [$reply createElement wsdl:output output]
$output setAttribute message ${serviceName}:${oper}Out
}
##
## Types
##
GenerateScheme Server $serviceName $reply $types
append msg \
{<?xml version="1.0" encoding="utf-8"?>} \
"\n" \
[$reply asXML \
-indent 4 \
-escapeNonASCII \
-doctypeDeclaration 0 \
]
$reply delete
return $msg
}
###########################################################################
#
# Private Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PRIVATE<<
#
# Procedure Name : ::WS::Server::generateWsdl
#
# Description : Generates a WSDL for a registered service.
#
# Arguments :
# serviceName - The name of the service
# sock - The socket to return the WSDL on
# args - not used
#
# Returns :
# 1 - On error
# 0 - On success
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PRIVATE<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
# 2 12/12/2009 W.Kocjan Support for services over SSL in Tclhttpd
#
#
###########################################################################
proc ::WS::Server::generateWsdl {serviceName sock args} {
variable serviceArr
variable procInfo
variable mode
array set serviceData $serviceArr($serviceName)
set operList [lsort -dictionary [dict get $procInfo $serviceName operationList]]
::log::log debug "Generating WSDL for $serviceName on $sock with {$args}"
if {![info exists serviceArr($serviceName)]} {
set msg "Unknown service '$serviceName'"
switch -exact -- $mode {
tclhttpd {
::Httpd_ReturnData \
$sock \
"text/html; charset=UTF-8" \
"<html><head><title>Webservice Error</title></head><body><h2>$msg</h2></body></html>" \
404
}
embedded {
::WS::Embeded::ReturnData \
$sock \
"text/html; charset=UTF-8" \
"<html><head><title>Webservice Error</title></head><body><h2>$msg</h2></body></html>" \
404
}
channel {
::WS::Channel::ReturnData \
$sock \
"text/xml; charset=UTF-8" \
"<html><head><title>Webservice Error</title></head><body><h2>$msg</h2></body></html>" \
404
}
rivet {
headers type text/html
headers numeric 404
puts "<html><head><title>Webservice Error</title></head><body><h2>$msg</h2></body></html>"
}
aolserver {
::WS::AOLserver::ReturnData \
$sock \
text/html \
"<html><head><title>Webservice Error</title></head><body><h2>$msg</h2></body></html>" \
404
}
wibble {
upvar 1 [lindex $args 0] responseDict
::WS::Wibble::ReturnData responseDict text/html "<html><head><title>Webservice Error</title></head><body><h2>$msg</h2></body></html>" 404
}
default {
## Do nothing
}
}
return 1
}
switch -exact -- $mode {
tclhttpd {
upvar #0 ::Httpd$sock s
set urlPrefix ""
catch {
set urlPrefix [lindex $s(self) 0]://$serviceData(-host)
set urlPrefix [lindex $s(self) 0]://$s(mime,host)
}
set xml [GetWsdl $serviceName $urlPrefix]
::Httpd_ReturnData $sock "text/xml; charset=UTF-8" $xml 200
}
channel {
set xml [GetWsdl $serviceName]
::WS::Channel::ReturnData $sock "text/xml; charset=UTF-8" $xml 200
}
embedded {
set xml [GetWsdl $serviceName]
::WS::Embeded::ReturnData $sock "text/xml; charset=UTF-8" $xml 200
}
rivet {
set xml [GetWsdl $serviceName]
headers type text/xml
headers numeric 200
puts $xml
}
aolserver {
set xml [GetWsdl $serviceName]
::WS::AOLserver::ReturnData $sock text/xml $xml 200
}
wibble {
set xml [GetWsdl $serviceName]
upvar 1 [lindex $args 0] responseDict
::WS::Wibble::ReturnData responseDict text/xml $xml 200
}
default {
## Do nothing
}
}
}
###########################################################################
#
# Public Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PUBLIC<<
#
# Procedure Name : ::WS::Server::GenerateScheme
#
# Description : Generate a scheme
#
# Arguments :
# mode - Client/Server
# serviceName - The service name
# doc - The document to add the scheme to
# parent - The parent node of the scheme
#
# Returns : nothing
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PUBLIC<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 02/15/2008 G.Lester Made Scheme generation a utility
# 2 02/03/2008 G.Lester Moved scheme generation into WS::Utils namespace
#
###########################################################################
proc ::WS::Server::GenerateScheme {mode serviceName doc parent} {
variable serviceArr
array set serviceData $serviceArr($serviceName)
set targetNamespace "http://$serviceData(-host)$serviceData(-prefix)"
return [::WS::Utils::GenerateScheme $mode $serviceName $doc $parent $targetNamespace]
}
###########################################################################
#
# Private Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PRIVATE<<
#
# Procedure Name : ::WS::Server::generateInfo
#
# Description : Generate an HTML description of the service, the operations
# and all applicable type definitions.
#
# Arguments :
# serviceName - The name of the service
# sock - The socket to return the WSDL on
# args - not used
#
# Returns :
# 1 - On error
# 0 - On success
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PRIVATE<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Server::generateInfo {service sock args} {
variable serviceArr
variable procInfo
variable mode
::log::log debug "Generating HTML Documentation for $service on $sock with {$args}"
if {![info exists serviceArr($service)]} {
set msg "Unknown service '$service'"
switch -exact -- $mode {
tclhttpd {
::Httpd_ReturnData \
$sock \
"text/html; charset=UTF-8" \
"<html><head><title>Webservice Error</title></head><body><h2>$msg</h2></body></html>" \
404
}
embedded {
::WS::Embeded::ReturnData \
$sock \
"text/html; charset=UTF-8" \
"<html><head><title>Webservice Error</title></head><body><h2>$msg</h2></body></html>" \
404
}
channel {
::WS::Channel::ReturnData \
$sock \
text/html \
"<html><head><title>Webservice Error</title></head><body><h2>$msg</h2></body></html>" \
404
}
rivet {
headers type "text/html; charset=UTF-8"
headers numeric 404
puts "<html><head><title>Webservice Error</title></head><body><h2>$msg</h2></body></html>"
}
aolserver {
::WS::AOLserver::ReturnData \
$sock \
text/html \
"<html><head><title>Webservice Error</title></head><body><h2>$msg</h2></body></html>" \
404
}
wibble {
upvar 1 [lindex $args 0] responseDict
::WS::Wibble::ReturnData responseDict \
text/html \
"<html><head><title>Webservice Error</title></head><body><h2>$msg</h2></body></html>" \
404
}
default {
## Do nothing
}
}
return 1
}
set menuList {
{List of Operations} {#TOC}
{Operation Details} {#OperDetails}
{Simple Types} {#SimpleTypeDetails}
{Custom Types} {#CustomTypeDetails}
}
##
## Display Service General Information
##
append msg [generateGeneralInfo $serviceArr($service) $menuList]
##
## Display TOC
##
append msg [generateTocInfo $serviceArr($service) $menuList]
##
## Display Operations
##
::log::log debug "\tDisplay Operations"
append msg [generateOperationInfo $serviceArr($service) $menuList]
##
## Display custom types
##
::log::log debug "\tDisplay custom types"
append msg [generateCustomTypeInfo $serviceArr($service) $menuList]
##
## Display list of simple types
##
::log::log debug "\tDisplay list of simply types"
append msg [generateSimpleTypeInfo $serviceArr($service) $menuList]
##
## All Done
##
append msg [::html::end]
switch -exact -- $mode {
tclhttpd {
::Httpd_ReturnData $sock "text/html; charset=UTF-8" $msg 200
}
embedded {
::WS::Embeded::ReturnData $sock "text/html; charset=UTF-8" $msg 200
}
channel {
::WS::Channel::ReturnData $sock "text/html; charset=UTF-8" $msg 200
}
rivet {
headers numeric 200
headers type text/html
puts $msg
}
aolserver {
::WS::AOLserver::ReturnData $sock text/html $msg 200
}
wibble {
upvar 1 [lindex $args 0] responseDict
::WS::Wibble::ReturnData responseDict text/html $msg 200
}
default {
## Do nothing
}
}
}
###########################################################################
#
# Private Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PRIVATE<<
#
# Procedure Name : ::WS::Server::displayType
#
# Description : Formats the type, including a link to a complex type.
#
# Arguments :
# serviceName - The name of the service
# type - The type
#
# Returns : Formatted type information.
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PRIVATE<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Server::displayType {serviceName type} {
set testType [string trimright $type {()}]
if {([lindex [::WS::Utils::TypeInfo Server $serviceName $testType] 0] == 0) &&
([info exists ::WS::Utils::simpleTypes($testType)])} {
set result $type
} else {
set result [format {<a href="#type_%1$s">%2$s</a>} $testType $type]
}
return $result
}
###########################################################################
#
# Private Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PRIVATE<<
#
# Procedure Name : ::WS::Server::callOperation
#
# Description : Process the call to an operation. If an error occurs, a standard
# error packet is sent, otherwise the appropriate message type
# is sent.
#
# Arguments :
# serviceName - The name of the service
# sock - The socket to return the WSDL on
# args - not used
#
# Returns :
# 1 - On error
# 0 - On success
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PRIVATE<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Server::callOperation {service sock args} {
variable procInfo
variable serviceArr
variable mode
switch -exact -- $mode {
embedded {
upvar #0 ::WS::Embeded::Httpd$sock data
set inXML $data(query)
#parray data
}
wibble {
set requestDict [lindex $args 0]
upvar 1 [lindex $args 1] responseDict
set inXML [dict get $requestDict post xml ""]
}
default {
upvar #0 Httpd$sock data
set inXML $data(query)
}
}
::log::log debug "In ::WS::Server::callOperation {$service $sock $args}"
array set serviceInfo $serviceArr($service)
::log::log debug "\tDocument is {$inXML}"
set ::errorInfo {}
set ::errorCode {}
set ns $service
set inTransform $serviceInfo(-intransform)
set outTransform $serviceInfo(-outtransform)
set first [string first {<} $inXML]
if {$first > 0} {
set inXML [string range $inXML $first end]
}
if {![string equal $inTransform {}]} {
set inXML [$inTransform REQUEST $inXML]
}
dom parse $inXML doc
$doc documentElement top
::log::log debug [list $doc selectNodesNamespaces \
[list ENV http://schemas.xmlsoap.org/soap/envelope/ \
$service http://$serviceInfo(-host)$serviceInfo(-prefix)]]
$doc selectNodesNamespaces \
[list ENV http://schemas.xmlsoap.org/soap/envelope/ \
$service http://$serviceInfo(-host)$serviceInfo(-prefix)]
$doc documentElement rootNode
##
## Determine the name of the method being invoked.
##
set top [$rootNode selectNodes /ENV:Envelope/ENV:Body/*]
catch {$top localName} requestMessage
set legacyRpcMode 0
if {$requestMessage == ""} {
# older RPC/Encoded clients need to try nodeName instead.
# Python pySoap needs this.
catch {$top nodeName} requestMessage
set legacyRpcMode 1
}
::log::log debug "requestMessage = {$requestMessage}"
if {[string match {*Request} $requestMessage]} {
set operation [string range $requestMessage 0 end-7]
} else {
# broken clients might not have sent the correct Document Wrapped name.
# Python pySoap and Perl SOAP::Lite need this.
set operation $requestMessage
set legacyRpcMode 1
}
##
## Check that the method exists.
##
if {![dict exists $procInfo $service op$operation argList]} {
set msg "Method $operation not found"
::log::log error $msg
set ::errorInfo {}
set ::errorCode [list Server UNKNOWN_METHOD $operation]
set xml [generateError \
$serviceInfo(-traceEnabled) \
CLIENT \
$msg \
[list "errorCode" $::errorCode "stackTrace" $::errorInfo]]
catch {$doc delete}
::log::log debug "Leaving @ error 1::WS::Server::callOperation $xml"
switch -exact -- $mode {
tclhttpd {
::Httpd_ReturnData $sock "text/xml; charset=UTF-8" $xml 500
}
embedded {
::WS::Embeded::ReturnData $sock "text/xml; charset=UTF-8" $xml 500
}
rivet {
headers type text/xml
headers numeric 500
puts $xml
}
aolserver {
::WS::AOLserver::ReturnData $sock text/xml $xml 500
}
wibble {
::WS::Wibble::ReturnData responseDict text/xml $xml 500
}
default {
## Do nothing
}
}
return;
}
set baseName $operation
set cmdName op$baseName
set methodName "${ns}::$baseName"
##
## Parse the arguments for the method.
##
set argInfo [dict get $procInfo $ns $cmdName argList]
if {[catch {
foreach pass [list 1 2 3] {
set tclArgList {}
set gotAnyArgs 0
set argIndex 0
foreach argName [dict get $procInfo $ns $cmdName argOrder] {
set argType [string trim [dict get $argInfo $argName type]]
set typeInfoList [::WS::Utils::TypeInfo Server $service $argType]
if {$pass == 1} {
# access arguments by name using full namespace
set path $service:$argName
set node [$top selectNodes $path]
} elseif {$pass == 2} {
# legacyRpcMode only, access arguments by unqualified name
set path $argName
set node [$top selectNodes $path]
} else {
# legacyRpcMode only, access arguments by index
set path "legacy argument index $argIndex"
set node [lindex [$top childNodes] $argIndex]
incr argIndex
}
if {[string equal $node {}]} {
::log::log debug "did not find argument for $argName using $path, leaving blank"
lappend tclArgList {}
continue
}
::log::log debug "found argument $argName using $path, processing $node"
set gotAnyArgs 1
switch -exact -- $typeInfoList {
{0 0} {
##
## Simple non-array
##
lappend tclArgList [$node asText]
}
{0 1} {
##
## Simple array
##
set tmp {}
foreach row $node {
lappend tmp [$row asText]
}
lappend tclArgList $tmp
}
{1 0} {
##
## Non-simple non-array
##
lappend tclArgList [::WS::Utils::convertTypeToDict Server $service $node $argType $top]
}
{1 1} {
##
## Non-simple array
##
set tmp {}
set argType [string trimright $argType {()}]
foreach row $node {
lappend tmp [::WS::Utils::convertTypeToDict Server $service $row $argType $top]
}
lappend tclArgList $tmp
}
default {
## Do nothing
}
}
}
::log::log debug "gotAnyArgs $gotAnyArgs, legacyRpcMode $legacyRpcMode"
if {$gotAnyArgs || !$legacyRpcMode} break
}
::log::log debug "finalargs $tclArgList"
} errMsg]} {
::log::log error $errMsg
set localerrorCode $::errorCode
set localerrorInfo $::errorInfo
set xml [generateError \
$serviceInfo(-traceEnabled) \
CLIENT \
"Error Parsing Arguments -- $errMsg" \
[list "errorCode" $localerrorCode "stackTrace" $localerrorInfo]]
catch {$doc delete}
::log::log debug "Leaving @ error 3::WS::Server::callOperation $xml"
switch -exact -- $mode {
tclhttpd {
::Httpd_ReturnData $sock "text/xml; charset=UTF-8" $xml 500
}
embedded {
::WS::Embeded::ReturnData $sock "text/xml; charset=UTF-8" $xml 500
}
channel {
::WS::Channel::ReturnData $sock "text/xml; charset=UTF-8" $xml 500
}
rivet {
headers type text/xml
headers numeric 500
puts $xml
}
aolserver {
::WS::AOLserver::ReturnData $sock text/xml $xml 500
}
wibble {
::WS::Wibble::ReturnData responseDict text/xml $xml 500
}
default {
## Do nothing
}
}
return;
}
##
## Run the premonitor hook, if necessary.
##
if {[info exists serviceInfo(-premonitor)] && [string length $serviceInfo(-premonitor)]} {
set precmd $serviceInfo(-premonitor)
lappend precmd PRE $service $operation $tclArgList
catch $precmd
}
##
## Convert the HTTP request headers.
##
set headerList {}
foreach headerType $serviceInfo(-inheaders) {
if {[string equal $headerType {}]} {
continue
}
foreach node [$top selectNodes data:$headerType] {
lappend headerList [::WS::Utils::convertTypeToDict Server $service $node $headerType $top]
}
}
##
## Actually execute the method.
##
if {[catch {
set cmd $serviceInfo(-checkheader)
switch -exact -- $mode {
wibble {
lappend cmd \
$ns \
$baseName \
[dict get $requestDict peerhost] \
[dict keys [dict get $requestDict header]] \
$headerList
}
embedded {
lappend cmd $ns $baseName $data(ipaddr) $data(headers) $headerList
}
default {
lappend cmd $ns $baseName $data(ipaddr) $data(headerlist) $headerList
}
}
eval $cmd
set results [eval \$methodName $tclArgList]
# generate a reply packet
set xml [generateReply $ns $baseName $results]
# regsub "<!DOCTYPE\[^>\]+>\n" $xml {} xml
catch {$doc delete}
set xml [string map {{<?xml version="1.0"?>} {<?xml version="1.0" encoding="utf-8"?>}} $xml]
if {![string equal $outTransform {}]} {
set xml [$outTransform REPLY $xml $operation $results]
}
if {[info exists serviceInfo(-postmonitor)] &&
[string length $serviceInfo(-postmonitor)]} {
set precmd $serviceInfo(-postmonitor)
lappend precmd POST $service $operation OK $results
catch $precmd
}
::log::log debug "Leaving ::WS::Server::callOperation $xml"
switch -exact -- $mode {
tclhttpd {
::Httpd_ReturnData $sock "text/xml; charset=UTF-8" $xml 200
}
embedded {
::WS::Embeded::ReturnData $sock "text/xml; charset=UTF-8" $xml 200
}
channel {
::WS::Channel::ReturnData $sock "text/xml; charset=UTF-8" $xml 200
}
rivet {
headers type text/xml
headers numeric 200
puts $xml
}
aolserver {
::WS::AOLserver::ReturnData $sock text/xml $xml 200
}
wibble {
::WS::Wibble::ReturnData responseDict text/xml $xml 200
}
default {
## Do nothing
}
}
} msg]} {
##
## Handle errors
##
set localerrorCode $::errorCode
set localerrorInfo $::errorInfo
if {[info exists serviceInfo(-postmonitor)] &&
[string length $serviceInfo(-postmonitor)]} {
set precmd $serviceInfo(-postmonitor)
lappend precmd POST $service $operation ERROR $msg
catch $precmd
}
set xml [generateError \
$serviceInfo(-traceEnabled) \
CLIENT \
$msg \
[list "errorCode" $localerrorCode "stackTrace" $localerrorInfo]]
catch {$doc delete}
::log::log debug "Leaving @ error 2::WS::Server::callOperation $xml"
switch -exact -- $mode {
tclhttpd {
::Httpd_ReturnData $sock "text/xml; charset=UTF-8" $xml 500
}
embedded {
::WS::Embeded::ReturnData $sock "text/xml; charset=UTF-8" $xml 500
}
channel {
::WS::Channel::ReturnData $sock "text/xml; charset=UTF-8" $xml 500
}
rivet {
headers type text/xml
headers numeric 500
puts $xml
}
aolserver {
::WS::AOLserver::ReturnData $sock text/xml $xml 500
}
wibble {
::WS::Wibble::ReturnData responseDict text/xml $xml 500
}
default {
## Do nothing
}
}
return;
}
return;
}
###########################################################################
#
# Private Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PRIVATE<<
#
# Procedure Name : ::WS::Server::generateError
#
# Description : Generate a standard error packet
#
# Arguments :
# includeTrace - Boolean indicate if the trace is to be included.
# faultcode - The code describing the error
# faultstring - The string describing the error.
# detail - Optional details of error.
#
# Returns : XML formatted standard error packet
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PRIVATE<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Server::generateError {includeTrace faultcode faultstring detail} {
::log::log debug "Entering ::WS::Server::generateError $faultcode $faultstring {$detail}"
set code [lindex $detail 1]
switch -exact -- $code {
"VersionMismatch" {
set code "SOAP-ENV:VersionMismatch"
}
"MustUnderstand" {
set code "SOAP-ENV:MustUnderstand"
}
"Client" {
set code "SOAP-ENV:Client"
}
"Server" {
set code "SOAP-ENV:Server"
}
default {
## Do nothing
}
}
dom createDocument "SOAP-ENV:Envelope" doc
$doc documentElement env
$env setAttribute \
"xmlns:SOAP-ENV" "http://schemas.xmlsoap.org/soap/envelope/" \
"xmlns:xsi" "http://www.w3.org/1999/XMLSchema-instance" \
"xmlns:xsd" "http://www.w3.org/1999/XMLSchema" \
"xmlns:SOAP-ENC" "http://schemas.xmlsoap.org/soap/encoding/"
$env appendChild [$doc createElement "SOAP-ENV:Body" bod]
$bod appendChild [$doc createElement "SOAP-ENV:Fault" flt]
$flt appendChild [$doc createElement "SOAP-ENV:faultcode" fcd]
$fcd appendChild [$doc createTextNode $faultcode]
$flt appendChild [$doc createElement "SOAP-ENV:faultstring" fst]
$fst appendChild [$doc createTextNode $faultstring]
if { $detail != {} } {
$flt appendChild [$doc createElement "SOAP-ENV:detail" dtl0]
$dtl0 appendChild [$doc createElement "e:errorInfo" dtl]
$dtl setAttribute "xmlns:e" "urn:TclErrorInfo"
foreach {detailName detailInfo} $detail {
if {!$includeTrace && $detailName == "stackTrace"} {
continue
}
$dtl appendChild [$doc createElement $detailName err]
$err appendChild [$doc createTextNode $detailInfo]
}
}
# serialize the DOM document and return the XML text
append xml \
{<?xml version="1.0" encoding="utf-8"?>} \
"\n" \
[$doc asXML -indent none -doctypeDeclaration 0]
$doc delete
::log::log debug "Leaving (error) ::WS::Server::generateError $xml"
return $xml
}
###########################################################################
#
# Private Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PRIVATE<<
#
# Procedure Name : :WS::Server::generateReply
#
# Description : Generate the reply packet for an operation
#
# Arguments :
# serviceName - The name of the service
# operation - The name of the operation
# results - The results as a dictionary object
#
#
# Returns : The results as an XML formatted packet.
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PRIVATE<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Server::generateReply {serviceName operation results} {
::log::log debug "Entering ::WS::Server::generateReply $serviceName $operation {$results}"
variable serviceArr
array set serviceData $serviceArr($serviceName)
if {[info exists ::Config(docRoot)] && [file exists [file join $::Config(docRoot) $serviceName $operation.css]]} {
set replaceText [format {<?xml-stylesheet type="text/xsl" href="http://%s/css/%s/%s.css"?>}\
$serviceData(-host) \
$serviceName \
$operation]
append replaceText "\n"
} else {
set replaceText {}
}
dom createDocument "SOAP-ENV:Envelope" doc
$doc documentElement env
$env setAttribute \
"xmlns:SOAP-ENV" "http://schemas.xmlsoap.org/soap/envelope/" \
"xmlns:xsi" "http://www.w3.org/1999/XMLSchema-instance" \
"xmlns:xsd" "http://www.w3.org/1999/XMLSchema" \
"xmlns:SOAP-ENC" "http://schemas.xmlsoap.org/soap/encoding/" \
xmlns:$serviceName "http://$serviceData(-host)$serviceData(-prefix)"
if {[llength $serviceData(-outheaders)]} {
$env appendChild [$doc createElement "SOAP-ENV:Header" header]
foreach headerType $serviceData(-outheaders) {
#$header appendChild [$doc createElement ${serviceName}:${headerType} part]
#::WS::Utils::convertDictToType Server $serviceName $doc $part $results $headerType
::WS::Utils::convertDictToType Server $serviceName $doc $header $results $headerType
}
}
$env appendChild [$doc createElement "SOAP-ENV:Body" body]
$body appendChild [$doc createElement ${serviceName}:${operation}Results reply]
::WS::Utils::convertDictToType Server $serviceName $doc $reply $results ${serviceName}:${operation}Results
append xml \
{<?xml version="1.0" encoding="utf-8"?>} \
"\n" \
[$doc asXML -indent none -doctypeDeclaration 0]
#regsub "<!DOCTYPE\[^>\]*>\n" [::dom::DOMImplementation serialize $doc] $replaceText xml
$doc delete
::log::log debug "Leaving ::WS::Server::generateReply $xml"
return $xml
}
###########################################################################
#
# Private Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PRIVATE<<
#
# Procedure Name : :WS::Server::ok
#
# Description : Stub for header check
#
# Arguments :
# serviceName - The name of the service
# operation - The name of the operation
# results - The results as a dictionary object
#
#
# Returns : The results as an XML formatted packet.
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PRIVATE<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Server::ok {args} {
return;
}
###########################################################################
#
# Private Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PRIVATE<<
#
# Procedure Name : ::WS::Server::generateInfo
#
# Description : Generate an HTML description of the service, the operations
# and all applicable type definitions.
#
# Arguments :
# serviceName - The name of the service
# sock - The socket to return the WSDL on
# args - not used
#
# Returns :
# 1 - On error
# 0 - On success
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PRIVATE<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Server::generateGeneralInfo {serviceInfo menuList} {
variable procInfo
::log::log debug "\tDisplay Service General Information"
array set serviceData $serviceInfo
set service [dict get $serviceInfo -service]
::html::init
::html::author $serviceData(-author)
if {[string equal $serviceData(-description) {}]} {
::html::description "Automatically generated human readable documentation for '$service'"
} else {
::html::description $serviceData(-description)
}
if {$serviceData(-stylesheet) != ""} {
::html::headTag "link rel=\"stylesheet\" type=\"text/css\" href=\"$serviceData(-stylesheet)\""
}
set head $serviceData(-htmlhead)
set msg [::html::head $head]
append msg [::html::bodyTag]
array unset serviceData -service
if {[info exists serviceData(-description)]} {
set serviceData(-description) [::html::nl2br $serviceData(-description)]
}
set wsdl [format {<a href="%s/%s">WSDL(xml)</a>} $serviceData(-prefix) wsdl]
append msg [::html::openTag center] [::html::h1 "$head -- $wsdl"] [::html::closeTag] \
[::html::openTag table {border="2"}]
foreach key [lsort -dictionary [array names serviceData]] {
if {[string equal $serviceData($key) {}]} {
append msg [::html::row [string range $key 1 end] {<i>N/A</i>}]
} else {
append msg [::html::row [string range $key 1 end] $serviceData($key)]
}
}
append msg [::html::closeTag] \
"\n<hr/>\n"
return $msg
}
###########################################################################
#
# Private Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PRIVATE<<
#
# Procedure Name : ::WS::Server::generateInfo
#
# Description : Generate an HTML description of the service, the operations
# and all applicable type definitions.
#
# Arguments :
# serviceName - The name of the service
# sock - The socket to return the WSDL on
# args - not used
#
# Returns :
# 1 - On error
# 0 - On success
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PRIVATE<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Server::generateTocInfo {serviceInfo menuList} {
variable procInfo
##
## Display TOC
##
::log::log debug "\tTOC"
set service [dict get $serviceInfo -service]
append msg [::html::h2 {<a id='TOC'>List of Operations</a>}]
set operList {}
foreach oper [lsort -dictionary [dict get $procInfo $service operationList]] {
lappend operList $oper "#op_$oper"
}
append msg [::html::minorList $operList]
append msg "\n<br/>\n<center>" [::html::minorMenu $menuList] "</center>"
append msg "\n<hr/>\n"
return $msg
}
###########################################################################
#
# Private Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PRIVATE<<
#
# Procedure Name : ::WS::Server::generateInfo
#
# Description : Generate an HTML description of the service, the operations
# and all applicable type definitions.
#
# Arguments :
# serviceName - The name of the service
# sock - The socket to return the WSDL on
# args - not used
#
# Returns :
# 1 - On error
# 0 - On success
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PRIVATE<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Server::generateOperationInfo {serviceInfo menuList} {
variable procInfo
##
## Display Operations
##
::log::log debug "\tDisplay Operations"
set service [dict get $serviceInfo -service]
set operList {}
foreach oper [lsort -dictionary [dict get $procInfo $service operationList]] {
lappend operList $oper "#op_$oper"
}
append msg [::html::h2 {<a id='OperDetails'>Operation Details</a>}]
set docFormat [dict get $serviceInfo -docFormat]
foreach {oper anchor} $operList {
::log::log debug "\t\tDisplaying '$oper'"
append msg [::html::h3 "<a id='op_$oper'>$oper</a>"]
append msg [::html::h4 {Description}] "\n"
append msg [::html::openTag div {style="margin-left: 40px;"}]
switch -exact -- $docFormat {
"html" {
append msg [dict get $procInfo $service op$oper docs]
}
"text" -
default {
append msg [::html::nl2br [::html::html_entities [dict get $procInfo $service op$oper docs]]]
}
}
append msg [::html::closeTag]
append msg "\n"
append msg [::html::h4 {Inputs}] "\n"
append msg [::html::openTag div {style="margin-left: 40px;"}]
append msg [::html::openTag {table} {border="2"}]
append msg [::html::hdrRow Name Type Description]
foreach arg [dict get $procInfo $service op$oper argOrder] {
::log::log debug "\t\t\tDisplaying '$arg'"
if {[dict exists $procInfo $service op$oper argList $arg comment]} {
set comment [dict get $procInfo $service op$oper argList $arg comment]
} else {
set comment {}
}
append msg [::html::row \
$arg \
[displayType $service [dict get $procInfo $service op$oper argList $arg type]] \
$comment \
]
}
append msg [::html::closeTag]
append msg [::html::closeTag]
::log::log debug "\t\tReturns"
append msg [::html::h4 {Returns}] "\n"
append msg [::html::openTag div {style="margin-left: 40px;"}]
append msg [::html::openTag {table} {border="2"}]
append msg [::html::hdrRow Type Description]
if {[dict exists $procInfo $service op$oper returnInfo comment]} {
set comment [dict get $procInfo $service op$oper returnInfo comment]
} else {
set comment {}
}
append msg [::html::row \
[displayType $service [dict get $procInfo $service op$oper returnInfo type]] \
$comment \
]
append msg [::html::closeTag]
append msg [::html::closeTag]
append msg "\n<br/>\n<center>" [::html::minorMenu $menuList] "</center>"
append msg "\n<hr/>\n"
}
if {![llength $operList]} {
append msg "\n<br/>\n<center>" [::html::minorMenu $menuList] "</center>"
append msg "\n<hr/>\n"
}
return $msg
}
###########################################################################
#
# Private Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PRIVATE<<
#
# Procedure Name : ::WS::Server::generateInfo
#
# Description : Generate an HTML description of the service, the operations
# and all applicable type definitions.
#
# Arguments :
# serviceName - The name of the service
# sock - The socket to return the WSDL on
# args - not used
#
# Returns :
# 1 - On error
# 0 - On success
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PRIVATE<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Server::generateCustomTypeInfo {serviceInfo menuList} {
variable procInfo
##
## Display custom types
##
::log::log debug "\tDisplay custom types"
set service [dict get $serviceInfo -service]
append msg [::html::h2 {<a id='CustomTypeDetails'>Custom Types</a>}]
set localTypeInfo [::WS::Utils::GetServiceTypeDef Server $service]
foreach type [lsort -dictionary [dict keys $localTypeInfo]] {
::log::log debug "\t\tDisplaying '$type'"
set typeOverloadArray($type) 1
append msg [::html::h3 "<a id='type_$type'>$type</a>"]
set typeDetails [dict get $localTypeInfo $type definition]
append msg [::html::openTag {table} {border="2"}]
append msg [::html::hdrRow Field Type]
foreach part [lsort -dictionary [dict keys $typeDetails]] {
::log::log debug "\t\t\tDisplaying '$part'"
append msg [::html::row \
$part \
[displayType $service [dict get $typeDetails $part type]]
]
}
append msg [::html::closeTag]
}
append msg "\n<br/>\n<center>" [::html::minorMenu $menuList] "</center>"
append msg "\n<hr/>\n"
return $msg
}
###########################################################################
#
# Private Procedure Header - as this procedure is modified, please be sure
# that you update this header block. Thanks.
#
#>>BEGIN PRIVATE<<
#
# Procedure Name : ::WS::Server::generateInfo
#
# Description : Generate an HTML description of the service, the operations
# and all applicable type definitions.
#
# Arguments :
# serviceName - The name of the service
# sock - The socket to return the WSDL on
# args - not used
#
# Returns :
# 1 - On error
# 0 - On success
#
# Side-Effects : None
#
# Exception Conditions : None
#
# Pre-requisite Conditions : None
#
# Original Author : Gerald W. Lester
#
#>>END PRIVATE<<
#
# Maintenance History - as this file is modified, please be sure that you
# update this segment of the file header block by
# adding a complete entry at the bottom of the list.
#
# Version Date Programmer Comments / Changes / Reasons
# ------- ---------- ---------- -------------------------------------------
# 1 07/06/2006 G.Lester Initial version
#
#
###########################################################################
proc ::WS::Server::generateSimpleTypeInfo {serviceInfo menuList} {
variable procInfo
##
## Display list of simple types
##
::log::log debug "\tDisplay list of simply types"
set service [dict get $serviceInfo -service]
append msg [::html::h2 {<a id='SimpleTypeDetails'>Simple Types</a>}]
append msg "\n<br/>\n<center>" [::html::minorMenu $menuList] "</center>"
set localTypeInfo [::WS::Utils::GetServiceSimpleTypeDef Server $service]
foreach typeDetails [lsort -dictionary -index 0 $localTypeInfo] {
set type [lindex $typeDetails 0]
::log::log debug "\t\tDisplaying '$type'"
set typeOverloadArray($type) 1
append msg [::html::h3 "<a id='type_$type'>$type</a>"]
append msg [::html::openTag {table} {border="2"}]
append msg [::html::hdrRow Attribute Value]
foreach part [lsort -dictionary [dict keys [lindex $typeDetails 1]]] {
::log::log debug "\t\t\tDisplaying '$part'"
append msg [::html::row \
$part \
[dict get [lindex $typeDetails 1] $part]
]
}
append msg [::html::closeTag]
}
append msg "\n<hr/>\n"
return $msg
}
|