4

I am trying to access a SOAP service which has the following charateristics: 1. WSDL is available without authentication 2. The service is accessible over https with basic_auth 3. According to the SOAP service, the "Authorization" header needs to be included in every request

Here is my code for construction the soap client:

@wsdl="https://example.com/table.do&WSDL"
@proxy="http://internal.proxy.com:8080"
@basic_auth=["user","pass"]
@headers={"Authorization" => "Basic"}
client = Savon.client do |globals|
  globals.wsdl @wsdl
  globals.proxy @proxy
  globals.basic_auth @basic_auth
  globals.headers @headers
end

Here is the client.globals.inspect:

#<Savon::GlobalOptions:0x0000000382c7a8 @options={:encoding=>"UTF-8", 
:soap_version=>1, :namespaces=>{}, :logger=>#<Logger:0x0000000382c730 @progname=nil,
@level=0, @default_formatter=#<Logger::Formatter:0x0000000382c708 
@datetime_format=nil>, 
@formatter=nil, @logdev=#<Logger::LogDevice:0x0000000382c6b8 @shift_size=nil, 
@shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>,
 @mutex=#<Logger::LogDevice::LogDeviceMutex:0x0000000382c690 @mon_owner=nil, 
@mon_count=0, @mon_mutex=#<Mutex:0x0000000382c640>>>>, :log=>true, :filters=>[], 
:pretty_print_xml=>false, :raise_errors=>true, :strip_namespaces=>true, 
:convert_response_tags_to=>#<Proc:0x0000000382c5c8@/usr/local/rvm/gems/ruby-2.0.0-p0/gems/savon-2.1.0/lib/savon/options.rb:48 (lambda)>, 
:wsdl=>"https://example.com/table.do&WSDL", 
:proxy=>"http://internal.proxy.com:8080", 
:basic_auth=>["user", "pass"], 
:headers=>{"Authorization"=>"Basic"}}>

when i call:

client.call(:get, message: { sys_id: "67d2f77ed9377840c53fc6da9c094635" })

The service is returning:

DEBUG -- : HTTPI GET request to xseaddev.service-now.com (net_http)
INFO -- : SOAP request: https://xseaddev.service-now.com/change_task_list.do?displayvalue=all&SOAP
INFO -- : SOAPAction: "http://www.service-now.com/change_task/get", Content-Type: text/xml;charset=UTF-8, Content-Length: 408
DEBUG -- : <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://www.service-now.com" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="http://www.service-now.com/change_task"><env:Body><ins0:get><tns:sysId>67d2f77ed9377840c53fc6da9c094635</tns:sysId></ins0:get></env:Body></env:Envelope>
DEBUG -- : HTTPI POST request to xseaddev.service-now.com (net_http)
INFO -- : SOAP response (status 401)

Am i constructing the client incorrectly? I don't see any authentication headers being sent on either the GET or PoST requests. Do i need to add/remove anything to get this working? Your help would be appreciated.

Andrew
  • 203
  • 2
  • 10
  • by "Authorization" header, do they mean the HTTP or SOAP header? the [`:headers` option](http://savonrb.com/version2.html#headers) sets the HTTP header, while the [`:soap_header` option](http://savonrb.com/version2.html#soap-header) sets the SOAP header. – rubiii Mar 09 '13 at 12:21
  • They mean HTTP header. – Andrew Mar 11 '13 at 01:29
  • @rubiii , any thoughts on why this doesn't work? – Andrew Mar 20 '13 at 16:13
  • i actually tried this and couldn't find a problem with it. i would probably record the actual request to inspect it or look at server-side logs if possible. – rubiii Mar 20 '13 at 19:45
  • do i have to explicitely setup the http headers for an http request wuth basic auth, or will passing the basic_auth option to the client be enough to create the necessary headers? Right now I am not seeing any authentication headers in the request. – Andrew Apr 01 '13 at 20:48
  • the option should pass the credentials to the [httpi](http://github.com/savonrb/httpi) adapter and its client which should set the appropriate headers. – rubiii Apr 02 '13 at 07:31
  • ive been digging in the documentation, how can i show the raw http request/response headers? its not showing in :debug logging level. – Andrew Apr 02 '13 at 19:11
  • ok so definatly the :basic_auth credentials i am passing are not making it to the request headers. I've tested it and even hacked some of your code to test it. – Andrew Apr 02 '13 at 20:57
  • if you can you provide a failing test, please open an issue over at github so we cab get this resolved. we need you to follow up on this though. – rubiii Apr 02 '13 at 21:35

1 Answers1

4

I imagine you should be able to do the following:

client = Savon.client(endpoint: ENDPOINT, namespace: NAMESPACE, basic_auth: ["user", "password"])

(Or the same in block form).

Check this page under the "Authentication" heading: http://savonrb.com/version2/globals.html

(I am doing the same, but with a WSDL).

mydoghasworms
  • 18,233
  • 11
  • 61
  • 95