wiremock how to get post data - java

i'm trying to get data from the post does any one try
{
"name":"sasha",
"age":"15",
"country":"italy"
}
I will like to get the value sash from the post, any ideas?
only find to reply...
http://wiremock.org/docs/request-matching/
buy I don't want to reply, I want the data.
I would like something linke this:
String name = wiremock.withRequestBody(name());
print name -> sasha
something like this:
Body postBody = aResponse().withBody(matching("[?(#.name]"));
I'm trying to get data from the POST like curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d "{'json':{'name':'sasha'}}" 127.0.0.1:8080/to/post I want to get sasha

Related

How to accept json, xml, x-www-form-urlencoded in openapi driven spring boot application?

I'm implementing a petstore server in spring using the gradle plugin to generate classes for the API:
https://github.com/swagger-api/swagger-petstore/blob/swagger-petstore-v3-1.0.5/src/main/resources/openapi.yaml
An example for such a generated API code is
...
public interface UserApi {
...
#PostMapping(
value = "/user",
produces = { "application/json", "application/xml" },
consumes = { "application/json", "application/xml", "application/x-www-form-urlencoded" }
)
default ResponseEntity<User> createUser(#ApiParam(value = "Created user object" ) #Valid #RequestBody(required = false) User user) {
....
For a minimal example I don't even overwrite the above method.
With springdoc I can create a swagger ui page at http://localhost:8080/swagger-ui.html that is generated from the code.
There, I can generate curl requests for all media types offered y the api:
curl -X POST "http://localhost:8080/user" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"id\":0,\"username\":\"string\",\"firstName\":\"string\",\"lastName\":\"string\",\"email\":\"string\",\"password\":\"string\",\"phone\":\"string\",\"userStatus\":0}"
curl -X POST "http://localhost:8080/user" -H "accept: application/json" -H "Content-Type: application/xml" -d "<?xml version=\"1.0\" encoding=\"UTF-8\"?><User>\t<id>0</id>\t<username>string</username>\t<firstName>string</firstName>\t<lastName>string</lastName>\t<email>string</email>\t<password>string</password>\t<phone>string</phone>\t<userStatus>0</userStatus></User>"
curl -X POST "http://localhost:8080/user" -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -d "id=0&username=string&firstName=string&lastName=string&email=string&password=string&phone=string&userStatus=0"
The first(json) works, but for xml and x-www-form-urlencoded
I get:
{"timestamp":"2020-10-19T22:42:43.215+00:00","status":415,"error":"Unsupported Media Type","message":"","path":"/user"}
That response code is not in the generated default implementation, it must be thrown in the steps before.
There are similar questions already on stackoverflow, but through openapi I cannot just leave out annotations. Is there a way for me to implement a request accepting all three media types using openapi and spring boot?

get a pagingobject in http response requested over curl

Hello people i have a question about how to get JSON pagingObject in my response with a http curl get (curl running on jokto-linux-system).
i wanted to get a special page over the parameter $offset=0 and $limit=0.
But i dont know where to put the parameter to get on the right page of the serviceressource. I get all the ressources back but i need to see how much pages are used also i didnt see this too.
So my basic problem is the visibility and changing of the parameter $offset and $limit of the pagingObject of an Service/Ressource with amount of Ressourceelements.
Thank you very much for evry answer
This my basic "GET" i try: curl -i http://127.0.0.1:80/service/ressource/Elementuri
Tried to get an the object over header: curl -X GET -H "$offset" -H "$limit" http://127.0.0.1:80/service/ressource/elementuri
I tried it to set after the uri: curl -X GET http://127.0.0.1:80/service/ressource/elementuri?$offset=0&$limit=1
Dollar sign is probably not necessary.
curl http://127.0.0.1:80/service/ressource/elementuri?limit=2&offset=2

Convert Python request with image to cURL

I found this example of a API request. Unfortunately I didn't find any other example how to upload an image to the API.
As I'm not familiar with Python I'm trying to understand how to do the same in a cURL command.
import requests
auth_headers = {
'app_id': 'your_app_id',
'app_key': 'your_app_key'
}
url = 'https://XXXXXXX'
files = {
'source': open('media/test.jpg')
}
data = {
'timeout': 60
}
response = requests.post(url, files=files, data=data, headers=auth_headers)
I tried to convert it by trying out a cURL to python converter, but I don't know how to build it with the files.
In the end I want to do the request in JAVA, but I think if I would know the request in cURL I can figure it out.
Hope anyone can help me with that.
This will do it:
#!/bin/bash
args=(
-H 'app_id: your_app_id'
-H 'app_key: your_app_key'
-F 'source=#/path/to/file'
-F 'timeout=60'
'http://httpbin.org/post'
)
curl "${args[#]}"
or, as a one-liner:
curl -H 'app_id: your_app_id' -H 'app_key: your_app_key' -F 'source=#/path/to/file' -F 'timeout=60' 'http://httpbin.org/post'
Use -H to specify header fields (repeat for every field) and -F to specify form fields - either as key=value pairs, or filename=#path pairs. When -F is used, POST method is the default, and Content-Type is multipart/form-data (but that too can be overridden).

How to create campaign through Apple Search Ads API

I'm trying to create Campaign through Apple Search Ads API. So I use
curl -X POST https://api.searchads.apple.com/api/v1/campaigns \
--cert path/XXXX.p12 \
--pass **** \
-H "Authorization: orgId=xxxx" \
-d '{"budgetAmount":{"currency":"USD","amount": 50.0},"name": "weixinCampagin", "adamId":"414478124","adGroups": [{"name": "weixinCampaginAdGroup","startTime":"2017-03-17 00:00:00","defaultCpcBid": {"amount": 1,"currency":"USD"},"storeFronts": ["US"]}]}'
I got the following error messages:
{"data":null,"pagination":null,"error":{"errors":[{"messageCode":"INVALID_ATTRIBUTE_TYPE","message":"This is an invalid request. At least one field format is not readable by the system.","field":"Line#:1 Column#:50"}]}}
I have tried many times through different ways, but still not working. Is there any smart guys can help me?
Thanks in advance!
I think you need to specify that you're sending a json object.
curl \
--cert ./<FILENAME>.p12 \
--pass <PASSWORD> \
-H "Authorization: orgId=<ORG_ID>" \
-H "Content-Type: application/json" \
-d "<CAMPAIGN_DATA_FILE>.json" \
-X POST "https://api.searchads.apple.com/api/v1/campaigns"
Apart from content-type header,
The amount needs to be in string format
'{"budgetAmount":{"currency":"USD","amount": "50.0"},"name": "weixinCampagin", "adamId":"414478124","adGroups": [{"name": "weixinCampaginAdGroup","startTime":"2017-03-17 00:00:00","defaultCpcBid": {"amount": "1","currency":"USD"},"storeFronts": ["US"]}]}'
in https://developer.apple.com/library/content/documentation/General/Conceptual/AppStoreSearchAdsAPIReference/API_Overview.html
the sample also uses string for the amount item

Converting a Authenticated curl request to Apache Camel Request

curl -s -S -u user123:321pass https://12.15.13.12:3216 --data
'<?xml version="1.0" encoding="UTF-8"?><data>Hello Man</data>' -H 'Content-Type: text/xml' -k
I need to change this to a Apache Camel route call like :-
private ProducerTemplate producer;// there are setters for this.
producer.requestBodyAndHeaders(endpointUri, requestBody,addHeaders, String.class);
Main question is how do I pass username and password with this requestBodyAndHeaders.I tried passing through headers(header being map, key value pairs)

Categories

Resources