Quarkus calling Rest API with dynamic endpoint - quarkus

I used the micro profile to make a call to a specific API, it happens that this call gives me a list of URLs and I have to make a call for each URL returned.
My objective is call all of these URL e verify HTTP status returned.
"ApiResources": [
{
"ApiFamilyType": "products-services",
"ApiVersion": 1,
"ApiResourceId": "d33ff8af-5a1b-4b43-90d4-34237997d080",
"ApiDiscoveryEndpoints": [
{
"ApiEndpoint": "https://api.yyyyyyyy/v1/personal-accounts"
},
{
"ApiEndpoint": "https://api.xxxxxxx/business-accounts"
}
}
]

Related

Postman test of spring ArrayList getmapping response

I have a Spring Boot application that has a getmapping returning an ArrayList. This all works fine and it returns the arraylist as a json object in the body. I am trying to write a postman test on the response to verify the length of the arraylist that comes back. I cant seem to get it to find the arraylist on the object however since there doesn't appear to be any keys.
My Spring Code is:
#GetMapping(value="/getAllCars", produces = "application/json")
public #ResponseBody List<Car> getAllCars() {
return carManager.getAllCars();
}
The response in postman shows
[
{
"id": "19a94f8d-b1c1-4814-abba-57b1cb319478",
"name": "car1"
},
{
"id": "4e2568ca-f41a-480d-82b5-acede9109a6d",
"name": "car2",
},
{
"id": "4e2568ca-f41a-480d-82b5-acede9109a6d",
"name": "car3",
},
... (there is 72 total)
]
my test code in postman is is
pm.test("CarsLength" , function(){
const responseJson = pm.response.json;
pm.expect(responseJson.length).to.equal(72);
})
when i look at the postman console after logging the responseJson and responseJson.length its only logging out the function name and 2. responseJson[0] and responseJson[1] are both undefined when i log them out as well.
I dont have a key in my response json object is thats whats causing this? How can I access the objects to verify the length in a postman test?
The mistake is here:
pm.response.json --> pm.response.json()

Pass data to start of session (IVR)

Looking into starting a project using DialogFlow CX. Seems rather promising but have one issue I cannot seem to find an answer for. The agent will be connected to via IVR (from Flex/Callcenter). I need to gather some information on start so that I can identify the hotel/property that will be referenced in the conversation. I found session parameters but those are isolated to the session from start to finish but not passed to the start of a session. We are starting with about 60 properties and when the agent starts, it needs to "know" what property it is dealing with.
Another quick question - will I need a separate telephony integration number to run multiple concurrent instances?
I am really new to all this so my language may be off. Thanks in advance!!
Robert
Passing parameters to dialogflow Cx depends on your integration, but a general way to do this would be to call a webhook at the Welcome node with parameters set to null that you want to return with updated values from backend:
Return Response in the following manner and it will work via a webhook:
Link to Google Cloud Functions Webhook Example
{
"fulfillment_response":
{
"messages": [
{
"text": {
"text": [
"Test Response"
]
}
}
]
},
"session_info": {
"session": projects/project-name/locations/your-agent-location/agents/a6ed61ef-008b-49bb-8526-d8e68982d2b4/sessions/d3bd9c-9d9-8c8-4a8-f623bdb25,
"parameters": {
"property1": 746932,
"property2":34123
}
}
}
Python Flask Solution:
import os
from flask import Flask, request, redirect
app =Flask(__name__)
#app.route('/test', methods=['POST'])
def test():
req = request.get_json()
session_name=req['sessionInfo']['session']
print(req)
res = {
"fulfillment_response":
{
"messages": [
{
"text": {
"text": [
"Test Response"
]
}
}
]
},
"session_info": {
"session": session_name,
"parameters": {
"property1": 746932,
"property2":34123
}
}
}
return res
if __name__ == "__main__":
app.run(port=5000,debug=True)

CORS error with AWS api gateway and java lambda function

Today I created one api gateway on aws and one java lambda function. Then finally integrated api gateway with lambda function.
So when I hit the api using postman then it returns the result which is basically a list of customer. Till now everything looks fine. Following is the
#Override
public TestResponse handleRequest(Request input, Context context) {
TestService testService = SingletonServiceManager.getInstance().getTestService();
TestListResponse response = (TestListResponse)productListService.executeRequest(input);
return response;
}
After executing it returns following output.
{
"status": 200,
"products": [
{
"name": "test1",
"code": "test1",
"status": true
},
{
"name": "test2",
"code": "test2",
"status": true
}
]
}
but when I started integrating this with api call with Angular from local machine it start throwing CORS issue. Angular client using it CORS setting to connect.
Can someone help me on this. Do I need to enable something special from lambda function.
You need to enable CORS in your API Gateway configuration.

How to do an ElasticSearch using REST request body method and get the returned json formatted / pretty?

In issuing a search request, via REST Request Body method, such as
GET /bank/_search
{
"query": { "match_all": {} },
"sort": [
{ "account_number": "asc" }
]
}
is there a parameter that can be added anywhere to request the returned response body's json be formatted/pretty ?
The same search using REST Request URI enables to do that, like
GET /bank/_search?q=*&sort=account_number:asc&pretty
How to achieve the same using REST request body ?
Using ElasticSearch.NET's low level api, one have no control over the REST call, and can only provide the POST json.
var esClient = new ElasticLowLevelClient(_connectionSettings);
//postDataJson is the json depicted in the question's body
var postData = PostData.String(postDataJson);
var response = esClient.Search<StringResponse>("myIndex", postData);
One can send a third parameter, a SearchRequestParameters object, I can't find any property there for that.
You need to add to your request pretty=true
Like that:
GET /bank/_search?q=*&sort=account_number:asc&pretty=true
for more reference check here
EDIT
I didn't understand you at first, the pretty should be in the header of the request.
Try like that:
GET /bank/_search?pretty=true
{
"query": { "match_all": {} },
"sort": [
{ "account_number": "asc" }
]
}
EDIT 2
If you are using elstic.NET and you want too achieve pretty Jason.
You need to configure it in the connection.
Here is the method you should use(it's in the classConnectionConfiguration : ConnectionConfiguration<ConnectionConfiguration>):
/// <summary>
/// Forces all requests to have ?pretty=true querystring parameter appended,
/// causing Elasticsearch to return formatted JSON.
/// Also forces the client to send out formatted JSON. Defaults to <c>false</c>
/// </summary>
public T PrettyJson(bool b = true) => Assign(a =>
{
this._prettyJson = b;
const string key = "pretty";
if (!b && this._queryString[key] != null) this._queryString.Remove(key);
else if (b && this._queryString[key] == null)
this.GlobalQueryStringParameters(new NameValueCollection { { key, "true" } });
});
Here you can see the git

how to tell rest post data is invalid in spring

I have a post data request as the following,
{
"doctorId":1,
"userId":29,
"sampleConditions":[
{
"conditionId":"14",
"conditionName":"Acne",
"conditionDate":"2017-01-31"
}
],
"labOrder":{
"testId" : [1,2,3]
}
}
what happens, if the client gives the incorrect key
"sampleConditionss":[
{
"conditionId":"14",
"conditionName":"Acne",
"conditionDate":"2017-01-31"
}
],
Instead of giving sampleConditions, the client have sent the request as sampleConditionss.
How can i handle the request,
When you are using springs the spring framework will return 400 and you need not do anything here

Resources