You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to implement a POST requests that expects a JSON object in the Request Body like in the Pet Store example. To verify I checked out the Pet-Store jersey sample, but it doesn't work either.
Expected behavior
The Request body should be mapped to the Method Parameter of the POST method.
Actual behavior
When an Custom Object is expected as parameter the application returns an 415 Unsupported Media Type Status Code. Expecting a String works. It also works when I run an Unit test that does the request, but not when it is locally deployed using SAM.
Steps to reproduce
Check out and run the Jersey Pet Store example
Do a POST Request to add a Pet
Full log output
* Preparing request to http://localhost:3000/pets/
* Using libcurl/7.57.0-DEV OpenSSL/1.0.2o zlib/1.2.11 libssh2/1.7.0_DEV
* Current time is 2019-09-27T10:11:37.598Z
* Disable timeout
* Enable automatic URL encoding
* Disable SSL validation
* Enable cookie sending with jar of 0 cookies
* Found bundle for host localhost: 0x1a39a0b9680 [can pipeline]
* Re-using existing connection! (#4) with host localhost
* Connected to localhost (127.0.0.1) port 3000 (#4)
> POST /pets/ HTTP/1.1
> Host: localhost:3000
> User-Agent: insomnia/6.6.2
> Content-Type: application/json
> Accept: */*
> Content-Length: 135
| {
| "id": "bfbfbb42-2198-4e5d-99b9-03533a09c123",
| "breed": "Dalmatian",
| "name": "Bella",
| "dateOfBirth": 1209031368188
| }
* upload completely sent off: 135 out of 135 bytes
< HTTP/1.1 415 Unsupported Media Type
< Content-Type: application/json
< Date: Fri, 27 Sep 2019 10:11:40 GMT
< Content-Length: 0
* Connection #4 to host localhost left intact
The text was updated successfully, but these errors were encountered:
Jersey returns 415 (as per the Jax Rs specifications) when it cannot find a resource method that matches the the request content type - ie has a @Consumes annotation that matches the request's content type. The sample clearly has the correct annotation and your request is sending the correct Content-Type header. This leads me to believe that for some reason Jersey does not have access to the request headers. Up until not too long ago, there was a well documented issue with SAM CLI not supporting API Gateway's new multiValueHeaders property. The fix for this was released in version 0.17.0 of SAM CLI.
The whole long detour is to say: If you are using SAM CLI, could you make sure that you are running at least version 0.17.0?
Scenario
I want to implement a POST requests that expects a JSON object in the Request Body like in the Pet Store example. To verify I checked out the Pet-Store jersey sample, but it doesn't work either.
Expected behavior
The Request body should be mapped to the Method Parameter of the POST method.
Actual behavior
When an Custom Object is expected as parameter the application returns an 415 Unsupported Media Type Status Code. Expecting a String works. It also works when I run an Unit test that does the request, but not when it is locally deployed using SAM.
Steps to reproduce
Full log output
The text was updated successfully, but these errors were encountered: