Skip to content

The response handling when operating on the associated resource relationship seems incorrect? #2495

Open
@ximinghui

Description

@ximinghui

Take the following Plan entity class as a demonstration:

@Data
@Entity
public class Plan {

    @Id
    @GeneratedValue
    private UUID id;

    private String name;

    @ManyToOne
    private Process process;

    @OneToMany
    private Set<PlanItem> items;

}

Single-association resource

When I try to request:
curl -v -X PUT http://127.0.0.1:8080/plans/{id}/process
or
curl -v -X PUT http://127.0.0.1:8080/plans/{id}/process -H "Content-Type: application/json"
or
curl -v -X PUT http://127.0.0.1:8080/plans/{id}/process -H "Content-Type: text/uri-list"

I got the exact same response:

*   Trying 127.0.0.1:8080...
* Connected to 127.0.0.1 (127.0.0.1) port 8080
* using HTTP/1.x
> PUT /plans/765b7c48-f0e1-402b-9bd1-74448fd1a93d/process HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/8.13.0
> Accept: */*
>
< HTTP/1.1 500
< Vary: Origin
< Vary: Access-Control-Request-Method
< Vary: Access-Control-Request-Headers
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Sat, 21 Jun 2025 20:22:55 GMT
< Connection: close
<
{"cause":null,"message":"Must send only 1 link to update a property reference that isn't a List or a Map."}* we are done reading and this is set to close, stop send
* abort upload
* shutting down connection #0

We got a 500 (Internal Server Error) response here, maybe it should have been 400 (Bad Request)?

For the case where "Content-Type" is not present or its value is not "text/uri-list", perhaps a "410 (Unsupported Media Type)" response would be better?


Multiple-association resources

When I PUT, POST, or PATCH a multi-relational resource (http://127.0.0.1:8080/plans/{id}/items) without a request body, whether there is no Content-Type header or Content-Type: application/json or Content-Type: text/uri-list, the response is always 204 (this phenomenon is also extremely deceptive.):

*   Trying 127.0.0.1:8080...
* Connected to 127.0.0.1 (127.0.0.1) port 8080
* using HTTP/1.x
> PUT /plans/765b7c48-f0e1-402b-9bd1-74448fd1a93d/items HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/8.13.0
> Accept: */*
>
< HTTP/1.1 204
< Vary: Origin
< Vary: Access-Control-Request-Method
< Vary: Access-Control-Request-Headers
< Date: Sat, 21 Jun 2025 20:32:44 GMT
<
* Connection #0 to host 127.0.0.1 left intact

Should we also respond with 410 (Unsupported Media Type) when Content-Type does not exist or its value is not "text/uri-list"?

In addition, considering that the semantics of POST is to create new data, should the response be 400 (Bad Request) if the POST request does not carry a request body?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions