2005-02-18 05:35:25 -05:00
|
|
|
require File.dirname(__FILE__) + '/abstract_unit'
|
|
|
|
require 'webrick'
|
|
|
|
require 'webrick/log'
|
|
|
|
require 'singleton'
|
|
|
|
|
|
|
|
module ClientTest
|
2005-02-18 18:55:29 -05:00
|
|
|
class Person < ActionWebService::Struct
|
2005-02-18 05:35:25 -05:00
|
|
|
member :firstnames, [:string]
|
|
|
|
member :lastname, :string
|
|
|
|
|
|
|
|
def ==(other)
|
|
|
|
firstnames == other.firstnames && lastname == other.lastname
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-02-18 18:55:29 -05:00
|
|
|
class API < ActionWebService::API::Base
|
2005-02-18 05:35:25 -05:00
|
|
|
api_method :void
|
|
|
|
api_method :normal, :expects => [:int, :int], :returns => [:int]
|
|
|
|
api_method :array_return, :returns => [[Person]]
|
|
|
|
api_method :struct_pass, :expects => [[Person]], :returns => [:bool]
|
|
|
|
api_method :client_container, :returns => [:int]
|
2005-02-19 04:07:35 -05:00
|
|
|
api_method :named_parameters, :expects => [{:key=>:string}, {:id=>:int}]
|
2005-02-25 18:39:39 -05:00
|
|
|
api_method :thrower
|
2005-02-18 05:35:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class NullLogOut
|
|
|
|
def <<(*args); end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Container < ActionController::Base
|
2005-02-18 16:22:52 -05:00
|
|
|
web_service_api API
|
2005-02-18 05:35:25 -05:00
|
|
|
|
2005-02-25 18:39:39 -05:00
|
|
|
attr_accessor :value_void
|
|
|
|
attr_accessor :value_normal
|
|
|
|
attr_accessor :value_array_return
|
|
|
|
attr_accessor :value_struct_pass
|
|
|
|
attr_accessor :value_named_parameters
|
2005-02-18 05:35:25 -05:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
@session = @assigns = {}
|
|
|
|
@value_void = nil
|
|
|
|
@value_normal = nil
|
|
|
|
@value_array_return = nil
|
|
|
|
@value_struct_pass = nil
|
2005-02-19 04:07:35 -05:00
|
|
|
@value_named_parameters = nil
|
2005-02-18 05:35:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def void
|
|
|
|
@value_void = @method_params
|
|
|
|
end
|
|
|
|
|
|
|
|
def normal
|
|
|
|
@value_normal = @method_params
|
|
|
|
5
|
|
|
|
end
|
|
|
|
|
|
|
|
def array_return
|
|
|
|
person = Person.new
|
|
|
|
person.firstnames = ["one", "two"]
|
|
|
|
person.lastname = "last"
|
|
|
|
@value_array_return = [person]
|
|
|
|
end
|
|
|
|
|
|
|
|
def struct_pass
|
|
|
|
@value_struct_pass = @method_params
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def client_container
|
|
|
|
50
|
|
|
|
end
|
|
|
|
|
2005-02-19 04:07:35 -05:00
|
|
|
def named_parameters
|
|
|
|
@value_named_parameters = @method_params
|
|
|
|
end
|
|
|
|
|
2005-02-25 18:39:39 -05:00
|
|
|
def thrower
|
|
|
|
raise "Hi"
|
2005-02-18 05:35:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class AbstractClientLet < WEBrick::HTTPServlet::AbstractServlet
|
|
|
|
def initialize(controller)
|
|
|
|
@controller = controller
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_instance(*args)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def require_path_info?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def do_GET(req, res)
|
|
|
|
raise WEBrick::HTTPStatus::MethodNotAllowed, "GET request not allowed."
|
|
|
|
end
|
|
|
|
|
|
|
|
def do_POST(req, res)
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class AbstractServer
|
|
|
|
include ClientTest
|
|
|
|
include Singleton
|
|
|
|
attr :container
|
|
|
|
def initialize
|
|
|
|
@container = Container.new
|
|
|
|
@clientlet = create_clientlet(@container)
|
|
|
|
log = WEBrick::BasicLog.new(NullLogOut.new)
|
|
|
|
@server = WEBrick::HTTPServer.new(:Port => server_port, :Logger => log, :AccessLog => log)
|
|
|
|
@server.mount('/', @clientlet)
|
|
|
|
@thr = Thread.new { @server.start }
|
|
|
|
until @server.status == :Running; end
|
|
|
|
at_exit { @server.stop; @thr.join }
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
def create_clientlet
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
def server_port
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|