DieboldInc / vcloud-ruby

Ruby bindings to the VMware vCloud Director REST API
MIT License
13 stars 8 forks source link

Issue with parse result from vCD #2

Open jonnyfiveiq opened 12 years ago

jonnyfiveiq commented 12 years ago

HI again,

All connected, and returning the list of orgs. Next to create an org object, where it fails. Using your example code I cannot get it to work, any help much appreciated.

There is only one org called testorg at the moment.

@session.get_org_references.each do |org_ref| @org_name = org_ref.name puts @org_name end @org = @session.get_org_from_name(@org_name)

/Users/~/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/gems/1.9.1/gems/nokogiri-1.5.5/lib/nokogiri/xml/document.rb:55:in read_memory': xmlParseCharRef: invalid xmlChar value 1 (Nokogiri::XML::SyntaxError) from /Users/~/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/gems/1.9.1/gems/nokogiri-1.5.5/lib/nokogiri/xml/document.rb:55:inparse' from /Users/~/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/gems/1.9.1/gems/nokogiri-1.5.5/lib/nokogiri/xml.rb:33:in XML' from /Users/~/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/gems/1.9.1/gems/nokogiri-happymapper-0.5.5/lib/happymapper.rb:261:inparse' from /Users/~/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/gems/1.9.1/gems/nokogiri-happymapper-0.5.5/lib/happymapper.rb:666:in parse' from /Users/~/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/gems/1.9.1/gems/vcloud-0.0.1.1/lib/vcloud/parses_xml.rb:30:inparse_xml' from /Users/~/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/gems/1.9.1/gems/vcloud-0.0.1.1/lib/vcloud/rest_api.rb:88:in parse_response' from /Users/~/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/gems/1.9.1/gems/vcloud-0.0.1.1/lib/vcloud/rest_api.rb:9:inrefresh' from /Users/~/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/gems/1.9.1/gems/vcloud-0.0.1.1/lib/vcloud/base_vcloud_entity.rb:30:in from_reference' from /Users/~/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/gems/1.9.1/gems/vcloud-0.0.1.1/lib/vcloud/client.rb:76:inget_org_from_name' from /Users/~/NetBeansProjects/vCloud Director/lib/main.rb:19:in `

'

jonnyfiveiq commented 12 years ago

Further info... here is the XML that came back in string_or_io

<?xml version="1.0" encoding="UTF-8"?>

Testb Organization Testb Organization
jonnyfiveiq commented 12 years ago

Sorry closed by mistake... still an issue.

jonnyfiveiq commented 12 years ago

Ok managed to put a band aid round the problem it seems that the ParseOptions set to STRICT break it, by changing this to default_xml, this resolved the issue. Can you recommend how to fix this longer term via the vcloud gem rather than me changing the happymapper.rb...many thanks

xml = Nokogiri::XML(xml, nil, nil, Nokogiri::XML::ParseOptions::STRICT) #OLD LINE

xml = Nokogiri::XML(xml, nil, nil, Nokogiri::XML::ParseOptions::DEFAULT_XML) #NEW AMENDED LINE node = xml.root

zrob commented 12 years ago

Couple questions.

1) What version of director are you working against? We built this against 1.5, so there may be some odditites on other versions.

2) That xml you posted is clearly incomplete. Was that b/c of github filtering something out or is that exactly what you got, including the whitespace and 'Testb Organization' twice at the end?

jonnyfiveiq commented 12 years ago

Thanks for responseŠ

  1. The version of vCD is 1.5.1.622844
  2. The XML was cut by GitHub, if I edited the comment it all showed up, here it is in full <?xml version="1.0" encoding="UTF-8"?> <Org xmlns="http://www.vmware.com/vcloud/v1.5" name="testorg" id="urn:vcloud:org:9cb7efae-48d6-498e-a036-956053fca308" type="application/vnd.vmware.vcloud.org+xml" href="https://vcd/api/org/9cb7efae-48d6-498e-a036-956053fca308" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcd/api/v1.5/schema/master.xsd"> <Link rel="down" type="application/vnd.vmware.vcloud.tasksList+xml" href="https://vcd/api/tasksList/9cb7efae-48d6-498e-a036-956053fca308"/> <Link rel="down" type="application/vnd.vmware.vcloud.catalog+xml" name="Test Cat" href="https://vcd/api/catalog/5089f14e-d176-4859-84b5-787f97627180"/> <Link rel="down" type="application/vnd.vmware.vcloud.controlAccess+xml" href="https://vcd/api/org/9cb7efae-48d6-498e-a036-956053fca308/catalog/5089f 14e-d176-4859-84b5-787f97627180/controlAccess/"/> <Link rel="controlAccess" type="application/vnd.vmware.vcloud.controlAccess+xml" href="https://vcd/api/org/9cb7efae-48d6-498e-a036-956053fca308/catalog/5089f 14e-d176-4859-84b5-787f97627180/action/controlAccess"/> <Link rel="down" type="application/vnd.vmware.vcloud.catalog+xml" name="Main Catalog" href="https://vcd/api/catalog/fa5a7f4c-d852-4e2b-9dbe-908fa64ddc63"/> <Link rel="down" type="application/vnd.vmware.vcloud.controlAccess+xml" href="https://vcd/api/org/9cb7efae-48d6-498e-a036-956053fca308/catalog/fa5a7 f4c-d852-4e2b-9dbe-908fa64ddc63/controlAccess/"/> <Link rel="controlAccess" type="application/vnd.vmware.vcloud.controlAccess+xml" href="https://vcd/api/org/9cb7efae-48d6-498e-a036-956053fca308/catalog/fa5a7 f4c-d852-4e2b-9dbe-908fa64ddc63/action/controlAccess"/> <Link rel="down" type="application/vnd.vmware.vcloud.orgNetwork+xml" name="Internal Network" href="https://vcd/api/network/541ec761-24ae-4662-90ed-0dbed787f846"/> <Link rel="down" type="application/vnd.vmware.vcloud.orgNetwork+xml" name="External Network" href="https://vcd/api/network/e69279da-0300-4eb0-9a11-8203a60a533b"/> <Link rel="down" type="application/vnd.vmware.vcloud.metadata+xml" href="https://vcd/api/org/9cb7efae-48d6-498e-a036-956053fca308/metadata"/> Testb Organization Testb Organization

From: Zach Robinson notifications@github.com Reply-To: DieboldInc/vcloud-ruby <reply+i-7827575-d083e9fe8a73fe1bdb45798ca4696be1118f114e-2084157@reply.gith ub.com> Date: Wednesday, 24 October 2012 15:44 To: DieboldInc/vcloud-ruby vcloud-ruby@noreply.github.com Cc: John Hardy john@jhardy.co.uk Subject: Re: [vcloud-ruby] Issue with parse result from vCD (#2)

Couple questions.

1) What version of director are you working against? We built this against 1.5, so there may be some odditites on other versions.

2) That xml you posted is clearly incomplete. Was that b/c of github filtering something out or is that exactly what you got, including the whitespace and 'Testb Organization' twice at the end?

‹ Reply to this email directly or view it on GitHub https://github.com/DieboldInc/vcloud-ruby/issues/2#issuecomment-9742038 .

zrob commented 12 years ago

looks like it has to do with the unicode chars on these lines:

     <Description>&#22;&#3;&#22;&#26;Testb Organization&#1;</Description>
     <FullName>&#3;&#22;&#26;Testb Organization&#1;</FullName>

Those chars are html escaped and need to be html unescaped, for example using CGI.unescapeHTML(xml_stuff) before being fed to nokogiri for parsing. Looking at the best way to do that in the vcloud gem (maybe a restclient option or something).

zrob commented 12 years ago

I pushed up a new branch called 'unicode' that I think will fix your issue. If you get a chance to give it a try and let me know then I'll push it into the gem if all is good.