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