Class RESTWebService

    • Field Detail

      • RESPONSE_HEADER_ARRAYSIZE

        public static final String RESPONSE_HEADER_ARRAYSIZE
        The HTTP header parameter that provides the real size of an array of resources. It is for client side when a pagination mechanism is used in order to calculate the number of pages.
        See Also:
        Constant Field Values
    • Constructor Detail

      • RESTWebService

        public RESTWebService()
    • Method Detail

      • initContext

        @PostConstruct
        protected void initContext()
      • initWebResourceUri

        protected WebResourceUri initWebResourceUri()
        Default initialization of WebResourceUri instance for all WEB services extending RESTWebService class.

        This method can be overrated in case the default initialization is not satisfying a right behavior.

        In any case, the WebResourceUri is computed one time (and only one) per request and the result of computation is provided by getUri() method.

        Returns:
        a WebResourceUri instance.
      • createWebResourceUri

        protected WebResourceUri createWebResourceUri​(String webResourcePath)
        Creates a WebResourceUri instance from the specified relative path of a web resource. It is dedicated to be used by initWebResourceUri() but it can be used to create a custom WebResourceUri object to craft custom URIs.
        Parameters:
        webResourcePath - the relative base path of a web resource.
        Returns:
        a WebResourceUri instance.
      • getResourceBasePath

        protected abstract String getResourceBasePath()
        Gets the base path of the web resource relative to the root path of all the web resources in Silverpeas as given by SilverpeasWebResource.getBasePath().
        Returns:
        the relative path that identifies this REST web service among all other REST web services.
      • getHttpServletRequest

        public javax.servlet.http.HttpServletRequest getHttpServletRequest()
        Gets the HTTP servlet request mapped with the execution context of this web service.
        Returns:
        the HTTP servlet request.
      • getHttpServletResponse

        public javax.servlet.http.HttpServletResponse getHttpServletResponse()
        Gets the HTTP servlet response mapped with the execution context of this web service.
        Returns:
        the HTTP servlet response.
      • isUserDefined

        protected boolean isUserDefined()
        Is the user behind the request is well-defined in Silverpeas? In the case of an anonymous or public request, the user isn't identified in Silverpeas and therefore this method returns false.
        Returns:
        true if the user behind the request is well identified, false otherwise.
      • getUser

        protected User getUser()
        Gets the detail about the user that has called this web service. If the user isn't already identified by this web service, then null is returned.
        Returns:
        the detail about the user.
      • getUserPreferences

        protected UserPreferences getUserPreferences()
        Gets the preference of the user that requested the resource backed by this web service. If the user isn't already identified by this web service, then an identification is performed before through an authentication operation followed by an authorization validation. If the identification or the authorization fails, then a WebApplicationException is thrown with respectively an HTTP status code UNAUTHORIZED (401) or FORBIDDEN (403). If the preferences can be retrieved, then null is returned.
        Returns:
        the user preference or null if its preferences can be retrieved.
      • getUserRoles

        protected Collection<SilverpeasRole> getUserRoles()
        Gets roles of the authenticated user.
        Returns:
        a collection of roles played by the current authenticated and then identified user.
      • getOrganisationController

        protected OrganizationController getOrganisationController()
        Gets the organization controller.
        Returns:
        an OrganizationController instance.
      • getBundleLocation

        protected String getBundleLocation()
        Gets the location of the bundle to use.
        Returns:
        the classpath location of the localization bundle used by this Web service.
      • getBundle

        protected org.silverpeas.kernel.bundle.LocalizationBundle getBundle()
        Gets the bundle to use.
        Returns:
        the localization bundle to translate texts for the user.
      • getHighestUserRole

        public SilverpeasRole getHighestUserRole()
        Gets the highest role of the user behind the service call.
        Returns:
        the highest role the current authenticated and then identified user can play for this Web service.
      • process

        protected <R> RESTWebService.WebProcess<R> process​(RESTWebService.WebTreatment<R> webTreatment)
        This method permits to start the setting of a RESTWebService.WebTreatment.
        Type Parameters:
        R - the concrete type of the type the treatment will return.
        Parameters:
        webTreatment - a treatment to process in the behalf of a Web service.
        Returns:
        a process wrapping the treatment it will take in charge.
      • identifiedBy

        protected URI identifiedBy​(String... id)
        Convenient method to build a URI from the request's absolute path and the specified identifiers. Each identifier will be added to the absolute path as a path node in the returned URI.
        Parameters:
        id - one or more identifiers identifying uniquely the current requested web resource.
        Returns:
        a URI identifying uniquely in the Web the current requested resource.
      • identifiedBy

        protected URI identifiedBy​(javax.ws.rs.core.UriBuilder base,
                                   String... id)
        Convenient method to build a URI from the base URI represented by the specified UriBuilder and from the specified identifiers. Each identifier will be added to the base URI as a path node in the returned URI.
        Parameters:
        base - a UriBuilder instance representing the base URI from which the resulted URI will be computed.
        id - one or more identifiers identifying uniquely the current requested web resource.
        Returns:
        a URI identifying uniquely in the Web the current requested resource.
      • fromPage

        protected PaginationPage fromPage​(String page)
        Computes the PaginationPage according to the given asked page data.

        Page data is a String composed of two values separated by a semicolon :

        • Left value represents the page number. First page is '1'.
        • Right value represents the number of data per page.

        Parameters:
        page - the page information.
        Returns:
        the initialized PaginationPage.