quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.82k stars 2.69k forks source link

Spring Web @RequestHeader(Map<String,String>) throws RuntimeException #14051

Open jclingan opened 3 years ago

jclingan commented 3 years ago

Describe the bug I'm trying to access all request headers using Spring @RequestHeader in the same way that @Context HttpHeaders headers would provide access to all request headers.

When starting the application with mvn quarkus:dev, I get the following exception

Caused by: java.lang.RuntimeException: RESTEASY003875: Unable to find a constructor that takes a String param or a valueOf() or fromString() method for javax.ws.rs.HeaderParam("headers") on public java.lang.String org.acme.SpringGreetingController.hello(java.util.Map) for basetype: java.util.Map

Expected behavior A populated Map with HTTP headers, preferably a MultiValuedMap.

Actual behavior Above exception.

To Reproduce

See reproducer. Note, I'd like to use the Spring MultiValueMap, although the reproducer uses a Map. The reproducer is literally a project generated from code.quarkus.io with the Spring Web extension, with the hello() method updated as follows;

    public String hello(@RequestHeader MultiValueMap<String, String> headers) {
        headers.forEach((key, value) -> {
            System.out.println(key + "->" + value);
        })
ghost commented 3 years ago

/cc @geoand

geoand commented 3 years ago

Thanks for reporting @jclingan!

This will be a whole a lot easier to fix when we pivot the spring web compatibility to RESTEasy Reactive, so unless you really really need this soon, I'd rather wait.

jclingan commented 3 years ago

This is for the book Ken and I are writing. Yeah, shameless plug, LOL. I can put a NOTE in the book for now and wait for the fix.

geoand commented 3 years ago

Great, thanks 👍

jclingan commented 3 years ago

Any update?

geoand commented 3 years ago

Not yet.

I hope to rebase the Spring Web support on RESTEasy Reactive some time before 2.x

geoand commented 3 years ago

I will likely work on this after the 2.2 stabilization release is out

jclingan commented 3 years ago

Nudge :-)

geoand commented 3 years ago

I had to revert the "rebase" onto RESTEasy Reactive. I will hopefully get back to it before 2.5

liangyuanpeng commented 2 years ago

@geoand Thanks for your work and how can we get the request headers if we can't use @RequestHeader

I have try this and also failed. It just tell me javaax.ws.rs.NorSupportException

 @GetMapping
  public String hello(@Context HttpHeaders headers) {

Thanks any help.


update

The code should be:

@Context HttpHeaders headers
 @GetMapping
  public String hello() {
   // use headers to do something
}
geoand commented 2 years ago

@liangyuanpeng yup, as you mention one can mix and match the Spring and JAX-RS annotations and types.

aureamunoz commented 2 weeks ago

Hi! is this issue still relevant? @jclingan @liangyuanpeng If yes, can I have a reproducer? Otherwise, can I close it?