xmlrpcs 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +24 -0
- data/lib/xmlrpc/xmlrpcs.rb +59 -0
- data/test/xmlrpc/tc_tcp.rb +69 -0
- data/test/xmlrpc/tc_unix.rb +71 -0
- metadata +57 -0
data/README
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
This gems allow to easily change the transport layer in XMLRPC::Client class.
|
2
|
+
It adds a new class called XMLRPC::ClientS, subclass of the Client class. This
|
3
|
+
class must be subclassed to put your own transport code in it.
|
4
|
+
|
5
|
+
There are 3 private method that can be changed.
|
6
|
+
|
7
|
+
*new_socket* (info,async)
|
8
|
+
This method is called to create a new socket. Info is the parameter you passed
|
9
|
+
to the constructor and async is a boolean value that tells you if the socket
|
10
|
+
should be asyncrhonous.
|
11
|
+
The object returned must answer to read and write methods.
|
12
|
+
|
13
|
+
*read_response* (socket)
|
14
|
+
Must read the response from the socket and return the data. You may leave this
|
15
|
+
the default, but it will wait until the socket is closed.
|
16
|
+
|
17
|
+
*write_request* (socket,request)
|
18
|
+
Writes the request in the socket, this may be left as it is.
|
19
|
+
|
20
|
+
|
21
|
+
write_request and read_response have to be changed to use a specific protocol if you don't want the socket to be closed.
|
22
|
+
In the test i use a very simple one for instance which needs no explanation.
|
23
|
+
|
24
|
+
Author: Dario Meloni <mellon85@gmail.com>
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'xmlrpc/client'
|
2
|
+
|
3
|
+
|
4
|
+
# This gems allow to easily change the transport layer in XMLRPC::Client class.
|
5
|
+
# It adds a new class called XMLRPC::ClientS, subclass of the Client class.
|
6
|
+
|
7
|
+
module XMLRPC
|
8
|
+
|
9
|
+
|
10
|
+
# This class must be subclassed to put your own transport code in it.
|
11
|
+
# There are 3 private method that are to be changed.
|
12
|
+
#
|
13
|
+
# new_socket +MUST+ be redefined or will raise a NotImplementedError, while
|
14
|
+
# write_request and read_response have to be changed to use a specific
|
15
|
+
# protocol, the default is that there is no control on the write operation
|
16
|
+
# and the receiving the response is ended by the closoure of the socket. In
|
17
|
+
# the test i use a very simple protocol for instance which needs no
|
18
|
+
# explanation.
|
19
|
+
|
20
|
+
class ClientS < XMLRPC::Client
|
21
|
+
|
22
|
+
# The info parameter will be passed to the new_socket function as it is
|
23
|
+
def initialize(info=nil)
|
24
|
+
@info = info
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# This is called to create a new socket. Info is the parameter you
|
30
|
+
# passed to the constructor and async is a boolean value that tells you
|
31
|
+
# if the socket should be asyncrhonous. The object returned must answer
|
32
|
+
# to read and write methods.
|
33
|
+
def new_socket(info,async) # :doc:
|
34
|
+
raise NotImplementedError, "new_socket must be redefined"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Writes the request in the socket, this may be left as it is.
|
38
|
+
def write_request(socket,request) # :doc:
|
39
|
+
if socket.write(request) != request.length then
|
40
|
+
raise IOError, "Not all the data has been sent"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Must read the response from the socket and return the data. You may
|
45
|
+
# leave this the default, the default behavious is to wait until the
|
46
|
+
# socket is closed.
|
47
|
+
def read_response(socket) # :doc:
|
48
|
+
socket.read()
|
49
|
+
end
|
50
|
+
|
51
|
+
# do_rpc working with custom sockets
|
52
|
+
def do_rpc( request, async )
|
53
|
+
sock = new_socket(@info,async)
|
54
|
+
write_request(sock,request)
|
55
|
+
return read_response(sock)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
# Author: Dario Meloni <mellon85@gmail.com>
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'xmlrpcs'
|
6
|
+
require 'xmlrpc/server'
|
7
|
+
require 'socket'
|
8
|
+
|
9
|
+
$test_port="20000"
|
10
|
+
|
11
|
+
class TCPXMLClient < XMLRPC::ClientS
|
12
|
+
def new_socket(info,async)
|
13
|
+
TCPSocket.new(info["host"],info["port"])
|
14
|
+
end
|
15
|
+
|
16
|
+
def write_request(socket,request)
|
17
|
+
socket.write("#{request.length}\n")
|
18
|
+
socket.write(request)
|
19
|
+
end
|
20
|
+
|
21
|
+
def read_response(socket)
|
22
|
+
l = socket.readline
|
23
|
+
return socket.read(l.to_i)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class TCPXMLServer < XMLRPC::BasicServer
|
28
|
+
|
29
|
+
def serve()
|
30
|
+
@server = TCPServer.new('localhost',20000)
|
31
|
+
catch (:exit_serve) {
|
32
|
+
while(true)
|
33
|
+
@server.listen(5)
|
34
|
+
client, client_addr = @server.accept
|
35
|
+
l = client.readline
|
36
|
+
data = client.read(l.to_i)
|
37
|
+
pdata = process(data)
|
38
|
+
client.write("#{pdata.length}\n")
|
39
|
+
client.write(pdata)
|
40
|
+
client.close
|
41
|
+
end
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
attr_accessor :path
|
46
|
+
end
|
47
|
+
|
48
|
+
class TC_xmlrpcs_tcp < Test::Unit::TestCase
|
49
|
+
def setup
|
50
|
+
@s = TCPXMLServer.new()
|
51
|
+
@s.add_introspection
|
52
|
+
@s.add_handler("test.add") do |a,b|
|
53
|
+
a+b
|
54
|
+
end
|
55
|
+
@t = Thread.new do
|
56
|
+
@s.serve
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def teardown
|
61
|
+
Thread.kill(@t)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_create
|
65
|
+
c = TCPXMLClient.new({"host" => "localhost", "port" => "#{$test_port}"})
|
66
|
+
assert(c.call("test.add",2,3) == 5, "Failed calling test.add")
|
67
|
+
assert(c.call("system.listMethods"),"Failed system.listMethods")
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
# Author: Dario Meloni <mellon85@gmail.com>
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'xmlrpcs'
|
6
|
+
require 'xmlrpc/server'
|
7
|
+
require 'socket'
|
8
|
+
|
9
|
+
$socket_path="test.sock"
|
10
|
+
|
11
|
+
class UnixXMLClient < XMLRPC::ClientS
|
12
|
+
def new_socket(info,async)
|
13
|
+
UNIXSocket.new(info)
|
14
|
+
end
|
15
|
+
|
16
|
+
def write_request(socket,request)
|
17
|
+
socket.write("#{request.length}\n")
|
18
|
+
socket.write(request)
|
19
|
+
end
|
20
|
+
|
21
|
+
def read_response(socket)
|
22
|
+
l = socket.readline
|
23
|
+
return socket.read(l.to_i)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class UnixXMLServer < XMLRPC::BasicServer
|
28
|
+
|
29
|
+
def serve()
|
30
|
+
@server = UNIXServer.new(@path)
|
31
|
+
catch (:exit_serve) {
|
32
|
+
while(true)
|
33
|
+
@server.listen(5)
|
34
|
+
client, client_addr = @server.accept
|
35
|
+
l = client.readline
|
36
|
+
data = client.read(l.to_i)
|
37
|
+
pdata = process(data)
|
38
|
+
client.write("#{pdata.length}\n")
|
39
|
+
client.write(pdata)
|
40
|
+
client.close
|
41
|
+
end
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
attr_accessor :path
|
46
|
+
end
|
47
|
+
|
48
|
+
class TC_xmlrpcs_unix < Test::Unit::TestCase
|
49
|
+
def setup
|
50
|
+
@s = UnixXMLServer.new()
|
51
|
+
@s.path=$socket_path
|
52
|
+
@s.add_introspection
|
53
|
+
@s.add_handler("test.add") do |a,b|
|
54
|
+
a+b
|
55
|
+
end
|
56
|
+
@t = Thread.new do
|
57
|
+
@s.serve
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def teardown
|
62
|
+
Thread.kill(@t)
|
63
|
+
File.unlink($socket_path)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_create
|
67
|
+
c = UnixXMLClient.new($socket_path)
|
68
|
+
assert(c.call("test.add",2,3) == 5, "Failed calling test.add")
|
69
|
+
assert(c.call("system.listMethods"),"Failed system.listMethods")
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xmlrpcs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dario Meloni
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-26 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: mellon85@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- lib/xmlrpc/xmlrpcs.rb
|
26
|
+
- test/xmlrpc/tc_tcp.rb
|
27
|
+
- test/xmlrpc/tc_unix.rb
|
28
|
+
- README
|
29
|
+
has_rdoc: true
|
30
|
+
homepage: http://rubyforge.org/projects/xmlrpcs/
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
rubyforge_project: xmlrpcs
|
51
|
+
rubygems_version: 1.0.1
|
52
|
+
signing_key:
|
53
|
+
specification_version: 2
|
54
|
+
summary: Changes sockets for the XMLRPC Library
|
55
|
+
test_files:
|
56
|
+
- test/xmlrpc/tc_tcp.rb
|
57
|
+
- test/xmlrpc/tc_unix.rb
|