RocketAMF 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,8 @@
3
3
  RocketAMF is a full featured AMF0/3 serializer and deserializer with support for
4
4
  Flash -> Ruby and Ruby -> Flash class mapping, custom serializers, remoting
5
5
  gateway helpers that follow AMF0/3 messaging specs, and a suite of specs to
6
- ensure adherence to the specification documents put out by Adobe.
6
+ ensure adherence to the specification documents put out by Adobe. In addition,
7
+ it now fully supports Ruby 1.9.
7
8
 
8
9
  == INSTALL:
9
10
 
data/Rakefile CHANGED
@@ -23,7 +23,7 @@ end
23
23
 
24
24
  spec = Gem::Specification.new do |s|
25
25
  s.name = 'RocketAMF'
26
- s.version = '0.1.0'
26
+ s.version = '0.2.0'
27
27
  s.summary = 'Fast AMF serializer/deserializer with remoting request/response wrappers to simplify integration'
28
28
 
29
29
  s.files = FileList['README.rdoc', 'Rakefile', 'lib/**/*.rb', 'spec/**/*.rb', 'spec/**/*.bin', 'spec/spec.opts']
@@ -46,8 +46,8 @@ require 'rocketamf/remoting'
46
46
  # if is_amf?(env)
47
47
  # # Wrap request and response
48
48
  # env['rack.input'].rewind
49
- # request = RocketAMF::Request.new.populate_from_stream(env['rack.input'].read)
50
- # response = RocketAMF::Response.new
49
+ # request = RocketAMF::Envelope.new.populate_from_stream(env['rack.input'].read)
50
+ # response = RocketAMF::Envelope.new
51
51
  #
52
52
  # # Handle request
53
53
  # response.each_method_call request do |method, args|
@@ -18,15 +18,11 @@ module RocketAMF
18
18
  Serializer = RocketAMF::Pure::Serializer
19
19
  AMF3Serializer = RocketAMF::Pure::AMF3Serializer
20
20
 
21
- # Modify request and response so they can serialize/deserialize
22
- class Request
21
+ # Modify envelope so it can serialize/deserialize
22
+ class Envelope
23
23
  remove_method :populate_from_stream
24
- include RocketAMF::Pure::Request
25
- end
26
-
27
- class Response
28
24
  remove_method :serialize
29
- include RocketAMF::Pure::Response
25
+ include RocketAMF::Pure::Envelope
30
26
  end
31
27
  #:startdoc:
32
28
  end
@@ -2,9 +2,11 @@ require 'rocketamf/pure/io_helpers'
2
2
 
3
3
  module RocketAMF
4
4
  module Pure
5
- # Request deserialization module - provides a method that can be included into
6
- # RocketAMF::Request for deserializing the given stream.
7
- module Request
5
+ # Included into RocketAMF::Envelope, this module replaces the
6
+ # populate_from_stream and serialize methods with actual working versions
7
+ module Envelope
8
+ # Included into RocketAMF::Envelope, this method handles deserializing an
9
+ # AMF request/response into the envelope
8
10
  def populate_from_stream stream
9
11
  stream = StringIO.new(stream) unless StringIO === stream
10
12
 
@@ -45,13 +47,8 @@ module RocketAMF
45
47
  self
46
48
  end
47
49
 
48
- private
49
- include RocketAMF::Pure::ReadIOHelpers
50
- end
51
-
52
- # Response serialization module - provides a method that can be included into
53
- # RocketAMF::Response for deserializing the given stream.
54
- module Response
50
+ # Included into RocketAMF::Envelope, this method handles serializing an
51
+ # AMF request/response into the envelope
55
52
  def serialize
56
53
  stream = ""
57
54
 
@@ -92,6 +89,7 @@ module RocketAMF
92
89
  end
93
90
 
94
91
  private
92
+ include RocketAMF::Pure::ReadIOHelpers
95
93
  include RocketAMF::Pure::WriteIOHelpers
96
94
  end
97
95
  end
@@ -1,41 +1,29 @@
1
1
  module RocketAMF
2
- # Container for the AMF request.
3
- class Request
2
+ # Container for the AMF request/response.
3
+ class Envelope
4
4
  attr_reader :amf_version, :headers, :messages
5
5
 
