soybean 2.4.3 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -1
- data/Gemfile.lock +7 -2
- data/VERSION +1 -1
- data/config.ru +8 -0
- data/lib/soybean.rb +13 -2
- data/lib/soybean/application.rb +59 -0
- data/lib/soybean/{middleware.rb → engine.rb} +78 -8
- data/lib/soybean/generators/class_generator.rb +2 -2
- data/lib/soybean/generators/{middleware_generator.rb → engine_generator.rb} +4 -4
- data/lib/soybean/generators/service_generator.rb +7 -3
- data/lib/soybean/generators/templates/engine.rb +6 -0
- data/lib/soybean/generators/wsdl_generator.rb +34 -0
- data/lib/soybean/interface.rb +13 -0
- data/lib/{core_ext/module.rb → soybean/soap_attribute.rb} +0 -0
- data/soybean.gemspec +19 -9
- data/soybean.log +1353 -0
- metadata +58 -32
- data/lib/soybean/generators/templates/middleware.rb +0 -39
data/Gemfile
CHANGED
@@ -3,6 +3,10 @@ source "http://rubygems.org"
|
|
3
3
|
gem 'thor'
|
4
4
|
gem 'activesupport', '~> 3.1'
|
5
5
|
gem 'i18n'
|
6
|
+
gem 'nokogiri'
|
7
|
+
gem 'rack'
|
8
|
+
gem 'rack-mount'
|
9
|
+
|
6
10
|
#gem "soap4r-middleware-192", "~> 0.8.2", :require => "soap4r-middleware"
|
7
11
|
|
8
12
|
# Add dependencies to develop your gem here.
|
@@ -12,5 +16,4 @@ group :development do
|
|
12
16
|
gem "yard", "~> 0.6.0"
|
13
17
|
gem "bundler", "~> 1.0.0"
|
14
18
|
gem "jeweler", "~> 1.6.4"
|
15
|
-
gem "rcov", ">= 0"
|
16
19
|
end
|
data/Gemfile.lock
CHANGED
@@ -11,8 +11,11 @@ GEM
|
|
11
11
|
git (>= 1.2.5)
|
12
12
|
rake
|
13
13
|
multi_json (1.0.3)
|
14
|
+
nokogiri (1.5.0)
|
15
|
+
rack (1.3.4)
|
16
|
+
rack-mount (0.8.3)
|
17
|
+
rack (>= 1.0.0)
|
14
18
|
rake (0.9.2)
|
15
|
-
rcov (0.9.10)
|
16
19
|
rspec (2.3.0)
|
17
20
|
rspec-core (~> 2.3.0)
|
18
21
|
rspec-expectations (~> 2.3.0)
|
@@ -32,7 +35,9 @@ DEPENDENCIES
|
|
32
35
|
bundler (~> 1.0.0)
|
33
36
|
i18n
|
34
37
|
jeweler (~> 1.6.4)
|
35
|
-
|
38
|
+
nokogiri
|
39
|
+
rack
|
40
|
+
rack-mount
|
36
41
|
rspec (~> 2.3.0)
|
37
42
|
thor
|
38
43
|
yard (~> 0.6.0)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.0
|
data/config.ru
ADDED
data/lib/soybean.rb
CHANGED
@@ -6,8 +6,8 @@ require 'active_support/deprecation'
|
|
6
6
|
require 'active_support/dependencies'
|
7
7
|
require 'active_support/dependencies/autoload'
|
8
8
|
require 'active_support/core_ext/module/delegation'
|
9
|
-
require 'active_support/
|
10
|
-
require '
|
9
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
10
|
+
require 'logger'
|
11
11
|
|
12
12
|
$:.unshift File.absolute_path(File.join(File.dirname(__FILE__), '..', 'vendor/soap4r'))
|
13
13
|
|
@@ -16,5 +16,16 @@ ActiveSupport::Dependencies.autoload_paths << File.absolute_path(File.join(File.
|
|
16
16
|
|
17
17
|
module Soybean
|
18
18
|
extend ActiveSupport::Autoload
|
19
|
+
|
19
20
|
VERSION = File.read(File.expand_path('../../VERSION', __FILE__))
|
21
|
+
|
22
|
+
mattr_accessor :engines
|
23
|
+
self.engines = []
|
24
|
+
|
25
|
+
mattr_accessor :services
|
26
|
+
self.services = []
|
27
|
+
|
28
|
+
mattr_accessor :logger
|
29
|
+
self.logger = Logger.new(STDOUT)
|
30
|
+
|
20
31
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rack/builder'
|
2
|
+
require 'active_support/configurable'
|
3
|
+
|
4
|
+
module Soybean
|
5
|
+
class Application
|
6
|
+
|
7
|
+
attr_reader :services
|
8
|
+
|
9
|
+
def initialize(services, &block)
|
10
|
+
load!(services)
|
11
|
+
configure(&block)
|
12
|
+
|
13
|
+
logger.info "SOAP Services: START"
|
14
|
+
at_exit{ logger.info "SOAP Services: STOP" }
|
15
|
+
|
16
|
+
@app = Rack::Builder.new do
|
17
|
+
Soybean.engines.each do |engine|
|
18
|
+
engine.logger.info "Service found: #{engine.service.endpoint} route to /#{engine.service.class.name}" if engine.logger
|
19
|
+
map "/#{engine.service.endpoint}" do
|
20
|
+
run engine.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Soybean.engines.last.logger.info ""
|
25
|
+
end.to_app
|
26
|
+
end
|
27
|
+
|
28
|
+
def call(env)
|
29
|
+
@app.call(env)
|
30
|
+
end
|
31
|
+
|
32
|
+
def logger(new_logger=nil)
|
33
|
+
@logger = new_logger unless new_logger.nil?
|
34
|
+
@logger || Soybean.logger
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
def configure(&block)
|
40
|
+
instance_eval &block
|
41
|
+
|
42
|
+
logger.datetime_format = "%Y-%m-%d %H:%M:%S"
|
43
|
+
logger.formatter = proc { |severity, datetime, progname, msg|
|
44
|
+
"#{msg}\n"
|
45
|
+
}
|
46
|
+
|
47
|
+
Soybean.engines.each do |engine|
|
48
|
+
engine.logger = logger
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def load!(path)
|
53
|
+
$:.unshift path
|
54
|
+
ActiveSupport::Dependencies.autoload_paths << path
|
55
|
+
Dir["#{path}/engines/*"].each { |f| require f }
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -1,8 +1,16 @@
|
|
1
1
|
require 'soap/rpc/router'
|
2
2
|
|
3
3
|
module Soybean
|
4
|
-
|
4
|
+
|
5
|
+
class Engine
|
5
6
|
include SOAP
|
7
|
+
class_attribute :service, :instance_reader => false, :instance_writer => false
|
8
|
+
class_attribute :logger, :instance_reader => true, :instance_writer => false
|
9
|
+
self.logger = Soybean.logger
|
10
|
+
|
11
|
+
def self.inherited(subclass)
|
12
|
+
Soybean.engines << subclass
|
13
|
+
end
|
6
14
|
|
7
15
|
module ClassMethods
|
8
16
|
def setup
|
@@ -103,22 +111,75 @@ module Soybean
|
|
103
111
|
router.add_document_operation(receiver, soapaction, name, param_def, opt)
|
104
112
|
end
|
105
113
|
end
|
106
|
-
|
107
114
|
extend ClassMethods
|
108
115
|
|
109
116
|
def initialize(app = nil)
|
110
117
|
@app = app
|
118
|
+
setup!(self.class.service)
|
119
|
+
end
|
120
|
+
|
121
|
+
def setup!(service)
|
122
|
+
self.class.setup {}
|
123
|
+
service.class::Methods.each do |definitions|
|
124
|
+
opt = definitions.last
|
125
|
+
if opt[:request_style] == :document
|
126
|
+
self.class.router.add_document_operation(service, *definitions)
|
127
|
+
else
|
128
|
+
self.class.router.add_rpc_operation(service, *definitions)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
self.class.mapping_registry = Mappings::EncodedRegistry
|
132
|
+
self.class.literal_mapping_registry = Mappings::LiteralRegistry
|
111
133
|
end
|
112
134
|
|
113
135
|
def call(env)
|
114
|
-
|
136
|
+
s, h, b = with_logging(env, logger) do
|
115
137
|
handle(env)
|
116
|
-
else
|
117
|
-
# we can act as both a middleware and an app
|
118
|
-
@app ?
|
119
|
-
@app.call(env) :
|
120
|
-
(return 404, {"Content-Type" => "text/plain"}, ["404 - Not Found"])
|
121
138
|
end
|
139
|
+
return s, h, b
|
140
|
+
rescue => e
|
141
|
+
[200, {'Allow' => 'POST',
|
142
|
+
'Content-Type' => 'text/plain'}, [e.message,
|
143
|
+
e.backtrace.join("\n")]]
|
144
|
+
end
|
145
|
+
|
146
|
+
def with_logging(env, logger)
|
147
|
+
#Started GET "/" for 127.0.0.1 at 2011-09-28 14:21:28 +0400
|
148
|
+
# Processing by DashboardController#index as HTML
|
149
|
+
# User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 100 LIMIT 1
|
150
|
+
# Role Load (0.3ms) SELECT `roles`.* FROM `roles` INNER JOIN `assignments` ON `roles`.`id` = `assignments`.`role_id` WHERE `assignments`.`user_id` = 100
|
151
|
+
#Redirected to http://localhost:3000/municipal_services
|
152
|
+
#Completed 302 Found in 89ms
|
153
|
+
|
154
|
+
request = Rack::Request.new(env)
|
155
|
+
input_params = request.body.read
|
156
|
+
request.body.rewind
|
157
|
+
|
158
|
+
logger.info "Started %s \"%s\" for %s at %s. caller %s" % [request.request_method,
|
159
|
+
URI(env['REQUEST_URI']).path,
|
160
|
+
request.ip,
|
161
|
+
Time.now.strftime(logger.datetime_format),
|
162
|
+
request.referer] if logger
|
163
|
+
|
164
|
+
logger.info " Processing by %s" % [self.class.service.class.name] if logger
|
165
|
+
logger.debug " Headers: %s" % [request.header.inspect] if logger
|
166
|
+
logger.debug " Parameters: " if logger
|
167
|
+
|
168
|
+
logger.debug pretty_xml(input_params, ' ') if logger
|
169
|
+
|
170
|
+
s, h, b = yield
|
171
|
+
|
172
|
+
logger.debug "Response:" % [h.inspect] if logger
|
173
|
+
logger.debug " Headers: %s" % [h.inspect] if logger
|
174
|
+
logger.debug " Body: " if logger
|
175
|
+
|
176
|
+
logger.debug pretty_xml(b.join, ' ') if logger
|
177
|
+
|
178
|
+
return s, h, b
|
179
|
+
|
180
|
+
rescue => e
|
181
|
+
logger.error "\tERROR: \n%s" % [e.message] if logger
|
182
|
+
raise e
|
122
183
|
end
|
123
184
|
|
124
185
|
def handle(env)
|
@@ -177,5 +238,14 @@ module Soybean
|
|
177
238
|
end
|
178
239
|
nil
|
179
240
|
end
|
241
|
+
|
242
|
+
protected
|
243
|
+
def pretty_xml(string, ident=' ')
|
244
|
+
Nokogiri.XML(string) { |config| config.default_xml.noblanks }.to_xml(ident: 2).each_line.map do |line|
|
245
|
+
"#{ident}#{line}"
|
246
|
+
end.join
|
247
|
+
rescue
|
248
|
+
string
|
249
|
+
end
|
180
250
|
end
|
181
251
|
end
|
@@ -81,8 +81,8 @@ module Soybean
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def accessors
|
84
|
-
@attrdef.map do |attrname,
|
85
|
-
format("soap_attribute #{
|
84
|
+
@attrdef.map do |attrname, writeable, varname|
|
85
|
+
format("soap_attribute #{varname.underscore.to_sym.inspect}\n", 2)
|
86
86
|
end.join
|
87
87
|
end
|
88
88
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Soybean
|
2
2
|
module Generators
|
3
|
-
class
|
3
|
+
class EngineGenerator
|
4
4
|
include BaseGenerator
|
5
5
|
|
6
6
|
attr_reader :name, :model
|
@@ -10,15 +10,15 @@ module Soybean
|
|
10
10
|
|
11
11
|
def initialize(model)
|
12
12
|
@model = model
|
13
|
-
@name = (wsdl.name.name.underscore.gsub(/service$/, '') rescue 'base') + '
|
13
|
+
@name = (wsdl.name.name.underscore.gsub(/service$/, '') rescue 'base') + 'engine'
|
14
14
|
end
|
15
15
|
|
16
16
|
def dir
|
17
|
-
'
|
17
|
+
'engines'
|
18
18
|
end
|
19
19
|
|
20
20
|
def generate
|
21
|
-
source = File.expand_path("../templates/
|
21
|
+
source = File.expand_path("../templates/engine.rb", __FILE__)
|
22
22
|
context = instance_eval('binding')
|
23
23
|
content = ERB.new(::File.binread(source), nil, '-').result(context)
|
24
24
|
content
|
@@ -15,7 +15,7 @@ module Soybean
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def generate
|
18
|
-
(schemes + mappings + interface + model + specs +
|
18
|
+
(schemes + mappings + interface + model + specs + engines).map do |generator|
|
19
19
|
yield generator.fullpath(path), generator.generate, generator
|
20
20
|
end
|
21
21
|
end
|
@@ -32,8 +32,12 @@ module Soybean
|
|
32
32
|
@model ||= [ModelGenerator.new(@wsdl)]
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
36
|
-
@
|
35
|
+
def static
|
36
|
+
@static ||= [StaticGenerator.new(@wsdl)]
|
37
|
+
end
|
38
|
+
|
39
|
+
def engines
|
40
|
+
@engines ||= model.map { |m| EngineGenerator.new(m) }
|
37
41
|
end
|
38
42
|
|
39
43
|
def specs
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Soybean
|
2
|
+
module Generators
|
3
|
+
class WsdlGenerator
|
4
|
+
include BaseGenerator
|
5
|
+
|
6
|
+
attr_reader :name
|
7
|
+
|
8
|
+
def initialize(wsdl)
|
9
|
+
@wsdl = wsdl
|
10
|
+
@name = wsdl.name.name
|
11
|
+
end
|
12
|
+
|
13
|
+
def dir
|
14
|
+
'wsdl'
|
15
|
+
end
|
16
|
+
|
17
|
+
def filename
|
18
|
+
"#{name}.wsdl"
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate
|
22
|
+
if block_given?
|
23
|
+
yield File.join(dir, filename), dump
|
24
|
+
else
|
25
|
+
dump
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def dump
|
30
|
+
@wsdl.to_s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/soybean/interface.rb
CHANGED
@@ -5,10 +5,23 @@ module Soybean
|
|
5
5
|
def self.inherited(subclass)
|
6
6
|
self.interfaces ||= []
|
7
7
|
self.interfaces << subclass if subclass.superclass == Soybean::Interface
|
8
|
+
Soybean.services << subclass if subclass.superclass < Soybean::Interface
|
8
9
|
end
|
9
10
|
|
10
11
|
def self.actions
|
11
12
|
self.instance_methods - Object.instance_methods
|
12
13
|
end
|
14
|
+
|
15
|
+
|
16
|
+
attr_reader :logger
|
17
|
+
|
18
|
+
def initialize(logger=Soybean.logger)
|
19
|
+
@logger = logger
|
20
|
+
end
|
21
|
+
|
22
|
+
def endpoint
|
23
|
+
self.class.name
|
24
|
+
end
|
25
|
+
|
13
26
|
end
|
14
27
|
end
|
File without changes
|
data/soybean.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{soybean}
|
8
|
-
s.version = "2.
|
8
|
+
s.version = "2.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Anton Sozontov"]
|
12
|
-
s.date = %q{2011-10-
|
12
|
+
s.date = %q{2011-10-17}
|
13
13
|
s.default_executable = %q{soybean}
|
14
14
|
s.description = %q{Generate soap web-services from you wsdl. Generate: all classes from xsd, and other.}
|
15
15
|
s.email = %q{a.sozontov@gmail.com}
|
@@ -28,27 +28,31 @@ Gem::Specification.new do |s|
|
|
28
28
|
"Rakefile",
|
29
29
|
"VERSION",
|
30
30
|
"bin/soybean",
|
31
|
-
"
|
31
|
+
"config.ru",
|
32
32
|
"lib/soybean.rb",
|
33
|
+
"lib/soybean/application.rb",
|
33
34
|
"lib/soybean/cli.rb",
|
34
35
|
"lib/soybean/complex_type.rb",
|
35
36
|
"lib/soybean/encoded_mapping_registry_creator.rb",
|
37
|
+
"lib/soybean/engine.rb",
|
36
38
|
"lib/soybean/generators/base_generator.rb",
|
37
39
|
"lib/soybean/generators/class_generator.rb",
|
40
|
+
"lib/soybean/generators/engine_generator.rb",
|
38
41
|
"lib/soybean/generators/interface_generator.rb",
|
39
42
|
"lib/soybean/generators/mapping_generator.rb",
|
40
|
-
"lib/soybean/generators/middleware_generator.rb",
|
41
43
|
"lib/soybean/generators/model_generator.rb",
|
42
44
|
"lib/soybean/generators/model_spec_generator.rb",
|
43
45
|
"lib/soybean/generators/service_generator.rb",
|
44
|
-
"lib/soybean/generators/templates/
|
46
|
+
"lib/soybean/generators/templates/engine.rb",
|
45
47
|
"lib/soybean/generators/templates/model_spec.rb",
|
46
48
|
"lib/soybean/generators/types_generator.rb",
|
49
|
+
"lib/soybean/generators/wsdl_generator.rb",
|
47
50
|
"lib/soybean/interface.rb",
|
48
51
|
"lib/soybean/interface_builder.rb",
|
49
52
|
"lib/soybean/literal_mapping_registry_creator.rb",
|
50
|
-
"lib/soybean/
|
53
|
+
"lib/soybean/soap_attribute.rb",
|
51
54
|
"soybean.gemspec",
|
55
|
+
"soybean.log",
|
52
56
|
"spec/soybean_spec.rb",
|
53
57
|
"spec/spec_helper.rb",
|
54
58
|
"vendor/soap4r/soap/attachment.rb",
|
@@ -224,30 +228,36 @@ Gem::Specification.new do |s|
|
|
224
228
|
s.add_runtime_dependency(%q<thor>, [">= 0"])
|
225
229
|
s.add_runtime_dependency(%q<activesupport>, ["~> 3.1"])
|
226
230
|
s.add_runtime_dependency(%q<i18n>, [">= 0"])
|
231
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
232
|
+
s.add_runtime_dependency(%q<rack>, [">= 0"])
|
233
|
+
s.add_runtime_dependency(%q<rack-mount>, [">= 0"])
|
227
234
|
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
228
235
|
s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
|
229
236
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
230
237
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
231
|
-
s.add_development_dependency(%q<rcov>, [">= 0"])
|
232
238
|
else
|
233
239
|
s.add_dependency(%q<thor>, [">= 0"])
|
234
240
|
s.add_dependency(%q<activesupport>, ["~> 3.1"])
|
235
241
|
s.add_dependency(%q<i18n>, [">= 0"])
|
242
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
243
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
244
|
+
s.add_dependency(%q<rack-mount>, [">= 0"])
|
236
245
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
237
246
|
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
238
247
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
239
248
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
240
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
241
249
|
end
|
242
250
|
else
|
243
251
|
s.add_dependency(%q<thor>, [">= 0"])
|
244
252
|
s.add_dependency(%q<activesupport>, ["~> 3.1"])
|
245
253
|
s.add_dependency(%q<i18n>, [">= 0"])
|
254
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
255
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
256
|
+
s.add_dependency(%q<rack-mount>, [">= 0"])
|
246
257
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
247
258
|
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
248
259
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
249
260
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
250
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
251
261
|
end
|
252
262
|
end
|
253
263
|
|