Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 1245

Show
Ignore:
Timestamp:
04/28/05 17:55:34 (4 years ago)
Author:
bitserf
Message:

default to using UTF-8 as response encoding for SOAP if none is
supplied, but if an encoding is supplied by caller, use that for the
response instead (NAKAMURA Hiroshi)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionwebservice/CHANGELOG

    r1244 r1245  
    33* Fix that generated WSDL was not using relative_url_root for base URI #1210 [Shugo Maeda] 
    44 
    5 * Use UTF-8 encoding for SOAP responses #1211 [Shugo Maeda
     5* Use UTF-8 encoding by default for SOAP responses, but if an encoding is supplied by caller, use that for the response  #1211 [Shugo Maeda, NAKAMURA Hiroshi
    66 
    77* If the WSDL was retrieved over HTTPS, use HTTPS URLs in the WSDL too 
  • trunk/actionwebservice/lib/action_web_service/dispatcher/abstract.rb

    r1171 r1245  
    3333            return_value = self.__send__(invocation.api_method.name) 
    3434          end 
    35           web_service_create_response(invocation.protocol, invocation.api, invocation.api_method, return_value) 
     35          web_service_create_response(invocation.protocol, invocation.protocol_options, invocation.api, invocation.api_method, return_value) 
    3636        end 
    3737 
     
    4444            raise(DispatcherError, "request canceled: #{cancellation_reason}") 
    4545          end 
    46           web_service_create_response(invocation.protocol, invocation.api, invocation.api_method, return_value) 
     46          web_service_create_response(invocation.protocol, invocation.protocol_options, invocation.api, invocation.api_method, return_value) 
    4747        end 
    4848 
     
    5151          invocation = Invocation.new 
    5252          invocation.protocol = request.protocol 
     53          invocation.protocol_options = request.protocol_options 
    5354          invocation.service_name = request.service_name 
    5455          if web_service_dispatching_mode == :layered 
     
    110111        end 
    111112 
    112         def web_service_create_response(protocol, api, api_method, return_value) 
     113        def web_service_create_response(protocol, protocol_options, api, api_method, return_value) 
    113114          if api.has_api_method?(api_method.name) 
    114115            return_type = api_method.returns ? api_method.returns[0] : nil 
     
    117118            return_type = ActionWebService::SignatureTypes.canonical_signature_entry(return_value.class, 0) 
    118119          end 
    119           protocol.encode_response(api_method.public_name + 'Response', return_value, return_type
     120          protocol.encode_response(api_method.public_name + 'Response', return_value, return_type, protocol_options
    120121        end 
    121122 
    122123        class Invocation # :nodoc: 
    123124          attr_accessor :protocol 
     125          attr_accessor :protocol_options 
    124126          attr_accessor :service_name 
    125127          attr_accessor :api 
  • trunk/actionwebservice/lib/action_web_service/dispatcher/action_controller_dispatcher.rb

    r1244 r1245  
    8686              public_method_name = api_method ? api_method.public_name : request.method_name 
    8787              return_type = ActionWebService::SignatureTypes.canonical_signature_entry(Exception, 0) 
    88               response = request.protocol.encode_response(public_method_name + 'Response', exception, return_type
     88              response = request.protocol.encode_response(public_method_name + 'Response', exception, return_type, request.protocol_options
    8989              send_web_service_response(response) 
    9090            else 
  • trunk/actionwebservice/lib/action_web_service/protocol/abstract.rb

    r1097 r1245  
    1818      end 
    1919 
    20       def decode_request(raw_request, service_name, protocol_options=nil
     20      def decode_request(raw_request, service_name, protocol_options={}
    2121      end 
    2222 
     
    2727      end 
    2828 
    29       def encode_response(method_name, return_value, return_type
     29      def encode_response(method_name, return_value, return_type, protocol_options={}
    3030      end 
    3131 
  • trunk/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb

    r1244 r1245  
    11require 'action_web_service/protocol/soap_protocol/marshaler' 
     2require 'soap/streamHandler' 
    23 
    34module ActionWebService # :nodoc: 
     
    1011       
    1112      class SoapProtocol < AbstractProtocol # :nodoc: 
     13        DefaultEncoding = 'utf-8' 
     14 
    1215        def marshaler 
    1316          @marshaler ||= SoapMarshaler.new 
     
    1720          return nil unless soap_action = has_valid_soap_action?(action_pack_request) 
    1821          service_name = action_pack_request.parameters['action'] 
    19           protocol_options = { :soap_action => soap_action } 
     22          charset = parse_charset(action_pack_request.env['HTTP_CONTENT_TYPE']) 
     23          protocol_options = {  
     24            :soap_action => soap_action, 
     25            :charset  => charset 
     26          } 
    2027          decode_request(action_pack_request.raw_post, service_name, protocol_options) 
    2128        end 
     
    2734        end 
    2835 
    29         def decode_request(raw_request, service_name, protocol_options=nil) 
    30           envelope = SOAP::Processor.unmarshal(raw_request) 
     36        def decode_request(raw_request, service_name, protocol_options={}) 
     37          charset = protocol_options[:charset] || DefaultEncoding 
     38          envelope = SOAP::Processor.unmarshal(raw_request, :charset => charset) 
    3139          unless envelope 
    3240            raise ProtocolError, "Failed to parse SOAP request message" 
     
    6775        end 
    6876 
    69         def encode_response(method_name, return_value, return_type
     77        def encode_response(method_name, return_value, return_type, protocol_options={}
    7078          if return_type 
    7179            return_binding = marshaler.register_type(return_type) 
     
    94102          end 
    95103          envelope = create_soap_envelope(response) 
    96           Response.new(SOAP::Processor.marshal(envelope), 'text/xml; charset=utf-8', return_value) 
     104          charset = protocol_options[:charset] || DefaultEncoding 
     105          Response.new(SOAP::Processor.marshal(envelope, :charset => charset), "text/xml; charset=#{charset}", return_value) 
    97106        end 
    98107 
     
    122131          end 
    123132 
     133          def parse_charset(content_type) 
     134            return DefaultEncoding if content_type.nil? 
     135            if /^text\/xml(?:\s*;\s*charset=([^"]+|"[^"]+"))$/i =~ content_type 
     136              $1 
     137            else 
     138              DefaultEncoding 
     139            end 
     140          end 
     141 
    124142          def create_soap_envelope(body) 
    125143            header = SOAP::SOAPHeader.new 
  • trunk/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb

    r1093 r1245  
    3535        end 
    3636 
    37         def encode_response(method_name, return_value, return_type
     37        def encode_response(method_name, return_value, return_type, protocol_options={}
    3838          return_value = true if return_value.nil? 
    3939          if return_type 
  • trunk/actionwebservice/test/abstract_dispatcher.rb

    r1171 r1245  
    378378    def is_exception?(obj) 
    379379      raise NotImplementedError 
     380    end 
     381 
     382    def update_request(ap_request) 
     383    end 
     384 
     385    def check_response(ap_response) 
    380386    end 
    381387 
     
    417423      ap_request = @protocol.encode_action_pack_request(service_name, public_method_name, body, :request_class => ActionController::TestRequest) 
    418424      ap_request.env.update(request_env) 
     425      update_request(ap_request) 
    419426      ap_response = ActionController::TestResponse.new 
    420427      container.process(ap_request, ap_response) 
    421428      # puts ap_response.body 
     429      check_response(ap_response) 
    422430      public_method_name, return_value = @protocol.decode_response(ap_response.body) 
    423431      unless is_exception?(return_value) || virtual 
  • trunk/actionwebservice/test/dispatcher_action_controller_soap_test.rb

    r1097 r1245  
    6969 
    7070  protected 
     71    def update_request(ap_request) 
     72      ap_request.env.update('HTTP_CONTENT_TYPE' => 'text/xml; charset=us-ascii') 
     73    end 
     74 
     75    def check_response(ap_response) 
     76      assert_equal 'text/xml; charset=us-ascii', ap_response.headers['Content-Type'] 
     77      assert_match /xml.*?encoding="us-ascii"/, ap_response.body 
     78    end 
     79 
    7180    def exception_message(soap_fault_exception) 
    7281      soap_fault_exception.detail.cause.message