Use Rails Logger with Savon gem - ruby-on-rails

I have the following code:
def soap_client
soap_client = Savon.client(
wsdl: "https://api.five9.com/wsadmin/AdminWebService?wsdl&user=apiloader#daxko.com",
namespace: "http://service.admin.ws.five9.com/",
headers: {"Authorization" => "Basic #{#realm}"},
env_namespace: :soapenv,
namespace_identifier: :ser,
ssl_verify_mode: :none,
logger: Rails.logger,
log: true
)
end
This works and logs everything to my console window. However, it doesn't actually log anything to the Rails.logger...
How can I use the default Rails.logger with Savon?
EDIT
I am using savon (2.3.2).

Related

How to solve this error " (pre:svcFault) Service Fault"?

I am trying to call a SOAP api using Savon gem. I am getting the following error: "(pre:svcFault) Service Fault"
I created both the header and message for the request.
Here is the request sent from SoapUI: SoapUI request.
i am getting a true response from SoapUI.
My code is shown below:
class SoapApi
require 'savon'
def self.initialize
header = {
"ebmCID" => "9366498d-bc79-4fad-be2b-fa1a0e84241a",
"ebmMID" => "9366498d-bc79-4fad-be2b-fa1a0e84241a",
"ebmRTID" => "9366498d-bc79-4fad-be2b-fa1a0e84241a",
"ebmSID" => "FMobile-FCUBS",
"ebmTimestamp" => "2019-06-10T12:27:46.1623586Z",
}
message = {
customerId: '00653473'
}
client = Savon.client(
:wsdl => "https://192.168.176.103:8012/tevs/pp.pm.evs.Customer_1.2?wsdl",
:ssl_verify_mode => :none
)
response = client.call(
:get_account_list,
:soap_header => header,
:message => message
)
return response
end
end
And here i am calling the above method:
#index.html.erb
<%=
SoapApi.initialize
puts #response
%>
Where you able to create a valid call using SoapUI (https://www.soapui.org.)? Try this first and make it work.
Next create a call from a plain ruby script - without Rails - which sends the same functional XML as you did in SoapUI before.
Third embed this code into your RoR application.
You can put the following in your client definition for better logging:
client = Savon.client(
:wsdl => "https://192.168.176.103:8012/tevs/pp.pm.evs.Customer_1.2?wsdl",
:ssl_verify_mode => :none,
log: true,
log_level: :debug,
pretty_print_xml: true
)
Compare the output with your working SoapUI example.

ruby Savon use camelcase instead snake

i'm using savon gem for SOAP request building, i need snake_case_elements, but when i inspect it seems converted to CamelCase, am i missing something here? Here is a result
And how i did it:
gls_url = 'https://adi-test.gls-poland.pl/adeplus/pm1/ade_webapi2.php?wsdl'
username = '612305291'
password = 'KGpartt2016'
#client = Savon.client(wsdl: gls_url,
log: true,
logger: Rails.logger,
log_level: :debug,
pretty_print_xml: true)
ats = #client.call(:ade_login, message: {
user_name: username,
user_password: password
})
You can use convert_request_keys_to option to tell Gyoku how to convert the keys (if at all):
#client = Savon.client(wsdl: gls_url, convert_request_keys_to: :none)

rails pass soap basic auth with savon

I'm trying to send soap request with basic authentication with savon gem
My soap server is set up with wash_out gem
class OrdersController < ApplicationController
soap_service namespace: 'sir:WashOut', wsse_username: SIRA[:auth][:username], wsse_password: SIRA[:auth][:password]
....
When i make a request to soap server via savon i get an error:
#client = Savon.client(
wsdl: "http://localhost:3000/orders/wsdl",
soap_header: { 'Username' =>SIRA[:auth][:username], 'Password' => SIRA[:auth][:password] }
)
#response = #client.call(:notify ).to_hash
On the last command i get an error
Savon::SOAPFault: (Server) Missing required UsernameToken
client = Savon.client(
wsdl: 'http://service.example.com?wsdl',
soap_header: {
"AuthenticateRequest" =>
{"apiKey" => "****** your api *********"}},
pretty_print_xml: true)
client.operations
response = client.call(:function)
Note: "apiKey" is my prams to authenticate, your can be different
I've tried this and it works!
#client = Savon.client(
wsdl: "http://localhost:3000/orders/wsdl",
wsse_auth: [SIRENA[:auth][:username], SIRENA[:auth][:password] ],
logger: Rails.logger
)
#response = #client.call(:notify, ).to_hash
For Savon 2. Basic authorization can be done as follows:
#client = Savon.client(
wsdl: "http://localhost:3000/orders/wsdl",
basic_auth: ["username", "password"]
)
#response = #client.call(:notify ).to_hash

