0

i have write a REST web service in java.But If I want to receive Accept : application/json header ,how to do that?If I want to receive more custom header like "CDMI-Speciation-1.0" , how can i receive both headers?

My web service is like that:

@PUT
@Consumes("application/json")
@Produces("application/json")
public vodi doPut(){.....}

My request should be like : curl --header "Content-Type:application/json" --header Accept:application/json" --header "CDMI-Specification-1.0" http://localhost/user -v

What I know is @Conusmes is for "Content-Type" .Is it?

thanks

Tarlog
  • 10,024
  • 2
  • 43
  • 67
sudo
  • 1,525
  • 7
  • 34
  • 59
  • Yes, `Consumes` is for the Content-Type of the request, and `Produces` is for the Accept of the request, and the Content-Type of the response. – Tyler Jun 29 '11 at 23:34

1 Answers1

4

There are annotations that can retrieve the http headers, for example:

@PUT
@Consumes("application/json")
@Produces("application/json")
public void doPut(@Context HttpHeaders hh){
    .....
}

You can also retrieve a single header:

@PUT
@Consumes("application/json")
@Produces("application/json")
public void doPut(@HeaderParam("Accept") acceptHeader){
    .....
}

See here for more information.

PJvG
  • 1,310
  • 3
  • 16
  • 33
kwo
  • 1,834
  • 1
  • 15
  • 9