soap4r-ng 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +15 -0
  2. data/bin/wsdl2ruby.rb +140 -0
  3. data/bin/xsd2ruby.rb +92 -0
  4. data/lib/soap/attachment.rb +109 -0
  5. data/lib/soap/attrproxy.rb +35 -0
  6. data/lib/soap/baseData.rb +1095 -0
  7. data/lib/soap/element.rb +278 -0
  8. data/lib/soap/encodingstyle/aspDotNetHandler.rb +208 -0
  9. data/lib/soap/encodingstyle/handler.rb +121 -0
  10. data/lib/soap/encodingstyle/literalHandler.rb +196 -0
  11. data/lib/soap/encodingstyle/soapHandler.rb +560 -0
  12. data/lib/soap/filter.rb +14 -0
  13. data/lib/soap/filter/filterchain.rb +52 -0
  14. data/lib/soap/filter/handler.rb +32 -0
  15. data/lib/soap/filter/streamhandler.rb +30 -0
  16. data/lib/soap/generator.rb +299 -0
  17. data/lib/soap/header/handler.rb +62 -0
  18. data/lib/soap/header/handlerset.rb +71 -0
  19. data/lib/soap/header/mappinghandler.rb +48 -0
  20. data/lib/soap/header/simplehandler.rb +45 -0
  21. data/lib/soap/httpconfigloader.rb +140 -0
  22. data/lib/soap/mapping.rb +13 -0
  23. data/lib/soap/mapping/encodedregistry.rb +541 -0
  24. data/lib/soap/mapping/factory.rb +389 -0
  25. data/lib/soap/mapping/literalregistry.rb +392 -0
  26. data/lib/soap/mapping/mapping.rb +577 -0
  27. data/lib/soap/mapping/registry.rb +296 -0
  28. data/lib/soap/mapping/rubytypeFactory.rb +446 -0
  29. data/lib/soap/mapping/schemadefinition.rb +171 -0
  30. data/lib/soap/mapping/typeMap.rb +107 -0
  31. data/lib/soap/mapping/wsdlencodedregistry.rb +212 -0
  32. data/lib/soap/mapping/wsdlliteralregistry.rb +249 -0
  33. data/lib/soap/marshal.rb +60 -0
  34. data/lib/soap/mimemessage.rb +243 -0
  35. data/lib/soap/nestedexception.rb +43 -0
  36. data/lib/soap/netHttpClient.rb +242 -0
  37. data/lib/soap/ns.rb +39 -0
  38. data/lib/soap/parser.rb +253 -0
  39. data/lib/soap/processor.rb +67 -0
  40. data/lib/soap/property.rb +330 -0
  41. data/lib/soap/proxy.rb +15 -0
  42. data/lib/soap/rpc/cgistub.rb +249 -0
  43. data/lib/soap/rpc/driver.rb +222 -0
  44. data/lib/soap/rpc/element.rb +375 -0
  45. data/lib/soap/rpc/httpserver.rb +144 -0
  46. data/lib/soap/rpc/methodDef.rb +69 -0
  47. data/lib/soap/rpc/proxy.rb +573 -0
  48. data/lib/soap/rpc/router.rb +663 -0
  49. data/lib/soap/rpc/rpc.rb +26 -0
  50. data/lib/soap/rpc/soaplet.rb +201 -0
  51. data/lib/soap/rpc/standaloneServer.rb +44 -0
  52. data/lib/soap/soap.rb +154 -0
  53. data/lib/soap/streamHandler.rb +302 -0
  54. data/lib/soap/version.rb +9 -0
  55. data/lib/soap/wsdlDriver.rb +165 -0
  56. data/lib/wsdl/binding.rb +66 -0
  57. data/lib/wsdl/data.rb +65 -0
  58. data/lib/wsdl/definitions.rb +237 -0
  59. data/lib/wsdl/documentation.rb +33 -0
  60. data/lib/wsdl/import.rb +81 -0
  61. data/lib/wsdl/importer.rb +39 -0
  62. data/lib/wsdl/info.rb +51 -0
  63. data/lib/wsdl/message.rb +55 -0
  64. data/lib/wsdl/operation.rb +152 -0
  65. data/lib/wsdl/operationBinding.rb +241 -0
  66. data/lib/wsdl/param.rb +94 -0
  67. data/lib/wsdl/parser.rb +180 -0
  68. data/lib/wsdl/part.rb +53 -0
  69. data/lib/wsdl/port.rb +67 -0
  70. data/lib/wsdl/portType.rb +76 -0
  71. data/lib/wsdl/service.rb +62 -0
  72. data/lib/wsdl/soap/address.rb +41 -0
  73. data/lib/wsdl/soap/binding.rb +50 -0
  74. data/lib/wsdl/soap/body.rb +59 -0
  75. data/lib/wsdl/soap/cgiStubCreator.rb +93 -0
  76. data/lib/wsdl/soap/classDefCreator.rb +434 -0
  77. data/lib/wsdl/soap/classDefCreatorSupport.rb +241 -0
  78. data/lib/wsdl/soap/classNameCreator.rb +55 -0
  79. data/lib/wsdl/soap/clientSkeltonCreator.rb +107 -0
  80. data/lib/wsdl/soap/complexType.rb +174 -0
  81. data/lib/wsdl/soap/data.rb +43 -0
  82. data/lib/wsdl/soap/definitions.rb +201 -0
  83. data/lib/wsdl/soap/driverCreator.rb +121 -0
  84. data/lib/wsdl/soap/element.rb +34 -0
  85. data/lib/wsdl/soap/encodedMappingRegistryCreator.rb +74 -0
  86. data/lib/wsdl/soap/fault.rb +57 -0
  87. data/lib/wsdl/soap/header.rb +87 -0
  88. data/lib/wsdl/soap/headerfault.rb +57 -0
  89. data/lib/wsdl/soap/literalMappingRegistryCreator.rb +116 -0
  90. data/lib/wsdl/soap/mappingRegistryCreator.rb +59 -0
  91. data/lib/wsdl/soap/mappingRegistryCreatorSupport.rb +377 -0
  92. data/lib/wsdl/soap/methodDefCreator.rb +200 -0
  93. data/lib/wsdl/soap/operation.rb +113 -0
  94. data/lib/wsdl/soap/servantSkeltonCreator.rb +92 -0
  95. data/lib/wsdl/soap/servletStubCreator.rb +105 -0
  96. data/lib/wsdl/soap/standaloneServerStubCreator.rb +101 -0
  97. data/lib/wsdl/soap/wsdl2ruby.rb +227 -0
  98. data/lib/wsdl/types.rb +45 -0
  99. data/lib/wsdl/wsdl.rb +25 -0
  100. data/lib/wsdl/xmlSchema/all.rb +25 -0
  101. data/lib/wsdl/xmlSchema/annotation.rb +35 -0
  102. data/lib/wsdl/xmlSchema/any.rb +62 -0
  103. data/lib/wsdl/xmlSchema/anyAttribute.rb +49 -0
  104. data/lib/wsdl/xmlSchema/attribute.rb +105 -0
  105. data/lib/wsdl/xmlSchema/attributeGroup.rb +69 -0
  106. data/lib/wsdl/xmlSchema/choice.rb +59 -0
  107. data/lib/wsdl/xmlSchema/complexContent.rb +98 -0
  108. data/lib/wsdl/xmlSchema/complexExtension.rb +120 -0
  109. data/lib/wsdl/xmlSchema/complexRestriction.rb +105 -0
  110. data/lib/wsdl/xmlSchema/complexType.rb +194 -0
  111. data/lib/wsdl/xmlSchema/content.rb +96 -0
  112. data/lib/wsdl/xmlSchema/data.rb +117 -0
  113. data/lib/wsdl/xmlSchema/element.rb +154 -0
  114. data/lib/wsdl/xmlSchema/enumeration.rb +37 -0
  115. data/lib/wsdl/xmlSchema/fractiondigits.rb +38 -0
  116. data/lib/wsdl/xmlSchema/group.rb +101 -0
  117. data/lib/wsdl/xmlSchema/import.rb +53 -0
  118. data/lib/wsdl/xmlSchema/importHandler.rb +45 -0
  119. data/lib/wsdl/xmlSchema/importer.rb +103 -0
  120. data/lib/wsdl/xmlSchema/include.rb +48 -0
  121. data/lib/wsdl/xmlSchema/length.rb +38 -0
  122. data/lib/wsdl/xmlSchema/list.rb +49 -0
  123. data/lib/wsdl/xmlSchema/maxexclusive.rb +38 -0
  124. data/lib/wsdl/xmlSchema/maxinclusive.rb +38 -0
  125. data/lib/wsdl/xmlSchema/maxlength.rb +38 -0
  126. data/lib/wsdl/xmlSchema/minexclusive.rb +38 -0
  127. data/lib/wsdl/xmlSchema/mininclusive.rb +38 -0
  128. data/lib/wsdl/xmlSchema/minlength.rb +38 -0
  129. data/lib/wsdl/xmlSchema/parser.rb +168 -0
  130. data/lib/wsdl/xmlSchema/pattern.rb +37 -0
  131. data/lib/wsdl/xmlSchema/ref.rb +34 -0
  132. data/lib/wsdl/xmlSchema/schema.rb +179 -0
  133. data/lib/wsdl/xmlSchema/sequence.rb +55 -0
  134. data/lib/wsdl/xmlSchema/simpleContent.rb +70 -0
  135. data/lib/wsdl/xmlSchema/simpleExtension.rb +63 -0
  136. data/lib/wsdl/xmlSchema/simpleRestriction.rb +133 -0
  137. data/lib/wsdl/xmlSchema/simpleType.rb +88 -0
  138. data/lib/wsdl/xmlSchema/totaldigits.rb +38 -0
  139. data/lib/wsdl/xmlSchema/union.rb +36 -0
  140. data/lib/wsdl/xmlSchema/unique.rb +35 -0
  141. data/lib/wsdl/xmlSchema/whitespace.rb +38 -0
  142. data/lib/wsdl/xmlSchema/xsd2ruby.rb +177 -0
  143. data/lib/xsd/charset.rb +190 -0
  144. data/lib/xsd/codegen.rb +13 -0
  145. data/lib/xsd/codegen/classdef.rb +209 -0
  146. data/lib/xsd/codegen/commentdef.rb +35 -0
  147. data/lib/xsd/codegen/gensupport.rb +277 -0
  148. data/lib/xsd/codegen/methoddef.rb +71 -0
  149. data/lib/xsd/codegen/moduledef.rb +209 -0
  150. data/lib/xsd/datatypes.rb +1465 -0
  151. data/lib/xsd/datatypes1999.rb +21 -0
  152. data/lib/xsd/iconvcharset.rb +33 -0
  153. data/lib/xsd/mapping.rb +69 -0
  154. data/lib/xsd/namedelements.rb +133 -0
  155. data/lib/xsd/ns.rb +183 -0
  156. data/lib/xsd/qname.rb +80 -0
  157. data/lib/xsd/xmlparser.rb +81 -0
  158. data/lib/xsd/xmlparser/libxmlparser.rb +135 -0
  159. data/lib/xsd/xmlparser/nokogiriparser.rb +58 -0
  160. data/lib/xsd/xmlparser/ogaparser.rb +63 -0
  161. data/lib/xsd/xmlparser/oxparser.rb +101 -0
  162. data/lib/xsd/xmlparser/parser.rb +101 -0
  163. data/lib/xsd/xmlparser/rexmlparser.rb +58 -0
  164. metadata +236 -0