6
- def initialize
7
- @amf_version = 0
8
- @headers = []
9
- @messages = []
6
+ def initialize props={}
7
+ @amf_version = props[:amf_version] || 0
8
+ @headers = props[:headers] || []
9
+ @messages = props[:messages] || []
10
10
  end
11
11
 
12
- # Populates the request from the given stream or string. Returns self for easy
12
+ # Populates the envelope from the given stream or string. Returns self for easy
13
13
  # chaining.
14
14
  #
15
15
  # Example:
16
16
  #
17
- # req = RocketAMF::Request.new.populate_from_stream(env['rack.input'].read)
17
+ # req = RocketAMF::Envelope.new.populate_from_stream(env['rack.input'].read)
18
18
  #--
19
- # Implemented in pure/remoting.rb RocketAMF::Pure::Request
19
+ # Implemented in pure/remoting.rb RocketAMF::Pure::Envelope
20
20
  def populate_from_stream stream
21
21
  raise AMFError, 'Must load "rocketamf/pure"'
22
22
  end
23
- end
24
-
25
- # Container for the response of the AMF call. Includes serialization and request
26
- # handling code.
27
- class Response
28
- attr_accessor :amf_version, :headers, :messages
29
23
 
30
- def initialize
31
- @amf_version = 0
32
- @headers = []
33
- @messages = []
34
- end
35
-
36
- # Serializes the response to a string and returns it
24
+ # Serializes the envelope to a string and returns it
37
25
  #--
38
- # Implemented in pure/remoting.rb RocketAMF::Pure::Response
26
+ # Implemented in pure/remoting.rb RocketAMF::Pure::Envelope
39
27
  def serialize
40
28
  raise AMFError, 'Must load "rocketamf/pure"'
41
29
  end
@@ -66,14 +54,15 @@ module RocketAMF
66
54
  response_value = Values::AcknowledgeMessage.new(command_msg)
67
55
  else
68
56
  e = Exception.new("CommandMessage #{command_msg.operation} not implemented")
69
- e.set_backtrace ["RocketAMF::Response each_method_call"]
57
+ e.set_backtrace ["RocketAMF::Envelope each_method_call"]
70
58
  response_value = Values::ErrorMessage.new(command_msg, e)
71
59
  end
72
60
  when Values::RemotingMessage
73
61
  # Using RemoteObject style message calls
74
62
  remoting_msg = m.data
75
63
  acknowledge_msg = Values::AcknowledgeMessage.new(remoting_msg)
76
- body = dispatch_call :method => remoting_msg.source+'.'+remoting_msg.operation, :args => remoting_msg.body, :source => remoting_msg, :block => block
64
+ method_base = remoting_msg.source.to_s.empty? ? '' : remoting_msg.source+'.'
65
+ body = dispatch_call :method => method_base+remoting_msg.operation, :args => remoting_msg.body, :source => remoting_msg, :block => block
77
66
 
78
67
  # Response should be the bare ErrorMessage if there was an error
79
68
  if body.is_a?(Values::ErrorMessage)
@@ -95,7 +84,7 @@ module RocketAMF
95
84
  @constructed = true
96
85
  end
97
86
 
98
- # Return the serialized response as a string
87
+ # Return the serialized envelope as a string
99
88
  def to_s
100
89
  serialize
101
90
  end
@@ -111,7 +100,21 @@ module RocketAMF
111
100
  end
112
101
  end
113
102
 
114
- # RocketAMF::Request or RocketAMF::Response header
103
+ class Request < Envelope #:nodoc:
104
+ def initialize props={}
105
+ $stderr.puts("DEPRECATION WARNING: Use RocketAMF::Envelope instead of RocketAMF::Request")
106
+ super(props)
107
+ end
108
+ end
109
+
110
+ class Response < Envelope #:nodoc:
111
+ def initialize props={}
112
+ $stderr.puts("DEPRECATION WARNING: Use RocketAMF::Envelope instead of RocketAMF::Request")
113
+ super(props)
114
+ end
115
+ end
116
+
117
+ # RocketAMF::Envelope header
115
118
  class Header
116
119
  attr_accessor :name, :must_understand, :data
117
120
 
@@ -122,7 +125,7 @@ module RocketAMF
122
125
  end
123
126
  end
124
127
 
125
- # RocketAMF::Request or RocketAMF::Response message
128
+ # RocketAMF::Envelope message
126
129
  class Message
