Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

Changeset 1868

Show
Ignore:
Timestamp:
06/30/07 12:39:06 (1 year ago)
Author:
nahi
Message:
  • added an API for filtering streamhandler to capture/generate HTTP header. closes #276.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/soap/filter.rb

    r1831 r1868  
    1 # SOAP4R - SOAP envelope filter. 
     1# SOAP4R - SOAP filter. 
    22# Copyright (C) 2000-2007  NAKAMURA, Hiroshi <nahi@ruby-lang.org>. 
    33 
     
    88 
    99require 'soap/filter/filterchain' 
     10# envelope filter 
    1011require 'soap/filter/handler' 
     12# steram filter 
     13require 'soap/filter/streamhandler' 
  • trunk/lib/soap/filter/filterchain.rb

    r1831 r1868  
    1 # SOAP4R - SOAP envelope filter handler
     1# SOAP4R - SOAP filter chain
    22# Copyright (C) 2000-2007  NAKAMURA, Hiroshi <nahi@ruby-lang.org>. 
    33 
  • trunk/lib/soap/netHttpClient.rb

    r1824 r1868  
    3131  attr_accessor :receive_timeout 
    3232  attr_reader :test_loopback_response 
     33  attr_reader :request_filter           # ignored for now. 
    3334 
    3435  def initialize(proxy = nil, agent = nil) 
     
    3738    @debug_dev = nil 
    3839    @test_loopback_response = [] 
     40    @request_filter = Filter::FilterChain.new 
    3941    @session_manager = SessionManager.new 
    4042    @no_proxy = @ssl_config = @protocol_version = nil 
  • trunk/lib/soap/streamHandler.rb

    r1824 r1868  
    99require 'soap/soap' 
    1010require 'soap/httpconfigloader' 
     11require 'soap/filter/filterchain' 
    1112begin 
    1213  require 'stringio' 
     
    2223class StreamHandler 
    2324  RUBY_VERSION_STRING = "ruby #{ RUBY_VERSION } (#{ RUBY_RELEASE_DATE }) [#{ RUBY_PLATFORM }]" 
     25 
     26  attr_reader :filterchain 
    2427 
    2528  class ConnectionData 
     
    4346  end 
    4447 
     48  def initialize 
     49    @filterchain = Filter::FilterChain.new 
     50  end 
     51 
    4552  def self.parse_media_type(str) 
    4653    if /^#{ MediaType }(?:\s*;\s*charset=([^"]+|"[^"]+"))?$/i !~ str 
     
    5663  end 
    5764 
    58   def send(endpoint_url, conn_data, soapaction = nil, charset = nil) 
    59     # send a ConnectionData to specified endpoint_url. 
     65  def send(url, conn_data, soapaction = nil, charset = nil) 
     66    # send a ConnectionData to specified url. 
    6067    # return value is a ConnectionData with receive_* property filled. 
    6168    # You can fill values of given conn_data and return it. 
    6269  end 
    6370 
    64   def reset(endpoint_url = nil) 
     71  def reset(url = nil) 
    6572    # for initializing connection status if needed. 
    6673    # return value is not expected. 
     
    99106  end 
    100107 
     108  class HttpPostRequestFilter 
     109    def initialize(filterchain) 
     110      @filterchain = filterchain 
     111    end 
     112 
     113    def filter_request(req) 
     114      @filterchain.each do |filter| 
     115        filter.on_httppost_outbound(req) 
     116      end 
     117    end 
     118 
     119    def filter_response(req, res) 
     120      @filterchain.each do |filter| 
     121        filter.on_httppost_inbound(req, res) 
     122      end 
     123    end 
     124  end 
    101125 
    102126public 
     
    114138    super() 
    115139    @client = Client.new(nil, "SOAP4R/#{ Version }") 
     140    @client.request_filter << HttpPostRequestFilter.new(@filterchain) 
    116141    @wiredump_file_base = nil 
    117142    @charset = @wiredump_dev = nil 
     
    135160  end 
    136161 
    137   def send(endpoint_url, conn_data, soapaction = nil, charset = @charset) 
     162  def send(url, conn_data, soapaction = nil, charset = @charset) 
    138163    conn_data.soapaction ||= soapaction # for backward conpatibility 
    139     conn_data = send_post(endpoint_url, conn_data, charset) 
     164    conn_data = send_post(url, conn_data, charset) 
    140165    @client.save_cookie_store if @cookie_store 
    141166    conn_data 
    142167  end 
    143168 
    144   def reset(endpoint_url = nil) 
    145     if endpoint_url.nil? 
     169  def reset(url = nil) 
     170    if url.nil? 
    146171      @client.reset_all 
    147172    else 
    148       @client.reset(endpoint_url) 
     173      @client.reset(url) 
    149174    end 
    150175    @client.save_cookie_store if @cookie_store 
     
    182207  end 
    183208 
    184   def send_post(endpoint_url, conn_data, charset) 
     209  def send_post(url, conn_data, charset) 
    185210    conn_data.send_contenttype ||= StreamHandler.create_media_type(charset) 
    186211 
     
    192217    end 
    193218 
    194     extra = {} 
    195     extra['Content-Type'] = conn_data.send_contenttype 
    196     extra['SOAPAction'] = "\"#{ conn_data.soapaction }\"" 
    197     extra['Accept-Encoding'] = 'gzip' if send_accept_encoding_gzip? 
     219    extheader = {} 
     220    extheader['Content-Type'] = conn_data.send_contenttype 
     221    extheader['SOAPAction'] = "\"#{ conn_data.soapaction }\"" 
     222    extheader['Accept-Encoding'] = 'gzip' if send_accept_encoding_gzip? 
    198223    send_string = conn_data.send_string 
    199224    @wiredump_dev << "Wire dump:\n\n" if @wiredump_dev 
     
    201226      retry_count = 0 
    202227      while true 
    203         res = @client.post(endpoint_url, send_string, extra
     228        res = @client.post(url, send_string, extheader
    204229        if RETRYABLE and HTTP::Status.redirect?(res.status) 
    205230          retry_count += 1 
     
    207232            raise HTTPStreamError.new("redirect count exceeded") 
    208233          end 
    209           endpoint_url = res.header["location"][0] 
    210           puts "redirected to #{endpoint_url}" if $DEBUG 
     234          url = res.header["location"][0] 
     235          puts "redirected to #{url}" if $DEBUG 
    211236        else 
    212237          break 
     
    214239      end 
    215240    rescue 
    216       @client.reset(endpoint_url) 
     241      @client.reset(url) 
    217242      raise 
    218243    end