304 htpp code in web services and Jax-ws - spring-ws

We are using :
* at the service side webservices with Spring Ws
* at client side Jax-ws
It seems there is no documentation at all about using ETAG & the 304 http code in webservices.
Sending back a 304 code seems to be already implemented in Spring MVC.
Do you know if with those two technologies implement this stuff is possible or and easy ?
Right now i dont know if i can skip sending back the usual response in Spring WS with just a HTTP Code.
Im using endpoint with JaxB at the server side.
Thanks in advance for your help.

Related

Post Https SOAP request for performing an action in application using robot framework

I wrote this robot framework test to post a https request to a webservice. The request body is in xml format and not in Json. I have used request library for this, but i am receiving error when i post using the code listed below.
With postman, i had send the body as raw data and got response as 200 ok, but when i try to do the same in robot framework its throwing error 404.
Please help me on this:
Is requests library relevant for post of https xml data soap request
to a web service?
Can any modification be made to below code for posting a https request
to a web service?
Is there any other library through which we could achieve calling
soap web service?
The Robot Framework Script
***Library***
Library String
Library Collections
Library RequestsLibrary
***Variables***
${user} = username
${passwd} = pwd
&{headers} Content-Type=application/soap+xml or text/xml Authorization=Basic encrypted details
${body_request} = <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://example.com/schemas</a:Action><a:MessageID>msgid</a:MessageID><a:ReplyTo><a:Address>url</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">serviceurl</a:To></s:Header><s:Body xmlns:xsi=body"></s:Body></s:Envelope>
*** Test Cases ***
${auth}= Create List ${user} ${passwd}
Create Session alias=proc url=url headers=${headers} auth=${auth}
Sleep 5
${resp2} Post Request alias=proc uri=url data=${body_request} json=None params=None
headers=${headers} files=None allow_redirects=True timeout=None
Should Be Equal As Strings ${resp2.status_code} 200
Log To Console ${resp2.status_code}
Answers to your question mentioned below,
Is requests library relevant for post of https xml data soap request to a web service? - yes, it can be used. however, there are better ways to achieve the same, see the solution below.
Can any modification be made to below code for posting a https request to a web service? - I think it is nothing to do with https, since 400 is bad request, you need to look at the body.
Is there any other library through which we could achieve calling soap web service? - SudsLibrary.
Although, you can make use of requests module to achieve your solution,
My philosophy when making use of robotframework is "SIMPLY MAKE USE OF EXISTING LIBRARIES" which is already verified. Please do not spend time to solve the problem keeping the thought process of "using a language".
Solution
Please make use of "SudsLibrary" library for SOAP requests, look at Keyword Documentation for your reference.
SudsLibrary is a library for functional testing of SOAP-based web services. SudsLibrary is based on Suds, a dynamic SOAP 1.1 client.
pip install robotframework-sudslibrary3
When you use the above library your code would be something similar to the one seen below,
*** Settings ***
Library SudsLibrary
Library Collections
*** Test Cases ***
Sample Testcase On SOAP
${BASE_URL} Set Variable http://www.someservice.com
${SERVICE} Create Dictionary
... name=someservice
... wsdl=someservice.asmx?WSDL
${PORT} Set variable SERVICE_PORT
${METHOD} Set variable CALLSOMEACTION
Set Binding SOAP-ENV http://www.w3.org/2003/05/soap-envelope
Create Soap Client ${BASE_URL}/${SERVICE.name}/${SERVICE.wsdl}
Set Port ${PORT}
Set Headers Content-Type application/soap+xml
Set Headers Authorization Basic encrypted details
Set Headers Soapaction ${EMPTY}
Set Headers Action "${BASE_URL}/${SERVICE.name}/${METHOD}"
${result} Call Soap Method ${METHOD}

Electron - How to sniff http request body

I have a simple electron app which loads a certain website.
This website is doing http get/post requests. I want to sniff the body of the server responses.
I already checked out the webRequest module which seemed pretty nice. Unfortunetely, it handles all data EXCEPT the body.
How can I sniff the body of the server responses?
Found out that this is not possible. Also its not a an Electron issue, rather a chromium one - Electron just wraps the chromium API.
Finally I managed to inject a javascript (inside the api service) which forwards me all data received from the server via ipc
https://electronjs.org/docs/api/ipc-main

CXF post api fails via jmeter

Trying to automate my test cases using jmeter. I have used cxf for rest apis on my web server. I have an api which actually takes a java object as parameter. On jmeter I have selected the POST method under HTTP-request and sending json data in Body data. The api gets called fine. However the parameter comes null and hence by api fails. I did try changing the parameter to String object, however I get this string as null.
Is this the right way to call apis via jmeter. Or is this failing because I have used cxf on my server.
Any help is appreciated.
Thanks
Most likely you need to add a HTTP Header Manager and configure it to send Content-Type header with the value of application/json
See Testing SOAP/REST Web Services Using JMeter for detailed explanation on JMeter configuration for REST API testing.
Other thing you could try out is using SoapUI tool to send the request to your CXF endpoint and if it succeeds - inspect the request and configure JMeter accordingly. By the way, SoapUI has some limited load testing capabilities, may be it will be enough for your scenario

How to connect iOS App to Symfony2 RESTful Webservice?

I have an iOS app that is working and able to connect to a RESTful PHP Webservice. The webservice was initially built in native PHP and now I am migrating it to a Symfony2 web service. On the iOS side, I am sending requests as JSON, the server processes the data and returns a JSON response data, everything works pretty well.
Now, my symfony2 webservice is able to respond with the correct response to requests made from the browser window or terminal using httpie (for testing) and it returns json data in the browswer window if I specify .json in the parameters. However, I am not sure how to make the iOS app send the request rather than the browser. I am using the FOSRestBundle if that information is of any significance. Here is an example from the terminal:
http http://serveripaddress/web/app_dev.php/users/1.json Accept:application/json
It returns json data representation of the user with the id = 1 as expected:
HTTP/1.1 200 OK
Allow: GET, PUT, DELETE
Cache-Control: no-cache
Content-Type: application/json
Date: Fri, 29 Nov 2013 20:15:43 GMT
Server: Apache/2.2.22 (Ubuntu)
Set-Cookie: PHPSESSID=n8o72oq61isruuov1bqgc9udf5; path=/
Transfer-Encoding: chunked
X-Debug-Token: 6c3818
X-Powered-By: PHP/5.3.10-1ubuntu3.8
{
"id": 1,
"last_name": "Robinson",
"first_name": "Jack",
....More data truncated ...
}
From my browser, I can get the same result by using: http://serveripaddress/web/app_dev.php/users/1.json in the address bar. How can I make the iOS app send the same request? I guess the only change I need is in the symfony2 code to accept the request? Kindly give a brief example and I can figure out the rest from the example.
Edited with more detail:
Just to clarify, what I need is how to initiate a connection to the server-side REST Symfony2 application. Again, this I have previously done when using native PHP but how do I connect to a Symfony2 route? While using the native version, what I did was to construct a dictionaryWithObjectandKeys passing key value pairs of the command (on the PHP side) and the arguments as JSON and having the server side return JSON data response and a success or failure, simple and straightforward. How can this be done if I am using Symfony2 which I guess the commands now become a route? I am using AFNetworking and everything on the iOS client side should not need changes except the part where I connect to Symfony2. Kindly give an example to give me a concrete picture.
You can use AFNetworking 2 for example. It is a complete framework that allows you to consume web services (and more).
By the way, you could simply use (and fire) NSURLRequest, but if your application interact a lot with a webService i recommend to use AFNetworking. (Trust me, it is really something that you want to know how to use if you want to make apps on iOS)
I think binding to session and cookies may violate REST nature. I strongly recommend you to use something like WSSE. You can use EscapeWSSEAuthenticationBundle for WSSE. Or create your own.
Also useful link to dive deep:
How to create a custom Authentication Provider
Configure WSSE on Symfony2 with FOSRestBundle

Grails - detect if request is over HTTP or HTTPS

In Grails how do you ask if the request coming in is http or https?
Should you approach this from the request object?
Use request.isSecure(). This isn't a Grails feature btw, it's in the javax.servlet.ServletRequest interface.

Resources