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

Enhance Quarkus support for Spring @RequestParam annotated parameters. #45233

Merged
merged 1 commit into from
Mar 13, 2025

Conversation

aureamunoz
Copy link
Member

@aureamunoz aureamunoz commented Dec 20, 2024

Related to #43705

Several improvements have been implemented to enhance Quarkus support for Spring @RequestParam annotated parameters.

Support for Map and Multimap in RESTEasy

The handleMapParam method has been added to extract all URL parameters and store them in a Jakarta Map or Multimap, depending on the user’s code definition.
A new ParameterConverter (MapConverter) has been introduced to transform received parameters into a Map or Multimap when the ParameterHandler detects that the endpoint expects this type of structure.
The ResteasyReactiveRequestContext.getQueryParameter method has been modified to support these new data types.

Retrieving parameters without knowing their names

A new getParametersMap method has been added to the API, allowing retrieval of all URL parameters without requiring prior knowledge of their names.
This method integrates with ParamExtractor, which does not work directly with endpoint parameters but instead processes their characteristics (name, single/multi-value, encoding, etc.).
Since Map and Multimap cannot always be distinguished (both may contain multiple values per key), the method returns a unified Map<String, List<String>>, allowing ParamHandler to process it consistently.

Support for Spring’s MultiValueMap

A dedicated extractor, SpringMultiValueMapParamExtractor, has been created to read request parameters and store them in a Spring MultiValueMap<String, String>.
This was implemented using MethodScannerBuildItem, which detects methods with @RequestParam annotations. If the parameter type is MultiValueMap<String, String>, a specific extractor is instantiated to convert request parameters accordingly.
As a result, users can now define methods in a Quarkus @RestController with a MultiValueMap<String, String> parameter, and it will behave just like in Spring:

@PostMapping("/api/foos")
@ResponseBody
public String handle(@RequestParam MultiValueMap<String, String> params) {
    return params.toString();
}

Making @RequestParam required by default

In Spring, parameters annotated with @RequestParam are required by default unless explicitly marked as optional.
MethodScannerBuildItem is used to enforce this behavior, ensuring that parameters must have a value unless explicitly declared as optional.
If a required parameter is missing, SpringRequestParamHandler handles the response by returning a 400 Bad Request error.

Supporting multiple values in @RequestParam separated by comma

Spring allows @RequestParam List<String> to receive multiple values in a comma-separated format from the URL.
To replicate this behavior, the SpringMultiValueListParamExtractor has been added, which automatically converts these values into a List<String>.

Copy link

quarkus-bot bot commented Dec 20, 2024

Thanks for your pull request!

Your pull request does not follow our editorial rules. Could you have a look?

  • title should preferably start with an uppercase character (if it makes sense!)
  • description should not be empty, describe your intent or provide links to the issues this PR is fixing (using Fixes #NNNNN) or changelogs

This message is automatically generated by a bot.

@quarkus-bot quarkus-bot bot added the area/spring Issues relating to the Spring integration label Dec 20, 2024
@aureamunoz aureamunoz force-pushed the support-request-param-map-43705 branch from 57d15ac to 0ee9c51 Compare January 3, 2025 13:42
@quarkus-bot quarkus-bot bot added the area/rest label Jan 3, 2025
@aureamunoz aureamunoz force-pushed the support-request-param-map-43705 branch 4 times, most recently from 22e5638 to 88ef3ec Compare January 10, 2025 14:11
@aureamunoz aureamunoz force-pushed the support-request-param-map-43705 branch 2 times, most recently from 0810e13 to 2199afb Compare January 17, 2025 16:24
@aureamunoz aureamunoz force-pushed the support-request-param-map-43705 branch 6 times, most recently from a860066 to d09ef82 Compare February 5, 2025 16:21
@aureamunoz aureamunoz changed the title wip 43705 Enhance Quarkus support for Spring @RequestParam annotated parameters. Feb 5, 2025
@aureamunoz aureamunoz marked this pull request as ready for review February 5, 2025 16:23
@aureamunoz
Copy link
Member Author

cc @geoand @cescoffier

This comment has been minimized.

This comment has been minimized.

@aureamunoz aureamunoz force-pushed the support-request-param-map-43705 branch from d09ef82 to 2662b14 Compare February 21, 2025 11:05

This comment has been minimized.

This comment has been minimized.

@aureamunoz aureamunoz force-pushed the support-request-param-map-43705 branch from 2a06da6 to 0fd1911 Compare February 24, 2025 09:46

This comment has been minimized.

@aureamunoz aureamunoz force-pushed the support-request-param-map-43705 branch from 0fd1911 to 9fcc868 Compare February 26, 2025 14:18

This comment has been minimized.

@aureamunoz aureamunoz force-pushed the support-request-param-map-43705 branch from 9fcc868 to f049005 Compare March 3, 2025 16:26

This comment has been minimized.

@aureamunoz aureamunoz force-pushed the support-request-param-map-43705 branch from f049005 to 69a1265 Compare March 5, 2025 10:37

This comment has been minimized.

@aureamunoz aureamunoz force-pushed the support-request-param-map-43705 branch from 69a1265 to 0e1771a Compare March 10, 2025 17:34

This comment has been minimized.

@aureamunoz aureamunoz force-pushed the support-request-param-map-43705 branch from 0e1771a to 5b3f121 Compare March 11, 2025 11:09

This comment has been minimized.

@gsmet
Copy link
Member

gsmet commented Mar 11, 2025

@aureamunoz once you're done, it's probably a good idea to squash all your commits :)

@aureamunoz
Copy link
Member Author

@aureamunoz once you're done, it's probably a good idea to squash all your commits :)

Yes, of course

@aureamunoz aureamunoz force-pushed the support-request-param-map-43705 branch from 7bea8ed to 503084a Compare March 11, 2025 14:37

This comment has been minimized.

@aureamunoz aureamunoz force-pushed the support-request-param-map-43705 branch from 503084a to 1c63455 Compare March 13, 2025 12:09
@aureamunoz
Copy link
Member Author

I refactored with your suggestions and squashed commits

@aureamunoz aureamunoz requested a review from geoand March 13, 2025 12:12
Copy link
Contributor

@geoand geoand left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link

quarkus-bot bot commented Mar 13, 2025

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit 1c63455.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.


Flaky tests - Develocity

⚙️ JVM Tests - JDK 17

📦 extensions/smallrye-reactive-messaging-kafka/deployment

io.quarkus.smallrye.reactivemessaging.kafka.deployment.testing.KafkaDevServicesContinuousTestingWorkingAppPropsTestCase.testContinuousTestingScenario3 - History

  • io.quarkus.builder.BuildException: Build failure: Build failed due to errors [error]: Build step io.quarkus.redis.deployment.client.DevServicesRedisProcessor\#startRedisContainers threw an exception: java.lang.RuntimeException: org.testcontainers.containers.ContainerLaunchException: Container startup failed for image docker.io/redis:7 at io.quarkus.redis.deployment.client.DevServicesRedisProcessor.startRedisContainers(DevServicesRedisProcessor.java:124) at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:732) at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:856) - java.lang.RuntimeException
java.lang.RuntimeException: 
io.quarkus.builder.BuildException: Build failure: Build failed due to errors
	[error]: Build step io.quarkus.redis.deployment.client.DevServicesRedisProcessor#startRedisContainers threw an exception: java.lang.RuntimeException: org.testcontainers.containers.ContainerLaunchException: Container startup failed for image docker.io/redis:7
	at io.quarkus.redis.deployment.client.DevServicesRedisProcessor.startRedisContainers(DevServicesRedisProcessor.java:124)
	at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:732)
	at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:856)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:255)
	at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)

@geoand geoand merged commit 746f5eb into quarkusio:main Mar 13, 2025
53 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.22 - main milestone Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest area/spring Issues relating to the Spring integration triage/flaky-test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants