Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

root/branches/1_5/lib/wsdl/soap/standaloneServerStubCreator.rb

Revision 1948, 3.1 kB (checked in by nahi, 1 year ago)
  • let ClassNameCreator? handle modulepath. Foo::Baz and Bar::Baz have the same name (Baz) but these are different qnames so there's no need for name crash avoidaidance. closes #413.
  • Property svn:eol-style set to native
  • Property svn:keywords set to author date id revision
Line 
1 # WSDL4R - Creating standalone server stub code from WSDL.
2 # Copyright (C) 2000-2007  NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
3
4 # This program is copyrighted free software by NAKAMURA, Hiroshi.  You can
5 # redistribute it and/or modify it under the same terms of Ruby's license;
6 # either the dual license version in 2003, or any later version.
7
8
9 require 'wsdl/info'
10 require 'wsdl/soap/mappingRegistryCreator'
11 require 'wsdl/soap/methodDefCreator'
12 require 'wsdl/soap/classDefCreatorSupport'
13
14
15 module WSDL
16 module SOAP
17
18
19 class StandaloneServerStubCreator
20   include ClassDefCreatorSupport
21
22   attr_reader :definitions
23
24   def initialize(definitions, name_creator, modulepath = nil)
25     @definitions = definitions
26     @name_creator = name_creator
27     @modulepath = modulepath
28   end
29
30   def dump(service_name)
31     warn("- Standalone stub can have only 1 port for now.  So creating stub for the first port and rests are ignored.")
32     warn("- Standalone server stub ignores port location defined in WSDL.  Location is http://localhost:10080/ by default.  Generated client from WSDL must be configured to point this endpoint manually.")
33     services = @definitions.service(service_name)
34     unless services
35       raise RuntimeError.new("service not defined: #{service_name}")
36     end
37     ports = services.ports
38     if ports.empty?
39       raise RuntimeError.new("ports not found for #{service_name}")
40     end
41     port = ports[0]
42     if port.porttype.nil?
43       raise RuntimeError.new("porttype not found for #{port}")
44     end
45     dump_porttype(port.porttype)
46   end
47
48 private
49
50   def dump_porttype(porttype)
51     class_name = mapped_class_name(porttype.name, @modulepath)
52     defined_const = {}
53     result = MethodDefCreator.new(@definitions, @name_creator, @modulepath, defined_const).dump(porttype.name)
54     methoddef = result[:methoddef]
55
56     wsdl_name = @definitions.name ? @definitions.name.name : 'default'
57     mrname = safeconstname(wsdl_name + 'MappingRegistry')
58    
59     c1 = XSD::CodeGen::ClassDef.new(class_name)
60     c1.def_require("soap/rpc/standaloneServer")
61     c1.def_code <<-EOD
62 Methods = [
63 #{methoddef.gsub(/^/, "  ")}
64 ]
65     EOD
66     defined_const.each do |ns, tag|
67       c1.def_const(tag, dq(ns))
68     end
69     c2 = XSD::CodeGen::ClassDef.new(class_name + "App",
70       "::SOAP::RPC::StandaloneServer")
71     c2.def_method("initialize", "*arg") do
72       <<-EOD
73         super(*arg)
74         servant = #{class_name}.new
75         #{class_name}::Methods.each do |definitions|
76           opt = definitions.last
77           if opt[:request_style] == :document
78             @router.add_document_operation(servant, *definitions)
79           else
80             @router.add_rpc_operation(servant, *definitions)
81           end
82         end
83         self.mapping_registry = #{mrname}::EncodedRegistry
84         self.literal_mapping_registry = #{mrname}::LiteralRegistry
85       EOD
86     end
87     c1.dump + "\n" + c2.dump + format(<<-EOD)
88
89       if $0 == __FILE__
90         # Change listen port.
91         server = #{class_name}App.new('app', nil, '0.0.0.0', 10080)
92         trap(:INT) do
93           server.shutdown
94         end
95         server.start
96       end
97     EOD
98   end
99 end
100
101
102 end
103 end
Note: See TracBrowser for help on using the browser.