Send XML request from Rails application. XML model payment implementation - ruby-on-rails

I am working on the implementation of a payment system on my website. But as the payment system works according to the old model, all requests go through XML. I need to send XML (the code is attached below) to the URL and get a response. How could i send XML post request with Ruby on Rails. I need to send in to this url https://setmpos.ykb.com/PosnetWebService/XML?xmldata=%3CposnetRequest%3E%0D%0A++%3Cmid%3E... Where xmldata is query parametr.
<?xml version="1.0" encoding="ISO-8859-9"?>
<posnetRequest>
<mid>6700000067</mid>
<tid>67000067</tid>
<tranDateRequired>1</tranDateRequired>
<sale>
<amount>2451</amount>
<ccno>4506349116608409</ccno>
<currencyCode>TL</currencyCode>
<cvc>000</cvc>
<expDate>0703</expDate>
<orderID>1s3456z8901234567890123</orderID>
<installment>00</installment>
</sale>
</posnetRequest>

Related

jersey client webtarget URL with non-standard encoding

Suppose the following HTTP request:
POST index.php?/api/v2/add_result_for_case/123/777
This appears in TestRail documentation at https://support.gurock.com/hc/en-us/articles/7077819312404-Results#addresultforcase
Now, I am trying to use Jersey as follows:
testRailClient()
.target(testRailUrl)
.path("/index.php")
.queryParam("/api/v2/add_result_for_case/123/777")
.request()
.post(Entity.json(...))
But, its URL gets encoded by Jersey, as follows:
https://testrail.host/index.php?%2Fapi%2Fv2%2Fadd_result_for_case%2F131143%2F131143=
Any suggestion how to make it generate the request as required by TestRail?

Spring WebServiceTemplate URL

In the Spring guides a webservice is published at locationUri "/ws".
The getCountryRequest webservice is consumed using the WebServiceTemplate's marshallSendAndReceive method at "http://localhost:8080/ws/countries".
When using soapUI I consume the webservice at "http://localhost:8080/ws/" and specify the name of the webservice in the SOAP body.
So how does the WebServiceTemplate exactly use the "countries" suffix and how does it exactly map to the message with name getCountryRequest?
To answer my own question:
The wsdl is publishing the webservice at
<soap:address location="http://localhost:8080/ws"/>
But the MessageDispatcherServlet is listening at "http://localhost:8080/ws/*".
So anything beneath that URL is just passed onto SOAP and works.
I can use http://localhost:8080/ws/ (I still wonder why the WebServiceTemplate doesn't just use the WSDL SOAP address), http://localhost:8080/ws/countries or http://localhost:8080/ws/anythingGoes.
It just doesn't matter.

Rails not getting params from HTTP request

