Guys I have got an issue with wsdl processing.
Cerberus FTP server has it's own wsdl API for server configuration
www.cerberusftp.com/support/help/webservices.htm
I tried to execute some functions with ruby and savon like this:
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
require 'savon'
client = Savon.client(wsdl: "http://192.168.1.5:10001/wsdl/Cerberus.wsdl")
response = client.call(:server_information) do
message credentials: {user: "admin", password: "123"}
end
From sniffer I can see POST request
<?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://cerberusllc.com/service/cerberusftpservice" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
- <env:Body>
- <tns:ServerInformationRequest>
- <tns:credentials>
<tns:user>admin</tns:user>
<tns:password>123</tns:password>
</tns:credentials>
</tns:ServerInformationRequest>
</env:Body>
</env:Envelope>
Also I tried tool Membarene SOAP client
<s12:Envelope xmlns:s12='http://www.w3.org/2003/05/soap-envelope'>
<s12:Body>
<ns1:ServerInformationRequest xmlns:ns1='http://cerberusllc.com/service/cerberusftpservice'>
<ns1:credentials xmlns:ns1='http://cerberusllc.com/common'>
<ns1:user>admin</ns1:user>
<ns1:password>123</ns1:password>
</ns1:credentials>
</ns1:ServerInformationRequest>
</s12:Body>
</s12:Envelope>
It's POST request slightly different and it works.
Any idea how to do the same in ruby + savon ?
I've resolved that issue.
I generate XML query manually.
it looks like:
client = Savon.client(wsdl: "http://example.com:10001/wsdl/Cerberus.wsdl")
variable = client.call(:add_group xml: "your xml " ) # you can generate this xml via SoapUI tool or Membarene SOAP client.
My standard response:
download SoapUI
build a valid, successful call
rebuild in Ruby with Savon (not RoR)
ask questions here and you will receive help :-)
Related
I am using ruby 1.9.3 with rails 3.1. My requirement is that there is a parser file like below. when i opened with browser; Tags are not aligned in order. After the <item>; the data are clubbed format. There is a presence of
<?xml version="1.0" encoding="utf-8"?>
when I opened in sublime text; it shows after the <item>
<![CDATA[<?xml version="1.0" encoding="utf-8"?>
also after the </item> there is ]]> present. The data needs to be parsed are inside this <item></item>. the method called parse_file form Nokogiri called only start_element, end_element. When we tried manually by editing the file via removing the above statements; then it will call the characters method to fetch the data. Below is the example code.is there any other way?.
<batch transactionType="HC"><item><?xml version="1.0" encoding="utf-8"?><C><CI><Ve>00501</Ve></CI></C></item></batch>
You can do it easily using "xml-simple". Assuming your XML file name is "test.xml", first install the gem:
gem install xml-simple
Then, you can try:
require "XmlSimple"
abc = XmlSimple.xml_in File.read("test.xml")
puts abc['item']
The output should be:
{"C"=>[{"CI"=>[{"Ve"=>["00501"]}]}]}
The below works perfectly in SoapUI (that's where I constructed it), but when I copy the exact request and attempt to execute with cURL in the bash command line (cygwin actually), it says:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:Client.NoSOAPAction</faultcode>
<faultstring>no SOAPAction header!</faultstring>
<detail/>
</soapenv:Fault>
</soapenv:Body>
The command I'm using is:
curl -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction:" -d "<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ebay:apis:eBLBaseComponents"><soapenv:Header><urn:RequesterCredentials><urn:eBayAuthToken>AgA***GO</urn:eBayAuthToken></urn:RequesterCredentials></soapenv:Header><soapenv:Body><urn:GetMyeBaySellingRequest><urn:Version>793</urn:Version><urn:ActiveList><urn:Include>1</urn:Include><urn:IncludeNotes>0</urn:IncludeNotes></urn:ActiveList><urn:OutputSelector>ActiveList.ItemArray.Item.ItemID</urn:OutputSelector><urn:DetailLevel>ReturnAll</urn:DetailLevel><urn:HideVariations>1</urn:HideVariations></urn:GetMyeBaySellingRequest></soapenv:Body></soapenv:Envelope>" -X POST https://api.ebay.com/wsapi?callname=GetMyeBaySelling
I've used this exact syntax on other APIs with no issue, not sure what's different about eBay.
Open your wsdl. search for the operation which you are using to send this "GetMyeBaySellingRequest" request.
Copy the soap action from there and add in you command line
"SOAPAction: add soap action here from bindings or from soapui"
or in SOAP UI click on the operation and see at bottom left corner, you will see "operation properties". From there copy soap action value and put it in your command.
Please help me, I need code for my WSDL file for below wsdl file url using RUBY language parameter can be passed as pcEmployeecode...
Parameter can passed as STRING ie.,pcEmployeeCode="02385"
url ="http://online.mccolls.com.au:8080/wsa/wsa1/wsdl?targetURI=urn:OHWebServiceFMGT"
Please Refer this WSDL file and post me if you have sucess fully got the response result...
Any idea's....
I used like this, Still error hitting.
require 'rubygems'
#require 'soap4r'
require 'http-access2'
require 'soap/rpc/driver'
require 'soap/rpc/driver'
require 'net/http'
Net::HTTP.version_1_2
url =
"http://online.mccolls.com.au:8080/wsa/wsa1/wsdl?targetURI=urn:OHWebServiceFMGT"
soap = SOAP::RPC::Driver.new(url,"urn:OHWebServiceFMGT")
soap.wiredump_dev = STDERR
soap.options["protocol.http.ssl_config.verify_mode"] =
OpenSSL::SSL::VERIFY_NONE
soap.add_method('getEmployeeFmgtDetails','pcEmployeeCode')
puts soap.getEmployeeFmgtDetails('02385')
How would I remove the HTTP headers from a Savon request for example
client.request 'v5:ProcessShipments' do
client.http.headers["SOAPAction"] = "example_post"
end
This would generate
DEBUG -- : SOAPAction: example_post
And the server would respond
Server did not recognize the value of HTTP Header SOAPAction: example_post.
However I dont want to have any SOAPAction(s)
I have tried to clear the variable and delete it. I search for a while and couldn't find anything so I hope this hasn't been asked before.
Thanks in advance.
If I dont override it then by default Savon will use the client.request 'v5:ProcessShipments', which is also incorrect.
Here is a quote from savon documentation for the future references:
SOAPAction is an HTTP header information required by legacy services.
If present, the header value must have double quotes surrounding the
URI-reference (SOAP 1.1. spec, section 6.1.1).
By reading savon source code I figured out that Savon::Client#request method sets "SOAPAction" header automatically before it yields a block. I tried to delete SOAPAction header and it worked:
require 'savon'
client = Savon::Client.new do
wsdl.document = "test.wsdl"
end
client.request :wsdl, "sayHello" do
http.headers.delete("SOAPAction")
end
Here is the request it generates:
SOAP request: http://www.examples.com/SayHello/
DEBUG -- : Content-Type: text/xml;charset=UTF-8, Content-Length: 332
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:wsdl="http://www.examples.com/wsdl/HelloService.wsdl"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<wsdl:sayHello></wsdl:sayHello>
</env:Body>
</env:Envelope>
As you can see there is no SOAPAction HTTP header.
HTH
(GAVE UP ON INSTALLING CURB. POSTED NEW QUESTION PER SUGGESTION OF ONE OF THE RESPONDENTS)
I thought 'curl ' was 'built-in' but got an undefined method error in a sinatra app. is there a gem i need to add?
Same question for rails 3?
The application is that I have to simply 'hit' an external url (http://kickstartme.someplace.com?action=ACTIONNAME&token=XYZXYZXYZ) to kickstart a remote process.
the external url returns XML describing success/failure in the format:
<session>
<success>true</success>
<token>xyzxyzxyz</token>
<id>abcabcabc</id>
</session>
So really, ALL I need is for my rails and sinatra apps to hit that url and parse whatever is returned AND grcefully handle the remote server failing to reply.
require 'open-uri'
require 'nokogiri'
response = open("http://kickstartme.someplace.com?action=ACTIONNAME&token=XYZXYZXYZ").read
doc = Nokogiri::XML(response)
Use curb, a Ruby binding to libcurl. You will get all the curl features without having to shell out with system.
curl -b "auth=abcdef; ASP.NET_SessionId=lotsatext;" example.com
turns into
curl = Curl::Easy.new('http://example.com/')
curl.cookies = 'auth=abcdef; ASP.NET_SessionId=big-wall-of-text;'
curl.perform
More curb examples