Adding namespace in version 2 of Savon - savon

What is the analogy of this Savon version 1 code in Savon version 2?
client = Savon::Client.new do
wsdl.endpoint = "http://..."
wsdl.namespace = "http://..." # target namespace
end

In version 2 of Savon you need to use following syntax:
client = Savon.client do
wsdl 'https://...'
namespace 'http://...'
end

the preferred way to execute those in Savon 2.x is
client = Savon.client(
wsdl: 'http://...'
namespace: 'http://...',
log: true,
log_level: :debug,
pretty_print_xml: true
)
rc = client.call(:soap_methods_name,
message: { :param1 => 'value1', :param2 => 'value2' })

Related

send request to a tls 1.2 web server in node soap

I need to send request to a web server which is TLS 1.2 in node soap
any idea how to achieve that?
You have to set the secureOptions with a constant on the ClientSSLSecurity method.
var constants = require('constants');
client.setSecurity(new soap.ClientSSLSecurity(
'/path/to/key',
'/path/to/cert',
'/path/to/ca-cert',
{
strictSSL: true,
rejectUnauthorized: false,
hostname: 'some-hostname',
secureOptions: constants.SSL_OP_NO_TLSv1_2,
forever: true,
},
));

Rails and Devise Missing link to host

I am very confused with how to provide the default_url_options. I am getting this error
Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
I am using spreecommerce which uses devise for authentication. This error is occurring durring password reset on my development environment. I have not tested it in a production environment yet.
I am using this in my environments/development
config.default_url_options = { host: 'localhost:3000' }
Rails.application.routes.default_url_options[:host] = 'localhost:3000'
in my rails console when I do Rails.application.routes.default_url_options I get {:host => Rails.application.config.domain}. The same thing happends when I do Rails.applicaiton.default_url_options
None of the solutions I have found have worked.
TL;DR In my case Spree::Store.current vanished - I had to recreate it.
I tried set default_url_options for routes and into environments. But with no luck.
So I got into spree_auth_devise-3.1.0 gem source code:
#confirmation_url = spree.spree_user_confirmation_url(:confirmation_token => token, :host => Spree::Store.current.url)
So for the host, it's using Spree::Store. Then I went into console and got that my Spree::Store.current is empty:
(byebug) Spree::Store.current.url
nil
So simply creating a store with dummy data resolved my problem.
store = Spree::Store.new
store.name = 'test'
store.url = 'http://localhost:3000'
store.code = 'spree'
store.default = true
store.save

omniauth-facebook not returning email

We just updated our ruby version to 2.0 from 1.9.3. From what I can tell we haven't updated omniauth omniauth-facebook or oauth in the upgrade. The upgrade however broke facebook login. Looking at the logs I don't see an email coming back in the omniauth hash.
Here's my initializer, which loads my yml file where I define the secret and whatnot.
omniauth.rb initializer
class OmniAuthConfig
class << self
def load(file = 'omniauth.yml')
configuration_file = File.join(Rails.root, 'config', file)
if File.exists?(configuration_file)
File.open(configuration_file) do |configuration|
configuration = YAML.load(configuration)[Rails.env.to_sym]
configuration.each do |key, value|
cattr_accessor(key)
send("#{key}=", value)
end
end
end
end
end
end
OmniAuthConfig.load
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook,
OmniAuthConfig.facebook_api_key,
OmniAuthConfig.facebook_api_secret,
scope: 'email',
client_options: { ssl: { ca_file: "/etc/ssl/certs/ca-certificates.crt" } }
end
Censored logs:
--- !ruby/hash:OmniAuth::AuthHash
provider: facebook
uid:
info: !ruby/hash:OmniAuth::AuthHash::InfoHash
image: http://graph.facebook.com//picture?type=square
credentials: !ruby/hash:OmniAuth::AuthHash
token: HUGE_TOKEN_STRING
expires_at: 1485547306
expires: true
extra: !ruby/hash:OmniAuth::AuthHash
raw_info: !binary |-
HASH_THINGY

Savon 2.11.1 set soap header after client is instantiated Rails + SSRS

