Add HTTP header to SOAP request via groovy-wslite - soap

I am trying to add a HTTP header into my SOAP request. The code is written in groovy and is using groovy-wslite library. My code looks like the following:
def client = new SOAPClient(AConfig.url)
client.httpClient.sslTrustStoreFile = abcd
client.httpClient.sslTrustStorePassword =AConfig.password
How do I add HTTP header to the client object?

You can't add an HTTP header to the client object itself.
Instead, each SOAP request that the client sends out can have its own set of HTTP headers added to it.
The first parameter to the send method can contain the HTTP headers. Here is an example:
String content = "<....SOAP message body here...>"
SOAPClient client = new SOAPClient(AConfig.url)
Map requestParams = [ headers: [ CustomHeader: "My custom header" ] ]
client.send(requestParams, content)

Related

How to make the search parameters in http request as dynamic in jmeter

http request: http://ipAddress:Port/SomeResource?Param1=value1&Param2=value2&......
so on.
This is a http request sample in jmeter that hits a rest api and gets response in JSON format.
Here the challenge is Param1, param2, param3 .... these search parameters number is not constant it may change depending on the call so i am making a csv file that contains rows that contain search parameters in coma separated format.
CSV file is like
param1,param2
param1,param2,param3
param1
I am using a CSV data configure to pull data from the csv file and put it in the http request
And putting this in http request like
Now if the param is null i don't want see this in http request header
so how to do this in jmeter.
Remove all "Parameters" from the HTTP Request, it should be clean
Add JSR223 PreProcessor as a child of the HTTP Request sampler you would like to parameterize
Put the following code into "Script" area:
1.upto(4, {
if (vars.get('param' + "$it") != null) {
sampler.addArgument(vars.get('param' + "$it"),'someValue')
}
})
Add JSR223 PostProcessor as a child of the request you would like to parameterize
Put the following code into "Script" area:
1.upto(4, {
vars.remove("param" + "$it")
})
That's it, you should now get what you need. You will not see the changes in JMeter GUI, you will only be able to observe them in the runtime using View Results Tree listener

Is it possible that a simple Akka Http request is so much different from a curl one?

I'm trying to download data from the European Central Bank API. A simple curl works fine:
curl "https://sdw-wsrest.ecb.europa.eu/service/data/EXR/D.USD.EUR.SP00.A?startPeriod=2018-06-06&endPeriod=2018-06-06"
But when I try to achieve the same thing with Akka Http, all of a sudden I get a 500 error. Here is the code (you can run it in the browser and see it for yourself): https://scastie.scala-lang.org/ynqKN3ClQJmPUruybgR37g. Because the URLs are exactly the same, it means that the requests themselves must be different. How is that possible?
It looks like you need to add an Accept header to your request. This seems to work:
val httpRequest = HttpRequest(
method = HttpMethods.GET,
headers = List(Accept()),
uri = uri)
val futureResponse = Http().singleRequest(httpRequest)
It appears that the service you are calling requires the Accept header and curl adds an Accept: */* header by default.

How to remove spray-can/1.3.3 from response

I use spray.io to serve HTTP requests. In response there is information about spray framework that I would like to remove. So how to remove "Server: spray-can/1.3.3" from the response header in spray?
You can set this via application.conf:
spray.can {
server {
# The value of the `Server` header to produce.
# Set to the empty string to disable rendering of the server header.
server-header = spray-can/${spray.version}
}
}

How to create a SOAP message from JSON payload in mule

I need to transform the following json payload into a soap message and send the message to a consumer, the consumer edits the data and sends back the soap message.
I haven't done much in soap. I only have REST experience. what steps do I need to take in a process like this?
what is the best approach?
[{"salesOrderId":"00004-5-6","saleName":"House Sale","status":"processing"}, {"salesOrderId":"00001-2-3","saleName":"Car Sale","status":"processing"}]
There are various way to perform this transformation, for example:
PATH - 1
Json To XML (with transformer or string set payload)
Xml To SOAP Request using XSLT, transformer or string set payload.
Send SOAP Request sobre HTTP (POST / Content-type: applicacion/xml / soapAction)
PATH - 2
Json To SOAP Request using Groovy, XSLT or string set payload.
Send SOAP Request sobre HTTP-OUTBOUND (POST / Content-type: applicacion/xml / soapAction)
PATH - 3
Json To SOAP Request Proxy (WSDL To Java).
Send SOAP Request sobre HTTP-OUTBOUND (POST / Content-type: applicacion/xml / soapAction)
The easiest way of doing it is extract the JSON elements from the JSON payload by using <json:json-to-object-transformer/>and store each node value in variables like flow variable in Mule.
Then You can create the SOAP request using XSLT and passing the flow variables value into XSLT as <mulexml:context-property/>
ref:- https://developer.mulesoft.com/docs/display/current/XSLT+Transformer
Once your SOAP XML is created, you can simply post them to your HTTP outbound endpoint pointing to your external web service you need to consume
Try using Mule DataMapper. That helps you to convert a JSON to XML in the more easier way. You can try it in Anypoint Studio of Mule.

post data to REST API using RESTClient for firefox addon

I am using RESTClient for firefox addon to test REST API, i set some headers that's working fine if i set request body and method to GET , i couldn't access data via my PHP application, but headers available
**Request headers**
Content-Type : application/json
**Request Body**
[
{
"data1" : "value1",
"data2" : "value2",
"data3" : 1
}
]
How do i set Request body correctly?
Set a body to GET requests is a "nonsense" because GET means retrieve some information and the body of a request is used to send data.
It is precisely from this point of view that web servers, most of the time, ignore the body of a GET request, which could explain why you can't get your data from your PHP script.
If the purpose of your request is to create or update a resource you should consider using a POST or PUT to be REST.
There is already a topic opened with almost the same question here : HTTP GET with request body