Class: RocketAMF::Response

Inherits:
Object
  • Object
show all
Includes:
Pure::Response
Defined in:
lib/rocketamf/remoting.rb,
lib/rocketamf/pure.rb

Overview

Container for the response of the AMF call. Includes serialization and request handling code.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Pure::WriteIOHelpers

#byte_order, #byte_order_little?, #pack_double, #pack_int16_network, #pack_int8, #pack_integer, #pack_word32_network

Constructor Details

#initializeResponse

Returns a new instance of Response.



30
31
32
33
34
# File 'lib/rocketamf/remoting.rb', line 30

def initialize
  @amf_version = 0
  @headers = []
  @messages = []
end

Instance Attribute Details

#amf_versionObject

Returns the value of attribute amf_version.



28
29
30
# File 'lib/rocketamf/remoting.rb', line 28

def amf_version
  @amf_version
end

#headersObject

Returns the value of attribute headers.



28
29
30
# File 'lib/rocketamf/remoting.rb', line 28

def headers
  @headers
end

#messagesObject

Returns the value of attribute messages.



28
29
30
# File 'lib/rocketamf/remoting.rb', line 28

def messages
  @messages
end

Instance Method Details

#each_method_call(request, &block) ⇒ Object

Builds response from the request, iterating over each method call and using the return value as the method call’s return value – Iterate over all the sent messages. If they’re somthing we can handle, like a command message, then simply add the response message ourselves. If it’s a method call, then call the block with the method and args, catching errors for handling. Then create the appropriate response message using the return value of the block as the return value for the method call.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rocketamf/remoting.rb', line 51

def each_method_call request, &block
  raise 'Response already constructed' if @constructed

  # Set version from response
  # Can't just copy version because FMS sends version as 1
  @amf_version = request.amf_version == 3 ? 3 : 0 

  request.messages.each do |m|
    # What's the request body?
    case m.data
    when Values::CommandMessage
      # Pings should be responded to with an AcknowledgeMessage built using the ping
      # Everything else is unsupported
      command_msg = m.data
      if command_msg.operation == Values::CommandMessage::CLIENT_PING_OPERATION
        response_value = Values::AcknowledgeMessage.new(command_msg)
      else
        response_value = Values::ErrorMessage.new(Exception.new("CommandMessage #{command_msg.operation} not implemented"), command_msg)
      end
    when Values::RemotingMessage
      # Using RemoteObject style message calls
      remoting_msg = m.data
      acknowledge_msg = Values::AcknowledgeMessage.new(remoting_msg)
      body = dispatch_call :method => remoting_msg.source+'.'+remoting_msg.operation, :args => remoting_msg.body, :source => remoting_msg, :block => block

      # Response should be the bare ErrorMessage if there was an error
      if body.is_a?(Values::ErrorMessage)
        response_value = body
      else
        acknowledge_msg.body = body
        response_value = acknowledge_msg
      end
    else
      # Standard response message
      response_value = dispatch_call :method => m.target_uri, :args => m.data, :source => m, :block => block
    end

    target_uri = m.response_uri
    target_uri += response_value.is_a?(Values::ErrorMessage) ? '/onStatus' : '/onResult'
    @messages << ::RocketAMF::Message.new(target_uri, '', response_value)
  end

  @constructed = true
end

#serializeObject

Serializes the response to a string and returns it. – Implemented in pure/remoting.rb RocketAMF::Pure::Response

Raises:



39
40
41
# File 'lib/rocketamf/remoting.rb', line 39

def serialize
  raise AMFError, 'Must load "rocketamf/pure"'
end

#to_sObject

Return the serialized response as a string



97
98
99
# File 'lib/rocketamf/remoting.rb', line 97

def to_s
  serialize
end