Ruby: Savon AddressFilter mismatch at the EndpointDispatcher SOAP API

I am new to SOAP and I am having lots of trouble with Savon.
The API I am trying to access has really simplistic documentation: http://www.sona-systems.com/support/docs/sona_api_docs.pdf
When making a call, the API expects authentication in the parameters being sent. Here is my code:
client = Savon.client(
wsdl: "https://school.sona-systems.com/services/SonaAPI.svc?singleWsdl",
soap_header: {'To:' => "http://www.sona-systems.com/"},
pretty_print_xml: true,
soap_version: 2
)
response = client.call(:get_study_list) do
message username: "foo", password: "bar"
end
I am getting the following error:
Savon::SOAPFault: (s:Sender) The message with To '' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree.
what is the soap_header: suppose to do?
I also cannot get to the url you provided. you should add log: true, log_level: :debug to your client definition to get more information.
try this:
client = Savon.client(
wsdl: "https://kellogg-elab.sona-systems.com/services/SonaAPI.svc?wsdl",
pretty_print_xml: true,
log: true,
log_level: :debug
)
puts client.operations
# then call a method of the service like this
resp = client.call(:get_study_list,
message: {username: "foo", password: "bar"}
)

Using Savon and nokogiri to make a Soap Request

A sample request that I am trying to make looks like this:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetList xmlns="http://tempuri.org/">
<listRequest i:type="b:NpsListRequest" xmlns:a="http://schemas.datacontract.org/2004/07/Services.List" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:b="http://schemas.datacontract.org/2004/07/Services.List.Strategies">
<a:id>1</a:id>
</listRequest>
</GetList>
</s:Body>
</s:Envelope>
I can replicate that exactly, using Nokogiri, like so:
builder = Nokogiri::XML::Builder.new do |xml|
xml['s'].Envelope('xmlns:s' => "http://schemas.xmlsoap.org/soap/envelope/") {
xml['s'].Body {
xml.GetList('xmlns' => "http://tempuri.org/") {
xml.listRequest('i:type' => "b:NpsListRequest", 'xmlns:a' => "http://schemas.datacontract.org/2004/07/Services.List", 'xmlns:i' => "http://www.w3.org/2001/XMLSchema-instance", 'xmlns:b' => "http://schemas.datacontract.org/2004/07/Services.List.Strategies") {
xml['a'].id(1)
}
}
}
}
end
builder.to_xml
Then, I build my soap_client using Savon:
def soap_client
soap_client = Savon.client(
wsdl: "http://1.1.1.1/Api.svc?wsdl", #PLE
headers: {"Authorization" => "Basic"},
basic_auth: ['user', 'password'],
env_namespace: :soapenv,
namespace_identifier: :ser,
ssl_verify_mode: :none,
log: true,
:pretty_print_xml => true
)
end
Now, I need to make a :get_list call that looks like the above sample request.
soap_client.operations returns this:
[:get_list] So I know I'm authenticated and the client is working correctly.
I can't figure out how to actually make the :get_list call.
I would like something simple where I don't even have to use Nokogiri to build my own xml, like this:
soap_client.call :get_list, message: {id => 1}
But that doesn't seem to be a feasible solution. Any thoughts on how I can pass the XML I'm building using Nokogiri through to the :get_list call for my soap_client? I am open to other suggestions as well.

Resources