diff options
author | Leon Breedt <bitserf@gmail.com> | 2005-04-28 17:55:34 +0000 |
---|---|---|
committer | Leon Breedt <bitserf@gmail.com> | 2005-04-28 17:55:34 +0000 |
commit | 8694a79bb2d543a46867454b743c38ce85380e4e (patch) | |
tree | b6bd7b711773f0305b9368521ebb20821d696143 /actionwebservice/lib/action_web_service/protocol | |
parent | 896fea505b67f6dd842a58c72bcd919c593d925a (diff) | |
download | rails-8694a79bb2d543a46867454b743c38ce85380e4e.tar.gz rails-8694a79bb2d543a46867454b743c38ce85380e4e.tar.bz2 rails-8694a79bb2d543a46867454b743c38ce85380e4e.zip |
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)
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1245 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionwebservice/lib/action_web_service/protocol')
3 files changed, 26 insertions, 8 deletions
diff --git a/actionwebservice/lib/action_web_service/protocol/abstract.rb b/actionwebservice/lib/action_web_service/protocol/abstract.rb index d8830968d0..3819aa2ade 100644 --- a/actionwebservice/lib/action_web_service/protocol/abstract.rb +++ b/actionwebservice/lib/action_web_service/protocol/abstract.rb @@ -17,7 +17,7 @@ module ActionWebService # :nodoc: request end - def decode_request(raw_request, service_name, protocol_options=nil) + def decode_request(raw_request, service_name, protocol_options={}) end def encode_request(method_name, params, param_types) @@ -26,7 +26,7 @@ module ActionWebService # :nodoc: def decode_response(raw_response) end - def encode_response(method_name, return_value, return_type) + def encode_response(method_name, return_value, return_type, protocol_options={}) end def protocol_client(api, protocol_name, endpoint_uri, options) diff --git a/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb b/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb index b3f1be2ae4..3e5bad0086 100644 --- a/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb +++ b/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb @@ -1,4 +1,5 @@ require 'action_web_service/protocol/soap_protocol/marshaler' +require 'soap/streamHandler' module ActionWebService # :nodoc: module Protocol # :nodoc: @@ -9,6 +10,8 @@ module ActionWebService # :nodoc: end class SoapProtocol < AbstractProtocol # :nodoc: + DefaultEncoding = 'utf-8' + def marshaler @marshaler ||= SoapMarshaler.new end @@ -16,7 +19,11 @@ module ActionWebService # :nodoc: def decode_action_pack_request(action_pack_request) return nil unless soap_action = has_valid_soap_action?(action_pack_request) service_name = action_pack_request.parameters['action'] - protocol_options = { :soap_action => soap_action } + charset = parse_charset(action_pack_request.env['HTTP_CONTENT_TYPE']) + protocol_options = { + :soap_action => soap_action, + :charset => charset + } decode_request(action_pack_request.raw_post, service_name, protocol_options) end @@ -26,8 +33,9 @@ module ActionWebService # :nodoc: request end - def decode_request(raw_request, service_name, protocol_options=nil) - envelope = SOAP::Processor.unmarshal(raw_request) + def decode_request(raw_request, service_name, protocol_options={}) + charset = protocol_options[:charset] || DefaultEncoding + envelope = SOAP::Processor.unmarshal(raw_request, :charset => charset) unless envelope raise ProtocolError, "Failed to parse SOAP request message" end @@ -66,7 +74,7 @@ module ActionWebService # :nodoc: [method_name, return_value] end - def encode_response(method_name, return_value, return_type) + def encode_response(method_name, return_value, return_type, protocol_options={}) if return_type return_binding = marshaler.register_type(return_type) marshaler.annotate_arrays(return_binding, return_value) @@ -93,7 +101,8 @@ module ActionWebService # :nodoc: end end envelope = create_soap_envelope(response) - Response.new(SOAP::Processor.marshal(envelope), 'text/xml; charset=utf-8', return_value) + charset = protocol_options[:charset] || DefaultEncoding + Response.new(SOAP::Processor.marshal(envelope, :charset => charset), "text/xml; charset=#{charset}", return_value) end def protocol_client(api, protocol_name, endpoint_uri, options={}) @@ -121,6 +130,15 @@ module ActionWebService # :nodoc: soap_action end + def parse_charset(content_type) + return DefaultEncoding if content_type.nil? + if /^text\/xml(?:\s*;\s*charset=([^"]+|"[^"]+"))$/i =~ content_type + $1 + else + DefaultEncoding + end + end + def create_soap_envelope(body) header = SOAP::SOAPHeader.new body = SOAP::SOAPBody.new(body) diff --git a/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb b/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb index af3c1a49f6..d20fe05726 100644 --- a/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb +++ b/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb @@ -34,7 +34,7 @@ module ActionWebService # :nodoc: [nil, XMLRPC::Marshal.load_response(raw_response)] end - def encode_response(method_name, return_value, return_type) + def encode_response(method_name, return_value, return_type, protocol_options={}) return_value = true if return_value.nil? if return_type return_value = value_to_xmlrpc_wire_format(return_value, return_type) |