Uploaded image for project: '[Read Only] - Hippo Site Toolkit 2'
  1. [Read Only] - Hippo Site Toolkit 2
  2. HSTTWO-4133

@ParametersInfo annotation usages for parameters in JAX-RS Resource class

    XMLWordPrintable

Details

    • New Feature
    • Status: Closed
    • Normal
    • Resolution: Fixed
    • None
    • 5.1.0
    • None
    • None
    • Turing Sprint 166, Turing Sprint 167, Turing Sprint 168, Turing Sprint 169

    Description

      So far, JAX-RS resource components don't have a support to use parameters and @ParametersInfo annotation, unlike HstComponent classes.
      As a result, there have been different practices and patterns in reality between different people.
      When they need to make it configurable, some people make a JAX-RS resource class read HST Container configuration, mount properties, system properties, spring-injected properties directly with passed system properties, etc, etc.

      If a JAX-RS component can also use @ParametersInfo annotation like HstComponent in the class level, and if it can read either sitemap item level hst:parameternames and hst:parametervalues (for context/content-aware jaxrs) or mount level hst:parameternames and hst:parametervalues (for plain jaxrs classes), then it would be very convenient to developers.

      Developers may apply different parameters in either sitemap item (Content-Aware JAX-RS) or mount (Plain JAX-RS) to the same JAX-RS resource classes to behave differently based on the configurations. This will be very helpful in both Content-Aware and Plain JAX-RS because developers can use the same technique of @ParametersInfo annotation.

      So, they can configure specific parameters for JAX-rs in a more aligned way, also in a more unified way through sitemapitem or mount parameters.

      Here's an example scenario:

      • Developer annotates a JAX-RS class with @ParametersInfo annotation in the class level like the following:
        @Produces({MediaType.APPLICATION_JSON})
        @Consumes({MediaType.APPLICATION_JSON})
        @Path("/NewsDocument/")
        @ParametersInfo(type=NewsDocumentResourceInfo.class)
        public class NewsDocumentResource extends BaseRestResource {
        
            @GET
            @Path("/")
            public Pageable<NewsDocument> index(@Context HttpServletRequest request, @Context ParametersInfoProvider paramsInfoProvider) {
                final NewsDocumentResourceInfo paramsInfo = paramsInfoProvider.getParametersInfo();
                // read params ... such as search scope, tags, sort order, etc.
                final String scopePath = paramsInfo.getScopePath();
                final String tags = paramsInfo.getTags();
                final String sortFields = paramsInfo.getSortFields();
                final String sortOrder = paramsInfo.getSortOrder();
                // do query based on the parameters set...
                // ...
            }
        }
        
      • ParametersInfoProvider is a new interface defined in HST to return a proper ParametersInfo instance, similarly to ParamsUtils in hst-client. And, the ParametersInfoProvider instance will be provided automatically by the underlying CXF provider injected in spring by adopting the technique explained in "Custom Contexts" section here: http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-CustomContexts
      • By default, a ParametersInfo instance will be returned to read from either matched sitemap item hst:parameternames/hst:parametervalues for context/content-aware jaxrs services, or matched mount's hst:parameternames/hst:parametervalues for plain jaxrs services.
      • In the latter case (plain jaxrs services), they can prefix parameter names if they want to group mount parameters for different plain jaxrs service classes, with defining multiple ParametersInfo class types.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              wko Woonsan Ko (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: