I am developing a application in Spring-data-rest. I am testing the POST requests from POSTMAN client to test whether the data is inserting into DB.In my DB i have a cartItems table. I am able to POST the data while i POST the JSON as Follows: merchandise, cart and merchandiseType are foreign key references.
{
"rate": 500,
"quantity": 1,
"amount": 500,
"createdAt": "2015-04-12T23:40:00.000+0000",
"updatedAt": "2015-04-14T21:35:20.000+0000",
"merchandise": "http://localhost:8080/sportsrest/merchandises/10",
"cart":"http://localhost:8080/sportsrest/carts/902",
"merchandiseType":"http://localhost:8080/sportsrest/merchandiseTypes/1"
}
But while i POST the data as below i am getting error: Instead of URL for merchandise i placed the merchandise JSON which i already tested the POST request for merchandise table JSON:
{
"rate": 500,
"quantity": 1,
"amount": 500,
"createdAt": "2015-04-12T23:40:00.000+0000",
"updatedAt": "2015-04-14T21:35:20.000+0000",
"merchandise": {
"id": 4,
"shortDescription": "white football",
"rate": 500,
"updatedAt": "2015-04-24T18:30:00.000+0000",
"createdAt": "2015-04-20T18:30:00.000+0000",
"longDescription": "test description for binary 1001",
"type": "1"
},
"cart":"http://localhost:8080/sportsrest/carts/902",
"merchandiseType":"http://localhost:8080/sportsrest/merchandiseTypes/1"
}
I am getting following ERROR:
{
"cause": {
"cause": {
"cause": null,
"message": "Template must not be null or empty!"
},
"message": "Template must not be null or empty! (through reference chain: co.vitti.sports.bean.CartItem[\"merchandise\"])"
},
"message": "Could not read JSON: Template must not be null or empty! (through reference chain: co.vitti.sports.bean.CartItem[\"merchandise\"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Template must not be null or empty! (through reference chain: co.vitti.sports.bean.CartItem[\"merchandise\"])"
}
Can some one please help me to why i am getting this error.
Thanks.
I guess you didn't provide the Content-Type: application/json header.
Try to annotate your "MerchandiseRepository" with "#RestResource(exported = false)".
Related
I am using the following SDK to search for and purchase flights via Amadeus:
https://github.com/autotune/amadeus/pull/1/files
This was a previously abandoned project I have decided to take on and make work. As part of that project I am trying to purchase a ticket in the sandbox environment and getting the following error:
{
"errors": [
{
"code": 477,
"title": "INVALID FORMAT",
"detail": "carrier code is a 2 or 3 alphanum except YY and YYY",
"source": {
"pointer": "/data/flightOffers[0]/itineraries[1]/segments[0]/operating/carrierCode",
"example": "AF"
},
"status": 400
}
]
}
Here is the json data being sent:
{
"type": "flight-order",
"travelers": [
{
"id": "1",
"dateOfBirth": "1990-02-15",
"name": {
"firstName": "Foo",
"lastName": "Bar"
},
"gender": "MALE",
"contact": {
"emailAddress": "foo#bar.com",
"phones": [
{
"deviceType": "MOBILE",
"countryCallingCode": "33",
"number": "5555555555"
}
]
}
}
],
"ticketingAgreement": {
"option": "DELAY_TO_CANCEL",
"delay": "6D"
},
"remarks": {},
"operating": {
"carrierCode": "UA"
}
}
Any help appreciated!
The error suggests that the sent payload is invalid. I'd advice you use a tool like Curl or Postman to verify you're using the right API documentation, before debugging actual code.
After further reading your PR and checking the API reference at :
https://developers.amadeus.com/self-service/category/air/api-doc/flight-create-orders/api-reference
I think you need to confirm that the Carrier code being passed is available in the segments under:
flightOffers > itineraries > segments
Although the API reference doesn't have operating > carrierCode like you used in the data sent, my guess after seeing the API error response you shared is that they are performing a check against the flight offers passed.
I suggest you check the results gotten when you call the flightOffers and also add it to the payload sent to the sandbox.
I am using Microsoft Graph Delta functionality to track changes in a message folder, I built my request referring to the Delta documentation
When I received the response, it has duplicate key id in it.
Request URL:
/v1.0/users/me/mailFolders('inbox')/messages/delta?$top=2&$select=id
and this is the response I am receiving:
{
"#odata.context":
"https://graph.microsoft.com/v1.0/$metadata#Collection(message)",
"#odata.nextLink":
"https://graph.microsoft.com/v1.0/users/me/mailFolders('inbox')/messages/delta?$skiptoken={token}",
"value": [
{
"#odata.type": "#microsoft.graph.message",
"#odata.etag": "W/\"{etag}\"",
"id": "xxxxxxxxxx",
"id": "xxxxxxxxxx"
},
{
"#odata.type": "#microsoft.graph.message",
"#odata.etag": "W/\"{etag}",
"id": "xxxxxxx",
"id": "xxxxxxx"
}
]
}
Is there something I am doing wrong or missing here? TIA
In my MySQL database, I have a table named Messages which is having 4 rows , with unique message ID as 1,2,3,4.
When using REST Api I am accessing collection resource:
http://localhost:8080/messenger/webapi/messages
I am getting all the message entries as JSON , which is expected;
Please find below :
[
{
"author": "Vineet",
"creation": "09/12/2017",
"id": 1,
"message": "Message1"
},
{
"author": "Puneet",
"creation": "09/12/2017",
"id": 2,
"message": "Message2"
},
{
"author": "Dad",
"creation": "09/12/2017",
"id": 3,
"message": "Message3"
},
{
"author": "Mom",
"creation": "09/12/2017",
"id": 4,
"message": "Message4"
}
]
When using REST Api I am accessing the individual resource:
http://localhost:8080/messenger/webapi/messages/1 or
http://localhost:8080/messenger/webapi/messages/2 or
http://localhost:8080/messenger/webapi/messages/3 or
http://localhost:8080/messenger/webapi/messages/4
I am getting the expected response for every single resource e.g. for 1
{
"author": "Vineet",
"creation": "09/12/2017",
"id": 1,
"message": "Message1"
}
Problem : When I am trying to access url :
http://localhost:8080/messenger/webapi/messages/9 , where 9 is a resource that never exists in database.
I am getting a blank page or the last loaded page. and The HTTP Code coming is : 204.
When "9" id is not present , why is not there 404 message ?
Why 204 ?
The route is correct and only the paramerter which you have provided is wrong so there is no way you will get a 404 which is page not found but the request has hit service so it a successful service hit
I hope you can handle the error in exception handling.
I am new to SoapUI, I ran a post request in it for creating a user. It returned success code 201 (Same as Postman), which should be, but it is not showing any data under JSON tab in Response window. Where it should show some data as the request is returning data in JSON format in Postman.
The response returned in the Postman is:
{
"id": 107,
"creationTime": "2017-06-23T12:55:13.870+0000",
"lastUpdateTime": "2017-06-23T12:55:13.870+0000",
"username": "Testuserr",
"name": null,
"firstname": null,
"type": null,
"avatar": null,
"mobile": null,
"office": null,
"email": null,
"enabled": false,
"_links": {
"self": {
"href": "http://server/...../user/107"
},
"consultantUser": {
"href": "http://server/...../user/107"
},
"roles": {
"href": "http://server/...../user/107/roles"
},
"regularRole": {
"href": "http://server/...../user/107/regularRole"
},
"userSkills": {
"href": "http://server/...../user/107/userSkills"
},
"experiences": {
"href": "http://server/...../user/107/experiences"
},
"educations": {
"href": "http://server/...../user/107/educations"
},
"assignments": {
"href": "http://server/...../user/107/assignments"
},
"certificats": {
"href": "http://server/...../user/107/certificats"
},
"organisation": {
"href": "http://server/...../user/107/organisation"
},
"sections": {
"href": "http://server/...../user/107/sections"
}
}
}
Where in SoapUI it shows nothing.
But if am running the same request 2nd time it shows
{
"cause": {
"cause": {
"cause": null,
"message": "Duplicate entry 'TestName20181' for key UK_r43af9ap4edm43mmtq01oddj6'"
},
"message": "could not execute statement"
}
Which is same as Postman, and should be. Then what is the problem with first time?
Help me if there was anything, I was missing during execution ... thanks...
I just figured out the difference, the content-type/media-type is blank for 201/200.Postman intelligently detects the content-type as json and displays.
I just walked to Developer desk to confirm if root cause is right and yes it is,
For 400 (negative tests):
In the exception handler class, they return with media type as
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
return new ResponseEntity(errors, responseHeaders, HttpStatus.BAD_REQUEST);
But for 201/200 (positive tests):
They dont set contentType, its global or default setting as per spring boot framework.
Solution#1: So DEV has to explicitly set the contentType as JSON for SOAP UI to display the json body so that we can write test scripts in it or else you will only see null response in SOAPUI though it is 200/201.
Solution#2: In your SOAP UI request, add a parameter in 'Header' as Accept = application/json. This will solve your problem without dev support.
Thanks to https://community.smartbear.com/t5/SoapUI-Pro/Change-the-reponse-from-content-type-text-html-to-text-json/td-p/39628
Screenshot
I would like to handle assertion property content according to below responses, for both success and failure.
Success response:
{
"task": "userLogin",
"response": {
"code": 0,
"status": "success",
"error_message": "",
"success_message": "",
"data": {
"userId": "65",
"username": "indian",
"email": "test#gmail.com",
"token": "b0aef6139ffdc1041e01f7587a0dcf61",
"userType": "trial",
"profile_picture": "test.png"
}
}
}
Failure response: will have only the data node missing, and remaining nodes will be present.
"data":
{
"userId": "65",
"username": "indian",
"email": "test#gmail.com",
"token": "b0aef6139ffdc1041e01f7587a0dcf61",
"userType": "trial",
"profile_picture": "test.png"
}
You can use a very simple XPath assertion, keeping in mind that internally SoapUI converts everything into XML representation.
XPath:
exists(//*:data)
Expected:
true
Update based on your comments.
Your original requirement was not clear. The node is present it is just empty. In that case the XPath assertion would be:
empty(//*:data)
Expected:
false
Handy XPath reference.