Changes between Version 28 and Version 29 of PluginDevelopmentGuide


Ignore:
Timestamp:
09.05.2013 16:39:42 (12 years ago)
Author:
jri
Comment:

Extract values from HTTP requests

Legend:

Unmodified
Added
Removed
Modified
  • PluginDevelopmentGuide

    v28 v29  
    959959* Annotate each service method with one of `@GET`, `@POST`, `@PUT`, or `@DELETE` to declare the HTTP method that will invoke that service method. 
    960960 
    961 * Annotate each service method with `@Path` to declare the URI template that will invoke that service method. The URI template can contain parameters, notated as `{...}`. 
     961* Annotate each service method with `@Path` to declare the URI template that will invoke that service method. The URI template can contain parameters, notated with curly braces `{...}`. 
    962962 
    963963* Annotate service method parameters with `@PathParam` to map URI template parameters to service method parameters. 
     
    10221022}}} 
    10231023 
    1024  
    1025  
    1026 JAX-RS: Java API for RESTful Web Services 
     1024JAX-RS: Java API for RESTful Web Services[[BR]] 
    10271025http://jsr311.java.net/nonav/releases/1.1/spec/spec.html 
     1026 
     1027==== Extract values from HTTP requests ==== 
     1028 
     1029This 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 
     1036A 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 
     10381. The type is a primitive type like `int`, `long`, `float`, `double`, `boolean`. 
     1039 
     10402. The type have a constructor that accepts a single `String` argument. 
     1041 
     10423. 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 
     10464. The type is `List<T>`, `Set<T>`, or `SortedSet<T>`, where `T` satisfies 2 or 3 above. 
     1047 
     1048==== Provider Classes ====