server/executionhandlers/ruby/connection.rb in cpee-2.1.47 vs server/executionhandlers/ruby/connection.rb in cpee-2.1.48
- old
+ new
@@ -62,14 +62,14 @@
@guard_files = []
@guard_items = []
end # }}}
def prepare(readonly, endpoints, parameters, replay=false) #{{{
- if replay && @controller.attributes[:replayer]
- @handler_endpoint = @controller.attributes[:replayer]
- else
- @handler_endpoint = endpoints.is_a?(Array) ? endpoints.map{ |ep| readonly.endpoints[ep] }.compact : readonly.endpoints[endpoints]
+ @handler_endpoint = endpoints.is_a?(Array) ? endpoints.map{ |ep| readonly.endpoints[ep] }.compact : readonly.endpoints[endpoints]
+ if @controller.attributes['mock']
+ @handler_endpoint_orig = @handler_endpoint
+ @handler_endpoint = @controller.attributes['mock'].to_s + '?original_endpoint=' + Riddl::Protocols::Utils::escape(@handler_endpoint)
end
params = parameters.dup
params[:arguments] = params[:arguments].dup if params[:arguments]
params[:arguments]&.map! do |ele|
t = ele.dup
@@ -129,19 +129,27 @@
params << Riddl::Header.new("CPEE-REPLAY",@controller.attributes['replayer_target']) if @controller.attributes[:replayer] && @controller.attributes['replayer_target']
@controller.attributes.each do |key,value|
params << Riddl::Header.new("CPEE-ATTR-#{key.to_s.gsub(/_/,'-')}",value)
end
- tendpoint = @handler_endpoint.sub(/^http(s)?-(get|put|post|delete):/,'http\\1:')
- type = $2 || parameters[:method] || 'post'
+ status = result = headers = nil
+ catch :no_mock do
+ tendpoint = @handler_endpoint.sub(/^http(s)?-(get|put|post|delete):/,'http\\1:')
+ type = $2 || parameters[:method] || 'post'
- client = Riddl::Client.new(tendpoint)
+ client = Riddl::Client.new(tendpoint)
- @handler_passthrough = callback
- @controller.callback(self,callback,:'activity-uuid' => @handler_activity_uuid, :label => @label, :activity => @handler_position)
+ @handler_passthrough = callback
+ @controller.callback(self,callback,:'activity-uuid' => @handler_activity_uuid, :label => @label, :activity => @handler_position)
- status, result, headers = client.request type => params
+ status, result, headers = client.request type => params
+ if status == 561
+ @handler_endpoint = @handler_endpoint_orig
+ throw :no_mock
+ end
+ end
+
if status < 200 || status >= 300
headers['CPEE_SALVAGE'] = true
c = result[0]&.value
c = c.read if c.respond_to? :read
callback([ Riddl::Parameter::Complex.new('error','application/json',StringIO.new(JSON::generate({ 'status' => status, 'error' => c }))) ], headers)
@@ -268,11 +276,11 @@
end
if result.is_a? String
enc = detect_encoding(result)
enc == 'OTHER' ? result : (result.encode('UTF-8',enc) rescue convert_to_base64(result))
else
- result
+ Riddl::Parameter::Array[*result]
end
end
def detect_encoding(text)
if text.is_a? String
@@ -351,9 +359,11 @@
else
@controller.cancel_callback(@handler_passthrough)
@handler_passthrough = nil
if options['CPEE_SALVAGE']
@handler_continue.continue WEEL::Signal::Salvage
+ elsif options['CPEE_STOP']
+ @handler_continue.continue WEEL::Signal::Stop
else
@handler_continue.continue
end
end
end