127
130
  attr_accessor :target_uri, :response_uri, :data
128
131
 
@@ -105,13 +105,15 @@ module RocketAMF
105
105
  # Optional "root cause" of the error
106
106
  attr_accessor :rootCause
107
107
 
108
- def initialize message, exception
108
+ def initialize message=nil, exception=nil
109
109
  super message
110
110
 
111
- @e = exception
112
- @faultCode = @e.class.name
113
- @faultDetail = @e.backtrace.join("\n")
114
- @faultString = @e.message
111
+ unless exception.nil?
112
+ @e = exception
113
+ @faultCode = @e.class.name
114
+ @faultDetail = @e.backtrace.join("\n")
115
+ @faultString = @e.message
116
+ end
115
117
  end
116
118
 
117
119
  def to_amf serializer
@@ -0,0 +1,117 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe RocketAMF::Envelope do
4
+ describe 'deserializer' do
5
+ it "should handle remoting message from remote object" do
6
+ req = create_envelope("remotingMessage.bin")
7
+
8
+ req.headers.length.should == 0
9
+ req.messages.length.should == 1
10
+ message = req.messages[0].data
11
+ message.should be_a(RocketAMF::Values::RemotingMessage)
12
+ message.messageId.should == "FE4AF2BC-DD3C-5470-05D8-9971D51FF89D"
13
+ message.body.should == [true]
14
+ end
15
+
16
+ it "should handle command message from remote object" do
17
+ req = create_envelope("commandMessage.bin")
18
+
19
+ req.headers.length.should == 0
20
+ req.messages.length.should == 1
21
+ message = req.messages[0].data
22
+ message.should be_a(RocketAMF::Values::CommandMessage)
23
+ message.messageId.should == "7B0ACE15-8D57-6AE5-B9D4-99C2D32C8246"
24
+ message.body.should == {}
25
+ end
26
+ end
27
+
28
+ describe 'serializer' do
29
+ it "should serialize response when converted to string" do
30
+ res = RocketAMF::Envelope.new
31
+ res.should_receive(:serialize).and_return('serialized')
32
+ res.to_s.should == 'serialized'
33
+ end
34
+
35
+ it "should serialize a simple call" do
36
+ res = RocketAMF::Envelope.new :amf_version => 3
37
+ res.messages << RocketAMF::Message.new('/1/onResult', '', 'hello')
38
+
39
+ expected = request_fixture('simple-response.bin')
40
+ res.serialize.should == expected
41
+ end
42
+
43
+ it "should serialize a AcknowledgeMessage response" do
44
+ ak = RocketAMF::Values::AcknowledgeMessage.new
45
+ ak.clientId = "7B0ACE15-8D57-6AE5-B9D4-99C2D32C8246"
46
+ ak.messageId = "7B0ACE15-8D57-6AE5-B9D4-99C2D32C8246"
47
+ ak.timestamp = 0
48
+ res = RocketAMF::Envelope.new :amf_version => 3
49
+ res.messages << RocketAMF::Message.new('/1/onResult', '', ak)
50
+
51
+ expected = request_fixture('acknowledge-response.bin')
52
+ res.serialize.should == expected
53
+ end
54
+ end
55
+
56
+ describe 'message handler' do
57
+ it "should respond to ping command" do
58
+ res = RocketAMF::Envelope.new
59
+ req = create_envelope('commandMessage.bin')
60
+ res.each_method_call req do |method, args|
61
+ nil
62
+ end
63
+
64
+ res.messages.length.should == 1
65
+ res.messages[0].data.should be_a(RocketAMF::Values::AcknowledgeMessage)
66
+ end
67
+
68
+ it "should fail on unsupported command" do
69
+ res = RocketAMF::Envelope.new
70
+ req = create_envelope('unsupportedCommandMessage.bin')
71
+ res.each_method_call req do |method, args|
72
+ nil
73
+ end
74
+
75
+ res.messages.length.should == 1
76
+ res.messages[0].data.should be_a(RocketAMF::Values::ErrorMessage)
77
+ res.messages[0].data.faultString.should == "CommandMessage 10000 not implemented"
78
+ end
79
+
80
+ it "should handle RemotingMessages properly" do
81
+ res = RocketAMF::Envelope.new
82
+ req = create_envelope('remotingMessage.bin')
83
+ res.each_method_call req do |method, args|
84
+ method.should == 'WritesController.save'
85
+ args.should == [true]
86
+ true
87
+ end
88
+
89
+ res.messages.length.should == 1
90
+ res.messages[0].data.should be_a(RocketAMF::Values::AcknowledgeMessage)
91
+ res.messages[0].data.body.should == true
92
+ end
93
+
94
+ it "should catch exceptions properly" do
95
+ res = RocketAMF::Envelope.new
96
+ req = create_envelope('remotingMessage.bin')
97
+ res.each_method_call req do |method, args|
98
+ raise 'Error in call'
99
+ end
100
+
101
+ res.messages.length.should == 1
102
+ res.messages[0].data.should be_a(RocketAMF::Values::ErrorMessage)
103
+ res.messages[0].target_uri.should =~ /onStatus$/
104
+ end
105
+
106
+ it "should not crash if source missing on RemotingMessage" do
107
+ res = RocketAMF::Envelope.new
108
+ req = create_envelope('remotingMessage.bin')
109
+ req.messages[0].data.instance_variable_set("@source", nil)
110
+ lambda {
111
+ res.each_method_call req do |method,args|
112
+ true
113
+ end
114
+ }.should_not raise_error
115
+ end
116
+ end
117
+ end
@@ -18,7 +18,7 @@ describe RocketAMF::Values::ErrorMessage do
18
18
  end
