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

Changeset 1825

Show
Ignore:
Timestamp:
06/02/07 10:39:39 (2 years ago)
Author:
nahi
Message:
  • filter support.
    you can add filters to intercept before SOAP marshalling and SOAP unmarshalling. filters are invoked in sequence. see filter sample at test/soap/filter/test_filter.rb
    closes #350.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/install.rb

    r1781 r1825  
    6868  install_dir(SRCPATH, 'soap', 'encodingstyle') 
    6969  install_dir(SRCPATH, 'soap', 'header') 
     70  install_dir(SRCPATH, 'soap', 'filter') 
    7071  install_dir(SRCPATH, 'wsdl') 
    7172  install_dir(SRCPATH, 'wsdl', 'xmlSchema') 
  • trunk/lib/soap/element.rb

    r1824 r1825  
    9595class SOAPBody < SOAPStruct 
    9696  include SOAPEnvelopeElement 
     97 
     98  attr_reader :is_fault 
    9799 
    98100  def initialize(data = nil, is_fault = false) 
     
    115117    name = ns.name(@elename) 
    116118    generator.encode_tag(name, attrs) 
    117     if @is_fault 
    118       yield(@data) 
    119     else 
    120       @data.each do |data| 
    121         yield(data) 
    122       end 
     119    @data.each do |data| 
     120      yield(data) 
    123121    end 
    124122    generator.encode_tag_end(name, true) 
  • trunk/lib/soap/rpc/cgistub.rb

    r1824 r1825  
    149149  end 
    150150  alias add_rpc_headerhandler add_headerhandler 
     151 
     152  def filterchain 
     153    @router.filterchain 
     154  end 
    151155 
    152156  # method entry interface 
  • trunk/lib/soap/rpc/driver.rb

    r1824 r1825  
    6363  __attr_proxy :return_response_as_xml, true 
    6464  __attr_proxy :headerhandler 
     65  __attr_proxy :filterchain 
    6566  __attr_proxy :streamhandler 
    6667  __attr_proxy :test_loopback_response 
  • trunk/lib/soap/rpc/element.rb

    r1824 r1825  
    304304  end 
    305305 
     306  def retval 
     307    @retval 
     308  end 
     309 
    306310  def retval=(retval) 
    307311    @retval = retval 
  • trunk/lib/soap/rpc/httpserver.rb

    r1824 r1825  
    104104  alias add_rpc_headerhandler add_headerhandler 
    105105 
     106  def filterchain 
     107    @router.filterchain 
     108  end 
     109 
    106110  # method entry interface 
    107111 
  • trunk/lib/soap/rpc/proxy.rb

    r1824 r1825  
    1313require 'soap/rpc/rpc' 
    1414require 'soap/rpc/element' 
     15require 'soap/header/handlerset' 
     16require 'soap/filter' 
    1517require 'soap/streamHandler' 
    1618require 'soap/mimemessage' 
     
    3335  attr_accessor :return_response_as_xml 
    3436  attr_reader :headerhandler 
     37  attr_reader :filterchain 
    3538  attr_reader :streamhandler 
    3639 
     
    5558    @return_response_as_xml = false 
    5659    @headerhandler = Header::HandlerSet.new 
     60    @filterchain = Filter::FilterChain.new 
    5761    @mapping_registry = nil 
    5862    @literal_mapping_registry = ::SOAP::Mapping::LiteralRegistry.new 
     
    249253 
    250254  def marshal(env, opt) 
     255    @filterchain.each do |filter| 
     256      env = filter.on_outbound(env, opt) 
     257      break unless env 
     258    end 
    251259    send_string = Processor.marshal(env, opt) 
    252260    StreamHandler::ConnectionData.new(send_string) 
     
    255263  def unmarshal(conn_data, opt) 
    256264    contenttype = conn_data.receive_contenttype 
     265    xml = nil 
    257266    if /#{MIMEMessage::MultipartContentType}/i =~ contenttype 
    258267      opt[:external_content] = {} 
     
    267276      opt[:charset] = @mandatorycharset || 
    268277        StreamHandler.parse_media_type(mime.root.headers['content-type'].str) 
    269       env = Processor.unmarshal(mime.root.content, opt) 
    270       if @return_response_as_xml 
    271         opt[:response_as_xml] = mime.root.content 
    272       end 
     278      xml = mime.root.content 
    273279    else 
    274280      opt[:charset] = @mandatorycharset || 
    275281        ::SOAP::StreamHandler.parse_media_type(contenttype) 
    276       env = Processor.unmarshal(conn_data.receive_string, opt) 
    277       if @return_response_as_xml 
    278         opt[:response_as_xml] = conn_data.receive_string 
    279       end 
     282      xml = conn_data.receive_string 
     283    end 
     284    @filterchain.reverse_each do |filter| 
     285      xml = filter.on_inbound(xml, opt) 
     286      break unless xml 
     287    end 
     288    env = Processor.unmarshal(xml, opt) 
     289    if @return_response_as_xml 
     290      opt[:response_as_xml] = xml 
    280291    end 
    281292    unless env.is_a?(::SOAP::SOAPEnvelope) 
  • trunk/lib/soap/rpc/router.rb

    r1824 r1825  
    1313require 'soap/rpc/rpc' 
    1414require 'soap/rpc/element' 
     15require 'soap/header/handlerset' 
     16require 'soap/filter' 
    1517require 'soap/streamHandler' 
    1618require 'soap/mimemessage' 
     
    3032  attr_accessor :generate_explicit_type 
    3133  attr_accessor :external_ces 
     34  attr_reader :filterchain 
    3235 
    3336  def initialize(actor) 
     
    4144    @operation_by_qname = {} 
    4245    @headerhandlerfactory = [] 
     46    @filterchain = Filter::FilterChain.new 
    4347  end 
    4448 
     
    168172        op.call(env.body, @mapping_registry, @literal_mapping_registry, 
    169173          create_mapping_opt) 
     174      conn_data.is_fault = true if soap_response.is_a?(SOAPFault) 
    170175      default_encodingstyle = op.response_default_encodingstyle 
    171176    rescue Exception => e 
     
    175180      wsdl_fault_details = op.faults && op.faults[e.class.name] 
    176181      soap_response = fault(e, wsdl_fault_details) 
     182      conn_data.is_fault = true 
    177183      default_encodingstyle = nil 
    178184    end 
    179     conn_data.is_fault = true if soap_response.is_a?(SOAPFault) 
    180185    header = call_headers(headerhandler) 
    181186    if op.response_use.nil? 
     
    184189      conn_data 
    185190    else 
    186       body = SOAPBody.new(soap_response
     191      body = SOAPBody.new(soap_response, conn_data.is_fault
    187192      env = SOAPEnvelope.new(header, body) 
    188193      marshal(conn_data, env, default_encodingstyle) 
     
    192197  # Create fault response string. 
    193198  def create_fault_response(e) 
    194     env = SOAPEnvelope.new(SOAPHeader.new, SOAPBody.new(fault(e, nil))) 
     199    env = SOAPEnvelope.new(SOAPHeader.new, SOAPBody.new(fault(e, nil), true)) 
    195200    opt = {} 
    196201    opt[:external_content] = nil 
     202    @filterchain.reverse_each do |filter| 
     203      env = filter.on_outbound(env, opt) 
     204      break unless env 
     205    end 
    197206    response_string = Processor.marshal(env, opt) 
    198207    conn_data = StreamHandler::ConnectionData.new(response_string) 
     
    283292 
    284293  def unmarshal(conn_data) 
     294    xml = nil 
    285295    opt = {} 
    286296    contenttype = conn_data.receive_contenttype 
     
    297307      opt[:charset] = 
    298308        StreamHandler.parse_media_type(mime.root.headers['content-type'].str) 
    299       env = Processor.unmarshal(mime.root.content, opt) 
     309      xml = mime.root.content 
    300310    else 
    301311      opt[:charset] = ::SOAP::StreamHandler.parse_media_type(contenttype) 
    302       env = Processor.unmarshal(conn_data.receive_string, opt) 
    303     end 
     312      xml = conn_data.receive_string 
     313    end 
     314    @filterchain.each do |filter| 
     315      xml = filter.on_inbound(xml, opt) 
     316      break unless xml 
     317    end 
     318    env = Processor.unmarshal(xml, opt) 
    304319    charset = opt[:charset] 
    305320    conn_data.send_contenttype = "text/xml; charset=\"#{charset}\"" 
     
    312327    opt[:default_encodingstyle] = default_encodingstyle 
    313328    opt[:generate_explicit_type] = @generate_explicit_type 
     329    @filterchain.reverse_each do |filter| 
     330      env = filter.on_outbound(env, opt) 
     331      break unless env 
     332    end 
    314333    response_string = Processor.marshal(env, opt) 
    315334    conn_data.send_string = response_string