I'm trying to integrate my rails app with a Sql Server Reports Services (SSRS) using Savon 2.11.1. I'm using the ReportServicesExecution2005 WSDL. The problem I have is that I have to add a session_id to the soap header after the client has been instantiated. This is because the session_id is generated by SSRS after the client makes a call to load_report.
client = Savon.client(wsdl: "https://somewsdl.asmx?wsdl", basic_auth: ["user", "pass"])
this call returns the session_id in the response:
response = client.call(:load_report, message: {report: "path/to/report"} )
the soap header needs to contain the session_id in the client when this call is made:
client.call(:set_execution_parameters, message: { report: "path/to/report", parameters: params } )
Tried this but it didn't work:
client.call(:set_execution_parameters, soap_header: {"session_id" => #session_id}, message: { report: "path/to/report", parameters: params } )
I get the following error:
(soap:Client) The session identifier is missing. A session identifier
is required for this operation. --->
Microsoft.ReportingServices.Diagnostics.Utilities.MissingSessionIdException:
The session identifier is missing. A session identifier is required
for this operation.
Thanks for the help an advance.
You should use the soap_header hash to pass session id like
response = client.call(:set_execution_parameters, :soap_header => { :session_id => sid })
Cheers
The solution I found(while clunky) was to create a new client via Savon and pass the existing client values plus the new execution_id/session_Id into the constructor. This did the trick. Code example below.
Initial Savon Client:
#exeClient = Savon.client(wsdl: "some_wsdl.asmx?wsdl", basic_auth: ["user", "pass"],
convert_request_keys_to: :camelcase, soap_header: {"execution_id" => ""} )
call load_report to get execution_id:
#data = #exeClient.call(:load_report, message: {report: "/path/to/report"} )
Access execution_id:
#report = #data.to_hash
#execution_id = #report[:load_report_response][:execution_info][:execution_id]
Create new client that has access to run the report via the execution_id:
#newClient = Savon.client(wsdl: "/path/to/report/wsdl", basic_auth: ["user", "pass"],
:soap_header => {:"tns:TrustedUserHeader" => {"tns:UserName"=> "" , "tns:UserToken" => ""}, :"tns:ExecutionHeader" => {"tns:ExecutionID" => #execution_id}})
Create Params Hash:
param1 = { :Parameter_value =>{
:"Name" => "nameOfParam",
:"Value" => current_user.company_id
}
}
Call setExecutionParameters:
response = #newClient.call(:set_execution_parameters, message: { "Parameters" => param1} )
Now it works. Note that its important how you specify namespaces with Savon. If you don't do it correctly, the namespace will not be specified on some tags; which will make the soap call fail.

getting bad request from ruby on rails ssl post

Looked at: Escaping parameters in set_form_data POST, and Ruby on Rails HTTPS Post Bad Request
def send_request(params)
host = "https://hc.mercurydev.net"
uri = URI.parse(host)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
xml = build_xml_for_checkout(params)
http.start do |http|
req = Net::HTTP::Post.new('http://www.mercurypay.com/InitializePayment')
header = {'Host' => 'hc.mercurydev.net', 'Content-Type' => 'text/xml; charset=utf-8', 'Content-Length' => 'length', 'SOAPAction' => 'http://www.mercurypay.com/InitializePayment'}
req.set_form_data(header, xml)
response = http.request(req)
end
end
This is the first time I have had to build my own post request in ruby, I am sure that I am missing something simple, but what?
-- I have confirmation that the xml is 100% good, so it has to be something in my header or in how I'm building the request.
Edit: After looking at ruby-api-doc: I came up with this:
uri = URI.parse(host)
Net::HTTP.start(uri.hostname, uri.port,
:use_ssl => uri.scheme == 'https').start do |http|
req = Net::HTTP::Post.new uri.path
req.body = xml
req.set_form_data(header)
res = http.request req
end
Which returns (even if I restart my server) that I have an open HTTP session.
So ended up with this:
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
req = Net::HTTP::Post.new(uri.request_uri)
req.body = xml.to_s
req.initialize_http_header(header)
response = http.request(req)
The key that I was missing was the initialize_http_header() once I got that in there the soap api accepted my submission and then is was just an issue of making sure my syntax was correct.