Class: Seamless::Dispatcher

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/seamless/dispatcher.rb

Instance Method Summary collapse

Instance Method Details

#incoming(session, request, response) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/seamless/dispatcher.rb', line 30

def incoming(session,request,response)
  body = request.env['RAW_POST_DATA']
  if body
     node = REXML::Document.new(body)
     node.root.each_element('//message') do |message|
      requestid = message.attributes['requestid']
      type = message.attributes['type']
      text = message.text
      msg = JSON.parse(text)
      req = {'requestid'=>requestid, 'session'=>session}
      MessageBroker.send(req,type,msg)
     end
  end      
end

#outgoing(obj, type, message) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/seamless/dispatcher.rb', line 18

def outgoing(obj,type,message)
  queue = obj['session']['_seamless_mq']
  if !queue
    queue = [];
    obj['session']['_seamless_mq'] = queue
  end
  #TODO requestid
  queue << "<message requestid='' direction='OUTGOING' datatype='JSON' type='#{type}'><![CDATA["
  queue << message.to_json
  queue << ']]></message>'
end

#serialize(session, body) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/seamless/dispatcher.rb', line 5

def serialize(session,body)
  queue = session['_seamless_mq']
  body << '<?xml version="1.0"?>'
  body << "<messages version='1.0' sessionid='#{session.session_id}'>"
  if queue
    queue.each do |msg|
    body << msg
    end
    session['_seamless_mq']=[]
  end
  body << '</messages>'
end