pingidentity / scim2

The UnboundID SCIM 2.0 SDK for Java
185 stars 75 forks source link

PATCH request returns HTTP Status 415 #131

Open beldahanit opened 5 years ago

beldahanit commented 5 years ago

Describe the bug A PATCH request to my SCIM service returns HTTP 415 error status.

To Reproduce

The service method is defined in the same way as in the example: TestSingletonResourceEndpoint.java

@Path("{id}")
@PATCH
@Consumes({MEDIA_TYPE_SCIM, MediaType.APPLICATION_JSON})
@Produces({MEDIA_TYPE_SCIM, MediaType.APPLICATION_JSON})
public ScimResource modify(@PathParam("id") final String id, final PatchRequest patchRequest, @Context final UriInfo uriInfo) throws ScimException
{
...
}

The @PATCH annotation is pointing to the class: com.unboundid.scim2.server.PATCH Then the PATCH request (tested with Postman and via curl) looks as follows:

PATCH /IamScimServiceProvider/v2/Users/M0088976 HTTP/1.1
Host: host:8080
Authorization: Basic XXXXXXXXXXXXXXXXXXX==
Content-Type: application/scim+json
Accept: application/scim+json
User-Agent: PostmanRuntime/7.17.1
Cache-Control: no-cache
Postman-Token: 80d69005-dcae-428f-a833-658fd47855e3,725f6a51-4377-4d7d-9383-8f5cea822277
Host: host:8080
Accept-Encoding: gzip, deflate
Content-Length: 201
Connection: keep-alive
cache-control: no-cache

{
     "schemas":
      ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
     "Operations": [{
     "op":"remove",
     "path":"emails[type eq \"work\" and value ew \"example.com\"]"
     }]
}

Received response:

<h1>HTTP Status 415 – Nicht unterstützter Media-Type</h1>
    <hr class="line" />
    <p><b>Type</b> Status Report</p>
    <p><b>Message</b> Unsupported Media Type</p>
    <p><b>Beschreibung</b> The origin server is refusing to service the request because the payload is in a format not
        supported by this method on the target resource.</p>

Expected behavior The service should not return HTTP 415 as the payload and Headers comply (hopefully) with the https://tools.ietf.org/html/rfc7644

Additional context

FelixSchmitt-IDnow commented 5 years ago

Check the code you are using!

If you are looking at the stuff you've posted you will see:

Content-Type: applicatiosn/scim+json

There is an additional 's' character.

beldahanit commented 5 years ago

Sorry that was a typo when composing the example. I have corrected it above. It is actually throwing this error with the correct: Content-Type: application/scim+json

beldahanit commented 5 years ago

I was able to solve this issue by adding dependent jar files

to the application classpath. These files provide Jersey an ability to serialize and deserialize JSON request bodies.

Another option is to add a dependency artefact to the pom.xml file:

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
    <version>2.xx</version>
</dependency>