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

Setting headers and namespaces #9

Closed
auxbuss opened this issue Dec 14, 2009 · 10 comments
Closed

Setting headers and namespaces #9

auxbuss opened this issue Dec 14, 2009 · 10 comments

Comments

@auxbuss
Copy link

auxbuss commented Dec 14, 2009

Hi,

I'm wrapping a SOAP service and so have to repeat the same
soap block assignments at every SOAP call. Ideally, I'd like to "push" these
assignments up a level.

For example, currently I have something like:


class SomeApi
  WSDL = 'https://blah.com?WSDL'
  def SomeApi.get_all_freds(param1)
    client = Savon::Client.new WSDL
    client.get_all_freds do |soap|
      soap.namespaces["xmlns:wsdl"] = "urn:http://blah.com/more_blah"
      soap.header = { "wsdl:Credentials" => {
        "UserName" => :user, "Password" => :pass } }
      soap.body = { "wsdl:param" => param1 }
    end
  end
  def SomeApi.get_all_dinos(param2)
    client = Savon::Client.new WSDL
    client.get_all_dinos do |soap|
      soap.namespaces["xmlns:wsdl"] = "urn:http://blah.com/more_blah"
      soap.header = { "wsdl:Credentials" => {
        "UserName" => :user, "Password" => :pass } }
      soap.body = { "wsdl:param" => param2 }
    end
  end
end

Where I'd like to get to is:


class SomeApi
  def SomeApi.get_all_freds(param1)
    SomeSoapClient::instance.get_all_freds do |soap|
      soap.body = { "wsdl:param" => param1 }
    end
  end
  def SomeApi.get_all_dinos(param2)
    SomeSoapClient::instance.get_all_dinos do |soap|
      soap.body = { "wsdl:param" => param2 }
    end
  end
end

with something like:


class SomeSoapClient
  private_class_method :new
  @@instance = nil
  WSDL = 'https://blah.com?WSDL'
  def SomeSoapClient.instance
    unless @@instance then
      @@instance = Savon::Client.new WSDL unless @@instance
      @@instance.namespaces["xmlns:wsdl"] = "urn:http://blah.com/more_blah"
      @@instance.header = { "wsdl:Credentials" => {
        "UserName" => :user, "Password" => :pass } }
    end
    @@instance
  end
end

Any idea how I might get close to this? Or is there a better way? Thanks.

@rubiii
Copy link
Contributor

rubiii commented Dec 14, 2009

looks like something you could easily abstract in your application.

class SomeApi
  def self.get(type, param)
    soap_action = "get_#{type}"
    client = Savon::Client.new WSDL

    client.send(soap_action) do |soap|
      soap.namespaces["xmlns:wsdl"] = "urn:http://blah.com/more_blah"
      soap.header = { "wsdl:Credentials" => {
        "UserName" => :user, "Password" => :pass } }
      soap.body = { "wsdl:param" => param }
    end
  end
end

SomeApi.get :all_dinos, :before => "1996"

or whatever fits your style.

@auxbuss
Copy link
Author

auxbuss commented Dec 14, 2009

Interesting idea, but not all the methods are gets; a singleton soap client is essential (easily fixed above); and the parameters are not fixed -- hence my original suggested api outline that retained the block.

Are you against providing methods to add headers and namespace changes at the SOAP client layer?

@rubiii
Copy link
Contributor

rubiii commented Dec 14, 2009

need to ask if you're using savon without the wsdl, cause i have a little problem with globally setting the namespace. the default for all global/per request options is that the per request options are always favored before the global ones.

now savon can be used with and without its wsdl object, which also sets the namespace uri. to be consistent with all other options, when using the wsdl, the namespace uri retrieved from the wsdl would need to be used instead of the global one.

you know what i mean? don't know if that meets your requirements though.

@auxbuss
Copy link
Author

auxbuss commented Dec 15, 2009

I'm using WSDL.

It makes sense for the per request options to have priority, but are they not additive?

When I tried without the namespaces option, the namespace was not correctly picked up from the WSDL, that's why I am using that option.

@rubiii
Copy link
Contributor

rubiii commented Dec 15, 2009

it's ok. will add these features in the next version and leave the issue open until it's released.

@satsang
Copy link

satsang commented Dec 16, 2009

I would like to see general purpose http header support as well so those of us who have to deal with http basic auth vs wsse can use savon

@rubiii
Copy link
Contributor

rubiii commented Dec 17, 2009

http authentication is on my todo-list, but please stick to the topic when commenting on an issue. if you really feel you need to push the topic, just open another issue.

@rubiii
Copy link
Contributor

rubiii commented Dec 30, 2009

added to the official todo list at: http://rubiii.tadalist.com/lists/1459816/public

@rubiii
Copy link
Contributor

rubiii commented Jan 17, 2010

added support for global soap header and namespaces to the dev branch. this was long overdue. will be included in the next release.

please take a look at:
http://github.com/rubiii/savon/commit/d4ba521d94a4d4fa7747acee47d63f604113142b

@rubiii
Copy link
Contributor

rubiii commented Jan 17, 2010

released version 0.7.2 including a fix for this issue.

rubiii added a commit that referenced this issue Jun 3, 2013
Fixes issue with WSDL message element having no part element.
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants