# class GxG::Networking::SoapDriver

SOAP Classes:

### Public Class Methods

new(the_url=nil) click to toggle source

Example sites to test with: www.restfulwebservices.net/rest/WeatherForecastService.svc?wsdl www.restfulwebservices.net/wcf/WeatherForecastService.svc?wsdl graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl www.webservicex.com/CurrencyConvertor.asmx?wsdl

Calls superclass method

    # File lib/gxg/net_clients.rb, line 2062
    def initialize(the_url=nil)
      unless the_url.is_a?(::URI::Generic)
        raise ArgumentError, "You MUST provide a valid URI."
      end
      super()
      @user = nil
      @password = nil
      @interface = []
      @tns_url = nil
      ::Handsoap::http_driver = :net_http
      ::Handsoap::xml_query_driver = :rexml
      if the_url.query.to_s.downcase.include?("wsdl") || (the_url.path.to_s.downcase.include?("wsdl"))
        point = (the_url.scheme.to_s + "://")
        if the_url.user
          point << the_url.user
          @user = the_url.user
        end
        if the_url.password
          point << (":" << the_url.password)
          @password = the_url.password
        end
        if the_url.hostname
          if the_url.user
            point << ("@" << the_url.hostname)
          else
            point << the_url.hostname
          end
        end
        if the_url.path
          point << the_url.path
        end
        # Process WSDL, determine actual version number from that.
        http_tool = ::GxG::Networking::HttpClient.new
        response = http_tool.get(the_url, {:raw_response => true})
        if response
          wsdl_data = response.body.transcode({:replace => "."},::Encoding::UTF_8)
          if wsdl_data.include?("http://schemas.xmlsoap.org/soap/envelope/")
            wsdl_version = 1
          else
            wsdl_version = 2
          end
          ::GxG::Networking::SoapDriver::endpoint({:uri => (point), :version => (wsdl_version)})
          # Build Interface Data:
          document = ::Oga.parse_xml(wsdl_data)
          nodes = document.css("definitions")
          nodes.each do |node|
            next unless node.is_a?(Oga::XML::Element)
            node.attributes.each do |attribute|
              if ["tns", "targetNamespace"].include?(attribute.name)
                @tns_url = attribute.value
                break
              end
            end
            if @tns_url
              break
            end
          end
          unless @tns_url
            raise Exception, "Failed to load namespace (required)."
          end
          nodes = document.css("portType")
          base_names = []
          nodes.each do |node|
            next unless node.is_a?(::Oga::XML::Element)
            node.children.each do |the_operation|
              next unless the_operation.is_a?(::Oga::XML::Element)
              basename = nil
              the_operation.attributes.each do |attribute|
                if attribute.name == "name"
                  basename = attribute.value
                  break
                end
              end
              if basename
                record = {:base => (basename), :message => (("tns:" << basename).to_sym), :input => nil, :output => nil}
                the_operation.children.each do |the_io|
                  next unless the_io.is_a?(::Oga::XML::Element)
                  if ["input", "output"].include?(the_io.name)
                    the_io.attributes.each do |the_message|
                      if the_message.name == "message"
                        record[(the_io.name.to_sym)] = the_message.value
                      end
                    end
                  end
                end
                if record[:input] || record[:output]
                  base_names << record
                end
              end
            end
          end
          messages = document.css("message")
          base_names.each do |the_method|
            record = {:method => (the_method[:message]), :input => nil, :output => nil}
            messages.each do |the_message|
              next unless the_message.is_a?(::Oga::XML::Element)
              the_message.attributes.each do |the_attribute|
                direction_key = nil
                if the_method[:input].gsub(/^.+:/, "") == the_attribute.value
                  direction_key = :input
                end
                if the_method[:output].gsub(/^.+:/, "") == the_attribute.value
                  direction_key = :output
                end
                if direction_key
                  parameters = {}
                  the_message.children.each do |the_part|
                    next unless the_part.is_a?(::Oga::XML::Element)
                    if the_part.name == "part"
                      the_name = nil
                      the_type = nil
                      the_part.attributes.each do |the_parameter|
                        if the_parameter.name == "name"
                          the_name = the_parameter.value
                        end
                        if the_parameter.name == "type"
                          the_type = the_parameter.value
                        end
                        if the_parameter.name == "element"
                          the_type = the_parameter.value
                        end
                        if (the_name && the_type)
                          parameters[(the_name.to_sym)] = the_type
                          the_name = nil
                          the_type = nil
                        end
                      end
                    end
                  end
                  if parameters.keys.size > 0
                    record[(direction_key)] = parameters
                  end
                end
              end
            end
            if record[:input] || record[:output]
              @interface << record
            end
          end
          #
        else
          raise Exception, "Failed to retrieve WSDL data."
        end
      else
        raise ArgumentError, "No WSDL endpoint detected (required)."
      end
      #
      self
    end

### Public Instance Methods

interface() click to toggle source

    # File lib/gxg/net_clients.rb, line 2228
    def interface()
      @interface
    end

on_before_dispatch(the_document=nil) click to toggle source

    # File lib/gxg/net_clients.rb, line 2218
    def on_before_dispatch(the_document=nil)
      #
    end

on_create_document(the_document=nil) click to toggle source

Handsoap support hooks:

    # File lib/gxg/net_clients.rb, line 2212
    def on_create_document(the_document=nil)
      if @tns_url
        the_document.alias('tns', @tns_url)
      end
    end

on_response_document(the_document=nil) click to toggle source

    # File lib/gxg/net_clients.rb, line 2222
    def on_response_document(the_document=nil)
      if @tns_url
        the_document.add_namespace('ns', @tns_url)
      end
    end