Web Services problem: OpenSSL::X509::StoreError

Hi,

I have a Ruby script that invokes web services using SSL. It works.

In order to make my web service work over https (SSL) i had to :
_create a directory called “soap” in my working directory.
_create a file in that dir called property that contains :
client.protocol.http.ssl_config.ca_file = ca.pem
_add ca.pem in my working directory that contains my certificates.

So here is what I have in my working dir:
_client.rb
_soap
_soap/property
_ca.pem

The problem is when I try to integrate it in my Ruby on Rails
application I
have the error in my controller:

OpenSSL::X509::StoreError in Air searchController#search_trip

system lib

RAILS_ROOT: D:/www/airtravelonrails/config/…
Application Trace http://localhost:3000/air_search/search_trip# |
Framework
Trace http://localhost:3000/air_search/search_trip# | Full
Tracehttp://localhost:3000/air_search/search_trip#

C:/ruby/lib/ruby/site_ruby/1.8/http-access2.rb:532:in add_file' C:/ruby/lib/ruby/site_ruby/1.8/http-access2.rb:532:in set_trust_ca’
C:/ruby/lib/ruby/1.8/soap/httpconfigloader.rb:81:in set_ssl_config' C:/ruby/lib/ruby/1.8/soap/property.rb:140:in each’
C:/ruby/lib/ruby/1.8/soap/property.rb:139:in each' C:/ruby/lib/ruby/1.8/soap/httpconfigloader.rb:66:in set_ssl_config’
C:/ruby/lib/ruby/1.8/soap/httpconfigloader.rb:34:in set_options' C:/ruby/lib/ruby/1.8/wsdl/xmlSchema/importer.rb:65:in fetch’
C:/ruby/lib/ruby/1.8/wsdl/xmlSchema/importer.rb:30:in import' C:/ruby/lib/ruby/1.8/wsdl/importer.rb:18:in import’
C:/ruby/lib/ruby/1.8/soap/wsdlDriver.rb:124:in import' C:/ruby/lib/ruby/1.8/soap/wsdlDriver.rb:28:in initialize’
#{RAILS_ROOT}/app/controllers/air_search_controller.rb:39:in new' #{RAILS_ROOT}/app/controllers/air_search_controller.rb:39:in search_trip’
-e:3:in `load’
-e:3

So when I look closer in the file http-access2 line 532 we see that the
problem comes from the function:

def set_trust_ca(trust_ca_file_or_hashed_dir)
if FileTest.directory?(trust_ca_file_or_hashed_dir)
@cert_store.add_path(trust_ca_file_or_hashed_dir)
else
@cert_store.add_file(trust_ca_file_or_hashed_dir)
end
change_notify
end

from the line @cert_store.add_file(trust_ca_file_or_hashed_dir)

Is anybody knows how to use SSL Web Services in a Rails application?

Thank you.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

David Alphen wrote:

_create a file in that dir called property that contains :
client.protocol.http.ssl_config.ca_file = ca.pem

Can you change above “ca.pem” to fully qualified pathname such as
“D:/path/to/ca.pem” and see how it goes?

Regards,
// NaHi
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)

iQEVAwUBRmZN1B9L2jg5EEGlAQKpwQf+OE+vYNHovirqd1ka0W2DOT+OYiG7LMiu
AF3H8ikcQivu2gQExdJQUoyWNmHZzyqZtkEP0u6RCZVE/6t3knDsQXyK1oiewWIE
5vTmyNJOI3zlSH0s4VpS/7x59zbRqdSoMZMcAuFXFtHHSq0iqx97BAd2XijnwdaI
Tg4zhf/tJq1i17pUbxRuExqTZ+Zm3cFpPji/jzk95WwdBem2lbEdL0L3P5/Wu6/x
Mq4iljXARQGrJ4/++7kN7XtrFl7BHK4tgRtbqGweos9LGBnn504dUx1TacXUo4of
JsGDrko95mFmnelmgC0gtvE3h8KCz0ihEf/2q5r8S2hC9IYA0JUs8g==
=217h
-----END PGP SIGNATURE-----

So I have changed the path to the ca.pem file. I have an other error.
Let me
explain.
My problem is when I try to integrate it in my Rails application I have
an
argument error:
ArgumentError in Air searchController#rt_results

wrong number of arguments (1 for 0)

RAILS_ROOT: D:/www/airtravelonrails/config/…
Application Trace http://localhost:3000/air_search/rt_results# |
Framework
Trace http://localhost:3000/air_search/rt_results# | Full
Tracehttp://localhost:3000/air_search/rt_results#

C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/core_ext/array/conversions.rb:66:in
to_xml' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/core_ext/array/conversions.rb:66:in to_xml’

Which is weird. If I don’t pass any argument I have the error "wrong
number
of arguments (0 for 1) "…

Here is my controller:

require ‘soap/header/handler’
require ‘http-access2’
require ‘soap/wsdlDriver’

class AirSearchController < ApplicationController

before_filter :check_authentication

layout “layout”

def index

end

def airports_for_lookup
@airports = Airport.find(:all)
@headers[‘content-type’] = ‘text/javascript’
render :layout => false
end

class EmptyHeaderHandler < SOAP::Header::Handler
def on_outbound(header)
# dump SOAPHeader even if it has no item
header.force_encode = true
header.extraattr[‘xmlns’] =
http://webservices.site.com/definitions
# no item needed
nil
end
end

def rt_results

wsdl = "D:/www/airtravelonrails/app/controllers/myWsdl.wsdl"

factory = SOAP::WSDLDriverFactory.new(wsdl)
driver = factory.create_rpc_driver

driver.headerhandler << EmptyHeaderHandler.new(XSD::QName::EMPTY)

parameters = {
:messageActionDetails => { :functionDetails => { :actionCode => “***”
} },

:originatorDetails => [{ :deliveringSystem => [
:companyIdentification => “",
:locationCode
=>
"
” ],
:originatorIdentification => [ :travelAgent
=>
",
:inHouseId =>
"
”],

                       :agentDetail =>              [ 

:isoCountryCode =>
",
:isoCurrencyCode
=>
"
",
:isoLanguageCode
=>
"
*”],

                       :authorityCode => "*****" }],

:requestSection => [{
:availabilityProductInfo =>

                       # etc 

req = driver.Air_MultiAvailability(parameters)

end

end

I don’t know how to make a correct call to my web service…

Thank you.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

David Alphen wrote:

My problem is when I try to integrate it in my Rails application I have an
argument error:

  1. rt_results run fine without Rails environment, right?

ArgumentError in Air searchController#rt_results

wrong number of arguments (1 for 0)

C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/core_ext/array/conversions.rb:66:in
`to_xml’

  1. Can you show me the error dump of ‘arguments (0 for 1)’ as same as
    above, please? You get the same stack trace?

  2. WSDLDrverFactory#create_rpc_driver parses WSDL every time you call
    it and it’s heavy process. Please consider to use wsdl2ruby.rb or, call
    WSDLDriverFactory#create_rpc_driver only once and reuse the driver.

