wash_out 0.9.0.beta.1 → 0.9.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4791d7a762e3d5a75e9f8d3233ddd7d0b10a240f
4
- data.tar.gz: d0d43203c81135e8040258cf971bd5b849c95b2e
3
+ metadata.gz: b640e8dbbc4f8e47d5b4bf02e02a8eddb87f4022
4
+ data.tar.gz: d262ad3bd148080fc799e202ceacafde106413ec
5
5
  SHA512:
6
- metadata.gz: 925b2b09044af493d24e94e63a089cd81e56797c04c52ed8555605e0c306f9e99acec82427d4c010092af825508addb61e7b11b7bc3d28100db0d5353075bcc9
7
- data.tar.gz: 300d800215c4b1442e9eb85b1c07d67126b04b3d8cca50120072b5543e32d51f14db91d33fb7258aa8580c29942cc8518924dec2c63b5ebfd00e89479b509e09
6
+ metadata.gz: 6b50419b1b9249d150c5adc7a85ea40e0ca05cd88efd5596e3ec0a1f94606ade0cf88fa8997daca86c4bfb993e11db2052f0c6421047d19cdd4d1526e04cad4a
7
+ data.tar.gz: b8f74d77676cb1e6ae2084444dee8d8034bff01337c3a573727d9fbccd8675f677be2e19308d1faf5eeb80696344a9fea1da75e0ee573bee6e8d6749e2be16c2
data/README.md CHANGED
@@ -22,7 +22,7 @@ In your Gemfile, add this line:
22
22
 
23
23
  gem 'wash_out'
24
24
 
