Class: SimpleWS
- Inherits:
-
SOAP::RPC::StandaloneServer
- Object
- SOAP::RPC::StandaloneServer
- SimpleWS
- Defined in:
- lib/simplews.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Jobs
Constant Summary collapse
- VERSION =
"1.3.6"
- METHODS =
Saves method defined in the class to be served by the instances
{}
Class Method Summary collapse
-
.get_driver(url, name) ⇒ Object
Builds on the get_wsdl function to provide the client with a reference to the driver.
-
.get_wsdl(url, name) ⇒ Object
This is a helper function for clients.
-
.serve(name, args = [], types = {}, &block) ⇒ Object
Saves the method to be served by the instances.
Instance Method Summary collapse
-
#initialize(name = "WS", description = "", host = "localhost", port = "1984", *args) ⇒ SimpleWS
constructor
Creates an instance of a Server.
-
#serve(name, args = [], types = {}, &block) ⇒ Object
This method tells the server to provide a method named by the
name
parameter, with arguments listed in theargs
parameter. -
#wsdl(filename = nil) ⇒ Object
If
filename
is specified it saves theWSDL
file in that file.
Constructor Details
#initialize(name = "WS", description = "", host = "localhost", port = "1984", *args) ⇒ SimpleWS
Creates an instance of a Server. The parameter name
specifies the namespace
used in the WSDL
, description
is the description also included in the WSDL
. The parameters host
and port
, specify where the server will be listening, they are parameters of the super
class SOAP::RPC::StandaloneServer, they are made explicit here because they are included in the WSDL
as well.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/simplews.rb', line 86 def initialize(name="WS", description="", host="localhost", port="1984", *args) super(description, "urn:#{ name }", host, port, *args) @host = host @port = port @name = name @description = description @messages = [] @operations = [] @bindings = [] serve :wsdl, %w(), :return => :string METHODS.each{|name, info| serve name, info[:args], info[:types], &info[:block] } end |
Class Method Details
.get_driver(url, name) ⇒ Object
Builds on the get_wsdl function to provide the client with a reference to the driver. Again, only works with SimpleWS servers.
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/simplews.rb', line 67 def self.get_driver(url, name) require 'soap/wsdlDriver' require 'fileutils' tmp = File.open("/tmp/simpleWS.wsdl",'w') tmp.write SimpleWS::get_wsdl(url, name) tmp.close driver = SOAP::WSDLDriverFactory.new( "/tmp/simpleWS.wsdl" ).create_rpc_driver FileUtils.rm "/tmp/simpleWS.wsdl" driver end |
.get_wsdl(url, name) ⇒ Object
This is a helper function for clients. Given the url
where the server is listening, as well as the name of the server, it can manually access the wsdl
function and retrieve the complete WSDL
file. This works only in web servers of class SimpleWS, not on the general SOAP::RPC::StandaloneServer or any other type of web server.
58 59 60 61 62 63 |
# File 'lib/simplews.rb', line 58 def self.get_wsdl(url, name) require 'soap/rpc/driver' driver = SOAP::RPC::Driver.new(url, "urn:#{ name }") driver.add_method('wsdl') driver.wsdl end |
.serve(name, args = [], types = {}, &block) ⇒ Object
Saves the method to be served by the instances. The initialization of an instance check if there where any methods declared to be served in the class and add them.
134 135 136 |
# File 'lib/simplews.rb', line 134 def self.serve(name, args=[], types={}, &block) METHODS[name] = {:args => args, :types => types, :block => block} end |
Instance Method Details
#serve(name, args = [], types = {}, &block) ⇒ Object
This method tells the server to provide a method named by the name
parameter, with arguments listed in the args
parameter. The types
parameter specifies the types of the arguments as will be described in the WSDL
file (see the TYPES2WSDL constant). The actual method called will be the one with the same name. Optionally a block can be provided, this block will be used to define a function named as in name.
If the method returns something, then the type of the return value must be specified in the types
parameter as :return. If not value for :return parameter is specified in the types
parameter the method is taken to return no value. Other than that, if a parameter type is omitted it is taken to be :string.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/simplews.rb', line 116 def serve(name, args=[], types={}, &block) if block inline_name = "_inline_" + name.to_s add_to_ruby(inline_name, &block) add_method_as(self,inline_name, name.to_s,*args) else add_method(self,name.to_s,*args) end add_to_wsdl(name, args, types) nil end |
#wsdl(filename = nil) ⇒ Object
If filename
is specified it saves the WSDL
file in that file. If no filename
is specified it returns a string containing the WSDL
. The no parameter version is served by default, so that clients can use this method to access the complete WSDL
file, as used in get_wsdl and get_driver.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/simplews.rb', line 143 def wsdl(filename = nil) wsdl = WSDL_STUB.dup wsdl.gsub!(/\$\{MESSAGES\}/m,@messages.join("\n")) wsdl.gsub!(/\$\{OPERATIONS\}/m,@operations.join("\n")) wsdl.gsub!(/\$\{BINDINGS\}/m,@bindings.join("\n")) wsdl.gsub!(/\$\{NAME\}/,@name) wsdl.gsub!(/\$\{DESCRIPTION\}/,@description) wsdl.gsub!(/\$\{LOCATION\}/,"http://#{ @host }:#{ @port }") if filename fwsdl = File.open(filename,'w') fwsdl.write(wsdl) fwsdl.close nil else wsdl end end |