Changeset 1245
- Timestamp:
- 04/28/05 17:55:34 (4 years ago)
- Files:
-
- trunk/actionwebservice/CHANGELOG (modified) (1 diff)
- trunk/actionwebservice/lib/action_web_service/dispatcher/abstract.rb (modified) (5 diffs)
- trunk/actionwebservice/lib/action_web_service/dispatcher/action_controller_dispatcher.rb (modified) (1 diff)
- trunk/actionwebservice/lib/action_web_service/protocol/abstract.rb (modified) (2 diffs)
- trunk/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb (modified) (7 diffs)
- trunk/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb (modified) (1 diff)
- trunk/actionwebservice/test/abstract_dispatcher.rb (modified) (2 diffs)
- trunk/actionwebservice/test/dispatcher_action_controller_soap_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionwebservice/CHANGELOG
r1244 r1245 3 3 * Fix that generated WSDL was not using relative_url_root for base URI #1210 [Shugo Maeda] 4 4 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] 6 6 7 7 * 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 33 33 return_value = self.__send__(invocation.api_method.name) 34 34 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) 36 36 end 37 37 … … 44 44 raise(DispatcherError, "request canceled: #{cancellation_reason}") 45 45 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) 47 47 end 48 48 … … 51 51 invocation = Invocation.new 52 52 invocation.protocol = request.protocol 53 invocation.protocol_options = request.protocol_options 53 54 invocation.service_name = request.service_name 54 55 if web_service_dispatching_mode == :layered … … 110 111 end 111 112 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) 113 114 if api.has_api_method?(api_method.name) 114 115 return_type = api_method.returns ? api_method.returns[0] : nil … … 117 118 return_type = ActionWebService::SignatureTypes.canonical_signature_entry(return_value.class, 0) 118 119 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) 120 121 end 121 122 122 123 class Invocation # :nodoc: 123 124 attr_accessor :protocol 125 attr_accessor :protocol_options 124 126 attr_accessor :service_name 125 127 attr_accessor :api trunk/actionwebservice/lib/action_web_service/dispatcher/action_controller_dispatcher.rb
r1244 r1245 86 86 public_method_name = api_method ? api_method.public_name : request.method_name 87 87 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) 89 89 send_web_service_response(response) 90 90 else trunk/actionwebservice/lib/action_web_service/protocol/abstract.rb
r1097 r1245 18 18 end 19 19 20 def decode_request(raw_request, service_name, protocol_options= nil)20 def decode_request(raw_request, service_name, protocol_options={}) 21 21 end 22 22 … … 27 27 end 28 28 29 def encode_response(method_name, return_value, return_type )29 def encode_response(method_name, return_value, return_type, protocol_options={}) 30 30 end 31 31 trunk/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb
r1244 r1245 1 1 require 'action_web_service/protocol/soap_protocol/marshaler' 2 require 'soap/streamHandler' 2 3 3 4 module ActionWebService # :nodoc: … … 10 11 11 12 class SoapProtocol < AbstractProtocol # :nodoc: 13 DefaultEncoding = 'utf-8' 14 12 15 def marshaler 13 16 @marshaler ||= SoapMarshaler.new … … 17 20 return nil unless soap_action = has_valid_soap_action?(action_pack_request) 18 21 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 } 20 27 decode_request(action_pack_request.raw_post, service_name, protocol_options) 21 28 end … … 27 34 end 28 35 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) 31 39 unless envelope 32 40 raise ProtocolError, "Failed to parse SOAP request message" … … 67 75 end 68 76 69 def encode_response(method_name, return_value, return_type )77 def encode_response(method_name, return_value, return_type, protocol_options={}) 70 78 if return_type 71 79 return_binding = marshaler.register_type(return_type) … … 94 102 end 95 103 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) 97 106 end 98 107 … … 122 131 end 123 132 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 124 142 def create_soap_envelope(body) 125 143 header = SOAP::SOAPHeader.new trunk/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb
r1093 r1245 35 35 end 36 36 37 def encode_response(method_name, return_value, return_type )37 def encode_response(method_name, return_value, return_type, protocol_options={}) 38 38 return_value = true if return_value.nil? 39 39 if return_type trunk/actionwebservice/test/abstract_dispatcher.rb
r1171 r1245 378 378 def is_exception?(obj) 379 379 raise NotImplementedError 380 end 381 382 def update_request(ap_request) 383 end 384 385 def check_response(ap_response) 380 386 end 381 387 … … 417 423 ap_request = @protocol.encode_action_pack_request(service_name, public_method_name, body, :request_class => ActionController::TestRequest) 418 424 ap_request.env.update(request_env) 425 update_request(ap_request) 419 426 ap_response = ActionController::TestResponse.new 420 427 container.process(ap_request, ap_response) 421 428 # puts ap_response.body 429 check_response(ap_response) 422 430 public_method_name, return_value = @protocol.decode_response(ap_response.body) 423 431 unless is_exception?(return_value) || virtual trunk/actionwebservice/test/dispatcher_action_controller_soap_test.rb
r1097 r1245 69 69 70 70 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 71 80 def exception_message(soap_fault_exception) 72 81 soap_fault_exception.detail.cause.message