Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elaborate doc on reusable types #95

Closed
mbenabda opened this issue May 23, 2013 · 10 comments
Closed

Elaborate doc on reusable types #95

mbenabda opened this issue May 23, 2013 · 10 comments

Comments

@mbenabda
Copy link
Contributor

Hi,

I'm having a problem using washout 0.7.1 with Rails 4.0.0.rc1 and Savon 0.9.2

I beleive it's because of how i used reusable types, but I'm not sure. It would be awesome to have a more complete example in the doc, section "Reusable Types"

Here is an example of what I'm doing, where ResponseObject inherits from WashOut::Type

controller:

class SoapController < ApplicationController
  soap_action "getMetadata",
    :args => {
      :id => :string,
        :index => :integer,
        :count => :integer,
        :recursive => :boolean
      },
      :return => Metadata,
      :to => :get_metadata

  def get_metadata
    metadata = Metadata.fetch(params[:id], params[:index], params[:count], params[:recursive])
    render :soap => metadata                                                              # line 35 of soap_controller.rb
  end
end

model:

class Metadata < ResponseObject
  map :metadata_ => {
    :index => :integer,
    :count => :integer,
    :total => :integer,
    :mediaCollection => MediaCollection,
    :mediaMetadata => MediaMetadata
  }
end # class

class MetadataContainer < WashOut::Type
  type_name "metadata_con"
  map :metadata => Metadata
end

The model classes MediaCollection and MediaMetadata follow the same pattern as the Metadata class (with eventually other nested reusable types)

Running something like this gives me :
NoMethodError (undefined method '[]' for nil:NilClass) app/controllers/soap_controller.rb:35:in `get_metadata'

Any help would be appreciated.

Thank you,
Regards,
Mehdi.

@inossidabile
Copy link
Owner

Will try to reproduce it tomorrow.

@inossidabile
Copy link
Owner

Could you please provide an inspect of the entity you pass to render :soap?

@mbenabda
Copy link
Contributor Author

Thanks for giving it a look.

metadata.inspect :
{:index=>0, :count=>2, :total=>2, :mediaCollection=>[{:id=>"search", :title=>"Search", :itemType=>"container"}, {:id=>"profile", :title=>"Profile", :itemType=>"container"}], :mediaMetadata=>[nil, nil]}

@mbenabda
Copy link
Contributor Author

Did you manage to reproduce the issue ?

@inossidabile
Copy link
Owner

Not really. Is the issue connected to the PR you made?

@mbenabda
Copy link
Contributor Author

Hi,
Unfortunately it's not. it was related to my use of the nested types: the doc should mention that a response to be rendered via render :soap must match { :value => response_to_render } . I tried something simpler, and managed to both reproduce the issue, and have something working, but I couldn't format the response as i wanted to. Here is some code to reproduce :

Controller

soap_action "getSessionId",
              args: {
                :username => :string,
                :password => :string
              },
              :return => SessionId,
              :to => :get_session_id,
              :response_tag => "getSessionIdResponse"

  def get_session_id
    render :soap => SessionId.fetch(params[:username], params[:password])
  end

Model:

class SessionId < ResponseObject
  map :getSessionIdResult => :string

  def self.fetch(login, password)
    a_string = "0123456789"
    return { :getSessionIdResult => a_string }
  end

end

The code above code works if you replace

return { :getSessionIdResult => a_string }

with

return { :value => { :getSessionIdResult => a_string } }

in SessionId fetch()

and here is the generated soap response:

<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:tns="http://www.sonos.com/Services/1.1">
  <soap:Body>
    <getSessionIdResponse>
      <value xsi:type="tns:value">
        <getSessionIdResult xsi:type="xsd:string">
          0123456789
        </getSessionIdResult>
      </value>
    </getSessionIdResponse>
  </soap:Body>
</soap:Envelope>

but i would like to have something like this:

<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:tns="http://www.sonos.com/Services/1.1">
  <soap:Body>
    <getSessionIdResponse>
        <getSessionIdResult xsi:type="xsd:string">
          0123456789
        </getSessionIdResult>
    </getSessionIdResponse>
  </soap:Body>
</soap:Envelope>

any lead ?

Thank you

@inossidabile
Copy link
Owner

Ah, I see now. I wasn't able to reproduce that exactly because I used :valueautomatically 😯
That's a bug of renderer. It doesn't accept Types as first-level parameter. Fixing it.

@inossidabile
Copy link
Owner

The bug is fixed. It breaks backward compatibility however. Therefore I ticked it to 0.8. Try master pls. Let's ensure it works to release it.

@borjahormigos
Copy link

Hi inossidabile,

I've been working on the example what you're talking about and the bug it's fixed, but I'm having some problems when I change the config.wash_out.style = 'document'. For some reason the params[:var] of the soap_action are not transfered to the contained variable, as result of this, It's impossible to use WSDL style 'document'.

If you want to try you just have to change:

config.wash_out.style = 'document'

and, in the class "SessionId < ResponseObject"

a_string = login + pasword

PS: Thank's in advance for the GEM, It's so usefull

@borjahormigos
Copy link

Hi again,

Maybe I made a mistake, If I add at the begining of the controller next to It works, but when I was reading your source_code soap.rb I thought that this

included do
include WashOut::Dispatcher
self.soap_actions = {}
end

included It by default.

So don't lose your time with my previous question :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants