Wednesday, December 14, 2011

Using actionwebservice with Rails 2.3/3.1

I added the datanoise-actionwebservice gem to my Rails 2.3 project that I upgraded from Rails 1.2.6. I also had another project that I had upgraded to Rails 3.1 that happened to use the httpclient 2.2.4 gem. When trying to connect to a SOAP service endpoint over HTTPS using soap4r and an IP address instead of the server name, I got a SSL error with this partial stack trace:

OpenSSL::SSL::SSLError (hostname was not match with the server certificate):
/usr/lib/ruby/1.8/openssl/ssl-internal.rb:123:in `post_connection_check'
httpclient (2.2.4) lib/httpclient/session.rb:313:in `post_connection_check'
httpclient (2.2.4) lib/httpclient/session.rb:740:in `connect'
httpclient (2.2.4) lib/httpclient/timeout.rb:131:in `timeout'
httpclient (2.2.4) lib/httpclient/session.rb:731:in `connect'
httpclient (2.2.4) lib/httpclient/session.rb:594:in `query'
httpclient (2.2.4) lib/httpclient/session.rb:161:in `query'
httpclient (2.2.4) lib/httpclient.rb:1060:in `do_get_block'
httpclient (2.2.4) lib/httpclient.rb:869:in `do_request'
httpclient (2.2.4) lib/httpclient.rb:956:in `protect_keep_alive_disconnected'
httpclient (2.2.4) lib/httpclient.rb:868:in `do_request'
httpclient (2.2.4) lib/httpclient.rb:756:in `request'
httpclient (2.2.4) lib/httpclient.rb:666:in `post'
/usr/lib/ruby/1.8/soap/streamHandler.rb:170:in `send_post'
/usr/lib/ruby/1.8/soap/streamHandler.rb:109:in `send'
/usr/lib/ruby/1.8/soap/rpc/proxy.rb:170:in `route'
/usr/lib/ruby/1.8/soap/rpc/proxy.rb:141:in `call'
/usr/lib/ruby/1.8/soap/rpc/driver.rb:178:in `call'
/usr/lib/ruby/1.8/soap/rpc/driver.rb:232:in `get_account_id'
/usr/lib/ruby/gems/1.8/gems/datanoise-actionwebservice-2.3.2/lib/action_web_service/client/soap_client.rb:63:in `send'
/usr/lib/ruby/gems/1.8/gems/datanoise-actionwebservice-2.3.2/lib/action_web_service/client/soap_client.rb:63:in `perform_invocation'
/usr/lib/ruby/gems/1.8/gems/datanoise-actionwebservice-2.3.2/lib/action_web_service/client/base.rb:15:in `method_missing'

Thanks to jkraemer's post, I was able to add a file under lib/soap/property in my Rails app containing the setting:
client.protocol.http.ssl_config.verify_mode=OpenSSL::SSL::VERIFY_NONE
and the error went away. There are probably ways to configure this to use a specific cert as well, but I didn't investigate those.

Sunday, December 11, 2011

jQuery autocomplete source issues

I was trying to get a jQuery version 1.8 autocomplete call to work in Rails 3.1 without using the fancy helpers.  I had something like:

$(function() {
  $('#project-list-autocomplete').autocomplete({
    source: "/rails_controller/json_action"
  });
where json_action is a method that returns the autocomplete values, but I couldn't figure out the format of the JSON. It's:
[{"id":"1", "label":"autoanswer1"}, 
{"id":"2", "label":"autoanswer2"}]

and so on.