Sha256: 41da216d5b642f5b7ee9fa8b356b9d30b5f91c380fbfdee0267b37c393bf277a

Contents?: true

Size: 1.68 KB

Versions: 16

Compression:

Stored size: 1.68 KB

Contents

require "httpi"
require "savon/soap/response"

module Savon
  module SOAP

    # = Savon::SOAP::Request
    #
    # Executes SOAP requests.
    class Request

      # Content-Types by SOAP version.
      ContentType = { 1 => "text/xml;charset=UTF-8", 2 => "application/soap+xml;charset=UTF-8" }

      # Expects an <tt>HTTPI::Request</tt> and a <tt>Savon::SOAP::XML</tt> object.
      def initialize(request, soap)
        self.request = setup(request, soap)
      end

      # Accessor for the <tt>HTTPI::Request</tt>.
      attr_accessor :request

      # Executes the request and returns the response.
      def response
        @response ||= with_logging { HTTPI.post request }
      end

    private

      # Sets up the +request+ using a given +soap+ object.
      def setup(request, soap)
        request.url = soap.endpoint
        request.headers["Content-Type"] ||= ContentType[soap.version]
        request.body = soap.to_xml
        request
      end

      # Logs the HTTP request, yields to a given +block+ and returns a <tt>Savon::SOAP::Response</tt>.
      def with_logging
        log_request request.url, request.headers, request.body
        response = yield
        log_response response.code, response.body
        SOAP::Response.new response
      end

      # Logs the SOAP request +url+, +headers+ and +body+.
      def log_request(url, headers, body)
        Savon.log "SOAP request: #{url}"
        Savon.log headers.map { |key, value| "#{key}: #{value}" }.join(", ")
        Savon.log body
      end

      # Logs the SOAP response +code+ and +body+.
      def log_response(code, body)
        Savon.log "SOAP response (status #{code}):"
        Savon.log body
      end

    end
  end
end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
search_biomodel-1.0.0 search_biomodel/ruby/1.8/gems/savon-0.9.2/lib/savon/soap/request.rb
savon-0.9.2 lib/savon/soap/request.rb
s-savon-0.8.6 lib/savon/soap/request.rb
savon-0.9.1 lib/savon/soap/request.rb
savon-0.9.0 lib/savon/soap/request.rb
savon-0.8.6 lib/savon/soap/request.rb
savon-0.8.5 lib/savon/soap/request.rb
savon-0.8.4 lib/savon/soap/request.rb
savon-0.8.3 lib/savon/soap/request.rb
savon-0.8.2 lib/savon/soap/request.rb
savon-0.8.1 lib/savon/soap/request.rb
savon-0.8.0 lib/savon/soap/request.rb
savon-0.8.0.beta.4 lib/savon/soap/request.rb
savon-0.8.0.beta.3 lib/savon/soap/request.rb
savon-0.8.0.beta.2 lib/savon/soap/request.rb
savon-0.8.0.beta.1 lib/savon/soap/request.rb