Class: AMT::Service::Basic
- Inherits:
-
Handsoap::Service
- Object
- Handsoap::Service
- AMT::Service::Basic
- Defined in:
- lib/amt/service/basic.rb
Overview
This is the base class for all AMT SOAP services, implemented as Handsoap::Service. It provides an implementation of the Handsoap::Service methods which are common to most or all AMT SOAP services (and therefore avoids duplication). These include:
- #envelope_namespace
-
The envelope namespace used for AMT SOAP requests and responses. All AMT SOAP services have the same one.
- #request_content_type
-
The content type for the SOAP request. All AMT SOAP services have the same one.
- #uri
-
The endpoint URI of the SOAP service. It is automatically constructed from the #host, the #port and class name. There shouldn’t be any need to override this method in subclasses.
- #on_create_document, #on_response_document
-
These two Handsoap hooks are used to add the correct namespace to the request and response documents under the ‘ns’ alias. The namespace is stored in the @namespace variable and automatically set on object creation to (
CLASS_NAME
is the unqualified name of the subclass):"http://schemas.intel.com/platform/client/CLASS_NAME/2004/01"
Not all AMT services follow this namespace scheme (the year/month part was normally changed when methods were added in newer versions of the service), so the @namespace variable sometimes needs to be overwritten in the subclass initializer.
- #on_after_create_http_request
-
Used to set the #username and #password on the HTTP transport object.
Apart from that it provides a small wrapper method #soap_call which should be used instead of #invoke by subclasses for actually calling the remote SOAP method.
Direct Known Subclasses
HardwareAsset, NetworkAdministration, RemoteControl, SecurityAdministration
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
The hostname or IP of the service endpoint.
-
#port ⇒ Object
readonly
The port of the service endpoint.
Instance Method Summary collapse
-
#initialize(host, username, password, port = 16992) ⇒ Basic
constructor
Create a new SOAP client by connecting to
host
withusername
andpassword
on the givenport
(defaults to 16992 for non-SSL transport, use 16993 if you have configured SSL). -
#soap_call(soap_method, status_name = 'StatusCode') ⇒ Object
Utility function for calling a SOAP method - should be used by subclasses for all remote SOAP method invocations.
Constructor Details
#initialize(host, username, password, port = 16992) ⇒ Basic
Create a new SOAP client by connecting to host
with username
and password
on the given port
(defaults to 16992 for non-SSL transport, use 16993 if you have configured SSL).
The parameters host
and port
are used in #uri to construct the endpoint URI, username
and password
are set on the HTTP transport object in #on_after_create_http_request.
90 91 92 93 94 |
# File 'lib/amt/service/basic.rb', line 90 def initialize(host, username, password, port = 16992) @host, @port = host, port @username, @password = username, password @namespace = "http://schemas.intel.com/platform/client/#{self.class.name.sub(/^.*::/, '')}/2004/01" end |
Instance Attribute Details
#host ⇒ Object (readonly)
The hostname or IP of the service endpoint.
79 80 81 |
# File 'lib/amt/service/basic.rb', line 79 def host @host end |
#port ⇒ Object (readonly)
The port of the service endpoint.
82 83 84 |
# File 'lib/amt/service/basic.rb', line 82 def port @port end |
Instance Method Details
#soap_call(soap_method, status_name = 'StatusCode') ⇒ Object
Utility function for calling a SOAP method - should be used by subclasses for all remote SOAP method invocations.
Calls #invoke for the given SOAP method soap_method
. The body of the SOAP message is yielded exactly like with #invoke.
Returns the response which is augmented with a #process method that yields the response node if a block is given or otherwise just returns a hash with the method invocation status.
If the method invocation failed (determined by looking at the status_name
entry in the response), an AMT::InvocationError is raised.
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/amt/service/basic.rb', line 108 def soap_call(soap_method, status_name = 'StatusCode') response = invoke("ns:#{soap_method}", "#{@namespace}/#{soap_method}") do |msg| yield(msg) if block_given? end status = AMT::PTStatus.for(response.document.xpath("//ns:#{soap_method}Response/ns:#{status_name}/text()").to_i) raise AMT::InvocationError.new(status, response.document) unless status == :success def response.soap_method=(sm); @sm = sm; end def response.process; yield(document.xpath("//ns:#{@sm}Response")) if block_given?; end response.soap_method = soap_method response end |