Skip to content

Issue 2495: Response error codes handling for multi link request #2497

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

anayonkars
Copy link

This PR is to solve issue 2495.

It handles correction of error codes for single association resource. However, it doesn't (yet) handles multiple association resource.

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

In RepositoryPropertyReferenceController, handled response code for empty links.
Instead of IllegalArgumentException and HTTP 500, now it throws HttpMessageNotReadableException and HTTP 400

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>
In RepositoryPropertyReferenceController, handled response code for multiple links.
Instead of IllegalArgumentException and HTTP 500, now it throws HttpMessageNotReadableException and HTTP 400

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>
In RepositoryPropertyReferenceController, handled response code where no links are sent (List of Map).
Instead of IllegalArgumentException and HTTP 500, now it throws HttpMessageNotReadableException and HTTP 400

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>
Fixed test cases

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>
@anayonkars anayonkars marked this pull request as ready for review June 29, 2025 17:52
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 29, 2025
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 30, 2025
Copy link
Member

@mp911de mp911de left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting a pull request. I added a few comments. Right now, the PR causes more work on our side than it actually helps. Please apply formatting and resolve the commented-out code issues.

Please also squash all commits into one, feel free to force-push.


Function<ReferencedProperty, RepresentationModel<?>> handler = prop -> {

Class<?> propertyType = prop.property.getType();

if (prop.property.isCollectionLike()) {
/*if(HttpMethod.PATCH.equals(requestMethod)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is new code here being commented out?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's supposed to handle multiple association issue (returning HTTP 204 in case of empty/incorrect header). I've removed the commented code.

@@ -237,17 +237,35 @@ public ResponseEntity<RepresentationModel<?>> followPropertyReferenceCompact(Roo
consumes = { MediaType.APPLICATION_JSON_VALUE, SPRING_DATA_COMPACT_JSON_VALUE, TEXT_URI_LIST_VALUE })
public ResponseEntity<? extends RepresentationModel<?>> createPropertyReference(
RootResourceInformation resourceInformation, HttpMethod requestMethod,
@RequestBody(required = false) CollectionModel<Object> incoming, @BackendId Serializable id,
@RequestBody(required = false) CollectionModel<Object> incoming,
@RequestHeader(required = false) HttpHeaders requestHeaders,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -78,6 +77,7 @@ class RepositoryPropertyReferenceController /*extends AbstractRepositoryRestCont

private static final String BASE_MAPPING = "/{repository}/{id}/{property}";
private static final Collection<HttpMethod> AUGMENTING_METHODS = Arrays.asList(HttpMethod.PATCH, HttpMethod.POST);
private static final List<MediaType> SUPPORTED_CONTENT_TYPE = Arrays.asList(MediaType.APPLICATION_JSON, TEXT_URI_LIST);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We use tab indents, not spaces.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

/*@Test // GH-2495
void rejectsInvalidContentTypeForSingleValuedAssociation() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding new commented-out code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's supposed to handle multiple association issue (returning HTTP 204 in case of empty/incorrect header). I've removed the commented code.

Fixed merge conflicts

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>

DATAREST-2495

Cleaned up unnecessary code

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>

DATAREST-2495
Fixed test cases

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>

DATAREST-2495
In RepositoryPropertyReferenceController, handled response code where no links are sent (List of Map).
Instead of IllegalArgumentException and HTTP 500, now it throws HttpMessageNotReadableException and HTTP 400

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>

DATAREST-2495
In RepositoryPropertyReferenceController, handled response code for multiple links.
Instead of IllegalArgumentException and HTTP 500, now it throws HttpMessageNotReadableException and HTTP 400

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>

DATAREST-2495
In RepositoryPropertyReferenceController, handled response code for empty links.
Instead of IllegalArgumentException and HTTP 500, now it throws HttpMessageNotReadableException and HTTP 400

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>

# Conflicts:
#	spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceController.java
#	spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceControllerUnitTests.java
Fixed merge conflicts

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>

DATAREST-2495

Cleaned up unnecessary code

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>

DATAREST-2495
Fixed test cases

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>

DATAREST-2495
In RepositoryPropertyReferenceController, handled response code where no links are sent (List of Map).
Instead of IllegalArgumentException and HTTP 500, now it throws HttpMessageNotReadableException and HTTP 400

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>

DATAREST-2495
In RepositoryPropertyReferenceController, handled response code for multiple links.
Instead of IllegalArgumentException and HTTP 500, now it throws HttpMessageNotReadableException and HTTP 400

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>

DATAREST-2495
In RepositoryPropertyReferenceController, handled response code for empty links.
Instead of IllegalArgumentException and HTTP 500, now it throws HttpMessageNotReadableException and HTTP 400

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>

# Conflicts:
#	spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceController.java
#	spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceControllerUnitTests.java

DATAREST-2495
Fixed test cases

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>

DATAREST-2495
In RepositoryPropertyReferenceController, handled response code where no links are sent (List of Map).
Instead of IllegalArgumentException and HTTP 500, now it throws HttpMessageNotReadableException and HTTP 400

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>

DATAREST-2495
In RepositoryPropertyReferenceController, handled response code for multiple links.
Instead of IllegalArgumentException and HTTP 500, now it throws HttpMessageNotReadableException and HTTP 400

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>

DATAREST-2495
In RepositoryPropertyReferenceController, handled response code for empty links.
Instead of IllegalArgumentException and HTTP 500, now it throws HttpMessageNotReadableException and HTTP 400

Signed-off-by: Anayonkar Shivalkar <anayonkar.shivalkar@gmail.com>
@anayonkars anayonkars requested a review from mp911de June 30, 2025 15:23
@anayonkars
Copy link
Author

Apologies for formatting issues. I was able to configure eclipse formatter in intellij. However, couldn't fix import order. Please review and let me know in case of any issues.

…nse-handling-for-multi-link-request' into bug/spring-projectsGH-2495-Response-handling-for-multi-link-request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants