| 1026 | |
| 1027 | ==== Extract values from HTTP requests ==== |
| 1028 | |
| 1029 | This section describes in more detail how the service method argument values are extracted from the various parts of a HTTP request. As seen in the example above this is controlled by annotating the service method arguments. Besides `@PathParam` you can use further annotations: |
| 1030 | |
| 1031 | ||= Annotation =||= Semantics =|| |
| 1032 | || `@PathParam` || Extracts the value of a URI template parameter || |
| 1033 | || `@QueryParam` || Extracts the value of a URI query parameter || |
| 1034 | || `@HeaderParam` || Extracts the value of a header || |
| 1035 | |
| 1036 | A value extracted from a HTTP request is inherently a string. So DeepaMehta (resp. the underlying JAX-RS implementation) must know how to actually construct a Java object (resp. a scalar value) from it. That's why the type of a service method argument that is annotated with one of the annotations above must fulfill at least one of these criteria: |
| 1037 | |
| 1038 | 1. The type is a primitive type like `int`, `long`, `float`, `double`, `boolean`. |
| 1039 | |
| 1040 | 2. The type have a constructor that accepts a single `String` argument. |
| 1041 | |
| 1042 | 3. The type have a static method named `valueOf` that takes a single `String` argument and returns an instance of the type. |
| 1043 | |
| 1044 | Enum types are special in one regard as they already have a static `valueOf` method. If this one does not fit your need add a `fromString` method to your enum type that has the same characteristics as the `valueOf` method mentioned above. |
| 1045 | |
| 1046 | 4. The type is `List<T>`, `Set<T>`, or `SortedSet<T>`, where `T` satisfies 2 or 3 above. |
| 1047 | |
| 1048 | ==== Provider Classes ==== |