demo_wsclient_project.php-NORUN 4.3 KB

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