Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Passing instance of HTTP adapter to constructor throws error #10

Closed
marc-fez opened this issue May 4, 2014 · 9 comments
Closed

Passing instance of HTTP adapter to constructor throws error #10

marc-fez opened this issue May 4, 2014 · 9 comments

Comments

@marc-fez
Copy link

marc-fez commented May 4, 2014

According to the Savon 3 documentation, it is possible to send an instance of an adapter to the Sekken constructor.

Savon.new(wsdl_url, MyAdapter.new)

If I do this with HTTPClient, either a call to the 'new' method or with an instantiated object, I get an error:

client = Sekken.new(wsdl_url, HTTPClient.new)

TypeError: no implicit conversion of HTTP::Message into String
    from /home/marc/.rvm/gems/ruby-2.1.1/gems/nokogiri-1.6.1/lib/nokogiri/xml/document.rb:55:in `read_memory'
    from /home/marc/.rvm/gems/ruby-2.1.1/gems/nokogiri-1.6.1/lib/nokogiri/xml/document.rb:55:in `parse'
    from /home/marc/.rvm/gems/ruby-2.1.1/gems/nokogiri-1.6.1/lib/nokogiri/xml.rb:33:in `XML'
    from /home/marc/.rvm/gems/ruby-2.1.1/bundler/gems/sekken-e90ac1821663/lib/sekken/importer.rb:45:in `import_document'
    from /home/marc/.rvm/gems/ruby-2.1.1/bundler/gems/sekken-e90ac1821663/lib/sekken/importer.rb:19:in `import'
    from /home/marc/.rvm/gems/ruby-2.1.1/bundler/gems/sekken-e90ac1821663/lib/sekken/wsdl.rb:16:in `initialize'
    from /home/marc/.rvm/gems/ruby-2.1.1/bundler/gems/sekken-e90ac1821663/lib/sekken.rb:30:in `new'
    from /home/marc/.rvm/gems/ruby-2.1.1/bundler/gems/sekken-e90ac1821663/lib/sekken.rb:30:in `initialize'
    from (irb):52:in `new'
    from (irb):52
    from /home/marc/.rvm/rubies/ruby-2.1.1/bin/irb:11:in `<main>'
@tjarratt
Copy link
Contributor

tjarratt commented May 5, 2014

Hey @marc-fez thanks for filing this bug. At first I thought that this was a case of Sekken's experimental nature getting out of date with the documentation but I'm not so sure now...

It seems that Sekken is expecting the result of an HTTP request to return a string and HTTPClient is returning an HTTP::Message object instead. You could probably work around this in the meantime by creating your own adapter around HTTPClient. The real fix would be to aggressively try to #to_s whatever we pass to Nokogiri, since we truly expects a string.

@marc-fez
Copy link
Author

marc-fez commented May 6, 2014

Thanks @tjarratt. At first I thought it was a case of me not knowing what I'm doing. But after looking at it more, it appeared to be a bug.

I do also see the same behaviour even if i just pass the HTTPClient class to the constructor and not an instance like so:

client = Sekken.new(url, HTTPClient)
TypeError: no implicit conversion of HTTP::Message into String
    from /home/marc/.rvm/gems/ruby-2.1.1/gems/nokogiri-1.6.1/lib/nokogiri/xml/document.rb:55:in `read_memory'
    from /home/marc/.rvm/gems/ruby-2.1.1/gems/nokogiri-1.6.1/lib/nokogiri/xml/document.rb:55:in `parse'
    from /home/marc/.rvm/gems/ruby-2.1.1/gems/nokogiri-1.6.1/lib/nokogiri/xml.rb:33:in `XML'
    from /home/marc/.rvm/gems/ruby-2.1.1/bundler/gems/sekken-fc1e199c7ffb/lib/sekken/importer.rb:45:in `import_document'
    from /home/marc/.rvm/gems/ruby-2.1.1/bundler/gems/sekken-fc1e199c7ffb/lib/sekken/importer.rb:19:in `import'
    from /home/marc/.rvm/gems/ruby-2.1.1/bundler/gems/sekken-fc1e199c7ffb/lib/sekken/wsdl.rb:16:in `initialize'
    from /home/marc/.rvm/gems/ruby-2.1.1/bundler/gems/sekken-fc1e199c7ffb/lib/sekken.rb:30:in `new'
    from /home/marc/.rvm/gems/ruby-2.1.1/bundler/gems/sekken-fc1e199c7ffb/lib/sekken.rb:30:in `initialize'
    from (irb):3:in `new'
    from (irb):3
    from /home/marc/.rvm/rubies/ruby-2.1.1/bin/irb:11:in `<main>'

So I'm not sure what wrapping the class would do for me. But maybe I'll try to learn a little about using a debugger in ruby to see what I can figure out.

@marc-fez
Copy link
Author

marc-fez commented May 6, 2014

@tjarratt fixed it, not sure if i fixed it right or fixed it well, I'm pretty much a n00b at ruby, but it looks like if an instance of an HTTP adapter was passed, it's class ended up being HTTPClient (or whatever) while if nothing was passed, it ended up being a Sekken::HTTPClient.

And since I'm not sure how a pull request works...

I changed sekken/lib/sekken/http_client.rb line 11

    attr_accessor :client

And changed the initialize method in sekken/lib/sekken.rb line 28 to

  def initialize(wsdl, http = nil)
    if http.class == Class 
      @http_adapter = http
    end
    if http.class == Class || http.nil?
      @http = new_http_client
    else
      @http = new_http_client
      @http.client = http
    end
    @wsdl = WSDL.new(wsdl, @http)
  end

@tjarratt
Copy link
Contributor

tjarratt commented May 9, 2014

Thanks for the update @marc-fez. I took a look at the tests for this and I'm still not entirely sure what the original design goal was. Will need to take a closer look before I try to fix whatever bug is actually present. The code you posted is extremely helpful though for helping explain how someone might actually use this.

My thoughts at this precise moment is that you should be able to pass either a class or an instance of an http client to Sekken.new

@andreorvalho
Copy link

Have you found the answer to this problem? what is the difference between sekken and savon? I am having the same problem with savon...

@tjarratt
Copy link
Contributor

tjarratt commented Dec 2, 2014

Hey @andreorvalho I'm sorry that you're confused by Savon and Sekken. Hopefully we can clear that up.

  • Savon has been for some time a stable SOAP client for ruby.
  • Sekken was (at one point in time), v3 of Savon, which was intended to be a step towards a better interface

At some point, @rubiii pointed out that Sekken had a very different interface than Savon, and that users upgrading might have a hard time. Breaking out Sekken into a different gem was the solution to provide an existing library that works (Savon), but allow another experimental one to continue evolving (Sekken)..

If you're having problems with Savon, I suggest either filing an issue there, posting to stack overflow, or reading the docs on savonrb.com

Hope this helps!

@tjarratt tjarratt closed this as completed Dec 2, 2014
@stuarthannig
Copy link

This is still an issue when doing

adapter = HTTPClient.new
adapter.ssl_config.ssl_version = 'TLSv1'
client = Sekken.new(wsdl_url, adapter)

# TypeError: no implicit conversion of HTTP::Message into String
# from /Users/stuarthannig/.rvm/gems/ruby-2.1.4/gems/nokogiri-1.6.4/lib/nokogiri/xml/document.rb:55:in `read_memory'

@felixyz
Copy link

felixyz commented Nov 13, 2015

+1 Exact same scenario as @stuarthannig. I must set the SSL version because the server won't accept SSL3, but seems I can't do it with the current version of Sekken? @tjarratt

Any workarounds, if this has not yet been addressed?

@felixyz
Copy link

felixyz commented Nov 15, 2015

The solution is to use Sekken's own HTTPClient wrapper (lib/sekken/httpclient.rb). @stuarthannig's snippet then becomes:

adapter = Sekken::HTTPClient.new
adapter.client.ssl_config.ssl_version = 'TLSv1'
client = Sekken.new(wsdl_url, adapter)

I believe the issue with SSL versions will also be resolved by simply upgrading the HTTPClient dependency to at least 2.4.

@tjarratt

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

No branches or pull requests

5 participants