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

Ticket #6473 (new defect)

Opened 2 years ago

Last modified 7 months ago

XML namespace use causes error on XML post

Reported by: jmacomber Assigned to: David
Priority: high Milestone: 2.x
Component: ActionPack Version: 1.1.6
Severity: major Keywords: xmlns namespace
Cc:

Description (Last modified by bitsweat)

When submitting XML which contains a default namespace such as:

<profile xmlns="http://services.stuff.com/profile/request"> 
        <username>user1</username> 
        <password>pwd1</password> 
</profile> 

An exception is thrown:

Parameters: {"format"=>#<Mime::Type:0x2b662f8 
@string="application/xml", @synonyms=["text/xml", "application/x-xml"], 
@symbol=:xml>, "exception"=>"can't typecast 
\"http://services.stuff.com/profile/request\" (RuntimeError)", 
"action"=>"profile", "controller"=>"xml", "raw_post_data"=>"<profile 
xmlns=\"http://services.stuff.com/profile/request\">\n\t<username>user1</username>\n\t<password>pwd1</password>\n</profile>", 
"backtrace"=>["D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/acti­on_controller/cgi_ext/cgi_methods.rb:111:in 
`typecast_xml_value'", 
"D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­cgi_ext/cgi_methods.rb:99:in 
`typecast_xml_value'", 
"D:/ruby184/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in 
`inject'", 
"D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­cgi_ext/cgi_methods.rb:98:in 
`typecast_xml_value'", 
"D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­cgi_ext/cgi_methods.rb:99:in 
`typecast_xml_value'", 
"D:/ruby184/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in 
`inject'", 
"D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­cgi_ext/cgi_methods.rb:98:in 
`typecast_xml_value'", 
"D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­cgi_ext/cgi_methods.rb:71:in 
`parse_formatted_request_parameters'", 
"D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­cgi_process.rb:69:in 
`request_parameters'", 
"D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­request.rb:13:in 
`parameters'", 
"D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­session_management.rb:122:in 
`set_session_options_without_components'", 
"D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­components.rb:178:in 
`set_session_options'", 
"D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­session_management.rb:116:in 
`process'", 
"D:/ruby184/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in 
`dispatch'", 
"D:/ruby184/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:150:in 
`process_request'", 
"D:/ruby184/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:54:in 
`process!'", "D:/ruby184/lib/ruby/site_ruby/1.8/fcgi.rb:598:in 
`each_cgi'", "D:/ruby184/lib/ruby/site_ruby/1.8/fcgi.rb:595:in 
`each_cgi'", 
"D:/ruby184/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:53:in 
`process!'", 
"D:/ruby184/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:23:in 
`process!'", 
"D:/eclipse3.2/eclipse/workspace/LCP-New/public/dispatch.fcgi:24"]} 

Change History

(in reply to: ↑ description ) 11/02/06 02:37:48 changed by hreynolds2

I am not seeing this behavior. With the following controller:

class XmlController < ApplicationController

def index

puts request.raw_post render :text => "No error processing XML with namespace"

end

end

... and the following client to test the controller:

require 'net/http' require 'uri' require 'rexml/document'

xml_string = "<profile xmlns=\"http://services.stuff.com/profile/request\">" +

"<username>user1</username><password>pwd1</password></profile>"

xml_document = REXML::Document.new(xml_string)

puts "sending XML in http POST" http_client = Net::HTTP.new('localhost', 3000) http_result = http_client.post('/xml', xml_document.to_s) puts "result type: " + http_result.class.name puts "result: " + http_result.body.to_s

... I am not having any trouble with getting this error. Please provide a test case demonstrating the error.

~harris

Replying to jmacomber:

When submitting XML which contains a default namespace such as: <profile xmlns="http://services.stuff.com/profile/request"> <username>user1</username> <password>pwd1</password> </profile> An exception is thrown: Parameters: {"format"=>#<Mime::Type:0x2b662f8 @string="application/xml", @synonyms=["text/xml", "application/x-xml"], @symbol=:xml>, "exception"=>"can't typecast \"http://services.stuff.com/profile/request\" (RuntimeError)", "action"=>"profile", "controller"=>"xml", "raw_post_data"=>"<profile xmlns=\"http://services.stuff.com/profile/request\">\n\t<username>user1</username>\n\t<password>pwd1</password>\n</profile>", "backtrace"=>["D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/acti­on_controller/cgi_ext/cgi_methods.rb:111:in `typecast_xml_value'", "D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­cgi_ext/cgi_methods.rb:99:in `typecast_xml_value'", "D:/ruby184/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `inject'", "D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­cgi_ext/cgi_methods.rb:98:in `typecast_xml_value'", "D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­cgi_ext/cgi_methods.rb:99:in `typecast_xml_value'", "D:/ruby184/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `inject'", "D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­cgi_ext/cgi_methods.rb:98:in `typecast_xml_value'", "D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­cgi_ext/cgi_methods.rb:71:in `parse_formatted_request_parameters'", "D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­cgi_process.rb:69:in `request_parameters'", "D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­request.rb:13:in `parameters'", "D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­session_management.rb:122:in `set_session_options_without_components'", "D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­components.rb:178:in `set_session_options'", "D:/ruby184/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/­session_management.rb:116:in `process'", "D:/ruby184/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in `dispatch'", "D:/ruby184/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:150:in `process_request'", "D:/ruby184/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:54:in `process!'", "D:/ruby184/lib/ruby/site_ruby/1.8/fcgi.rb:598:in `each_cgi'", "D:/ruby184/lib/ruby/site_ruby/1.8/fcgi.rb:595:in `each_cgi'", "D:/ruby184/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:53:in `process!'", "D:/ruby184/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:23:in `process!'", "D:/eclipse3.2/eclipse/workspace/LCP-New/public/dispatch.fcgi:24"]}

11/02/06 06:03:32 changed by bitsweat

  • description changed.

03/20/07 11:37:52 changed by oyku

I have encountered the same prroblem with Actionwebservice. Here's a sample request that offends

<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:si=\"http://soapinterop.org/xsd\">

<SOAP:Body>

<ns1:MyAppService xmlns:ns1=\"urn:myappxml\">

<ns1:key xsi:type=\"xsd:string\">xxxx</ns1:key> <ns1:client_id xsi:type=\"xsd:int\">10</ns1:client_id> <ns1:product_name xsi:type=\"xsd:string\">Some product</ns1:product_name> <ns1:price xsi:type=\"xsd:double\">1.2209e+2</ns1:price>

</ns1:MyAppService>

</SOAP:Body>

</SOAP:Envelope>

Although I get the same error, the process is completed as if there were no error. (please disregard the backslashes the xml is cpied from the log file) However through the invoke interface, the generated request is like this which is processed.

<?xml version="1.0" encoding="utf-8" ?> <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"

xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<env:Body>

<n1:MyAppService xmlns:n1="urn:myappxml"

env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">

<key xsi:type="xsd:string">xxxx</key> <client_id xsi:type="xsd:int">10</client_id> <product_name xsi:type="xsd:string">Some product</product_name> <price xsi:type="xsd:double">+122.09</price>

</n1:MyAppService>

</env:Body>

</env:Envelope>

12/12/07 05:07:51 changed by eggie5

I can confirm this error.

I've experienced this with XML generated from the .net framework xml serializers which includes namespaces.

As a workaround for rails I have add a deprecation layer to my code to remove any namespaces before request goes out.