server/executionhandlers/ruby/connection.rb in cpee-2.1.52 vs server/executionhandlers/ruby/connection.rb in cpee-2.1.53

- old
+ new

@@ -40,12 +40,12 @@ mess += err.message controller.notify("description/error", :message => mess) end# }}} def self::inform_connectionwrapper_error(arguments,err) # {{{ controller = arguments[0] - p err.message - p err.backtrace + puts err.message + puts err.backtrace controller.notify("executionhandler/error", :message => err.backtrace[0].gsub(/([\w -_]+):(\d+):in.*/,'\\1, Line \2: ') + err.message) end # }}} def self::inform_position_change(arguments,ipc={}) # {{{ controller = arguments[0] controller.notify("position/change", ipc) @@ -62,11 +62,11 @@ @label = '' @guard_files = [] @guard_items = [] end # }}} - def prepare(readonly, endpoints, parameters, replay=false) #{{{ + def prepare(readonly, endpoints, parameters) #{{{ @handler_endpoint = endpoints.is_a?(Array) ? endpoints.map{ |ep| readonly.endpoints[ep] }.compact : readonly.endpoints[endpoints] if @controller.attributes['twin_engine'] @handler_endpoint_orig = @handler_endpoint @handler_endpoint = @controller.attributes['twin_engine'].to_s + '?original_endpoint=' + Riddl::Protocols::Utils::escape(@handler_endpoint) end @@ -125,11 +125,11 @@ params << Riddl::Header.new("CPEE-INSTANCE-UUID",@controller.uuid) params << Riddl::Header.new("CPEE-CALLBACK",File.join(@controller.instance_url,'callbacks',callback,'/')) params << Riddl::Header.new("CPEE-CALLBACK-ID",callback) params << Riddl::Header.new("CPEE-ACTIVITY",@handler_position) params << Riddl::Header.new("CPEE-LABEL",@label||'') - params << Riddl::Header.new("CPEE-REPLAY",@controller.attributes['replayer_target']) if @controller.attributes[:replayer] && @controller.attributes['replayer_target'] + params << Riddl::Header.new("CPEE-TWIN-TARGET",@controller.attributes['twin_target']) if @controller.attributes['twin_target'] @controller.attributes.each do |key,value| params << Riddl::Header.new("CPEE-ATTR-#{key.to_s.gsub(/_/,'-')}",value) end status = result = headers = nil @@ -140,10 +140,12 @@ client = Riddl::Client.new(tendpoint) @handler_passthrough = callback @controller.callback(self,callback,:'activity-uuid' => @handler_activity_uuid, :label => @label, :activity => @handler_position) + pp params + status, result, headers = client.request type => params @guard_files += result if status == 561 if @controller.attributes['twin_translate'] @@ -155,34 +157,41 @@ when 'ir'; 'ipc-receive' when 'is'; 'ipc-send' else 'instantiation' end - JSON::parse(gtresult.value.read).each do |e| + JSON::parse(gtresult.first.value.read).each do |e| if e['type'] == transwhat @handler_endpoint = e['endpoint'] if e['endpoint'] e['arguments']&.each do |k,a| + if a.is_a? String + hname = a.gsub(/-/,'_') + a = headers[hname] if headers[hname] + elsif a.is_a? Hash + a.each do |k_ht, a_ht| + hname = a_ht.gsub(/-/,'_') + a[k_ht] = headers[hname] if headers[hname] + end + end params.each do |p| - p.value = a if p.name == k + if p.name == k + if a.is_a? String + p.value = a + elsif a.is_a? Hash + ohash = JSON::parse(p.value) rescue {} + ohash.merge!(a) + p.value = JSON.generate(ohash) + end + end end end end end end else @handler_endpoint = @handler_endpoint_orig end params.delete_if { |p| p.name == 'original_endpoint' } - params.each do |p| - if p.name == 'attributes' - t = JSON::parse(p.value) rescue {} - t['twin_engine'] = @controller.attributes['twin_engine'] if @controller.attributes['twin_engine'] - t['twin_target'] = @controller.attributes['twin_target'] if @controller.attributes['twin_target'] - t['twin_translate'] = @controller.attributes['twin_engine'] if @controller.attributes['twin_translate'] - p.value = t.to_json - end - end - pp params end end while status == 561 if status < 200 || status >= 300 headers['CPEE_SALVAGE'] = true