Regards,
// NaHi

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)

iQEVAwUBRmaznR9L2jg5EEGlAQLyuAf7Bx5niRktI/f7yba8RqbtgudzAA16lzAs
5ArxsghW1TLV3t6rX1Ike09nTmABvBvxcqb+6ieujj+i5nqCDxkdvO1OHbj4VT+C
kSI1vyAI+9B3/JpXrBkkEASssu6OxWEtDN/kVW/SPHn/yioAZr8AfkYchTVNWYw3
H/pbL6lfv3PjFK4Q7+H1G89ilgfzrUUIVf+dVr76ftoMZ1CWCAQ+o3JjlyPTxSFs
pisR/G6w2vp4FiEvpefuILRC1rWFCYKzwi6/bcTQUSTARs+7D2WJ6oErmEpGpPsE
oMZHjQ1PuC2JAdJyOUzK47u0AkgmuGODgm6Uyt9pzfLhLCaUDOJTgw==
=vD/H
-----END PGP SIGNATURE-----

  1. yes rt_results works fine without Rails environment.
  2. I have a different error, here is the application stack trace:

ArgumentError in Air searchController#rt_results

wrong number of arguments (0 for 1)

RAILS_ROOT: D:/www/airtravelonrails/config/…
Application Trace http://localhost:3000/air_search/rt_results# |
Framework
Trace http://localhost:3000/air_search/rt_results# | Full
Tracehttp://localhost:3000/air_search/rt_results#

(eval):4:in air_MultiAvailability' C:/ruby/lib/ruby/1.8/soap/wsdlDriver.rb:117:in send
C:/ruby/lib/ruby/1.8/soap/wsdlDriver.rb:117:in Air_MultiAvailability' #{RAILS_ROOT}/app/controllers/air_search_controller.rb:67:in rt_results’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in
send' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in perform_action_without_filters’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:632:in
`call_filter’

  1. Ok. I’ll do it.

++

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

David Alphen wrote:

  1. yes rt_results works fine without Rails environment.

OK.

  1. I have a different error, here is the application stack trace:

ArgumentError in Air searchController#rt_results
wrong number of arguments (0 for 1)

(eval):4:in air_MultiAvailability' C:/ruby/lib/ruby/1.8/soap/wsdlDriver.rb:117:insend
C:/ruby/lib/ruby/1.8/soap/wsdlDriver.rb:117:in `Air_MultiAvailability’

It’s normal. You need to pass one argument then. (BTW, you can call
driver.air_MultiAvailability instead of driver.Air_MultiAvailability.
Soap4r converts a method name to Ruby compliant safer name and add a
wrapper method for an original name as above)

So the actual problem is ‘wrong number of arguments (1 for 0)’ raised
from lib/active_support/core_ext/array/conversions.rb:66:in `to_xml’. I
can’t imagine why it’s called but a method name ‘to_xml’ is suspicious.
Two-ducks-close-but-not-the-same problem.

Please post a full stack trace of ‘wrong number of arguments (1 for 0)’?

Regards,
// NaHi

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)

iQEVAwUBRmbSaR9L2jg5EEGlAQLeDAf/QxpKFIX4i0W47pDa6xj8G2G1Wh1r6hJI
f78l+IK5VPM2Gp2xncUMjiqhYMfa3sj2bHC8avMSTDbI8l3aKprDC/Q45ETZHTnb
ZfUsGbfD/fee6RW3/6ZiyHi2HfPzto/cbw9RNWvEbbdLDYmjYLdYe3PMr1bHoJ0s
8rvY69TXmFivFl+Y+PiavyuSELe/oHwdGnsZHNTVXpL+KsSzqMuLNRPQOxA6jG1X
K23PiwCUXJtRL4E2fQleAlpHG+U7cdeiv5wssjQZzCYYiZEu2E2RodyZMHN/pWjo
t4Gnjmi2Qrf3K75/R2Qmu1IoSrgi1lOykZnVpPrm03pA52T5aEKwjg==
=TSi6
-----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I updated soap4r gem as 1.5.6-RC3.
You can get it from
http://dev.ctor.org/soap4r/wiki/WikiStart#a2007-06-07:1.5.6-RC3 .
Would you please try the latest release candidate?

David Alphen wrote:

Anyway, I’m still on the problem, I don’t understand what it could be, here
is the full stack trace:

Thanks. I found that generic Array has to_xml instance method in Rails
environment. The method requires Array’s elements to have to_xml method
with arity == 1 if it responds to to_xml. On the other hand, soap4r
requires Objects to have to_xml method with arity == 0 if it responds to
to_xml.

I just renamed the method name to_xml to to_xmlpart in soap4r. This new
feature is from soap4r-1.5.6 which is scheduled to be released on
2007-06-14.

Regards,
// NaHi

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)

iQEVAwUBRmgMaR9L2jg5EEGlAQIvRgf+JppfA5ApvC8ieDTGjXgKYKOQ9eMaiv+j
n86O9Mv/FBFnM25bIufoKzC8fHPnNvO8NT01X8ZjGfPmbdxVb5EgCjt9iZ5wtWBx
RDqXrMYjkIgNQdxv4NFZbSB7PJTiFl6Dznq4Vr8ML+Horf2YQ+xu9V5feSF4O3ri
9DKwHmo2RPp9Phg82y4TUOVJWkP38eIJXcctBCZ4YYrVy860q1ke/tOs+ip42fJd
r5uTIrPS9y9KBvlRmGqiSBZTyayqHKnl9Cpr1aEJI/53LtMXBDdx5rBwqxGLa/M8
Ij+1POTmN8G5HomMGp67V4FYlAWuvA7vHSRk5iFlamUD3R3gRqTJiw==
=6FW0
-----END PGP SIGNATURE-----

Ok, I have updated soap4r.
I wait for your next release (june 14th) so I could test again if my web
service works.

Thank you for your help and responsiveness.
Thanks for mentioning my name on your site.

++

Well I knew it was not the same problem, I’ve tried no argument just
like
that to test what was happening.
Anyway, I’m still on the problem, I don’t understand what it could be,
here
is the full stack trace:

C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/core_ext/array/conversions.rb:66:in
to_xml' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/core_ext/array/conversions.rb:66:into_xml’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/core_ext/array/conversions.rb:66:in
each' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/core_ext/array/conversions.rb:66:into_xml’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/vendor/builder/xmlbase.rb:140:in
call' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/vendor/builder/xmlbase.rb:140:in_nested_structures’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/vendor/builder/xmlbase.rb:60:in
method_missing' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/vendor/builder/xmlbase.rb:32:insend
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/vendor/builder/xmlbase.rb:32:in
tag!' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/core_ext/array/conversions.rb:66:into_xml’
C:/ruby/lib/ruby/1.8/soap/baseData.rb:749:in to_xml' C:/ruby/lib/ruby/1.8/soap/generator.rb:72:inencode_data’
C:/ruby/lib/ruby/1.8/soap/generator.rb:121:in encode_element' C:/ruby/lib/ruby/1.8/soap/element.rb:125:inencode’
C:/ruby/lib/ruby/1.8/soap/element.rb:124:in each' C:/ruby/lib/ruby/1.8/soap/element.rb:124:inencode’
C:/ruby/lib/ruby/1.8/soap/generator.rb:119:in encode_element' C:/ruby/lib/ruby/1.8/soap/generator.rb:75:inencode_data’
C:/ruby/lib/ruby/1.8/soap/generator.rb:136:in encode_element' C:/ruby/lib/ruby/1.8/soap/element.rb:264:inencode’
C:/ruby/lib/ruby/1.8/soap/generator.rb:134:in encode_element' C:/ruby/lib/ruby/1.8/soap/generator.rb:75:inencode_data’
C:/ruby/lib/ruby/1.8/soap/generator.rb:60:in generate' C:/ruby/lib/ruby/1.8/soap/processor.rb:30:inmarshal’
C:/ruby/lib/ruby/1.8/soap/rpc/proxy.rb:255:in marshal' C:/ruby/lib/ruby/1.8/soap/rpc/proxy.rb:167:inroute’
C:/ruby/lib/ruby/1.8/soap/rpc/proxy.rb:142:in call' C:/ruby/lib/ruby/1.8/soap/rpc/driver.rb:180:incall’
(eval):6:in air_MultiAvailability' C:/ruby/lib/ruby/1.8/soap/wsdlDriver.rb:117:insend
C:/ruby/lib/ruby/1.8/soap/wsdlDriver.rb:117:in Air_MultiAvailability' #{RAILS_ROOT}/app/controllers/air_search_controller.rb:67:inrt_results’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in
send' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:inperform_action_without_filters’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:632:in
call_filter' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:638:incall_filter’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:438:in
call' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:637:incall_filter’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:638:in
call_filter' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:438:incall’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:637:in
call_filter' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:638:incall_filter’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:449:in
call' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:637:incall_filter’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:619:in
perform_action_without_benchmark' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:inperform_action_without_rescue’
C:/ruby/lib/ruby/1.8/benchmark.rb:293:in measure' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:inperform_action_without_rescue’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/rescue.rb:83:in
perform_action' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:insend’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in
process_without_filters' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:624:inprocess_without_session_management_support’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/session_management.rb:114:in
process' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:330:inprocess’
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in
dispatch' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:78:inprocess’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in
synchronize' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:inprocess’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:618:in
process_client' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:ineach’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in
process_client' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:inrun’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in
initialize' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:innew’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in
run' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:ininitialize’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in
new' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:inrun’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:271:in
run' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:ineach’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in
run' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:127:inrun’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/command.rb:211:in
run' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:243 C:\ruby\bin\mongrel_rails:16:inload’
C:\ruby\bin\mongrel_rails:16
-e:3:in `load’
-e:3