@Consumes @Produces both

gudii9
gudii9 used Ask the Experts™
on
hi,

why we use both @Consumes @Produces on top of a  webservice method of a java class of jax-ws apart from @Post

please advise
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
The @Produces annotation is used to specify the MIME media types or representations a resource can produce and send back to the client. If @Produces is applied at the class level, all the methods in a resource can produce the specified MIME types by default. If applied at the method level, the annotation overrides any @Produces annotations applied at the class level.

If no methods in a resource are able to produce the MIME type in a client request, the JAX-RS runtime sends back an HTTP “406 Not Acceptable” error.

The value of @Produces is an array of String of MIME types. For example:
@Produces({"image/jpeg,image/png"})
The @Consumes annotation is used to specify which MIME media types of representations a resource can accept, or consume, from the client. If @Consumes is applied at the class level, all the response methods accept the specified MIME types by default. If applied at the method level, @Consumes overrides any @Consumes annotations applied at the class level.
@Produces is to the client
@Consumes  is from the client
Read more here
Distinguished Expert 2018
Commented:
@Consumes -> the web service accepts the specified content type from the client.
@Produces -> the web service sends as a response the specified content type to the client.

Author

Commented:
let me read this

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial