jersey 2: How to create custom HTTP param binding

后端 未结 4 2132
醉梦人生
醉梦人生 2020-12-05 15:08

I am trying to create a custom http param binding for my restful service. Please see the example below.

@POST
@Path(\"/user/{userId}/orders\")
@Produces(Medi         


        
4条回答
  •  旧时难觅i
    2020-12-05 15:16

    If your need is to retrieve all the http headers binding into one object, a solution could be to use the @Context annotation to get javax.ws.rs.core.HttpHeaders; which contains the list of all request headers.

    @POST
    @Path("/user/{userId}/orders")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public MyResult foo(@PathParam("userId") String someString, @Context HttpHeaders headers){
     // You can list all available HTTP request headers via following code :
       for(String header : headers.getRequestHeaders().keySet()){
         System.out.println(header);
       }
    }
    

提交回复
热议问题