25
- If you are upgrading from version < 0.8.5, replace `include WashOut::Soap` with `soap_service` at the controller level.
25
+ Please read [release details](https://github.com/inossidabile/wash_out/releases) if you are upgrading. We break backward compatibility between large ticks but you can expect it to be specified at release notes.
26
26
 
27
27
  ## Usage
28
28
 
@@ -147,10 +147,9 @@ To override the values on a specific controller just add an override as part of
147
147
  Available properties are:
148
148
 
149
149
  * **parser**: XML parser to use – `:rexml` or `:nokogiri`. The first one is default but the latter is much faster. Be sure to add `gem nokogiri` if you want to use it.
150
- * **style**: sets WSDL style. Supported values are: 'document' and 'rpc'.
150
+ * **wsdl_style**: sets WSDL style. Supported values are: 'document' and 'rpc'.
151
151
  * **catch_xml_errors**: intercept Rails parsing exceptions to return correct XML response for corrupt XML input. Default is `false`.
152
152
  * **namespace**: SOAP namespace to use. Default is `urn:WashOut`.
153
- * **snakecase**: *(DEPRECATED SINCE 0.4.0)* Determines if WashOut should modify parameters keys to snakecase. Default is `false`.
154
153
  * **snakecase_input**: Determines if WashOut should modify parameters keys to snakecase. Default is `false`.
155
154
  * **camelize_wsdl**: Determines if WashOut should camelize types within WSDL and responses. Supports `true` for CamelCase and `:lower` for camelCase. Default is `false`.
156
155
 
@@ -1,5 +1,3 @@
1
- require 'nori'
2
-
3
1
  module WashOut
4
2
  # The WashOut::Dispatcher module should be included in a controller acting
5
3
  # as a SOAP endpoint. It includes actions for generating WSDL and handling
@@ -10,28 +8,10 @@ module WashOut
10
8
  class SOAPError < Exception; end
11
9
  class ProgrammerError < Exception; end
12
10
 
13
- # This filter parses the SOAP request and puts it into +params+ array.
14
- def _parse_soap_parameters
15
-
16
- nori_parser = Nori.new(
17
- :parser => soap_config.parser,
18
- :strip_namespaces => true,
19
- :advanced_typecasting => true,
20
- :convert_tags_to => ( soap_config.snakecase_input ? lambda { |tag| tag.snakecase.to_sym } : lambda { |tag| tag.to_sym } ))
21
-
22
- @_params = nori_parser.parse(request.body.read)
23
- references = WashOut::Dispatcher.deep_select(@_params){|k,v| v.is_a?(Hash) && v.has_key?(:@id)}
24
-
25
- unless references.blank?
26
- replaces = {}; references.each{|r| replaces['#'+r[:@id]] = r}
27
- @_params = WashOut::Dispatcher.deep_replace_href(@_params, replaces)
28
- end
29
- end
30
-
31
11
  def _authenticate_wsse
32
12
 
33
13
  begin
34
- xml_security = @_params.values_at(:envelope, :Envelope).compact.first
14
+ xml_security = env['wash_out.soap_data'].values_at(:envelope, :Envelope).compact.first
35
15
  xml_security = xml_security.values_at(:header, :Header).compact.first
36
16
  xml_security = xml_security.values_at(:security, :Security).compact.first
37
17
  username_token = xml_security.values_at(:username_token, :UsernameToken).compact.first
@@ -49,7 +29,7 @@ module WashOut
49
29
  soap_action = request.env['wash_out.soap_action']
50
30
  action_spec = self.class.soap_actions[soap_action]
51
31
 
52
- xml_data = @_params.values_at(:envelope, :Envelope).compact.first
32
+ xml_data = env['wash_out.soap_data'].values_at(:envelope, :Envelope).compact.first
53
33
  xml_data = xml_data.values_at(:body, :Body).compact.first
54
34
  xml_data = xml_data.values_at(soap_action.underscore.to_sym,
55
35
  soap_action.to_sym).compact.first || {}
@@ -176,8 +156,6 @@ module WashOut
176
156
  def self.included(controller)
177
157
  controller.send :rescue_from, SOAPError, :with => :_render_soap_exception
178
158
  controller.send :helper, :wash_out
179
- controller.send :before_filter, :_parse_soap_parameters, :except => [
180
- :_generate_wsdl, :_invalid_action ]
181
159
  controller.send :before_filter, :_authenticate_wsse, :except => [
182
160
  :_generate_wsdl, :_invalid_action ]
183
161
  controller.send :before_filter, :_map_soap_parameters, :except => [
@@ -1,3 +1,5 @@
1
+ require 'nori'
2
+
1
3
  module WashOut
2
4
  # This class is a Rack middleware used to route SOAP requests to a proper
3
5
  # action of a given SOAP controller.
@@ -6,24 +8,64 @@ module WashOut
6
8
  @controller_name = "#{controller_name.to_s}_controller".camelize
7
9
  end
8
10
 
9
- def call(env)
10
- controller = @controller_name.constantize
11
+ def controller
12
+ @controller
13
+ end
14
+
15
+ def parse_soap_action(env)
16
+ return env['wash_out.soap_action'] if env['wash_out.soap_action']
17
+
18
+ soap_action = env['HTTP_SOAPACTION']
19
+
20
+ if soap_action.blank?
21
+ soap_action = parse_soap_parameters(env)
22
+ .values_at(:envelope, :Envelope).compact.first
23
+ .values_at(:body, :Body).compact.first
24
+ .keys.first.to_s
25
+ end
26
+
27
+ # RUBY18 1.8 does not have force_encoding.
28
+ soap_action.force_encoding('UTF-8') if soap_action.respond_to? :force_encoding
29
+
30
+ if controller.soap_config.namespace
31
+ namespace = Regexp.escape controller.soap_config.namespace.to_s
32
+ soap_action.gsub!(/^"?(#{namespace}(\/|#)?)?([^"]*)"?$/, '\3')
33
+ else
34
+ soap_action = soap_action[1...-1] if soap_action.starts_with?('"')
35
+ end
36
+
37
+ env['wash_out.soap_action'] = soap_action
38
+ end
11
39
 
12
- if soap_action = env['HTTP_SOAPACTION']
13
- # RUBY18 1.8 does not have force_encoding.
14
- soap_action.force_encoding('UTF-8') if soap_action.respond_to? :force_encoding
40
+ def parse_soap_parameters(env)
41
+ return env['wash_out.soap_data'] if env['wash_out.soap_data']
15
42
 
16
- if controller.soap_config.namespace
17
- namespace = Regexp.escape controller.soap_config.namespace.to_s
18
- soap_action.gsub!(/^\"(#{namespace}(\/|#)?)?(.*)\"$/, '\3')
19
- else
20
- soap_action = soap_action[1...-1]
21
- end
43
+ nori_parser = Nori.new(
44
+ :parser => controller.soap_config.parser,
45
+ :strip_namespaces => true,
46
+ :advanced_typecasting => true,
47
+ :convert_tags_to => ( controller.soap_config.snakecase_input ? lambda { |tag| tag.snakecase.to_sym } : lambda { |tag| tag.to_sym } ))
22
48
 
23
- env['wash_out.soap_action'] = soap_action
49
+ env['wash_out.soap_data'] = if env['rack.input'].respond_to? :string then env['rack.input'].string else env['rack.input'].read end
50
+ env['wash_out.soap_data'] = nori_parser.parse(env['wash_out.soap_data'])
51
+ references = WashOut::Dispatcher.deep_select(env['wash_out.soap_data']){|k,v| v.is_a?(Hash) && v.has_key?(:@id)}
52
+
53
+ unless references.blank?
54
+ replaces = {}; references.each{|r| replaces['#'+r[:@id]] = r}
55
+ env['wash_out.soap_data'] = WashOut::Dispatcher.deep_replace_href(env['wash_out.soap_data'], replaces)
24
56
  end
25
57
 
58
+ env['wash_out.soap_data']
59
+ end
60
+
61
+ def call(env)
62
+ @controller = @controller_name.constantize
63
+
64
+ soap_action = parse_soap_action(env)
65
+ soap_parameters = parse_soap_parameters(env)
66
+
26
67
  action_spec = controller.soap_actions[soap_action]
68
+
27
69
  if action_spec
28
70
  action = action_spec[:to]
29
71
  else
@@ -1,3 +1,3 @@
1
1
  module WashOut
2
- VERSION = "0.9.0.beta.1"
2
+ VERSION = "0.9.0.beta.2"
3
3
  end
@@ -7,12 +7,6 @@ describe WashOut::Dispatcher do
7
7
  class Dispatcher < ApplicationController
8
8
  soap_service
9
9
 
10
- def self.mock(text="")
11
- dispatcher = self.new
12
- dispatcher.request = OpenStruct.new(:body => OpenStruct.new(:read => text))
13
- dispatcher
14
- end
15
-
16
10
  def params
17
11
  @_params
18
12
  end
@@ -28,13 +22,13 @@ describe WashOut::Dispatcher do
28
22
  WashOut::Dispatcher.deep_replace_href({:bar => {:foo => {:@href => 1}}}, {1 => 2}).should == {:bar => {:foo => 2}}
29
23
  end
30
24
 
31
- it "parses typical request" do
25
+ xit "parses typical request" do
32
26
  dispatcher = Dispatcher.mock("<foo>1</foo>")
33
27
  dispatcher._parse_soap_parameters
34
28
  dispatcher.params.should == {:foo => "1"}
35
29
  end
36
30
 
37
- it "parses href request" do
31
+ xit "parses href request" do
38
32
  dispatcher = Dispatcher.mock <<-XML
39
33
  <root>
40
34
  <request>
@@ -90,6 +90,37 @@ describe WashOut do
90
90
  describe "Dispatcher" do
91
91
 
92
92
  context "simple actions" do
93
+ it "accepts requests with no HTTP header" do
94
+ mock_controller do
95
+ soap_action "answer", :args => nil, :return => :int
96
+ def answer
97
+ render :soap => "42"
98
+ end
99
+ end
100
+
101
+ request = <<-XML
102
+ <?xml version="1.0" encoding="UTF-8"?>
103
+ <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="false" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
104
+ <env:Body>
105
+ <tns:answer>
106
+ <value>42</value>
107
+ </tns:answer>
108
+ </env:Body>
109
+ </env:Envelope>
110
+ XML
111
+
112
+ HTTPI.post("http://app/api/action", request).body.should == <<-XML
113
+ <?xml version="1.0" encoding="UTF-8"?>
114
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="false">
115
+ <soap:Body>
116
+ <tns:answerResponse>
117
+ <Value xsi:type="xsd:int">42</Value>
118
+ </tns:answerResponse>
119
+ </soap:Body>
120
+ </soap:Envelope>
121
+ XML
122
+ end
123
+
93
124
  it "accept no parameters" do
94
125
  mock_controller do
95
126
  soap_action "answer", :args => nil, :return => :int
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wash_out
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0.beta.1
4
+ version: 0.9.0.beta.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Staal
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-08 00:00:00.000000000 Z
12
+ date: 2013-09-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nori
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  version: 1.3.1
114
114
  requirements: []
115
115
  rubyforge_project:
116
- rubygems_version: 2.0.6
116
+ rubygems_version: 2.0.3
117
117
  signing_key:
118
118
  specification_version: 4
119
119
  summary: Dead simple Rails 3 SOAP server library