19
19
 
20
20
  it "should serialize as a hash in AMF0" do
21
- response = RocketAMF::Response.new
21
+ response = RocketAMF::Envelope.new
22
22
  response.messages << RocketAMF::Message.new('1/onStatus', '', @message)
23
23
  response.serialize.should == request_fixture('amf0-error-response.bin')
24
24
  end
@@ -22,8 +22,8 @@ def object_fixture(binary_path)
22
22
  data
23
23
  end
24
24
 
25
- def create_request(binary_path)
26
- RocketAMF::Request.new.populate_from_stream(StringIO.new(request_fixture(binary_path)))
25
+ def create_envelope(binary_path)
26
+ RocketAMF::Envelope.new.populate_from_stream(StringIO.new(request_fixture(binary_path)))
27
27
  end
28
28
 
29
29
  # Helper classes
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: RocketAMF
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jacob Henry
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-07-04 00:00:00 -04:00
19
+ date: 2010-07-29 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies: []
22
22
 
@@ -45,8 +45,7 @@ files:
45
45
  - lib/rocketamf.rb
46
46
  - spec/amf/class_mapping_spec.rb
47
47
  - spec/amf/deserializer_spec.rb
48
- - spec/amf/request_spec.rb
49
- - spec/amf/response_spec.rb
48
+ - spec/amf/remoting_spec.rb
50
49
  - spec/amf/serializer_spec.rb
51
50
  - spec/amf/values/array_collection_spec.rb
52
51
  - spec/amf/values/messages_spec.rb
@@ -85,7 +84,6 @@ files:
85
84
  - spec/fixtures/objects/amf3-false.bin
86
85
  - spec/fixtures/objects/amf3-graphMember.bin
87
86
  - spec/fixtures/objects/amf3-hash.bin
88
- - spec/fixtures/objects/amf3-intVector.bin
89
87
  - spec/fixtures/objects/amf3-largeMax.bin
90
88
  - spec/fixtures/objects/amf3-largeMin.bin
91
89
  - spec/fixtures/objects/amf3-max.bin
@@ -93,7 +91,6 @@ files:
93
91
  - spec/fixtures/objects/amf3-mixedArray.bin
94
92
  - spec/fixtures/objects/amf3-null.bin
95
93
  - spec/fixtures/objects/amf3-objRef.bin
96
- - spec/fixtures/objects/amf3-objVector.bin
97
94
  - spec/fixtures/objects/amf3-primArray.bin
98
95
  - spec/fixtures/objects/amf3-string.bin
99
96
  - spec/fixtures/objects/amf3-stringRef.bin
@@ -150,8 +147,7 @@ summary: Fast AMF serializer/deserializer with remoting request/response wrapper
150
147
  test_files:
151
148
  - spec/amf/class_mapping_spec.rb
152
149
  - spec/amf/deserializer_spec.rb