@@ -0,0 +1,200 @@
1
+ # encoding: UTF-8
2
+ # WSDL4R - Creating method definition from WSDL
3
+ # Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
4
+
5
+ # This program is copyrighted free software by NAKAMURA, Hiroshi. You can
6
+ # redistribute it and/or modify it under the same terms of Ruby's license;
7
+ # either the dual license version in 2003, or any later version.
8
+
9
+
10
+ require 'wsdl/info'
11
+ require 'wsdl/soap/classDefCreatorSupport'
12
+ require 'soap/rpc/element'
13
+ require 'soap/rpc/methodDef'
14
+
15
+
16
+ module WSDL
17
+ module SOAP
18
+
19
+
20
+ class MethodDefCreator
21
+ include ClassDefCreatorSupport
22
+
23
+ attr_reader :definitions
24
+ # TODO: should not export this kind of stateful information.
25
+ # will be rewwritten in 1.6.1
26
+ attr_reader :assigned_method
27
+
28
+ def initialize(definitions, name_creator, modulepath, defined_const)
29
+ @definitions = definitions
30
+ @name_creator = name_creator
31
+ @modulepath = modulepath
32
+ @simpletypes = @definitions.collect_simpletypes
33
+ @complextypes = @definitions.collect_complextypes
34
+ @elements = @definitions.collect_elements
35
+ @defined_const = defined_const
36
+ @assigned_method = {}
37
+ end
38
+
39
+ def dump(name)
40
+ methoddef = ""
41
+ porttype = @definitions.porttype(name)
42
+ binding = porttype.find_binding
43
+ if binding
44
+ create(binding.name).each do |mdef|
45
+ methoddef << ",\n" unless methoddef.empty?
46
+ methoddef << dump_method(mdef).chomp
47
+ end
48
+ end
49
+ methoddef
50
+ end
51
+
52
+ def create(bindingname)
53
+ binding = @definitions.binding(bindingname)
54
+ if binding
55
+ return binding.operations.collect { |op_bind|
56
+ next unless op_bind.soapoperation # not a SOAP operation binding
57
+ create_methoddef(op_bind)
58
+ }
59
+ end
60
+ nil
61
+ end
62
+
63
+ private
64
+
65
+ def create_methoddef(op_bind)
66
+ op_info = op_bind.operation_info
67
+ name = assign_method_name(op_bind)
68
+ soapaction = op_info.boundid.soapaction
69
+ qname = op_bind.soapoperation_name
70
+ mdef = ::SOAP::RPC::MethodDef.new(name, soapaction, qname)
71
+ op_info.parts.each do |part|
72
+ if op_info.style == :rpc
73
+ mapped_class, qname = rpcdefinedtype(part)
74
+ else
75
+ mapped_class, qname = documentdefinedtype(part)
76
+ end
77
+ mdef.add_parameter(part.io_type, part.name, qname, mapped_class)
78
+ end
79
+ op_info.faults.each do |name, faultinfo|
80
+ faultclass = mapped_class_name(name, @modulepath)
81
+ mdef.faults[faultclass] = faultinfo
82
+ end
83
+ mdef.style = op_info.style
84
+ mdef.inputuse = op_info.inputuse
85
+ mdef.outputuse = op_info.outputuse
86
+ mdef
87
+ end
88
+
89
+ def dump_method(mdef)
90
+ style = mdef.style
91
+ inputuse = mdef.inputuse
92
+ outputuse = mdef.outputuse
93
+ paramstr = param2str(mdef.parameters)
94
+ if paramstr.empty?
95
+ paramstr = '[]'
96
+ else
97
+ paramstr = "[ " << paramstr.split(/\r?\n/).join("\n ") << " ]"
98
+ end
99
+ definitions = <<__EOD__
100
+ #{ndq(mdef.soapaction)},
101
+ #{dq(mdef.name)},
102
+ #{paramstr},
103
+ { :request_style => #{nsym(style)}, :request_use => #{nsym(inputuse)},
104
+ :response_style => #{nsym(style)}, :response_use => #{nsym(outputuse)},
105
+ :faults => #{mdef.faults.inspect} }
106
+ __EOD__
107
+ if style == :rpc
108
+ assign_const(mdef.qname.namespace, 'Ns')
109
+ return <<__EOD__
110
+ [ #{dqname(mdef.qname)},
111
+ #{definitions}]
112
+ __EOD__
113
+ else
114
+ return <<__EOD__
115
+ [ #{definitions}]
116
+ __EOD__
117
+ end
118
+ end
119
+
120
+ def assign_method_name(op_bind)
121
+ method_name = safemethodname(op_bind.name)
122
+ i = 1 # starts from _2
123
+ while @assigned_method.value?(method_name)
124
+ i += 1
125
+ method_name = safemethodname("#{op_bind.name}_#{i}")
126
+ end
127
+ @assigned_method[op_bind.boundid] = method_name
128
+ method_name
129
+ end
130
+
131
+ def rpcdefinedtype(part)
132
+ if mapped = basetype_mapped_class(part.type)
133
+ return ['::' + mapped.name, nil]
134
+ elsif definedtype = @simpletypes[part.type]
135
+ return [nil, definedtype.name]
136
+ elsif definedtype = @elements[part.element]
137
+ return [nil, part.element]
138
+ elsif definedtype = @complextypes[part.type]
139
+ case definedtype.compoundtype
140
+ when :TYPE_STRUCT, :TYPE_EMPTY, :TYPE_ARRAY, :TYPE_SIMPLE
141
+ type = mapped_class_name(part.type, @modulepath)
142
+ return [type, part.type]
143
+ when :TYPE_MAP
144
+ return [Hash.name, part.type]
145
+ else
146
+ raise NotImplementedError.new("must not reach here: #{definedtype.compoundtype}")
147
+ end
148
+ elsif part.type == XSD::AnyTypeName
149
+ return [nil, nil]
150
+ else
151
+ raise RuntimeError.new("part: #{part.name} cannot be resolved")
152
+ end
153
+ end
154
+
155
+ def documentdefinedtype(part)
156
+ if mapped = basetype_mapped_class(part.type)
157
+ return ['::' + mapped.name, XSD::QName.new(nil, part.name)]
158
+ elsif definedtype = @simpletypes[part.type]
159
+ if definedtype.base
160
+ return ['::' + basetype_mapped_class(definedtype.base).name, XSD::QName.new(nil, part.name)]
161
+ else
162
+ raise RuntimeError.new("unsupported simpleType: #{definedtype}")
163
+ end
164
+ elsif definedtype = @elements[part.element]
165
+ return ['::SOAP::SOAPElement', part.element]
166
+ elsif definedtype = @complextypes[part.type]
167
+ return ['::SOAP::SOAPElement', part.type]
168
+ else
169
+ raise RuntimeError.new("part: #{part.name} cannot be resolved")
170
+ end
171
+ end
172
+
173
+ def param2str(params)
174
+ params.collect { |param|
175
+ mappingstr = mapping_info2str(param.mapped_class, param.qname)
176
+ "[:#{param.io_type.id2name}, #{dq(param.name)}, #{mappingstr}]"
177
+ }.join(",\n")
178
+ end
179
+
180
+ def mapping_info2str(mapped_class, qname)
181
+ if qname.nil?
182
+ "[#{ndq(mapped_class)}]"
183
+ else
184
+ "[#{ndq(mapped_class)}, #{ndq(qname.namespace)}, #{dq(qname.name)}]"
185
+ end
186
+ end
187
+
188
+ def ele2str(ele)
189
+ qualified = ele
190
+ if qualified
191
+ "true"
192
+ else
193
+ "false"
194
+ end
195
+ end
196
+ end
197
+
198
+
199
+ end
200
+ end
@@ -0,0 +1,113 @@
1
+ # encoding: UTF-8
2
+ # WSDL4R - WSDL SOAP operation definition.
3
+ # Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
4
+
5
+ # This program is copyrighted free software by NAKAMURA, Hiroshi. You can
6
+ # redistribute it and/or modify it under the same terms of Ruby's license;
7
+ # either the dual license version in 2003, or any later version.
8
+
9
+
10
+ require 'wsdl/info'
11
+
12
+
13
+ module WSDL
14
+ module SOAP
15
+
16
+
17
+ class Operation < Info
18
+ class ParamInfo
19
+ attr_reader :style
20
+ attr_reader :op_name
21
+ attr_reader :optype_name
22
+ attr_reader :encodingstyle
23
+ attr_reader :headerparts
24
+ attr_reader :bodyparts
25
+ attr_reader :faultpart
26
+ attr_reader :soapaction
27
+
28
+ def initialize(style, use, encodingstyle, op_name, optype_name,
29
+ headerparts, bodyparts, faultpart, soapaction)
30
+ @style = style
31
+ @use = use
32
+ @encodingstyle = encodingstyle
33
+ @op_name = op_name
34
+ @optype_name = optype_name
35
+ @headerparts = headerparts
36
+ @bodyparts = bodyparts
37
+ @faultpart = faultpart
38
+ @soapaction = soapaction
39
+ end
40
+ end
41
+
42
+ attr_reader :soapaction
43
+ attr_reader :style
44
+
45
+ def initialize
46
+ super
47
+ @soapaction = nil
48
+ @style = nil
49
+ end
50
+
51
+ def parse_element(element)
52
+ nil
53
+ end
54
+
55
+ def parse_attr(attr, value)
56
+ case attr
57
+ when StyleAttrName
58
+ if ["document", "rpc"].include?(value.source)
59
+ @style = value.source.intern
60
+ else
61
+ raise Parser::AttributeConstraintError.new(
62
+ "Unexpected value #{ value }.")
63
+ end
64
+ when SOAPActionAttrName
65
+ @soapaction = value.source
66
+ else
67
+ nil
68
+ end
69
+ end
70
+
71
+ def operation_style
72
+ return @style if @style
73
+ if parent_binding.soapbinding
74
+ return parent_binding.soapbinding.style
75
+ end
76
+ nil
77
+ end
78
+
79
+ private
80
+
81
+ def parent_binding
82
+ parent.parent
83
+ end
84
+
85
+ def create_param_info(name_info, param)
86
+ op_style = operation_style()
87
+ op_use = param.soapbody_use
88
+ op_encodingstyle = param.soapbody_encodingstyle
89
+ op_name = name_info.op_name
90
+ optype_name = name_info.optype_name
91
+ soapheader = param.soapheader
92
+ headerparts = soapheader.collect { |item| item.find_part }
93
+ soapbody = param.soapbody
94
+ if soapbody.namespace
95
+ op_name = XSD::QName.new(soapbody.namespace, op_name.name)
96
+ end
97
+ if soapbody.parts
98
+ target = soapbody.parts.split(/\s+/)
99
+ bodyparts = name_info.parts.find_all { |part|
100
+ target.include?(part.name)
101
+ }
102
+ else
103
+ bodyparts = name_info.parts
104
+ end
105
+ faultpart = nil
106
+ ParamInfo.new(op_style, op_use, op_encodingstyle, op_name, optype_name,
107
+ headerparts, bodyparts, faultpart, parent.soapaction)
108
+ end
109
+ end
110
+
111
+
112
+ end
113
+ end
@@ -0,0 +1,92 @@
1
+ # encoding: UTF-8
2
+ # WSDL4R - Creating servant skelton code from WSDL.
3
+ # Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
4
+
5
+ # This program is copyrighted free software by NAKAMURA, Hiroshi. You can
6
+ # redistribute it and/or modify it under the same terms of Ruby's license;
7
+ # either the dual license version in 2003, or any later version.
8
+
9
+
10
+ require 'wsdl/info'
11
+ require 'wsdl/soap/classDefCreatorSupport'
12
+ require 'xsd/codegen'
13
+
14
+
15
+ module WSDL
16
+ module SOAP
17
+
18
+
19
+ class ServantSkeltonCreator
20
+ include ClassDefCreatorSupport
21
+ include XSD::CodeGen::GenSupport
22
+
23
+ attr_reader :definitions
24
+
25
+ def initialize(definitions, name_creator, modulepath = nil)
26
+ @definitions = definitions
27
+ @name_creator = name_creator
28
+ @modulepath = modulepath
29
+ end
30
+
31
+ def dump(porttype = nil)
32
+ result = ""
33
+ if @modulepath
34
+ result << "\n"
35
+ modulepath = @modulepath.respond_to?(:lines) ? @modulepath.lines : @modulepath # RubyJedi: compatible with Ruby 1.8.6 and above
36
+ result << modulepath.collect { |ele| "module #{ele}" }.join("; ")
37
+ result << "\n\n"
38
+ end
39
+ if porttype.nil?
40
+ @definitions.porttypes.each do |porttype|
41
+ result << dump_porttype(porttype)
42
+ result << "\n"
43
+ end
44
+ else
45
+ result << dump_porttype(porttype)
46
+ end
47
+ if @modulepath
48
+ result << "\n\n"
49
+ modulepath = @modulepath.respond_to?(:lines) ? @modulepath.lines : @modulepath # RubyJedi: compatible with Ruby 1.8.6 and above
50
+ result << modulepath.collect { |ele| "end" }.join("; ")
51
+ result << "\n"
52
+ end
53
+ result
54
+ end
55
+
56
+ private
57
+
58
+ def dump_porttype(porttype)
59
+ assigned_method = collect_assigned_method(@definitions, porttype.name, @modulepath)
60
+ class_name = mapped_class_basename(porttype.name, @modulepath)
61
+ c = XSD::CodeGen::ClassDef.new(class_name)
62
+ element_definitions = @definitions.collect_elements
63
+ binding = porttype.find_binding
64
+ if binding
65
+ binding.operations.each do |op_bind|
66
+ operation = op_bind.find_operation
67
+ if operation.nil?
68
+ warn("operation not found for binding: #{op_bind}")
69
+ next
70
+ end
71
+ name = assigned_method[op_bind.boundid] || operation.name
72
+ methodname = safemethodname(name)
73
+ input = operation.input
74
+ params = input.find_message.parts.collect { |part|
75
+ safevarname(part.name)
76
+ }
77
+ m = XSD::CodeGen::MethodDef.new(methodname, params) do <<-EOD
78
+ p [#{params.join(", ")}]
79
+ raise NotImplementedError.new
80
+ EOD
81
+ end
82
+ m.comment = dump_method_signature(methodname, operation, element_definitions)
83
+ c.add_method(m)
84
+ end
85
+ end
86
+ c.dump
87
+ end
88
+ end
89
+
90
+
91
+ end
92
+ end
@@ -0,0 +1,105 @@
1
+ # encoding: UTF-8
2
+ # WSDL4R - Creating servlet stub code from WSDL.
3
+ # Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
4
+
5
+ # This program is copyrighted free software by NAKAMURA, Hiroshi. You can
6
+ # redistribute it and/or modify it under the same terms of Ruby's license;
7
+ # either the dual license version in 2003, or any later version.
8
+
9
+
10
+ require 'wsdl/info'
11
+ require 'wsdl/soap/mappingRegistryCreator'
12
+ require 'wsdl/soap/methodDefCreator'
13
+ require 'wsdl/soap/classDefCreatorSupport'
14
+
15
+
16
+ module WSDL
17
+ module SOAP
18
+
19
+
20
+ class ServletStubCreator
21
+ include ClassDefCreatorSupport
22
+
23
+ attr_reader :definitions
24
+
25
+ def initialize(definitions, name_creator, modulepath = nil)
26
+ @definitions = definitions
27
+ @name_creator = name_creator
28
+ @modulepath = modulepath
29
+ end
30
+
31
+ def dump(service_name)
32
+ warn("- Servlet stub can have only 1 port for now. So creating stub for the first port and rests are ignored.")
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
+ methoddef = MethodDefCreator.new(@definitions, @name_creator, @modulepath, defined_const).dump(porttype.name)
54
+ wsdl_name = @definitions.name ? @definitions.name.name : 'default'
55
+ mrname = safeconstname(wsdl_name + 'MappingRegistry')
56
+ c1 = XSD::CodeGen::ClassDef.new(class_name)
57
+ c1.def_require("soap/rpc/soaplet")
58
+ c1.def_code <<-EOD
59
+ Methods = [
60
+ #{methoddef.gsub(/^/, " ")}
61
+ ]
62
+ EOD
63
+ defined_const.each do |ns, tag|
64
+ c1.def_const(tag, dq(ns))
65
+ end
66
+ c2 = XSD::CodeGen::ClassDef.new(class_name + "Servlet",
67
+ "::SOAP::RPC::SOAPlet")
68
+ c2.def_method("initialize", "router = nil") do
69
+ <<-EOD
70
+ super(router)
71
+ servant = #{class_name}.new
72
+ #{class_name}::Methods.each do |definitions|
73
+ opt = definitions.last
74
+ if opt[:request_style] == :document
75
+ @router.add_document_operation(servant, *definitions)
76
+ else
77
+ @router.add_rpc_operation(servant, *definitions)
78
+ end
79
+ end
80
+ @router.mapping_registry = #{mrname}::EncodedRegistry
81
+ @router.literal_mapping_registry = #{mrname}::LiteralRegistry
82
+ EOD
83
+ end
84
+ c1.dump + "\n" + c2.dump + format(<<-EOD)
85
+
86
+ if $0 == __FILE__
87
+ require 'webrick'
88
+ server = WEBrick::HTTPServer.new(
89
+ :BindAddress => "0.0.0.0",
90
+ :Port => 10080,
91
+ :DocumentRoot => "."
92
+ )
93
+ server.mount("/", #{c2.name}.new)
94
+ trap(:INT) do
95
+ server.shutdown
96
+ end
97
+ server.start
98
+ end
99
+ EOD
100
+ end
101
+ end
102
+
103
+
104
+ end
105
+ end