I'm trying to POST the following data to a Rails server (running on WebRick) from Android.
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<data>
<email>email.test#name.com</email>
<password>APassw0rd</password>
<remember_me>1</remember_me>
</data>
Now, the funny thing is that these data never show up in the params field in the controller.
Webrick does not output any parsing error. (And I guess it would post an error if it received a POST with no data attached:
Started POST "/users/sign_in.xml" for 192.168.1.94 at 2012-12-14 17:33:20 +0100
Processing by Users::SessionController#create as XML
Completed 500 Internal Server Error in 22643ms
I also found no trace of the data in the request.env variable. Actually, I see no HTTP_BODY in the dump fields. How can one see the raw body of the request? Would webrick really not complain if it received a POST with no attached data?
request.env would show the data as an IO object so you wouldn't be able to see your xml directly.
request.raw_post should return the raw data.
For rails to try and parse your xml into the params hash directly you need to set the content type of the request to application/xml. The 'processing as xml' stuff means that rails will try to render an xml response and doesn't necessarily have any bearing on the format of the posted data

Fault calling SAP web service with generated SUDZC proxy: CX_ST_MATCH_ELEMENT

Trying to call a SAP SOAP Web Service from a generated sudzc app shows errors I don't know:
SudzCExamples[5192:f803] <?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:sap-
com:document:sap:soap:functions:mc-style"><soap:Body><ZComUrlGetrecords>
<IYear>2012</IYear></ZComUrlGetrecords></soap:Body></soap:Envelope>
SudzCExamples[5192:f803] <soap-env:Envelope xmlns:soap-
env="http://schemas.xmlsoap.org/soap/envelope/"><soap-env:Header></soap-env:Header><soap-
env:Body><soap-env:Fault><faultcode>soap-env:Server</faultcode><faultstring
xml:lang="en">CX_ST_MATCH_ELEMENT:XSLT exception.System expected element
'IYear'</faultstring><detail><ns:SystemFault
xmlns:ns="http://www.sap.com/webas/710/soap/runtime/abap/fault/system/">
<Host>undefined</Host><Component>APPL</Component><ChainedException>
<Exception_Name>CX_SOAP_CORE</Exception_Name><Exception_Text>CX_ST_MATCH_ELEMENT:XSLT
exception.System expected element 'IYear'</Exception_Text></ChainedException>
<ChainedException><Exception_Name>CX_SXMLP</Exception_Name><Exception_Text>XSLT
exception</Exception_Text></ChainedException><ChainedException>
<Exception_Name>CX_ST_MATCH_ELEMENT</Exception_Name><Exception_Text>System expected
element 'IYear': Main Program:/1BCDWB/WSS825E06E4DEC40F9171D|
Program:/1BCDWB/WSS825E06E4DEC40F9171D| Line: 18| Valid:X</Exception_Text>
</ChainedException></ns:SystemFault></detail></soap-env:Fault></soap-env:Body></soap-
env:Envelope>
2012-03-11 20:09:30.631 SudzCExamples[5192:f803] soap-env:Server CX_ST_MATCH_ELEMENT:XSLT
exception.System expected element 'IYear'
(null)
The strange thing is that it seems as if the request has the IYear element. Can someone tell me where to search the problem?
I ran into this same problem yesterday and discovered the solution after some experimentation. First thing I did was use my SoapUI client to make the request successfully. SoapUI comes with a free trial and even if you do not use the free trial you can still use it to make accesses to the web service without registering it. I used the xml from the successful request I made to compare against the request that SudzC was making. They differ in several ways, and the way that SudzC forms the request is not sufficient.
My suggestion to you is to compare the two requests and change SudzC's request to match the SoapUI request. You can do this by editing the Soap source code that SudzC gives to you, this source code is found particularly in the Soap.m file in the createEnvelope function.
Also, if your requests have an empty header SudzC does not include the header part of the request. Hard code in an empty header after the namespace portion of the envelope. Doing all this fixed this exact issue for me.

How do I post XML to RESTFUL Web Service using Net::HTTP::Post?

I am having trouble getting this to work so any help would be appreciated! Basically, the request.body contains valid XML for the Web Service like so:
<somedata>
<name>Test Name 1</name>
<description>Some data for Unit testing</description>
</somedata>
...but the service returns empty XML. Note that the id field is returned suggesting that it does actually hit the database, but the name and description fields are nil:
<somedata>
<id type='integer'>1</id>
<name nil='true'></name>
<description nil='true'></description>
</somedata>
I have manually tested the RESTFUL service using Poster and it works fine.
Here is the code:
url = URI.parse('http://localhost:3000/someservice/')
request = Net::HTTP::Post.new(url.path)
request.body = "<?xml version='1.0' encoding='UTF-8'?><somedata><name>Test Name 1</name><description>Some data for Unit testing</description></somedata>"
response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}
#Note this test PASSES!
assert_equal '201 Created', response.get_fields('Status')[0]
Does anyone have any clues why the data in the XML post is not persisted?
Without knowing anything about the service, this is just a guess, but… is the service expecting a specific header that Poster is setting and you aren't?
If I were you, I'd use Wireshark, tcpflow or some other sniffer to look at the exact data Poster and your app are sending, and make sure they're identical. I've seen services that were sensitive to the weirdest things, like whitespace or user agent.

Resources