O'Reilly logo

Developing Middleware in Java EE 8 by Abdalla Mahmoud

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Custom responses

As discussed earlier, any response from a RESTful service may include:

  • Status code
  • Response entity
  • Content type

By default, any RESTful service that runs and returns normally without any problems will contain the status code 200 (OK). The response entity will be these value you return from the RESTful method. The content type will be these one specified by the @Produces annotation, as mentioned earlier.

Sometimes, you may need to customize the details of the response yourself at runtime, in one of the following scenarios:

  •  The response entity data type/MIME content type is not known until runtime
  •  A custom status code should be returned to the client according to some business logic inside the RESTful service code

In ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required