Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

415 Error on POST with Request Object #282

Closed
ssindelar opened this issue Sep 27, 2019 · 2 comments
Closed

415 Error on POST with Request Object #282

ssindelar opened this issue Sep 27, 2019 · 2 comments

Comments

@ssindelar
Copy link

  • Framework version: 1.3.2
  • Implementations: Jersey
  • OS: Windows 10

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

  1. Check out and run the Jersey Pet Store example
  2. 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
@sapessi
Copy link
Collaborator

sapessi commented Sep 27, 2019

Is this running through the SAM CLI @ssindelar?

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?

@ssindelar
Copy link
Author

ssindelar commented Oct 1, 2019

I followed the README.md and installed SAM through npm. But instead of a new version it installed 0.2.11.

With the current SAM version it works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants