PageRenderTime 59ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/README.md

http://github.com/timroes/aXMLRPC
Markdown | 314 lines | 214 code | 100 blank | 0 comment | 0 complexity | 40230848ea40ad2e1db3197d5ff2f21d MD5 | raw file
  1. What is aXMLRPC?
  2. ================
  3. aXMLRPC is a Java library with a leightweight XML-RPC client. XML-RPC is
  4. a specification for making remote procedure calls over the HTTP protocol
  5. in an XML format. The specificationc can be found under http://www.xmlrpc.com/spec.
  6. The library was developed for the use with Android. Since it has no dependencies to
  7. any Android library or any other 3rd-party library, it is fully functional in any
  8. common java virtual machine (not only on Android).
  9. You can control the client with some flags to extend its functionality. See the section
  10. about flags.
  11. How to include it?
  12. ==================
  13. How to include the aXMLRPC client into your project?
  14. There are several ways to do that:
  15. ### Include the source code
  16. You can just include all the source code from the `src` directory into the sourcecode
  17. of your project. If you use git yourself, you can use submodules to include the code
  18. as a module to yours. So you will always stay up to date with the library.
  19. ### Compile it as library
  20. aXMLRPC uses maven, so you can build it using
  21. mvn install
  22. ### Use Maven
  23. To use it on your Maven project, add it as a dependency on your pom.xml file:
  24. ```xml
  25. <dependency>
  26. <groupId>fr.turri</groupId>
  27. <artifactId>aXMLRPC</artifactId>
  28. <version>X.Y.Z</version>
  29. </dependency>
  30. ```
  31. where X.Y.Z is the current aXMLRPC version
  32. How to use the library?
  33. =======================
  34. You can use the library by initiating an `XMLRPCClient` and make calls over it:
  35. ```java
  36. try {
  37. XMLRPCClient client = new XMLRPCClient(new URL("http://example.com/xmlrpc"));
  38. Boolean b = (Boolean)client.call("isServerOk");
  39. Integer i = (Integer)client.call("add", 5, 10);
  40. } catch(XMLRPCServerException ex) {
  41. // The server throw an error.
  42. } catch(XMLRPCException ex) {
  43. // An error occured in the client.
  44. } catch(Exception ex) {
  45. // Any other exception
  46. }
  47. ```
  48. Instead of passing the parameters as seperated values, you can also pack them in
  49. an array and pass the array to the method, like in the following example:
  50. ```java
  51. // ... The try-catch has been ommited for clarity.
  52. XMLRPCClient client = new XMLRPCClient(url, "MyUserAgentString");
  53. client.call("someMethod", new Object[]{ o1, o2, o3 });
  54. // ...
  55. ```
  56. #### Asynchronous Calls
  57. The above method calls are synchronous. So the method `call` will return when the server responded
  58. or an error occured. There is also a possibility for asynchronous server calls.
  59. You need to implement an XMLRPCCallback that will get noticed about the respone (or error) from
  60. the server. The `callAsync` method can be used to make asynchronous calls. It returns an identifier
  61. that will also be send to the XMLRPCCallback instance with the response of the server, so your
  62. application can make multiple calls concurrently and use one listener for them, that distinguish
  63. between the different request by their ids.
  64. ```java
  65. XMLRPCCallback listener = new XMLRPCCallback() {
  66. public void onResponse(long id, Object result) {
  67. // Handling the servers response
  68. }
  69. public void onError(long id, XMLRPCException error) {
  70. // Handling any error in the library
  71. }
  72. public void onServerError(long id, XMLRPCServerException error) {
  73. // Handling an error response from the server
  74. }
  75. };
  76. XMLRPCClient client = new XMLRPCClient(url);
  77. long id = client.callAsync(listener, "add", 5, 10);
  78. ```
  79. You will be also able to cancel an asynchonous call. Just use the `cancel` method on the `XMLRPCClient` instance,
  80. like in the following example. The listener will not be notified, if the call is canceled.
  81. ```java
  82. XMLRPCClient client = new XMLRPCClient(url);
  83. long id = client.callAsync(listener, "method", params);
  84. // ...
  85. client.cancel(id);
  86. ```
  87. The data types
  88. --------------
  89. The specification give some data tags for the server response. If you want to work on the
  90. type you must cast the returning `Object` from the `call` method to its specific type.
  91. Which type to cast which XML server response, tells the following list:
  92. `i4`,`int` => `Integer`
  93. `boolean` => `Boolean`
  94. `string` => `String`
  95. `double` => `Double`
  96. `dateTime.iso8601` => `Date`
  97. `base64` => `byte[]` (`Byte[]` won't work)
  98. `array` => `Object[]`
  99. `struct` => `Map<String,Object>`
  100. `i8` => `Long` (see Flags)
  101. Flags
  102. -----
  103. The client takes as second parameter (or third if an user agent is given)
  104. a combination of multiple flags. It could work like the following example:
  105. ```java
  106. // ...
  107. XMLRPCClient client = new XMLRPCClient(url,
  108. XMLRPCClient.FLAGS_STRICT | XMLRPCClient.FLAGS_8BYTE_INT);
  109. // ...
  110. ```
  111. The following flags are implemented:
  112. #### FLAGS_STRICT
  113. The client should parse responses strict to specification.
  114. It will check if the given content-type is right.
  115. The method name in a call must only contain of A-Z, a-z, 0-9, _, ., :, /
  116. Normally this is not needed.
  117. #### FLAGS_8BYTE_INT
  118. The client will be able to handle 8 byte integer values (longs).
  119. The xml type tag `<i8>` will be used. This is not in the specification
  120. but some libraries and servers support this behaviour.
  121. If this isn't enabled you cannot recieve 8 byte integers and if you try to
  122. send a long, the value must be within the 4 byte integer range.
  123. #### FLAGS_ENABLE_COOKIES
  124. With this flag, the client will be able to handle cookies, meaning saving cookies
  125. from the server and sending it with every other request again. This is needed
  126. for some XML-RPC interfaces that support login.
  127. #### FLAGS_NIL
  128. The client will be able to send `null` values. A `null` value will be send
  129. as `<nil/>`. This extension is described under: http://ontosys.com/xml-rpc/extensions.php
  130. #### FLAGS_IGNORE_STATUSCODE
  131. With this flag enabled, the XML-RPC client will ignore the HTTP status
  132. code of the response from the server. According to specification the
  133. status code must be 200. This flag is only needed for the use with
  134. not standard compliant servers.
  135. #### FLAGS_FORWARD
  136. With this flag enabled, the client will forward the request, if
  137. the 301 or 302 HTTP status code has been received. If this flag is not
  138. set, the client will throw an exception on these HTTP status codes.
  139. #### FLAGS_SSL_IGNORE_INVALID_HOST
  140. With this flag enabled, the client will ignore, if the URL doesn't match
  141. the SSL Certificate. This should be used with caution. Normally the URL
  142. should always match the URL in the SSL certificate, even with self signed
  143. certificates.
  144. #### FLAGS_SSL_INGORE_INVALID_CERT
  145. With this flag enabled, the client will ignore all unverified SSL/TLS
  146. certificates. This must be used, if you use self-signed certificates
  147. or certificated from unknown (or untrusted) authorities.
  148. #### FLAGS_DEFAULT_TYPE_STRING
  149. With this flag enabled, a value with a missing type tag, will be parsed
  150. as a string element. This is just for incoming messages. Outgoing messages
  151. will still be generated according to specification.
  152. #### FLAGS_IGNORE_NAMESPACES
  153. With this flag enabled, the client ignores all namespaces
  154. used within the response from the server.
  155. #### FLAGS_USE_SYSTEM_PROXY
  156. With this flag enabled, the XMLRPCClient will use the system http
  157. proxy to connect to the XML-RPC server.
  158. #### FLAGS_NO_STRING_ENCODE
  159. By default outgoing string values will be encoded according to specification.
  160. Meaning the & sign will be encoded to `&amp;` and the "less then" sign to `&lt;`.
  161. If you set this flag, the encoding won't be done for outgoing string values.
  162. See `FLAGS_NO_STRING_DECODE` for the counterpart.
  163. #### FLAGS_NO_STRING_DECODE
  164. This prevents the decoding of incoming strings, meaning `&amp;` and `&lt;`
  165. won't be decoded to the & sign and the "less then" sign. See
  166. `FLAGS_NO_STRING_ENCODE` for the counterpart.
  167. #### FLAGS_DEBUG
  168. Will display additional information on the console.
  169. Do not use it in production.
  170. #### FLAGS_ACCEPT_NULL_DATE
  171. By default a response with an empty date (eg: `<value><dateTime.iso8601/></value>`)
  172. is invalid and hence throws an exception.
  173. With this flag, this input is accepted, and returns a null date
  174. Meta Flags
  175. ----------
  176. This can be used exactly the same as normal flags. But each meta flag is just a
  177. collection of different other flags. There is no functional difference in using
  178. a meta flag or all the containing flags. For detailed documentation on the single
  179. flags read the above section.
  180. #### FLAGS_SSL_IGNORE_ERRORS
  181. This flag disables all SSL warnings. It is an alternative to use
  182. FLAGS_SSL_IGNORE_INVALID_CERT | FLAGS_SSL_IGNORE_INVALID_HOST.
  183. #### FLAGS_APACHE_WS
  184. This flag should be used if the server is an apache ws xmlrpc server.
  185. This will set some flags, so that the not standard conform behavior
  186. of the server will be ignored.
  187. This will enable the following flags: FLAGS_IGNORE_NAMESPACES, FLAGS_NIL,
  188. FLAGS_DEFAULT_TYPE_STRING
  189. Using an arbitrary transport
  190. ============================
  191. aXMLRPC uses http with the java.net API. If you want to use another protocol or API, you can do:
  192. ```java
  193. boolean debug = false;
  194. SerializerHandler serializerHandler = new SerializerHandler(); // or you may build it with flags
  195. String payload = new Call(serializerHandler, "add", 5, 10).getXML(debug);
  196. InputStream istream = sendPayloadWithMyTransport(payload); // use your implementation here
  197. Integer i = (Integer) new ResponseParser.parse(serializerHandler, istream, debug);
  198. ```
  199. License
  200. =======
  201. The library is licensed under [MIT License] (http://www.opensource.org/licenses/mit-license.php).
  202. See the LICENSE file for the license text.
  203. For the uninformed reader: What does MIT mean?
  204. - You can copy this, modify it, distribute it, sell it, eat it.
  205. - You don't need to notice me about anything of the above.
  206. - If you make changes to it, it would be nice (but not obliged), if you would share it with me again.
  207. - Put the copyright notice and the LICENSE file in any copy you make.
  208. Bugs?
  209. =====
  210. If you find a bug or wish some enhancements for the library, please
  211. fill an issue here on github.
  212. Build status
  213. ============
  214. Status: ![Status](https://travis-ci.org/gturri/aXMLRPC.svg?branch=master)