server/handlerwrappers/default.rb in cpee-1.4.21 vs server/handlerwrappers/default.rb in cpee-1.4.23

- old
+ new

@@ -55,11 +55,15 @@ callback = Digest::MD5.hexdigest(Kernel::rand().to_s) (parameters[:arguments] || []).each do |s| if s.respond_to?(:mimetype) params << Riddl::Parameter::Complex.new(s.name.to_s,v.mimetype,v.value) else - params << Riddl::Parameter::Simple.new(s.name.to_s,CPEE::ValueHelper::generate(s.value)) + if s.name.to_s =~ /__$/ + params << Riddl::Parameter::Simple.new(s.name.to_s.chop.chop,CPEE::ValueHelper::generate(s.value),:query) + else + params << Riddl::Parameter::Simple.new(s.name.to_s,CPEE::ValueHelper::generate(s.value)) + end end end params << Riddl::Header.new("CPEE-BASE",@controller.base_url) params << Riddl::Header.new("CPEE-INSTANCE",@controller.instance) @@ -71,27 +75,28 @@ params << Riddl::Header.new("CPEE-LABEL",parameters[:label]||'') @controller.attributes.each do |key,value| params << Riddl::Header.new("CPEE-ATTR-#{key.to_s.gsub(/_/,'-')}",value) end - type = if @handler_endpoint.sub!(/^http(s)?-(get|put|post|delete):/,'http\\1:') - $2 - else - parameters[:method] || 'post' - end - client = Riddl::Client.new(@handler_endpoint) + tendpoint = @handler_endpoint.sub(/^http(s)?-(get|put|post|delete):/,'http\\1:') + type = $2 || parameters[:method] || 'post' + client = Riddl::Client.new(tendpoint) + @controller.callbacks[callback] = CPEE::Callback.new("callback activity: #{@handler_position}",self,:callback,nil,nil,:http) @handler_passthrough = callback status, result, headers = client.request type => params - raise "Could not #{parameters[:method] || 'post'} #{@handler_endpoint} - status: #{status}: #{result&.dig(0)&.value&.read}" if status < 200 || status >= 300 + raise "Could not #{type || 'post'} #{tendpoint} - status: #{status}: #{result&.dig(0)&.value&.read}" if status < 200 || status >= 300 if headers['CPEE_INSTANTIATION'] @controller.notify("task/instantiation", :instance => @controller.instance, :label => @label, :instance_name => @controller.info, :instance_uuid => @controller.uuid, :activity => @handler_position, :endpoint => @handler_endpoint, :received => CPEE::ValueHelper.parse(headers['CPEE_INSTANTIATION']), :timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"), :attributes => @controller.attributes_translated) end - unless headers['CPEE_CALLBACK'] && headers['CPEE_CALLBACK'] == 'true' + if headers['CPEE_CALLBACK'] && headers['CPEE_CALLBACK'] == 'true' && result.any? + headers['CPEE_UPDATE'] = true + callback result, headers + else callback result end else @controller.callbacks[passthrough] = CPEE::Callback.new("callback activity: #{@handler_position}",self,:callback,nil,nil,:http) @handler_passthrough = passthrough