Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > 282ba76331d32d96ac00e4024a30ac59 > files > 20

erlang-xmlrpc-1.13-2.fc14.x86_64.rpm

This directory contains five example Erlang XML-RPC servers. Four of
them are desribed in this README file. The fifth server is an example
of robust banking system and is described in a separate tutorial
(robust_banking.txt).

The servers are small and silly but together they utilize a majority
of the functionality provided by the library.

The first example (fib_server.erl) calculates Fibonacci values and is
a non-keepalive server. The second example (echo_server.erl) echoes
back any incoming parameters and is a non-keepalive server. The third
example (date_server.erl) calculates calendar values for given dates
and is a keepalive server which uses the state variable to provide
login state and different timeout settings. The fourth example
(validator.erl) is a validation server which can be used to validate
the library using the http://validator.xmlrpc.org/ service.

Run make to compile the servers.

You need to replace "../../xmerl/ebin" below to point at your
installation of the xmerl package.

If you intend to verify inter-operability with the example Java clients
you need to replace "../../apache/xmlrpc/bin/xmlrpc-1.1.jar" below to
point at your installation of the Apache XML-RPC library. Get it at
http://www.apache.org/. You furthermore need a recent installation of
Java/JDK. Get it at http://java.sun.com/.

Run 'make java_clients' to compile the Java clients.

Example 1: fib_server.erl
-------------------------
$ erl -pa ../ebin -pa ../../xmerl/ebin
Erlang (BEAM) emulator version 5.1.2.b2 [source]

Eshell V5.1.2.b2  (abort with ^G)
1> {ok, Pid} = xmlrpc:start_link({fib_server, handler}).
{ok,<0.30.0>}
2> xmlrpc:call({127, 0, 0, 1}, 4567, "/", {call, foo, []}).
{ok,{response,{fault,-1,"Unknown call: {call,foo,[]}"}}}
3> xmlrpc:call({127, 0, 0, 1}, 4567, "/", {call, fib, [0]}). 
{ok,{response,[1]}}
4> xmlrpc:call({127, 0, 0, 1}, 4567, "/", {call, fib, [4]}).
{ok,{response,[5]}}

Nothing fancy. Uses a new HTTP connection for each call and handles
unknown method calls gracefully.

FibClient.java could as well has been used to call the Fibonacci
server:

$ java -classpath ../../apache/xmlrpc/bin/xmlrpc-1.1.jar:. FibClient 0
1
$ java -classpath ../../apache/xmlrpc/bin/xmlrpc-1.1.jar:. FibClient 4
5

Stop the Fibonacci server:

5> xmlrpc:stop(Pid).
stop

Example 2: echo_server.erl
--------------------------
$ erl -pa ../ebin -pa ../../xmerl/ebin
Erlang (BEAM) emulator version 5.1.2.b2 [source]

Eshell V5.1.2.b2  (abort with ^G)
1> {ok, Pid} = xmlrpc:start_link({echo_server, handler}).
{ok,<0.30.0>}
2> xmlrpc:call({127, 0, 0, 1}, 4567, "/", {call, foo, []}).
{ok,{response,{fault,-1,"Unknown call: {call,foo,[]}"}}}
3> xmlrpc:call({127, 0, 0, 1}, 4567, "/", {call, echo, [42.0]}).
{ok,{response,[{array, [42.0000]}]}}
4> xmlrpc:call({127, 0, 0, 1}, 4567, "/", {call, echo, [2.6, {array, [5, "foo"]}, {struct, [{baz, 1}, {bar, {base64, "SDOMCVN=-kmDC*="}}]}]}).
{ok,{response,[{array,[2.60000,
                       {array,[5,"foo"]},
                       {struct,[{baz,1},{bar,{base64,"SDOMCVN=-kmDC*="}}]}]}]}}

The parameters are converted from Erlang to XML format before being
sent to the server. When the parameters arrive at the server they are
converted back to Erlang format. The server handler echoes the
parameters back as a response to the client, i.e. in the process
converting the parameters back to XML format. The response arrives at
the client which finally convert the parameters back to Erlang format. 

Nothing fancy. Uses a new HTTP connection for each call and handles
unknown method calls gracefully.

EchoClient.java could as well has been used to call the echo server:

$ java -classpath ../../apache/xmlrpc/bin/xmlrpc-1.1.jar:. EchoClient
[42.5, foo, 7]

Stop the echo server:

5> xmlrpc:stop(Pid).
stop

Example 3: date_server.erl
--------------------------
$ erl -pa ../ebin -pa ../../xmerl/ebin
Erlang (BEAM) emulator version 5.1.2.b2 [source]

Eshell V5.1.2.b2  (abort with ^G)
1> xmlrpc:start_link(4567, 1000, 300000, {date_server, handler}, {false, 0}).
{ok,<0.30.0>}
2> xmlrpc:call({127, 0, 0, 1}, 4567, "/", {call, calc, [{struct, [{is_leap_year, 1492}]}]}, true, 300000).
{ok,#Port<0.32>,{response,{fault,-3,"Not authenticated"}}}
3> xmlrpc:call({127, 0, 0, 1}, 4567, "/", {call, login, ["Foo", "Bar"]}, true, 300000).
{ok,#Port<0.40>,{response,{fault,-1,"Invalid authentication"}}}
4> {ok, S, _} = xmlrpc:call({127, 0, 0, 1}, 4567, "/", {call, login, ["Slarti", "Bartfast"]}, true, 300000).
{ok,#Port<0.42>,{response,["ok"]}}
5> xmlrpc:call(S, "/", {call, login, ["Slarti", "Bartfast"]}, true, 300000).
{ok,#Port<0.42>,{response,{fault,-2,"Already authenticated"}}}
6> xmlrpc:call(S, "/", {call, foo, []}, true, 300000).
{ok,#Port<0.42>,{response,{fault,-4,"Unknown call: {call,foo,[]}"}}}
7> xmlrpc:call(S, "/", {call, calc, [{struct, [{is_leap_year, 1492}]}]}, true, 300000).
{ok,#Port<0.42>,{response,[{array,[3,{struct,[{is_leap_year,true}]}]}]}}
8> xmlrpc:call(S, "/", {call, calc, [{struct, [{is_leap_year, 2010}]}]}, true, 300000).
{ok,#Port<0.42>,{response,[{array,[4,{struct,[{is_leap_year,false}]}]}]}}
9> xmlrpc:call(S, "/", {call, calc, [{struct, [{is_leap_year, 2010}, {days_since, {struct, [{y, 2002}, {m, 12}, {d, 10}]}}]}]}, true, 300000).
{ok,#Port<0.42>,
    {response,[{array,[5,{struct,[{is_leap_year,false},{days_since,731559}]}]}]}}
10> xmlrpc:call(S, "/", {call, logout, []}). 
{ok,{response,["ok"]}}
11> xmlrpc:call(S, "/", {call, calc, [{struct, [{is_leap_year, 2010}]}]}, true, 300000).
{error,#Port<0.42>,closed}

DateClient.java could as well has been used to call the date server:

$ java -classpath ../../apache/xmlrpc/bin/xmlrpc-1.1.jar:. DateClient
ok
[1, {days_since=731204}]
[2, {days_since=731204, day_of_week=Thursday, is_leap_year=true}]
ok

Stop the date server:

12> xmlrpc:stop(Pid).
stop

Example 4: validator.erl
--------------------------
$ erl -pa ../ebin -pa ../../xmerl/ebin
Erlang (BEAM) emulator version 5.1.2.b2 [source]

Eshell V5.1.2.b2  (abort with ^G)
1> {ok, Pid} = xmlrpc:start_link({validator, handler}).
{ok,<0.30.0>}

If your computer is connected to the Internet you can now verify that
the library is compliant with the validation service at
http://validator.xmlrpc.org/.

Stop the validator server:

2> xmlrpc:stop(Pid).
stop