1068 | | ==== Provider Classes ==== |
| 1068 | ==== Parsing the HTTP request body ==== |
| 1069 | |
| 1070 | Until here we talked about how to extract values from the HTTP request's path, the request's query string, or the request headers. This section describes how to feed the //HTTP request body// into your service methods. Feeding here refers to a) parsing the body's byte stream, b) constructing a Java object from it, and passing that Java object to a particular service method. |
| 1071 | |
| 1072 | JAX-RS can't know how to construct arbitrary application objects from a sole byte stream. That's why JAX-RS comprises a extension facility called //Provider Classes//. A provider class is responsible to read the request body, parse it, and construct an particular application object from it. It is the duty of the application developer to implement the required provider classes for the application objects. |
| 1073 | |
| 1074 | A service method that want to receive the constructed application object must have a dedicated parameter called (in JAX-RS speak) the //Entity Parameter//. The entity parameter stands for the entity that is represented in the request body. Unlike the other service method parameters the entity parameter has //no// annotation. A service method can have //one// entity parameter at most (a HTTP request has //one// body). |
| 1075 | |
| 1076 | To feed the HTTP request body into a service method you must: |
| 1077 | |
| 1078 | * Add an entity parameter to the service method. That is a parameter without any annotation. |
| 1079 | |
| 1080 | * Implement a provider class for the type of the entity parameter, resp. make sure such a provider class already exists (as part of the DeepaMehta Core or one of the installed DeepaMehta plugins). |