Class: VimSdk::Soap::StubAdapter
- Inherits:
-
Object
- Object
- VimSdk::Soap::StubAdapter
- Defined in:
- lib/ruby_vim_sdk/soap/stub_adapter.rb
Constant Summary collapse
- PC =
Vmodl::Query::PropertyCollector
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #compute_version_id(version) ⇒ Object
- #cookie ⇒ Object
-
#initialize(uri, version, http_client) ⇒ StubAdapter
constructor
A new instance of StubAdapter.
- #invoke_method(managed_object, method_info, arguments, outer_stub = nil) ⇒ Object
- #invoke_property(managed_object, property_info) ⇒ Object
- #serialize(object, info, version, namespace_map) ⇒ Object
- #serialize_request(managed_object, info, arguments) ⇒ Object
Constructor Details
#initialize(uri, version, http_client) ⇒ StubAdapter
Returns a new instance of StubAdapter.
9 10 11 12 13 14 15 16 |
# File 'lib/ruby_vim_sdk/soap/stub_adapter.rb', line 9 def initialize(uri, version, http_client) @uri = URI.parse(uri) @version = version @version_id = compute_version_id(version) @http_client = http_client @cookie = "" @property_collector = nil end |
Instance Attribute Details
#version ⇒ Object (readonly)
Returns the value of attribute version.
7 8 9 |
# File 'lib/ruby_vim_sdk/soap/stub_adapter.rb', line 7 def version @version end |
Instance Method Details
#compute_version_id(version) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/ruby_vim_sdk/soap/stub_adapter.rb', line 63 def compute_version_id(version) version_ns = VmomiSupport.version_namespace(version) if version_ns.index("/") "\"urn:#{version_ns}\"" else "" end end |
#cookie ⇒ Object
18 19 20 |
# File 'lib/ruby_vim_sdk/soap/stub_adapter.rb', line 18 def @http_client..find(@uri) end |
#invoke_method(managed_object, method_info, arguments, outer_stub = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ruby_vim_sdk/soap/stub_adapter.rb', line 22 def invoke_method(managed_object, method_info, arguments, outer_stub = nil) outer_stub = self if outer_stub.nil? headers = {"SOAPAction" => @version_id, "Accept-Encoding" => "gzip, deflate", "Content-Type" => "text/xml; charset=#{XML_ENCODING}"} request = serialize_request(managed_object, method_info, arguments) response = @http_client.post(@uri, request, headers) status = response.code if status == 200 || status == 500 object = SoapResponseDeserializer.new(outer_stub).deserialize(response.content, method_info.result_type) if outer_stub != self result = [status, object] elsif status == 200 result = object elsif object.kind_of?(Vmodl::MethodFault) raise SoapException.new(object.msg, object) else raise SoapException.new("Unknown SOAP fault", object) end else raise Net::HTTPError.new("#{status}", nil) end result end |
#invoke_property(managed_object, property_info) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ruby_vim_sdk/soap/stub_adapter.rb', line 49 def invoke_property(managed_object, property_info) filter_spec = PC::FilterSpec.new( :object_set => [PC::ObjectSpec.new(:obj => managed_object, :skip => false)], :prop_set => [PC::PropertySpec.new(:all => false, :type => managed_object.class, :path_set => [property_info.wsdl_name])]) if @property_collector.nil? service_instance = Vim::ServiceInstance.new("ServiceInstance", self) @property_collector = service_instance.retrieve_content.property_collector end @property_collector.retrieve_contents([filter_spec]).first.prop_set.first.val end |
#serialize(object, info, version, namespace_map) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ruby_vim_sdk/soap/stub_adapter.rb', line 102 def serialize(object, info, version, namespace_map) if version.nil? if object.kind_of?(Array) item_type = object.class.type_info version = item_type.version else if object.nil? return "" end version = object.class.type_info.version end end writer = StringIO.new SoapSerializer.new(writer, version, namespace_map).serialize(object, info) writer.string end |
#serialize_request(managed_object, info, arguments) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ruby_vim_sdk/soap/stub_adapter.rb', line 72 def serialize_request(managed_object, info, arguments) if !VmomiSupport.is_child_version(@version, info.version) fault = Vmodl::Fault::MethodNotFound.new fault.receiver = managed_object fault.method = info.name raise SoapException(fault) end namespace_map = SOAP_NAMESPACE_MAP.dup default_namespace = VmomiSupport.wsdl_namespace(@version) namespace_map[default_namespace] = "" result = [XML_HEADER, "\n", SOAP_ENVELOPE_START] result << SOAP_BODY_START result << "<#{info.wsdl_name} xmlns=\"#{default_namespace}\">" property = Property.new("_this", "Vmodl.ManagedObject", @version) property.type = Vmodl::ManagedObject result << serialize(managed_object, property, @version, namespace_map) info.arguments.zip(arguments).each do |parameter, argument| result << serialize(argument, parameter, @version, namespace_map) end result << "</#{info.wsdl_name}>" result << SOAP_BODY_END result << SOAP_ENVELOPE_END result.join("") end |