UDDI
[ class tree: UDDI ] [ index: UDDI ] [ all elements ]

Source for file UDDI.php

Documentation is available at UDDI.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | UDDI: A PHP class library implementing the Universal Description, |
  5. // | Discovery and Integration API for locating and publishing Web |
  6. // | Services listings in a UBR (UDDI Business Registry) |
  7. // +----------------------------------------------------------------------+
  8. // | This library is free software; you can redistribute it and/or |
  9. // | modify it under the terms of the GNU Lesser General Public |
  10. // | License as published by the Free Software Foundation; either |
  11. // | version 2.1 of the License, or (at your option) any later version. |
  12. // | |
  13. // | This library is distributed in the hope that it will be useful, |
  14. // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  15. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
  16. // | General Public License for more details. |
  17. // | |
  18. // | You should have received a copy of the GNU General Public License |
  19. // | along with this library; if not, write to the Free Software |
  20. // | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, |
  21. // | USA, or visit http://www.gnu.org/copyleft/gpl.html |
  22. // +----------------------------------------------------------------------+
  23. // | Authors: Jon Stephens & Lee Reynolds (authors of non-PEAR version) |
  24. // | Maintainers and PEARifiers: |
  25. // | Christian Wenz <chw@hauser-wenz.de> |
  26. // | Tobias Hauser <th@hauser-wenz.de> |
  27. // +----------------------------------------------------------------------+
  28. //
  29. // $Id$
  30. /* Original Credits:
  31.  
  32. phpUDDI
  33. A PHP class library implementing the Universal Description,
  34. Discovery and Integration API for locating and publishing Web
  35. Services listings in a UBR (UDDI Business Registry).
  36.  
  37. Copyright (C) 2002-2004 Lee Reynolds and Jon Stephens
  38.  
  39. This program is free software; you can redistribute it and/or
  40. modify it under the terms of the GNU General Public License
  41. as published by the Free Software Foundation; either version 2
  42. of the License, or (at your option) any later version.
  43.  
  44. This program is distributed in the hope that it will be useful,
  45. but WITHOUT ANY WARRANTY; without even the implied warranty of
  46. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  47. GNU General Public License for more details.
  48.  
  49. You should have received a copy of the GNU General Public License
  50. along with this program; if not, write to the Free Software
  51. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  52. or point your web browser to http://www.gnu.org/licenses/lgpl.html.
  53.  
  54. Conceived and developed in conjunction with the
  55. authors' work for the book "PHP Web Services" from Wrox Press
  56. Ltd. (ISBN-1861008074)
  57.  
  58. Original developers:
  59. Lee Reynolds lee@annasart.com
  60. Jon Stephens jon@hiveminds.info
  61.  
  62. Useful Links:
  63.  
  64. Wrox Press "Programmer To Programmer" Discussion Groups
  65. Pro PHP: http://p2p.wrox.com/list.asp?list=pro_php
  66. Pro XML: http://p2p.wrox.com/list.asp?list=xml
  67.  
  68. HiveMinds Group
  69. http://www.hiveminds.info/
  70. http://forums.hiveminds.info/
  71.  
  72. Version History:
  73.  
  74. 0.1 -- 15 November 2002 -- Basic Proof of concept
  75. 0.2 -- 20 November 2002 -- Base class redefinition to
  76. include public and private methods
  77. 0.3 -- 25 November 2002 -- All UDDI 2.0 Inquiry APIs implemented
  78. 0.3.1 -- 14 March 2004 -- small bugfixes (Christian); license change to LPGL (Lee, Jon)
  79.  
  80. Objective for 1.0 release is complete implementation of the UDDI 2.0 API
  81. (http://www.uddi.org/pubs/ProgrammersAPI-V2.04-Published-20020719.pdf).
  82.  
  83. Objective for 1.5 release is backwards compatibility with UDDI 1.0.
  84.  
  85. Objective for 2.0 release is complete implementation of the UDDI 3.0 API
  86. (http://www.uddi.org/pubs/uddi-v3.00-published-20020719.pdf).
  87.  
  88. */
  89.  
  90. require_once "PEAR.php";
  91.  
  92. /**
  93. * PEAR::UDDI
  94. * class that implements the UDDI API
  95. * @link http://www.uddi.org/
  96. *
  97. * pearified version of phpUDDI by Stephens & Reynolds
  98. *
  99. *
  100. * @category Web Services
  101. * @package UDDI
  102. * @version 0.2.0alpha1
  103. * @author Christian Wenz <chw@hauser-wenz.de>
  104. * @author Tobias Hauser <th@hauser-wenz.de>
  105. * @todo fully implement UDDI 2.0 (and later 1.0, 3.0)
  106. * @todo more helper functions (for analyzing the data returned by querying a UBR)
  107. * @todo maybe use more PEAR classes, especially for handling of HTTP requests (but that would make maintaining the PEAR-less version harder)
  108. Name:
  109. UDDI.php - UDDI Registry access library (PEARified version)
  110. Synopsis:
  111. require_once 'UDDI.php';
  112. Currently, UDDI_base supports 1 function call in one UDDI Api.
  113. Variables supported:
  114. $UDDI::_api
  115. currently 2 values are supported, and they represent 2 of the 6 published APIs by UDDI.org.
  116. 'Inquiry' which represents the search and _query API
  117. 'Publish' which represents the publishing API
  118. Usage:
  119. <code>
  120. $UDDI::_api = 'Inquiry'; // (default)
  121. $UDDI::_api = 'Publish';
  122. </code>
  123. $UDDI::_uddiversion
  124. This is the API version of the UPI spec you want to use
  125. Values are either 1, 2, or 3.
  126. Usage:
  127. <code>
  128. $UDDI::_uddiversion = 2;
  129. </code>
  130. Default:
  131. currently, the version default is '1';
  132. Note: As stated above, we are aiming for a 1.0 release of this library which implements
  133. the UDDI 2.0 Programming API; we cannot guarantee at this time that any of the API functions
  134. as implemented here will work correctly (or at all) unless you set the version to 2 as shown
  135. under 'Usage' immediately above or by setting the version when you call the UDDI class constructor:
  136. <code>
  137. $my_uddi = new UDDI("Microsoft", 2);
  138. </code>
  139. At a later date we will make this class compatible with UDDI Versions 1.0 and 3.0.
  140. $UDDI::_regarray
  141. We currently support 2 test registry entries. These are 'IBM' and 'Microsoft'.
  142. We also support 2 API interfaces.. These are, as noted above 'Inquiry', and 'Publish'.
  143. To add live registry entries, or your own test registry, you must append a multiple index array element
  144. to $UDDI::_regarray. The form for this follows:
  145. <code>
  146. array('registry name' =>
  147. array('Inquiry' =>
  148. array('url' =>'url_for_inquiry',
  149. 'port' => 80),
  150. 'Publish' =>
  151. array('url' => 'url_for_publish',
  152. 'port' => 443)));
  153. </code>
  154. Internally this is accessed as
  155. <code>URL = $_regarray['registry_name']['Inquiry']['url']</code>
  156. , and
  157. <code>port = $_regarray['registry_name']['Inquiry']['port']</code>
  158. PLEASE NOTE: You're adding elements to this array, instead of overwriting old ones.
  159. Usage:
  160. <code>
  161. $UDDI::_regarray = array('private' =>
  162. array('Inquiry' =>
  163. array('url' =>'url_for_inquiry',
  164. 'port' => 80),
  165. 'Publish' =>
  166. array('url' => 'url_for_publishing',
  167. 'port' => 443)));
  168. </code>
  169. $UDDI::_xmlns
  170. You can modify the XML namespace by reassigning a value to this
  171. Usage:
  172. <code>
  173. $UDDI::_xmlns = 'new_ns_definition';
  174. </code>
  175. Default:
  176. "urn:uddi-org:api"
  177. $UDDI::_debug
  178. Turns on debugging by echoing HTTP headers and UDDI queries.
  179. Usage:
  180. <code>
  181. $UDDI::_debug = TRUE;
  182. </code>
  183. Default:
  184. FALSE
  185. $UDDI::_transmit
  186. Turns on _posting of UDDI message to UBR.
  187. Usage:
  188. <code>
  189. $UDDI::_transmit = FALSE;
  190. </code>
  191. Default:
  192. TRUE;
  193. EXAMPLE:
  194. This queries IBM's UDDI Registry for the first 50 businesses whose names include
  195. the word "Acme", matches sorted first in ascending order by name, then in descending
  196. order by date last updated. The raw XML that's returned is escaped and echoed to the page.
  197. <code>
  198. $my_uddi = new UDDI("IBM", 1);
  199. $result = htmlspecialchars( $my_uddi->find_business(array("name"=>"%Acme%", "maxRows"=>50, "findQualifiers"=>"sortByNameAsc,sortByDateAsc") ) );
  200. echo "<pre>$result</pre>"
  201. </code>
  202. */
  203.  
  204. /**
  205. * version of corresponding phpUDDI version
  206. * still included so that moving from phpUDDI to PEAR::UDDI is easier
  207. */
  208.  
  209. define("UDDI_PHP_LIB_VERSION", "0.3.1p"); //suffix p = PEAR :-)
  210.  
  211. /**
  212. * UDDI
  213. *
  214. * class that implements the UDDI API
  215. *
  216. * @package UDDI
  217. * @author Christian Wenz <chw@hauser-wenz.de>
  218. * @author Tobias Hauser <th@hauser-wenz.de>
  219. */
  220. class UDDI extends PEAR
  221. {
  222. /**
  223. * version of package
  224. * @var string $_version
  225. */
  226. var $_version = "0.2.0alpha1";
  227.  
  228. /**
  229. * list of known registries
  230. * @var array $regarray
  231. */
  232.  
  233. var $_regarray =
  234. array('IBM' =>
  235. array('Inquiry' =>
  236. array('url' => "www-3.ibm.com/services/uddi/testregistry/inquiryapi",
  237. 'port' => 80),
  238. 'Publish' =>
  239. array('url' => "https://www-3.ibm.com/services/uddi/testregistry/protect/publishapi",
  240. 'port' => 443)),
  241.  
  242. 'Microsoft' =>
  243. array('Inquiry' =>
  244. array('url' =>"test.uddi.microsoft.com/inquire",
  245. 'port' => 80),
  246. 'Publish' =>
  247. array('url' =>"https://test.uddi.microsoft.com/publish",
  248. 'port' => 443)));
  249.  
  250.  
  251. /**
  252. * which API to use (Inquiry/Publish)
  253. * @var string $_api
  254. */
  255. var $_api = "Inquiry";
  256.  
  257. /**
  258. * used XML namespace
  259. * @var string $_xmlns
  260. */
  261. var $_xmlns = "urn:uddi-org:api";
  262.  
  263. /**
  264. * used UDDI version
  265. * @var string $_uddiversion
  266. */
  267. var $_uddiversion = 1;
  268.  
  269. /**
  270. * used XML generic version
  271. * @var string $_generic
  272. */
  273. var $_generic;
  274.  
  275. /**
  276. * debug mode
  277. * @var boolean $_debug
  278. */
  279. var $_debug = FALSE;
  280.  
  281. /**
  282. * Turns on _posting of UDDI message to UBR
  283. * @var boolean $_transmit
  284. */
  285. var $_transmit = TRUE;
  286.  
  287. /**
  288. * Host to use
  289. * @var string $_host
  290. */
  291. var $_host;
  292.  
  293. /**
  294. * URL to use
  295. * @var string $_url
  296. */
  297. var $_url;
  298.  
  299. /**
  300. * constructor
  301. *
  302. * @access public
  303. * @param string $registry name of registry to use
  304. * @param integer $version UDDI version to use
  305. */
  306. function UDDI($registry='IBM', $version=1)
  307. {
  308. $this->splitUrl($registry, $version);
  309. }
  310.  
  311. /**
  312. * retrieves information from URL and sets params
  313. *
  314. * @access public
  315. * @param string $registry name of registry to use
  316. * @param integer $version UDDI version to use
  317. */
  318. function splitUrl($registry, $version)
  319. {
  320. $this->_registry = $registry;
  321. $reg = $this->_regarray[$this->_registry][$this->_api]['url'];
  322. $reg = str_replace("http://", "", $reg);
  323. $pos = strpos($reg, '/')
  324. or PEAR::raiseError("Invalid registry POS = $pos, URL = '$reg'\n");
  325. $this->_host = substr($reg, 0, $pos);
  326. $this->_url = substr($reg, $pos, strlen($reg)-1);
  327.  
  328. if ($version>1) {
  329. $this->_xmlns .= "_v$version";
  330. }
  331.  
  332. $this->_generic = "$version.0";
  333. }
  334.  
  335. /**
  336. * assembles HTTP headers and posts these and the UDDI message to the UBR
  337. *
  338. * @access public
  339. * @param string $message the UDDI message to send
  340. * @return string $data data returned from the UBR
  341. */
  342. function post( $message )
  343. {
  344. $msg_length = strlen( $message );
  345. $php_version = phpversion();
  346. $date = str_replace( "+0000", "GMT", gmdate("r", time()) );
  347.  
  348. $header = "";
  349. $header .= "POST $this->_url HTTP/1.0\r\n";
  350. $header .= "Date: $date\r\n";
  351. $header .= "Content-Type: text/xml; charset=UTF-8\r\n";
  352. $header .= "User-agent: PEAR::UDDI/$this->_version php/$php_version\r\n";
  353. $header .= "Host: $this->_host\r\n";
  354. $header .= "SOAPAction: \"\"\r\n";
  355. $header .= "Content-Length: $msg_length\r\n\r\n";
  356.  
  357. // echoes HTTP header and UDDI message to page if true
  358. if ($this->_debug) {
  359. echo "<pre>" . htmlspecialchars( str_replace("><", ">\n<", $header . $message) ) . "</pre>";
  360. }
  361.  
  362. // sends header and message to UBR if true
  363. if ($this->_transmit) {
  364. $port = $this->_regarray[$this->_registry][$this->_api]['port'];
  365. $fp = fsockopen($this->_host, $port, $errno, $errstr, 5)
  366. or PEAR::raiseError("Couldn't connect to server at $this->_host:$port.<br />Error #$errno: $errstr.");
  367.  
  368. fputs($fp, $header)
  369. or PEAR::raiseError("Couldn't send HTTP headers.");
  370. fputs($fp, "$message\n\n")
  371. or PEAR::raiseError("Couldn't send UDDI message.");
  372.  
  373. $response = "";
  374. while (!feof($fp)) {
  375. $response .= fgets($fp, 1024)
  376. or PEAR::raiseError("No response from server.");
  377. }
  378. fclose($fp)
  379. or PEAR::raiseError("Warning: Couldn't close HTTP connection.");
  380.  
  381. $response = str_replace("><", ">\n<", $response);
  382. return $response;
  383. }
  384. }
  385.  
  386. /**
  387. * sends and UDDI query to the registry server
  388. *
  389. * @access public
  390. * @param string $method the UDDI message to send
  391. * @param array $params parameters for the query
  392. * @return string $data response from the registry server
  393. */
  394. function query($method, $params)
  395. {
  396. $message = $this->assemble($method, $params);
  397.  
  398. return $this->post( $message );
  399. }
  400.  
  401. /**
  402. * generate XML creating the UDDI query
  403. *
  404. * @access public
  405. * @param string $method the UDDI message to send
  406. * @param array $params parameters for the query
  407. * @return string $data the desired XML query code
  408. */
  409. function assemble($method, $params)
  410. {
  411. $head = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
  412. $head .= "<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">";
  413. $head .= "<Body>";
  414.  
  415. $end = "</$method></Body></Envelope>";
  416.  
  417. $attrib = "";
  418. $element = "";
  419.  
  420.  
  421. if (isset($params['discoveryURLs']) && ($params['discoveryURLs'] != '')) {
  422. $element .= "<discoveryURLs>" . $params['discoveryURLs'] . "</discoveryURLs>";
  423. }
  424.  
  425. if (isset($params['bindingKey']) && ($params['bindingKey'] != '')) {
  426. $element .= "<bindingKey>" . $params['bindingKey'] . "</bindingKey>";
  427. }
  428.  
  429. if (isset($params['businessKey']) && ($params['businessKey'] != '')) {
  430. $element .= "<businessKey>" . $params['businessKey'] . "</businessKey>";
  431. }
  432.  
  433. if (isset($params['serviceKey']) && ($params['serviceKey'] != '')) {
  434. if ($method == "find_binding") {
  435. $attrib .= " serviceKey=\"" . $params['serviceKey'] . "\"";
  436. }
  437. if ($method == "get_serviceDetail") {
  438. $element .= "<serviceKey>" . $params['serviceKey'] . "</serviceKey>";
  439. }
  440. }
  441.  
  442.  
  443. if (isset($params['tModelKey']) && ($params['tModelKey'] != '')) {
  444. $element .= "<tModelKey>uuid:" . $params['tModelKey'] . "</tModelKey>";
  445. }
  446.  
  447. if (isset($params['findQualifiers']) && ($params['findQualifiers'] != '')) {
  448. $element .= "<findQualifiers>";
  449. $findQualifiers = explode(',', $params['findQualifiers']);
  450. for ($i=0; $i<count($findQualifiers); $i++) {
  451. $element .= "<findQualifier>" . $findQualifiers[$i] . "</findQualifier>";
  452. }
  453. $element .= "</findQualifiers>";
  454. }
  455.  
  456. if (isset($params['tModelBag']) && ($params['tModelBag'] != '')) {
  457. $tModelKey = explode(',', $params['tModelBag']);
  458. $element .= "<tModelBag>";
  459. for ($i=0; $i<count($tModelKey); $i++) {
  460. $element .= "<tModelKey>uuid:" . $tModelKey[$i] . "</tModelKey>";
  461. $element .= "</tModelBag>";
  462. }
  463. }
  464.  
  465. if (isset($params['name']) && ($params['name'] != '')) {
  466. $lang = '';
  467. if (isset($params['lang']) && ($params['lang'] != '')) {
  468. $lang = "xml:lang=\"" . $lang . "\"";
  469. }
  470. $element .= "<name $lang>" . $params['name'] . "</name>";
  471. }
  472.  
  473. if (isset($params['identifierBag']) && ($params['identifierBag'] != '')) {
  474. $element .= "<identifierBag>";
  475. $keyedReference = explode(',', $params['identifierBag']);
  476. for ($i=0; $i<count( $keyedReference ); $i++) {
  477. $element .= "<keyedReference>" . $keyedReference[$i] . "</keyedReference>";
  478. }
  479. $element .= "</identifierBag>";
  480. }
  481.  
  482. if (isset($params['categoryBag']) && ($params['categoryBag'] != '')) {
  483. $element .= "<categoryBag>";
  484. $keyedReference = explode(',', $params['identifierBag']);
  485. for ($i=0; $i<count( $keyedReference ); $i++) {
  486. $element .= "<keyedReference>" . $keyedReference[$i]
  487. . "</keyedReference>";
  488. }
  489. $element .= "</categoryBag>";
  490. }
  491.  
  492. if (isset($params['maxRows']) && ($params['maxRows'] != '')) {
  493. $attrib .= " maxRows=\"" . $params['maxRows'] . "\"";
  494. }
  495.  
  496. $head .= "<$method $attrib xmlns=\"$this->_xmlns\" generic=\"$this->_generic\">";
  497.  
  498. $message = $head;
  499. $message .= $element;
  500. $message .= $end;
  501.  
  502. return $message;
  503. }
  504.  
  505. /**
  506. * Sends find_binding inquiry to UBR (searchs for bindings within a businessService element)
  507. *
  508. * @access public
  509. * @param array $params parameters for the query
  510. * @return string $data response from the registry server
  511. */
  512. function find_binding($params)
  513. {
  514. $data = $this->query("find_binding", $params);
  515. return $data;
  516. }
  517.  
  518. /**
  519. * Sends find_business inquiry to UBR (searchs businessEntity elements)
  520. *
  521. * @access public
  522. * @param array $params parameters for the query
  523. * @return string $data response from the registry server
  524. */
  525. function find_business($params)
  526. {
  527. $data = $this->query("find_business", $params);
  528. return $data;
  529. }
  530.  
  531. /**
  532. * Sends find_relatedBusinesses inquiry to UBR (searchs for related businessEntity elements for a given businessKey)
  533. *
  534. * @access public
  535. * @param array $params parameters for the query
  536. * @return string $data response from the registry server
  537. */
  538. function find_relatedBusinesses($params)
  539. {
  540. $data = $this->query("find_relatedBusinesses", $params);
  541. return $data;
  542. }
  543.  
  544. /**
  545. * Sends find_service inquiry to UBR (searchs for businessService elements)
  546. *
  547. * @access public
  548. * @param array $params parameters for the query
  549. * @return string $data response from the registry server
  550. */
  551. function find_service($params)
  552. {
  553. $data = $this->query("find_service", $params);
  554. return $data;
  555. }
  556.  
  557. /**
  558. * Sends find_tModel inquiry to UBR (searchs for tModel elements)
  559. *
  560. * @access public
  561. * @param array $params parameters for the query
  562. * @return string $data response from the registry server
  563. */
  564. function find_tModel($params)
  565. {
  566. $data = $this->query("find_tModel", $params);
  567. return $data;
  568. }
  569.  
  570. /**
  571. * Sends get_bindingDetail inquiry to UBR (returns bindingDetail elements for one or more bindingKey elements)
  572. *
  573. * @access public
  574. * @param array $params parameters for the query
  575. * @return string $data response from the registry server
  576. */
  577. function get_bindingDetail($params)
  578. {
  579. $data = $this->query("get_bindingDetail", $params);
  580. return $data;
  581. }
  582.  
  583. /**
  584. * Sends get_businessDetail inquiry to UBR (returns information about one or more businessEntity elements)
  585. *
  586. * @access public
  587. * @param array $params parameters for the query
  588. * @return string $data response from the registry server
  589. */
  590. function get_businessDetail($params)
  591. {
  592. $data = $this->query("get_businessDetail", $params);
  593. return $data;
  594. }
  595.  
  596. /**
  597. * Sends get_businessDetailExt inquiry to UBR (returns extended information about one or more businessEntity elements)
  598. *
  599. * @access public
  600. * @param array $params parameters for the query
  601. * @return string $data response from the registry server
  602. */
  603. function get_businessDetailExt($params)
  604. {
  605. $data = $this->query("get_businessDetailExt", $params);
  606. return $data;
  607. }
  608.  
  609. /**
  610. * Sends get_serviceDetail inquiry to UBR (returns information about one or more businessService elements)
  611. *
  612. * @access public
  613. * @param array $params parameters for the query
  614. * @return string $data response from the registry server
  615. */
  616. function get_serviceDetail($params)
  617. {
  618. $data = $this->query("get_serviceDetail", $params);
  619. return $data;
  620. }
  621.  
  622. /**
  623. * Sends get_tModelDetail inquiry to UBR (returns information about one or more tModel elements)
  624. *
  625. * @access public
  626. * @param array $params parameters for the query
  627. * @return string $data response from the registry server
  628. */
  629. function get_tModelDetail($params)
  630. {
  631. $data = $this->query("get_tModelDetail", $params);
  632. return $data;
  633. }
  634. }
  635. ?>

Documentation generated on Fri, 9 Apr 2004 17:18:56 +0200 by phpDocumentor 1.3.0RC2