demo_wsclient_productorservice.php-NORUN 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/webservices/demo_wsclient_productorservice.php
  19. * \brief Demo page to make a client call to Dolibarr WebServices "server_product"
  20. */
  21. // This is to make Dolibarr working with Plesk
  22. set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
  23. require_once '../master.inc.php';
  24. require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
  25. $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_productorservice.php';
  26. //$WS_DOL_URL = 'http://localhost:8080/'; // To test with Soapui mock. If not a page, should end with /
  27. $WS_METHOD1 = 'createProductOrService';
  28. $WS_METHOD2 = 'getProductOrService';
  29. $WS_METHOD3 = 'getListOfProductsOrServices';
  30. $ns='http://www.dolibarr.org/ns/';
  31. // Set the WebService URL
  32. dol_syslog("Create nusoap_client for URL=".$WS_DOL_URL);
  33. $soapclient1 = new nusoap_client($WS_DOL_URL);
  34. if ($soapclient1)
  35. {
  36. $soapclient1->soap_defencoding='UTF-8';
  37. $soapclient1->decodeUTF8(false);
  38. }
  39. $soapclient2 = new nusoap_client($WS_DOL_URL);
  40. if ($soapclient2)
  41. {
  42. $soapclient2->soap_defencoding='UTF-8';
  43. $soapclient2->decodeUTF8(false);
  44. }
  45. $soapclient3 = new nusoap_client($WS_DOL_URL);
  46. if ($soapclient3)
  47. {
  48. $soapclient3->soap_defencoding='UTF-8';
  49. $soapclient3->decodeUTF8(false);
  50. }
  51. // Call the WebService method and store its result in $result.
  52. $authentication=array(
  53. 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
  54. 'sourceapplication'=>'DEMO',
  55. 'login'=>'admin',
  56. 'password'=>'changeme',
  57. 'entity'=>'');
  58. // Test url 1
  59. if ($WS_METHOD1)
  60. {
  61. $parameters = array('authentication'=>$authentication,'id'=>1,'ref'=>'');
  62. dol_syslog("Call method ".$WS_METHOD1);
  63. $result1 = $soapclient1->call($WS_METHOD1,$parameters,$ns,'');
  64. if (! $result1)
  65. {
  66. print $soapclient1->error_str;
  67. print "<br>\n\n";
  68. print $soapclient1->request;
  69. print "<br>\n\n";
  70. print $soapclient1->response;
  71. exit;
  72. }
  73. }
  74. // Test url 2
  75. if ($WS_METHOD2)
  76. {
  77. $parameters = array('authentication'=>$authentication,'id'=>1,'ref'=>'');
  78. dol_syslog("Call method ".$WS_METHOD2);
  79. $result2 = $soapclient2->call($WS_METHOD2,$parameters,$ns,'');
  80. if (! $result2)
  81. {
  82. print $soapclient2->error_str;
  83. print "<br>\n\n";
  84. print $soapclient2->request;
  85. print "<br>\n\n";
  86. print $soapclient2->response;
  87. exit;
  88. }
  89. }
  90. // Test url 3
  91. if ($WS_METHOD3)
  92. {
  93. $parameters = array('authentication'=>$authentication,'filterproduct'=>array('type'=>-1));
  94. dol_syslog("Call method ".$WS_METHOD3);
  95. $result3 = $soapclient3->call($WS_METHOD3,$parameters,$ns,'');
  96. if (! $result3)
  97. {
  98. print $soapclient3->error_str;
  99. print "<br>\n\n";
  100. print $soapclient3->request;
  101. print "<br>\n\n";
  102. print $soapclient3->response;
  103. exit;
  104. }
  105. }
  106. /*
  107. * View
  108. */
  109. header("Content-type: text/html; charset=utf8");
  110. print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'."\n";
  111. echo '<html>'."\n";
  112. echo '<head>';
  113. echo '<title>WebService Test: '.$WS_METHOD1.'</title>';
  114. echo '</head>'."\n";
  115. echo '<body>'."\n";
  116. echo 'NUSOAP_PATH='.NUSOAP_PATH.'<br>';
  117. echo "<h2>Request:</h2>";
  118. echo '<h4>Function</h4>';
  119. echo $WS_METHOD1;
  120. echo '<h4>SOAP Message</h4>';
  121. echo '<pre>' . htmlspecialchars($soapclient1->request, ENT_QUOTES) . '</pre>';
  122. //echo '<hr>';
  123. echo "<h2>Response:</h2>";
  124. echo '<h4>Result</h4>';
  125. echo '<pre>';
  126. print_r($result1);
  127. echo '</pre>';
  128. echo '<h4>SOAP Message</h4>';
  129. echo '<pre>' . htmlspecialchars($soapclient1->response, ENT_QUOTES) . '</pre>';
  130. print '<hr>';
  131. echo "<h2>Request:</h2>";
  132. echo '<h4>Function</h4>';
  133. echo $WS_METHOD2;
  134. echo '<h4>SOAP Message</h4>';
  135. echo '<pre>' . htmlspecialchars($soapclient2->request, ENT_QUOTES) . '</pre>';
  136. //echo '<hr>';
  137. echo "<h2>Response:</h2>";
  138. echo '<h4>Result</h4>';
  139. echo '<pre>';
  140. print_r($result2);
  141. echo '</pre>';
  142. echo '<h4>SOAP Message</h4>';
  143. echo '<pre>' . htmlspecialchars($soapclient2->response, ENT_QUOTES) . '</pre>';
  144. print '<hr>';
  145. echo "<h2>Request:</h2>";
  146. echo '<h4>Function</h4>';
  147. echo $WS_METHOD3;
  148. echo '<h4>SOAP Message</h4>';
  149. echo '<pre>' . htmlspecialchars($soapclient3->request, ENT_QUOTES) . '</pre>';
  150. //echo '<hr>';
  151. echo "<h2>Response:</h2>";
  152. echo '<h4>Result</h4>';
  153. echo '<pre>';
  154. print_r($result3);
  155. echo '</pre>';
  156. echo '<h4>SOAP Message</h4>';
  157. echo '<pre>' . htmlspecialchars($soapclient3->response, ENT_QUOTES) . '</pre>';
  158. echo '</body>'."\n";
  159. echo '</html>'."\n";
  160. ?>