Zend_XmlRpc_Client.xml 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.xmlrpc.client">
  4. <title>Zend_XmlRpc_Client</title>
  5. <sect2 id="zend.xmlrpc.client.introduction">
  6. <title>Introduction</title>
  7. <para>
  8. Zend Framework provides support for consuming remote <acronym>XML-RPC</acronym>
  9. services as a client in the <classname>Zend_XmlRpc_Client</classname>
  10. package. Its major features include automatic type conversion
  11. between <acronym>PHP</acronym> and <acronym>XML-RPC</acronym>, a server proxy object,
  12. and access to server introspection capabilities.
  13. </para>
  14. </sect2>
  15. <sect2 id="zend.xmlrpc.client.method-calls">
  16. <title>Method Calls</title>
  17. <para>
  18. The constructor of <classname>Zend_XmlRpc_Client</classname> receives the
  19. <acronym>URL</acronym> of the remote <acronym>XML-RPC</acronym> server endpoint as its
  20. first parameter. The new instance returned may be used to call any number of
  21. remote methods at that endpoint.
  22. </para>
  23. <para>
  24. To call a remote method with the <acronym>XML-RPC</acronym> client, instantiate it
  25. and use the <methodname>call()</methodname> instance method. The code sample
  26. below uses a demonstration <acronym>XML-RPC</acronym> server on the Zend Framework
  27. website. You can use it for testing or exploring the
  28. <classname>Zend_XmlRpc</classname> components.
  29. </para>
  30. <example id="zend.xmlrpc.client.method-calls.example-1">
  31. <title>XML-RPC Method Call</title>
  32. <programlisting language="php"><![CDATA[
  33. $client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
  34. echo $client->call('test.sayHello');
  35. // hello
  36. ]]></programlisting>
  37. </example>
  38. <para>
  39. The <acronym>XML-RPC</acronym> value returned from the remote method call will be
  40. automatically unmarshaled and cast to the equivalent <acronym>PHP</acronym> native
  41. type. In the example above, a <acronym>PHP</acronym> <type>String</type> is returned
  42. and is immediately ready to be used.
  43. </para>
  44. <para>
  45. The first parameter of the <methodname>call()</methodname> method receives the
  46. name of the remote method to call. If the remote method requires
  47. any parameters, these can be sent by supplying a second, optional
  48. parameter to <methodname>call()</methodname> with an <type>Array</type> of
  49. values to pass to the remote method:
  50. </para>
  51. <example id="zend.xmlrpc.client.method-calls.example-2">
  52. <title>XML-RPC Method Call with Parameters</title>
  53. <programlisting language="php"><![CDATA[
  54. $client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
  55. $arg1 = 1.1;
  56. $arg2 = 'foo';
  57. $result = $client->call('test.sayHello', array($arg1, $arg2));
  58. // $result is a native PHP type
  59. ]]></programlisting>
  60. </example>
  61. <para>
  62. If the remote method doesn't require parameters, this optional
  63. parameter may either be left out or an empty <methodname>array()</methodname>
  64. passed to it. The array of parameters for the remote method can
  65. contain native <acronym>PHP</acronym> types, <classname>Zend_XmlRpc_Value</classname>
  66. objects, or a mix of each.
  67. </para>
  68. <para>
  69. The <methodname>call()</methodname> method will automatically convert the
  70. <acronym>XML-RPC</acronym> response and return its equivalent <acronym>PHP</acronym>
  71. native type. A <classname>Zend_XmlRpc_Response</classname> object for the return value
  72. will also be available by calling the <methodname>getLastResponse()</methodname>
  73. method after the call.
  74. </para>
  75. </sect2>
  76. <sect2 id="zend.xmlrpc.value.parameters">
  77. <title>Types and Conversions</title>
  78. <para>
  79. Some remote method calls require parameters. These are given to
  80. the <methodname>call()</methodname> method of <classname>Zend_XmlRpc_Client</classname>
  81. as an array in the second parameter. Each parameter may be
  82. given as either a native <acronym>PHP</acronym> type which will be automatically
  83. converted, or as an object representing a specific <acronym>XML-RPC</acronym> type
  84. (one of the <classname>Zend_XmlRpc_Value</classname> objects).
  85. </para>
  86. <sect3 id="zend.xmlrpc.value.parameters.php-native">
  87. <title>PHP Native Types as Parameters</title>
  88. <para>
  89. Parameters may be passed to <methodname>call()</methodname> as native
  90. <acronym>PHP</acronym> variables, meaning as a <type>String</type>,
  91. <type>Integer</type>, <type>Float</type>,
  92. <type>Boolean</type>, <type>Array</type>, or an
  93. <type>Object</type>. In this case, each <acronym>PHP</acronym> native type will
  94. be auto-detected and converted into one of the <acronym>XML-RPC</acronym> types
  95. according to this table:
  96. </para>
  97. <table id="zend.xmlrpc.value.parameters.php-native.table-1">
  98. <title>PHP and XML-RPC Type Conversions</title>
  99. <tgroup cols="2">
  100. <thead>
  101. <row>
  102. <entry><acronym>PHP</acronym> Native Type</entry>
  103. <entry><acronym>XML-RPC</acronym> Type</entry>
  104. </row>
  105. </thead>
  106. <tbody>
  107. <row>
  108. <entry>integer</entry>
  109. <entry>int</entry>
  110. </row>
  111. <row>
  112. <entry>Zend_Crypt_Math_BigInteger</entry>
  113. <entry>i8</entry>
  114. </row>
  115. <row>
  116. <entry>double</entry>
  117. <entry>double</entry>
  118. </row>
  119. <row>
  120. <entry>boolean</entry>
  121. <entry>boolean</entry>
  122. </row>
  123. <row>
  124. <entry>string</entry>
  125. <entry>string</entry>
  126. </row>
  127. <row>
  128. <entry>null</entry>
  129. <entry>nil</entry>
  130. </row>
  131. <row>
  132. <entry>array</entry>
  133. <entry>array</entry>
  134. </row>
  135. <row>
  136. <entry>associative array</entry>
  137. <entry>struct</entry>
  138. </row>
  139. <row>
  140. <entry>object</entry>
  141. <entry>array</entry>
  142. </row>
  143. <row>
  144. <entry>Zend_Date</entry>
  145. <entry>dateTime.iso8601</entry>
  146. </row>
  147. <row>
  148. <entry>DateTime</entry>
  149. <entry>dateTime.iso8601</entry>
  150. </row>
  151. </tbody>
  152. </tgroup>
  153. </table>
  154. <note>
  155. <title>What type do empty arrays get cast to?</title>
  156. <para>
  157. Passing an empty array to an <acronym>XML-RPC</acronym> method is problematic,
  158. as it could represent either an array or a struct.
  159. <classname>Zend_XmlRpc_Client</classname> detects such conditions and
  160. makes a request to the server's
  161. <command>system.methodSignature</command> method to determine the
  162. appropriate <acronym>XML-RPC</acronym> type to cast to.
  163. </para>
  164. <para>
  165. However, this in itself can lead to issues. First off,
  166. servers that do not support
  167. <command>system.methodSignature</command> will log failed
  168. requests, and <classname>Zend_XmlRpc_Client</classname> will resort to
  169. casting the value to an <acronym>XML-RPC</acronym> array type. Additionally,
  170. this means that any call with array arguments will result in
  171. an additional call to the remote server.
  172. </para>
  173. <para>
  174. To disable the lookup entirely, you can call the
  175. <methodname>setSkipSystemLookup()</methodname> method prior to making
  176. your <acronym>XML-RPC</acronym> call:
  177. </para>
  178. <programlisting language="php"><![CDATA[
  179. $client->setSkipSystemLookup(true);
  180. $result = $client->call('foo.bar', array(array()));
  181. ]]></programlisting>
  182. </note>
  183. </sect3>
  184. <sect3 id="zend.xmlrpc.value.parameters.xmlrpc-value">
  185. <title>Zend_XmlRpc_Value Objects as Parameters</title>
  186. <para>
  187. Parameters may also be created as <classname>Zend_XmlRpc_Value</classname>
  188. instances to specify an exact <acronym>XML-RPC</acronym> type. The primary reasons
  189. for doing this are:
  190. <itemizedlist>
  191. <listitem>
  192. <para>
  193. When you want to make sure the correct parameter
  194. type is passed to the procedure (i.e. the
  195. procedure requires an integer and you may get it
  196. from a database as a string)
  197. </para>
  198. </listitem>
  199. <listitem>
  200. <para>
  201. When the procedure requires <property>base64</property> or
  202. <property>dateTime.iso8601</property> type (which doesn't exists as a
  203. <acronym>PHP</acronym> native type)
  204. </para>
  205. </listitem>
  206. <listitem>
  207. <para>
  208. When auto-conversion may fail (i.e. you want to
  209. pass an empty <acronym>XML-RPC</acronym> struct as a parameter. Empty
  210. structs are represented as empty arrays in <acronym>PHP</acronym>
  211. but, if you give an empty array as a parameter it
  212. will be auto-converted to an <acronym>XML-RPC</acronym> array since
  213. it's not an associative array)
  214. </para>
  215. </listitem>
  216. </itemizedlist>
  217. </para>
  218. <para>
  219. There are two ways to create a <classname>Zend_XmlRpc_Value</classname>
  220. object: instantiate one of the <classname>Zend_XmlRpc_Value</classname>
  221. subclasses directly, or use the static factory method
  222. <methodname>Zend_XmlRpc_Value::getXmlRpcValue()</methodname>.
  223. </para>
  224. <table id="zend.xmlrpc.value.parameters.xmlrpc-value.table-1">
  225. <title>Zend_XmlRpc_Value Objects for XML-RPC Types</title>
  226. <tgroup cols="3">
  227. <thead>
  228. <row>
  229. <entry><acronym>XML-RPC</acronym> Type</entry>
  230. <entry><classname>Zend_XmlRpc_Value</classname> Constant</entry>
  231. <entry><classname>Zend_XmlRpc_Value</classname> Object</entry>
  232. </row>
  233. </thead>
  234. <tbody>
  235. <row>
  236. <entry>int</entry>
  237. <entry>
  238. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER</constant>
  239. </entry>
  240. <entry><classname>Zend_XmlRpc_Value_Integer</classname></entry>
  241. </row>
  242. <row>
  243. <entry>i8</entry>
  244. <entry>
  245. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_I8</constant>
  246. </entry>
  247. <entry><classname>Zend_XmlRpc_Value_BigInteger</classname></entry>
  248. </row>
  249. <row>
  250. <entry>ex:i8</entry>
  251. <entry>
  252. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_APACHEI8</constant>
  253. </entry>
  254. <entry><classname>Zend_XmlRpc_Value_BigInteger</classname></entry>
  255. </row>
  256. <row>
  257. <entry>double</entry>
  258. <entry>
  259. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_DOUBLE</constant>
  260. </entry>
  261. <entry><classname>Zend_XmlRpc_Value_Double</classname></entry>
  262. </row>
  263. <row>
  264. <entry>boolean</entry>
  265. <entry>
  266. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_BOOLEAN</constant>
  267. </entry>
  268. <entry><classname>Zend_XmlRpc_Value_Boolean</classname></entry>
  269. </row>
  270. <row>
  271. <entry>string</entry>
  272. <entry>
  273. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_STRING</constant>
  274. </entry>
  275. <entry><classname>Zend_XmlRpc_Value_String</classname></entry>
  276. </row>
  277. <row>
  278. <entry>nil</entry>
  279. <entry>
  280. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_NIL</constant>
  281. </entry>
  282. <entry><classname>Zend_XmlRpc_Value_Nil</classname></entry>
  283. </row>
  284. <row>
  285. <entry>ex:nil</entry>
  286. <entry>
  287. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_APACHENIL</constant>
  288. </entry>
  289. <entry><classname>Zend_XmlRpc_Value_Nil</classname></entry>
  290. </row>
  291. <row>
  292. <entry>base64</entry>
  293. <entry>
  294. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64</constant>
  295. </entry>
  296. <entry><classname>Zend_XmlRpc_Value_Base64</classname></entry>
  297. </row>
  298. <row>
  299. <entry>dateTime.iso8601</entry>
  300. <entry>
  301. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME</constant>
  302. </entry>
  303. <entry><classname>Zend_XmlRpc_Value_DateTime</classname></entry>
  304. </row>
  305. <row>
  306. <entry>array</entry>
  307. <entry>
  308. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_ARRAY</constant>
  309. </entry>
  310. <entry><classname>Zend_XmlRpc_Value_Array</classname></entry>
  311. </row>
  312. <row>
  313. <entry>struct</entry>
  314. <entry>
  315. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT</constant>
  316. </entry>
  317. <entry><classname>Zend_XmlRpc_Value_Struct</classname></entry>
  318. </row>
  319. </tbody>
  320. </tgroup>
  321. </table>
  322. <para>
  323. <note>
  324. <title>Automatic Conversion</title>
  325. <para>
  326. When building a new <classname>Zend_XmlRpc_Value</classname>
  327. object, its value is set by a <acronym>PHP</acronym> type. The
  328. <acronym>PHP</acronym> type will be converted to the specified type using
  329. <acronym>PHP</acronym> casting. For example, if a string is given as a
  330. value to the <classname>Zend_XmlRpc_Value_Integer</classname>
  331. object, it will be converted using
  332. <command>(int)$value</command>.
  333. </para>
  334. </note>
  335. </para>
  336. </sect3>
  337. </sect2>
  338. <sect2 id="zend.xmlrpc.client.requests-and-responses">
  339. <title>Server Proxy Object</title>
  340. <para>
  341. Another way to call remote methods with the <acronym>XML-RPC</acronym> client is to
  342. use the server proxy. This is a <acronym>PHP</acronym> object that proxies a remote
  343. <acronym>XML-RPC</acronym> namespace, making it work as close to a native
  344. <acronym>PHP</acronym> object as possible.
  345. </para>
  346. <para>
  347. To instantiate a server proxy, call the <methodname>getProxy()</methodname>
  348. instance method of <classname>Zend_XmlRpc_Client</classname>. This will
  349. return an instance of <classname>Zend_XmlRpc_Client_ServerProxy</classname>.
  350. Any method call on the server proxy object will be forwarded to
  351. the remote, and parameters may be passed like any other <acronym>PHP</acronym>
  352. method.
  353. </para>
  354. <example id="zend.xmlrpc.client.requests-and-responses.example-1">
  355. <title>Proxy the Default Namespace</title>
  356. <programlisting language="php"><![CDATA[
  357. $client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
  358. $service = $client->getProxy(); // Proxy the default namespace
  359. $hello = $service->test->sayHello(1, 2); // test.Hello(1, 2) returns "hello"
  360. ]]></programlisting>
  361. </example>
  362. <para>
  363. The <methodname>getProxy()</methodname> method receives an optional argument
  364. specifying which namespace of the remote server to proxy. If it
  365. does not receive a namespace, the default namespace will be
  366. proxied. In the next example, the 'test' namespace
  367. will be proxied:
  368. </para>
  369. <example id="zend.xmlrpc.client.requests-and-responses.example-2">
  370. <title>Proxy Any Namespace</title>
  371. <programlisting language="php"><![CDATA[
  372. $client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
  373. $test = $client->getProxy('test'); // Proxy the "test" namespace
  374. $hello = $test->sayHello(1, 2); // test.Hello(1,2) returns "hello"
  375. ]]></programlisting>
  376. </example>
  377. <para>
  378. If the remote server supports nested namespaces of any depth,
  379. these can also be used through the server proxy. For example, if
  380. the server in the example above had a method
  381. <command>test.foo.bar()</command>, it could be called as
  382. <command>$test->foo->bar()</command>.
  383. </para>
  384. </sect2>
  385. <sect2 id="zend.xmlrpc.client.error-handling">
  386. <title>Error Handling</title>
  387. <para>
  388. Two kinds of errors can occur during an <acronym>XML-RPC</acronym> method call:
  389. <acronym>HTTP</acronym> errors and <acronym>XML-RPC</acronym> faults. The
  390. <classname>Zend_XmlRpc_Client</classname> recognizes each and provides the ability
  391. to detect and trap them independently.
  392. </para>
  393. <sect3 id="zend.xmlrpc.client.error-handling.http">
  394. <title>HTTP Errors</title>
  395. <para>
  396. If any <acronym>HTTP</acronym> error occurs, such as the remote
  397. <acronym>HTTP</acronym> server returns a <emphasis>404 Not Found</emphasis>, a
  398. <classname>Zend_XmlRpc_Client_HttpException</classname> will be thrown.
  399. </para>
  400. <example id="zend.xmlrpc.client.error-handling.http.example-1">
  401. <title>Handling HTTP Errors</title>
  402. <programlisting language="php"><![CDATA[
  403. $client = new Zend_XmlRpc_Client('http://foo/404');
  404. try {
  405. $client->call('bar', array($arg1, $arg2));
  406. } catch (Zend_XmlRpc_Client_HttpException $e) {
  407. // $e->getCode() returns 404
  408. // $e->getMessage() returns "Not Found"
  409. }
  410. ]]></programlisting>
  411. </example>
  412. <para>
  413. Regardless of how the <acronym>XML-RPC</acronym> client is used, the
  414. <classname>Zend_XmlRpc_Client_HttpException</classname> will be thrown
  415. whenever an <acronym>HTTP</acronym> error occurs.
  416. </para>
  417. </sect3>
  418. <sect3 id="zend.xmlrpc.client.error-handling.faults">
  419. <title>XML-RPC Faults</title>
  420. <para>
  421. An <acronym>XML-RPC</acronym> fault is analogous to a <acronym>PHP</acronym>
  422. exception. It is a special type returned from an <acronym>XML-RPC</acronym> method
  423. call that has both an error code and an error message. <acronym>XML-RPC</acronym>
  424. faults are handled differently depending on the context of how the
  425. <classname>Zend_XmlRpc_Client</classname> is used.
  426. </para>
  427. <para>
  428. When the <methodname>call()</methodname> method or the server
  429. proxy object is used, an <acronym>XML-RPC</acronym> fault will result in a
  430. <classname>Zend_XmlRpc_Client_FaultException</classname> being thrown.
  431. The code and message of the exception will map directly to
  432. their respective values in the original <acronym>XML-RPC</acronym> fault
  433. response.
  434. </para>
  435. <example id="zend.xmlrpc.client.error-handling.faults.example-1">
  436. <title>Handling XML-RPC Faults</title>
  437. <programlisting language="php"><![CDATA[
  438. $client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
  439. try {
  440. $client->call('badMethod');
  441. } catch (Zend_XmlRpc_Client_FaultException $e) {
  442. // $e->getCode() returns 1
  443. // $e->getMessage() returns "Unknown method"
  444. }
  445. ]]></programlisting>
  446. </example>
  447. <para>
  448. When the <methodname>call()</methodname> method is used to make the
  449. request, the <classname>Zend_XmlRpc_Client_FaultException</classname> will be
  450. thrown on fault. A <classname>Zend_XmlRpc_Response</classname> object
  451. containing the fault will also be available by calling
  452. <methodname>getLastResponse()</methodname>.
  453. </para>
  454. <para>
  455. When the <methodname>doRequest()</methodname> method is used to make the
  456. request, it will not throw the exception. Instead, it will
  457. return a <classname>Zend_XmlRpc_Response</classname> object returned
  458. will containing the fault. This can be checked with
  459. <methodname>isFault()</methodname> instance method of
  460. <classname>Zend_XmlRpc_Response</classname>.
  461. </para>
  462. </sect3>
  463. </sect2>
  464. <sect2 id="zend.xmlrpc.client.introspection">
  465. <title>Server Introspection</title>
  466. <para>
  467. Some <acronym>XML-RPC</acronym> servers support the de facto introspection methods
  468. under the <acronym>XML-RPC</acronym> <emphasis>system.</emphasis> namespace.
  469. <classname>Zend_XmlRpc_Client</classname> provides special support for servers with
  470. these capabilities.
  471. </para>
  472. <para>
  473. A <classname>Zend_XmlRpc_Client_ServerIntrospection</classname> instance may be
  474. retrieved by calling the <methodname>getIntrospector()</methodname> method of
  475. <classname>Zend_XmlRpcClient</classname>. It can then be used to perform introspection
  476. operations on the server.
  477. </para>
  478. </sect2>
  479. <sect2 id="zend.xmlrpc.client.request-to-response">
  480. <title>From Request to Response</title>
  481. <para>
  482. Under the hood, the <methodname>call()</methodname> instance method of
  483. <classname>Zend_XmlRpc_Client</classname> builds a request object
  484. (<classname>Zend_XmlRpc_Request</classname>) and sends it to another method,
  485. <methodname>doRequest()</methodname>, that returns a response object
  486. (<classname>Zend_XmlRpc_Response</classname>).
  487. </para>
  488. <para>
  489. The <methodname>doRequest()</methodname> method is also available for use directly:
  490. </para>
  491. <example id="zend.xmlrpc.client.request-to-response.example-1">
  492. <title>Processing Request to Response</title>
  493. <programlisting language="php"><![CDATA[
  494. $client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
  495. $request = new Zend_XmlRpc_Request();
  496. $request->setMethod('test.sayHello');
  497. $request->setParams(array('foo', 'bar'));
  498. $client->doRequest($request);
  499. // $client->getLastRequest() returns instanceof Zend_XmlRpc_Request
  500. // $client->getLastResponse() returns instanceof Zend_XmlRpc_Response
  501. ]]></programlisting>
  502. </example>
  503. <para>
  504. Whenever an <acronym>XML-RPC</acronym> method call is made by the client through any
  505. means, either the <methodname>call()</methodname> method,
  506. <methodname>doRequest()</methodname> method, or server proxy, the last request
  507. object and its resultant response object will always be available
  508. through the methods <methodname>getLastRequest()</methodname> and
  509. <methodname>getLastResponse()</methodname> respectively.
  510. </para>
  511. </sect2>
  512. <sect2 id="zend.xmlrpc.client.http-client">
  513. <title>HTTP Client and Testing</title>
  514. <para>
  515. In all of the prior examples, an <acronym>HTTP</acronym> client was never specified.
  516. When this is the case, a new instance of
  517. <classname>Zend_Http_Client</classname> will be created with its default
  518. options and used by <classname>Zend_XmlRpc_Client</classname> automatically.
  519. </para>
  520. <para>
  521. The <acronym>HTTP</acronym> client can be retrieved at any time with the
  522. <methodname>getHttpClient()</methodname> method. For most cases, the default
  523. <acronym>HTTP</acronym> client will be sufficient. However, the
  524. <methodname>setHttpClient()</methodname> method allows for a different
  525. <acronym>HTTP</acronym> client instance to be injected.
  526. </para>
  527. <para>
  528. The <methodname>setHttpClient()</methodname> is particularly useful for unit testing.
  529. When combined with the <classname>Zend_Http_Client_Adapter_Test</classname>, remote
  530. services can be mocked out for testing. See the unit tests for
  531. <classname>Zend_XmlRpc_Client</classname> for examples of how to do this.
  532. </para>
  533. </sect2>
  534. </sect1>
  535. <!--
  536. vim:se ts=4 sw=4 et:
  537. -->