153
- - spec/amf/request_spec.rb
154
- - spec/amf/response_spec.rb
150
+ - spec/amf/remoting_spec.rb
155
151
  - spec/amf/serializer_spec.rb
156
152
  - spec/amf/values/array_collection_spec.rb
157
153
  - spec/amf/values/messages_spec.rb
@@ -1,25 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
2
-
3
- describe RocketAMF::Request do
4
- it "should handle remoting message from remote object" do
5
- req = create_request("remotingMessage.bin")
6
-
7
- req.headers.length.should == 0
8
- req.messages.length.should == 1
9
- message = req.messages[0].data
10
- message.should be_a(RocketAMF::Values::RemotingMessage)
11
- message.messageId.should == "FE4AF2BC-DD3C-5470-05D8-9971D51FF89D"
12
- message.body.should == [true]
13
- end
14
-
15
- it "should handle command message from remote object" do
16
- req = create_request("commandMessage.bin")
17
-
18
- req.headers.length.should == 0
19
- req.messages.length.should == 1
20
- message = req.messages[0].data
21
- message.should be_a(RocketAMF::Values::CommandMessage)
22
- message.messageId.should == "7B0ACE15-8D57-6AE5-B9D4-99C2D32C8246"
23
- message.body.should == {}
24
- end
25
- end
@@ -1,80 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
2
-
3
- describe RocketAMF::Response do
4
- it "should serialize response when converted to string" do
5
- res = RocketAMF::Response.new
6
- res.should_receive(:serialize).and_return('serialized')
7
- res.to_s.should == 'serialized'
8
- end
9
-
10
- it "should serialize a simple call" do
11
- res = RocketAMF::Response.new
12
- res.amf_version = 3
13
- res.messages << RocketAMF::Message.new('/1/onResult', '', 'hello')
14
-
15
- expected = request_fixture('simple-response.bin')
16
- res.serialize.should == expected
17
- end
18
-
19
- it "should serialize a AcknowledgeMessage response" do
20
- ak = RocketAMF::Values::AcknowledgeMessage.new
21
- ak.clientId = "7B0ACE15-8D57-6AE5-B9D4-99C2D32C8246"
22
- ak.messageId = "7B0ACE15-8D57-6AE5-B9D4-99C2D32C8246"
23
- ak.timestamp = 0
24
- res = RocketAMF::Response.new
25
- res.amf_version = 3
26
- res.messages << RocketAMF::Message.new('/1/onResult', '', ak)
27
-
28
- expected = request_fixture('acknowledge-response.bin')
29
- res.serialize.should == expected
30
- end
31
-
32
- it "should respond to ping command" do
33
- res = RocketAMF::Response.new
34
- req = create_request('commandMessage.bin')
35
- res.each_method_call req do |method, args|
36
- nil
37
- end
38
-
39
- res.messages.length.should == 1
40
- res.messages[0].data.should be_a(RocketAMF::Values::AcknowledgeMessage)
41
- end
42
-
43
- it "should fail on unsupported command" do
44
- res = RocketAMF::Response.new
45
- req = create_request('unsupportedCommandMessage.bin')
46
- res.each_method_call req do |method, args|
47
- nil
48
- end
49
-
50
- res.messages.length.should == 1
51
- res.messages[0].data.should be_a(RocketAMF::Values::ErrorMessage)
52
- res.messages[0].data.faultString.should == "CommandMessage 10000 not implemented"
53
- end
54
-
55
- it "should handle RemotingMessages properly" do
56
- res = RocketAMF::Response.new
57
- req = create_request('remotingMessage.bin')
58
- res.each_method_call req do |method, args|
59
- method.should == 'WritesController.save'
60
- args.should == [true]
61
- true
62
- end
63
-
64
- res.messages.length.should == 1
65
- res.messages[0].data.should be_a(RocketAMF::Values::AcknowledgeMessage)
66
- res.messages[0].data.body.should == true
67
- end
68
-
69
- it "should catch exceptions properly" do
70
- res = RocketAMF::Response.new
71
- req = create_request('remotingMessage.bin')
72
- res.each_method_call req do |method, args|
73
- raise 'Error in call'
74
- end
75
-
76
- res.messages.length.should == 1
77
- res.messages[0].data.should be_a(RocketAMF::Values::ErrorMessage)
78
- res.messages[0].target_uri.should =~ /onStatus$/
79
- end
80
- end