Can you not use the existing built in Mendix REST functionality? You can assign a microflow to an endpoint and that gives you the ability to change the HTTPResponse as a Mendix entity.
https://docs.mendix.com/howto/integration/publish-rest-service
If you want to write a REST service entirely in Java you will need to look at writing a RequestHandler. These have their place, but I would really recommend looking at using the built in functionality where possible to keep your app maintainable.
https://www.mendix.com/blog/requesthandlers-at-your-service/