This is my code by modifying quarkus-quickstarts-main:
package org.acme.spring.web;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@RestController
public class GreetingController {
@PostMapping("/post")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response allParams(String smell,
@RequestHeader HttpHeaders headers) {
return Response.ok("OK").build();
}
}
Exception during startup:
Caused by: java.lang.RuntimeException: Failed to process method 'org.acme.spring.web.GreetingController#allParams'
at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createResourceMethod(EndpointIndexer.java:703)
at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createEndpoints(EndpointIndexer.java:405)
at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createEndpoints(EndpointIndexer.java:286)
... 12 more
Caused by: java.lang.RuntimeException: Could not create converter for org.springframework.http.HttpHeaders for method javax.ws.rs.core.Response allParams(java.lang.String smell, org.springframework.http.HttpHeaders headers) on class org.acme.spring.web.GreetingController of type QUERY
at org.jboss.resteasy.reactive.server.processor.ServerEndpointIndexer.handleOtherParam(ServerEndpointIndexer.java:327)
at org.jboss.resteasy.reactive.server.processor.ServerEndpointIndexer.handleOtherParam(ServerEndpointIndexer.java:92)
at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.extractParameterInfo(EndpointIndexer.java:1335)
at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createResourceMethod(EndpointIndexer.java:536)
... 14 more
Caused by: java.lang.RuntimeException: Failed to find converter for org.springframework.http.HttpHeaders
at org.jboss.resteasy.reactive.server.processor.generation.converters.GeneratedConverterIndexerExtension.extractConverterImpl(GeneratedConverterIndexerExtension.java:106)
at org.jboss.resteasy.reactive.server.processor.ServerEndpointIndexer.extractConverter(ServerEndpointIndexer.java:513)
at org.jboss.resteasy.reactive.server.processor.ServerEndpointIndexer.handleOtherParam(ServerEndpointIndexer.java:323)
... 17 more
Can someone help how to make the HttpHeaders work?
I tried several alternatives but not working.
CodePudding user response:
You are mixing JAX-RS and Spring Web types which is not going to work.
You should instead do something like:
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("")
public class GreetingController {
@PostMapping("/post")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response allParams(String smell,
@Context HttpHeaders headers) {
return Response.ok("OK").build();
}
}