How to remove double codes using Mulesoft - soap

I want to compare SOAP action header with request url using mule 4. But SOAP action header coming with double quotes. Bcz of that both url are not match. I want remove these double codes or compare only string thing in mule 4.
attributes.headers.soapaction="http://test.com/test/addEmp"
%dw 2.0
output application/java
var requestUrl='http://test.com/test/addEmp'
---
attributes.headers.soapaction == requestUrl

I understand that you are receiving an HTTP request or response with a SOAP payload but with duplicated SOAPAction HTTP header, and you want to remove the duplicates that don't match a given value for the header. You can try a Transform that targets the attribute and use filterObject() to remove the incorrect duplicates:
%dw 2.0
output application/json
---
{
headers: attributes.headers filterObject ((value, key, index) -> key as String == "soapaction" and value == "http://test.com/test/addEmp")
}
Note that this will remove other attributes as well and leave only HTTP headers. Depending on what you are doing it may not be useful.

Are you trying to do something like this?
%dw 2.0
output application/json
var a = "some text"
var b = 'some text'
---
a == b
%dw 2.0
var requestUrl='http://test.com/test/addEmp'
var soapaction="http://test.com/test/addEmp"
//instead of the variable (soapaction) defined above, you can refer to it through attributes.
---
requestUrl == soapaction

Related

How to connect to Webservice REST with POST from Power BI

I am trying to connect to a webservice through Power BI but I still do not achieve result, first try to use the Web data source and with the Advanced Use add the Header that in my case is Content-Type and its value is application/json and additional as Body I have a token
Where I get as a result the following:
Additional also try to use as source "Blank Query", where I accessed the advanced editor section and add the following Query:
I get as an error the following:
To make sure that the Webservice works correctly and obtains a result I have used the Advanced REST Client tool and I have made the following configuration:
Where you can see that the Headers section I have added the Header name Content-Type and the value of the Header Value is application/json, in the Body section is where I have added the token
With this I realize that my Webservice gets an answer and that the service is working correctly, I would like someone to give me a little guidance in a short time to perform correctly
Supply the content to switch the method from GET to POST eg
Perform a POST against a URL, passing a binary JSON payload and
parsing the response as JSON.
https://learn.microsoft.com/en-us/powerquery-m/web-contents#example-2
let
url = "https://postman-echo.com/post",
headers = [#"Content-Type" = "application/json"],
postData = Json.FromValue([token = "abcdef"]),
response = Web.Contents(
url,
[
Headers = headers,
Content = postData
]
),
jsonResponse = Json.Document(response),
json = jsonResponse[json]
in
json
or
let
url = "https://postman-echo.com/post",
headers = [#"Content-Type" = "application/json"],
postData = Text.ToBinary("{ ""token"":""abcdef""}"),
response = Web.Contents(
url,
[
Headers = headers,
Content = postData
]
),
jsonResponse = Json.Document(response),
json = jsonResponse[json]
in
json

Karate Framework- AWS Auth throwing error "the request signature we calculated does not match the signature you provided" [duplicate]

First of all, thanks for build karate it's a very useful for test API's and UI's. We are using it to test a lot of our endpoints but we would like to know if there is a way or which is the best approach to handle requests with signature as part of the request in the header.
In our case we have two headers:
ApiKey: this value is always the same
Signature: this value depends on the request body content
Is there any way to inject the signature value just before the request is executed based on the request body content?
Here you can see two samples of the requests
Sample 1:
* url 'https://dev.sample.com'
* path '/api/user/getAll'
* header Content-Type = 'application/json'
* header ApiKey = 'XXX'
* header Signature = 'YYY'
And request { }
When method POST
Then status 200
Sample 2:
* url 'https://dev.sample.com'
* path '/api/user/getAll'
* header Content-Type = 'application/json'
* header ApiKey = 'XXX'
* header Signature = 'ZZZ'
And request { name: 'John' }
When method POST
Then status 200
Thanks
Karate has a "hook" for generating headers, but as of now it is not "aware" of the currently built request body + headers: https://github.com/intuit/karate#configure-headers
We got a similar request here, and are thinking of adding this capability: How to retrieve raw request contents before making a REST call in Karate DSL?
Maybe the OAuth examples will give you the way forward for your case for now: https://stackoverflow.com/a/55055111/143475
Feel free to raise an enhancement request, and we can get this in to the next version (with your help to test it). I'm thinking - what if you are able to call karate.get('request') from within the header JS function.
But for now all you need to do is do something like this:
* def body = { some: 'json' }
* karate.set('requestBody', body)
* url someUrl
* request body
* method post
And in the header.js function
function fn() {
var body = karate.get('requestBody');
var sign = Utils.sign(body);
return { Signature: sign };
}
EDIT: this will be implemented in Karate 1.0 onwards: https://github.com/intuit/karate/issues/1385

Verify API Response

Am getting the response of a request like this:
var response = command.PostCommand(testCommand);
I will like to validate that the response is in a json format so am doing it like this:
Assert.AreEqual("application/json", response.ContentType);
Is this way correctly or do i need to specifically validate it from the content-type header response?
You can use the IRestRequest.OnBeforeDeserialization callback to check the response content type before it gets deserialised:
var request = new RestRequest(url)
.AddQueryParameter(x, y); // whatever you need to configure
request.OnBeforeDeserialization =
response => CheckContentType(response.ContentType);
await client.PostAsync<MyResponse>(request);

How to pass response body field to other request's body (Gatling)

I have two end point.
-/authenticate
-/authenticate/verification
/authenticate return guid field on response body.
and /authenticate/verification requires that field on request body.
I have tried to get guid like this :
jsonPath("$..guid").saveAs("verificationGuid")
and pass it to other body :
.body(StringBody(s"{\"guid\":${verificationGuid}, \"code\":\"123456\"}"))
this is the code block:
def login = {
exec(http("Authenticate")
.post("/authenticate")
.body(StringBody(userString))
.headers(headerLogin)
.check(status is 200)
.check(jsonPath("$..guid").saveAs("verificationGuid"))
)
.exec(http( "Authenticate verify")
.post("/authenticate/verify")
.headers(headerLogin)
.body(StringBody(s"{\"guid\":${verificationGuid}, \"code\":\"123456\"}"))
.check(status is 200)
)
}
But it doesnt work, how can I do this?
Remove s from s"{\"guid\":${verificationGuid}, \"code\":\"123456\"}"). If s is in front of string every ${something} placeholder will be treated as Scala built in string interpolation and compiler will try to replace it with Scala variable, which in your case does not exist. Without s it will be treated as literal string and than caught by Gatling EL Parser and replaced with previously saved Gatling session attribute.

How to set Content-Type:application/json in ui5 oData.read() ?

When I call XSet/$count, I found the response is in xml, which is hard to parse.
I tried to call
oModel.read("/XSet/$count", {
urlParameters: "$format=json",
filters: [new Filter(this._oFilterState.aTaskFilter, false)],
});
calledXSet/$count?$format=json&$filter=(status eq 'NOT_STARTED')
returned
"System query option '$format' is not compatible with the return type."
But XSet/$count?$filter=(status eq 'NOT_STARTED')&$format=json can return a json format error response.
I want to try the second way, which is change Content-Type: application/xml to Content-Type: application/json. But failed to find this in API: https://sapui5.hana.ondemand.com/#/api/sap.ui.model.odata.v2.ODataModel/methods/read
The Model.read method requests for an XML response by setting the Accept header as
Accept:application/atom+xml,application/atomsvc+xml,application/xml
However the count request is a plaintext response. You could get the count in two ways, one would be setting the Model's payload to use json and the other way would be a jQuery AJAX call.
You could initialize the model with a json parameter set to true.
var oModel = sap.ui.model.odata.v2.ODataModel("Service_URL",{
json:true
});
This would pass a header with Accept:application/json