Class: UU::OS::REST::RemoteClient Deprecated
- Inherits:
-
Object
- Object
- UU::OS::REST::RemoteClient
- Defined in:
- uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb
Overview
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Client for invocation of REST uuAPI.
Class Method Summary (collapse)
-
+ (String) default_base_url
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
-
+ (Object) default_base_url=(base_url)
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
-
+ (String) default_path_prefix
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
-
+ (Object) default_path_prefix=(path_prefix)
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Instance Method Summary (collapse)
-
- (Object) add_header(name, value)
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
-
- (Object) add_parameter(name, value)
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
-
- (Object) auth_token=(token)
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
-
- (String) delete(method, uesuri = nil)
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
-
- (String) get(method, uesuri = nil)
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
-
- (BinaryValue) get_binary(method, uesuri = nil)
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
-
- (RemoteClient) initialize(base_url, service_path = nil)
constructor
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
-
- (String) post(method, uesuri = nil, data = nil)
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
-
- (BinaryValue) post_binary(method, uesuri = nil, data = nil)
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
-
- (Array<Numeric, String, Hash>) raw_delete(method, uesuri = nil)
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
-
- (Array<Numeric, String, Hash>) raw_get(method, uesuri = nil)
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
-
- (Array<Numeric, IO, Hash>) raw_get_binary(method, uesuri = nil)
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
-
- (Array<Numeric, String, Hash>) raw_post(method, uesuri = nil, data = nil)
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
-
- (Array<Numeric, IO, Hash>) raw_post_binary(method, uesuri = nil, data = nil)
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
-
- (Object) timeout=(timeout)
deprecated
Deprecated.
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Constructor Details
- (RemoteClient) initialize(base_url, service_path = nil)
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Creates new instance of REST client.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 134 def initialize(base_url, service_path = nil) = {} if (base_url.kind_of?Class) || (base_url.kind_of?Module) @service = base_url # Get service path service_path = @service::PATH if service_path.nil? base_url = nil # Load path_prefix from configuration file. path_prefix = get_config_param(service_path, @@SERVER_PATH_PARAM) path_prefix = self.class.default_path_prefix if path_prefix.nil? else path_prefix = '' end trust_hostname = get_config_param(service_path, @@TRUST_SERVER_HOSTNAME_PARAM) trust_cert = get_config_param(service_path, @@TRUST_SERVER_CERT_PARAM) if trust_hostname.nil? && trust_cert.nil? # Due to backward compatibility reasons, in case parameters are not defined, # SSL validation should be disabled (so unlike base URL and SSL version we # cannot leave configuration on CommandClient but need to force it). [:validate_ssl] = false elsif trust_hostname == 'false' && trust_cert == 'false' [:validate_ssl] = true else [:validate_ssl] = false end [:default_action] = :/' [:session_handler] = self [:command_handlers] = self [:main_object_uri_parameter_name] = :uesuri [:parameters_parameter_name] = '' [:base_url] = base_url [:default_base_url] = @@DEFAULT_BASE_URL [:use_legacy_config] = true [:append_routing_data] = false @base_path = concat_path(path_prefix, service_path) @client = UU::OS::CMD::CommandClient.new(@base_path, nil, ) @client.unwrap.set_header(:accept, @@DEFAULT_CONTENT_TYPE) @client.unwrap.set_header(:content-type', @@DEFAULT_CONTENT_TYPE) @default_query = UU::OS::HTTP::HTTPQuery.new self.timeout = @@DEFAULT_TIMEOUT end |
Class Method Details
+ (String) default_base_url
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Returns default base URL (this URL is used in case no URL is found in configuration file for a particular service application or system).
91 92 93 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 91 def self.default_base_url @@DEFAULT_BASE_URL end |
+ (Object) default_base_url=(base_url)
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Stores default base URL (this URL is used in case no URL is found in configuration file for a particular service application or system).
101 102 103 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 101 def self.default_base_url=(base_url) @@DEFAULT_BASE_URL = base_url end |
+ (String) default_path_prefix
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Returns default path prefix to be injected between
default_base_url
and PATH constant defined on UU service
classes.
111 112 113 114 115 116 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 111 def self.default_path_prefix if !Thread.current[@@PATH_PREFIX_PARAM] self.default_path_prefix=@@DEFAULT_PATH_PREFIX end Thread.current[@@PATH_PREFIX_PARAM] end |
+ (Object) default_path_prefix=(path_prefix)
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Stores default path prefix to be injected between
default_base_url
and PATH constant defined on UU service
classes.
124 125 126 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 124 def self.default_path_prefix=(path_prefix) Thread.current[@@PATH_PREFIX_PARAM] = path_prefix end |
Instance Method Details
- (Object) add_header(name, value)
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Adds HTTP header. This header will be used in request for each command invoked with this client instance.
192 193 194 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 192 def add_header(name, value) @client.unwrap.set_header(name, value) end |
- (Object) add_parameter(name, value)
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Adds HTTP query parameter. This parameter will be used in request for each command invoked with this client instance.
202 203 204 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 202 def add_parameter(name, value) @default_query[name] = value end |
- (Object) auth_token=(token)
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Sets HTTP authorization token to use for authentication and authorization. This token will be used in request header for each command invoked with this client instance.
182 183 184 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 182 def auth_token=(token) @auth_token = token end |
- (String) delete(method, uesuri = nil)
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Invokes HTTP DELETE and checks incoming response for errors.
427 428 429 430 431 432 433 434 435 436 437 438 439 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 427 def delete(method, uesuri = nil) # Delete is not implemented in CommandClient, so we have to use HTTPClient http_client = @client.unwrap delete = http_client.prepare_delete(@base_path, method) delete.parameters[:uesuri] = UU::OS::UESURI.new(uesuri) delete.parameters.merge!(@default_query) delete.headers[:authorization] = @auth_token || UU::OS::Security::Session.send(:get_authn_token) if !UU::OS::Env::Process.active_process_uri.nil? delete.headers[@@PROCESS_HEADER_PARAM] = UU::OS::Env::Process.active_process_uri.to_s end response = delete.execute return @client.wrap_result(response, :invocation_method => :delete, :main_object_uri_parameter_name => :uesuri).get end |
- (String) get(method, uesuri = nil)
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Invokes HTTP GET and checks incoming response for errors.
349 350 351 352 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 349 def get(method, uesuri = nil) params = {:invocation_method => :get} return @client.invoke(method, UU::OS::UESURI.new(uesuri), params) end |
- (BinaryValue) get_binary(method, uesuri = nil)
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Invokes HTTP GET and checks incoming response for errors. Response body is handed as binary value containing response body stream. Caller is responsible for closing this stream after it is processed.
365 366 367 368 369 370 371 372 373 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 365 def get_binary(method, uesuri = nil) params = {:invocation_method => :get, :stream_response => true, :binary_response => true} if @client.unwrap.instance_variable_get(:@headers)[:accept][0] == @@DEFAULT_CONTENT_TYPE # RemoteClient allowed to reconfigure Accept header for whole instance # (probably never used but we need it for backward compatibility). params[:accept] = @@STREAM_CONTENT_TYPE end return @client.invoke(method, UU::OS::UESURI.new(uesuri), params) end |
- (String) post(method, uesuri = nil, data = nil)
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Invokes HTTP POST and checks incoming response for errors.
384 385 386 387 388 389 390 391 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 384 def post(method, uesuri = nil, data = nil) params = {:invocation_method => :post} if data.kind_of?Hash params[:multipart_upload] = true end params[:parameters] = data return @client.invoke(method, UU::OS::UESURI.new(uesuri), params) end |
- (BinaryValue) post_binary(method, uesuri = nil, data = nil)
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Invokes HTTP POST and checks incoming response for errors. Response body is handed as binary value containing response body stream. Caller is responsible for closing this stream after it is processed.
405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 405 def post_binary(method, uesuri = nil, data = nil) params = {:invocation_method => :post, :stream_response => true, :binary_response => true} if data.kind_of?Hash params[:multipart_upload] = true end params[:parameters] = data if @client.unwrap.instance_variable_get(:@headers)[:accept][0] == @@DEFAULT_CONTENT_TYPE # RemoteClient allowed to reconfigure Accept header for whole instance # (probably never used but we need it for backward compatibility). params[:accept] = @@STREAM_CONTENT_TYPE end return @client.invoke(method, UU::OS::UESURI.new(uesuri), params) end |
- (Array<Numeric, String, Hash>) raw_delete(method, uesuri = nil)
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Invokes HTTP DELETE method without touching the incoming response.
327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 327 def raw_delete(method, uesuri = nil) # Delete is not implemented in CommandClient, so we have to use HTTPClient http_client = @client.unwrap delete = http_client.prepare_delete(@base_path, method) delete.parameters[:uesuri] = UU::OS::UESURI.new(uesuri) delete.parameters.merge!(@default_query) delete.headers[:authorization] = @auth_token || UU::OS::Security::Session.send(:get_authn_token) if !UU::OS::Env::Process.active_process_uri.nil? delete.headers[@@PROCESS_HEADER_PARAM] = UU::OS::Env::Process.active_process_uri.to_s end response = delete.execute return [response.status, response.body, transform_headers(response.headers)] end |
- (Array<Numeric, String, Hash>) raw_get(method, uesuri = nil)
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Invokes HTTP GET method without touching the incoming response.
233 234 235 236 237 238 239 240 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 233 def raw_get(method, uesuri = nil) params = {:invocation_method => :get, :raw_response => true} response = @client.invoke(method, UU::OS::UESURI.new(uesuri), params).unwrap body = response.body body = body.read if body.respond_to?(:read) body.force_encoding(@@DEFAULT_ENCODING) return [response.status, body, transform_headers(response.headers)] end |
- (Array<Numeric, IO, Hash>) raw_get_binary(method, uesuri = nil)
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Invokes HTTP GET method without touching the incoming response. Response body is handed as binary read only stream. Caller is responsible for closing this stream after it is processed.
252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 252 def raw_get_binary(method, uesuri = nil) params = {:invocation_method => :get, :raw_response => true, :stream_response => true, :binary_response => true} if @client.unwrap.instance_variable_get(:@headers)[:accept][0] == @@DEFAULT_CONTENT_TYPE # RemoteClient allowed to reconfigure Accept header for whole instance # (probably never used but we need it for backward compatibility). params[:accept] = @@STREAM_CONTENT_TYPE end response = @client.invoke(method, UU::OS::UESURI.new(uesuri), params).unwrap # Some commands rely on ability to rewind stream of downloaded # binary data (rest-client used tempfiles so this was possible). # Therefore to maintain backward compatibility, we also have to # also create tempfiles. return [response.status, TempfileIO.new(response.body), transform_headers(response.headers)] end |
- (Array<Numeric, String, Hash>) raw_post(method, uesuri = nil, data = nil)
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Invokes HTTP POST method without touching the incoming response.
276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 276 def raw_post(method, uesuri = nil, data = nil) params = {:invocation_method => :post, :raw_response => true} if data.kind_of?Hash params[:multipart_upload] = true end params[:parameters] = data response = @client.invoke(method, UU::OS::UESURI.new(uesuri), params).unwrap body = response.body body = body.read if body.respond_to?(:read) body.force_encoding(@@DEFAULT_ENCODING) return [response.status, body, transform_headers(response.headers)] end |
- (Array<Numeric, IO, Hash>) raw_post_binary(method, uesuri = nil, data = nil)
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Invokes HTTP POST method without touching the incoming response. Response body is handed as binary read only stream. Caller is responsible for closing this stream after it is processed.
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 300 def raw_post_binary(method, uesuri = nil, data = nil) params = {:invocation_method => :post, :raw_response => true, :stream_response => true, :binary_response => true} if data.kind_of?Hash params[:multipart_upload] = true end if @client.unwrap.instance_variable_get(:@headers)[:accept][0] == @@DEFAULT_CONTENT_TYPE # RemoteClient allowed to reconfigure Accept header for whole instance # (probably never used but we need it for backward compatibility). params[:accept] = @@STREAM_CONTENT_TYPE end params[:parameters] = data response = @client.invoke(method, UU::OS::UESURI.new(uesuri), params).unwrap # Some commands rely on ability to rewind stream of downloaded # binary data (rest-client used tempfiles so this was possible). # Therefore to maintain backward compatibility, we also have to # also create tempfiles. return [response.status, TempfileIO.new(response.body), transform_headers(response.headers)] end |
- (Object) timeout=(timeout)
To be used only for commands v1. For commands v2 use UU::OS::CMD::CommandClient
Sets request timeout (default value is 120 seconds)
211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/remote_client.rb', line 211 def timeout=(timeout) if timeout < 0 # HTTPClient uses zero for infinite timeout tval = 0 elsif timeout == 0 # therefore zero needs to be translated to minimal timeout tval = 0.001 else tval = timeout end @client.unwrap.connect_timeout = tval @client.unwrap.request_timeout = tval end |