Package org.silverpeas.core.web.rs
Class RESTWebService
- java.lang.Object
-
- org.silverpeas.core.web.rs.RESTWebService
-
- All Implemented Interfaces:
ProtectedWebResource
,WebAuthenticationValidation
,WebAuthorizationValidation
,SilverpeasWebResource
- Direct Known Subclasses:
AbstractAdminResource
,AbstractAttachmentResource
,AbstractCalendarResource
,AbstractContributionResource
,AbstractLoggingResource
,AbstractLookResource
,AbstractMessageResource
,AbstractNodeResource
,AbstractPasswordResource
,AbstractPublicationResource
,AbstractSimpleDocumentResource
,AbstractSubscriptionResource
,AbstractViewResource
,AuthenticationResource
,BundleResource
,CipherKeyResource
,CommentResource
,DocumentTemplateResource
,EmbedMediaPlayerResource
,EmbedMediaViewerResource
,FileUploadResource
,FilteredPdcResource
,ICalendarResource
,InboxUserNotificationResource
,InvitationResource
,LanguageResource
,ListNodeResource
,MyLinksResource
,MyPreferencesResource
,PdcClassificationResource
,PdcPredefinedClassificationResource
,PdcResource
,RatingResource
,RelationResource
,ReminderResource
,ReplacementResource
,SearchResource
,SelectionBasketResource
,SharingResource
,SilverpeasUserSessionTokenResource
,StreamingPlayerResource
,ThesaurusResource
,TicketResource
,UserGroupProfileResource
,UserProfileResource
,VariablesResource
,VolatileCacheResource
,WysiwygEditorConfigResource
@ComponentInstMustExistIfSpecified @WebEntityMustBeValid public abstract class RESTWebService extends Object implements ProtectedWebResource
The class of the Silverpeas REST web services. It provides all the common features required by the web services in Silverpeas like the user privilege checking.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
RESTWebService.WebProcess<R>
This class handles the execution of aRESTWebService.WebTreatment
.protected static interface
RESTWebService.WebTreatment<R>
Inner class handled by
-
Field Summary
Fields Modifier and Type Field Description static String
RESPONSE_HEADER_ARRAYSIZE
The HTTP header parameter that provides the real size of an array of resources.-
Fields inherited from interface org.silverpeas.core.web.SilverpeasWebResource
BASE_PATH
-
-
Constructor Summary
Constructors Constructor Description RESTWebService()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected WebResourceUri
createWebResourceUri(String webResourcePath)
Creates aWebResourceUri
instance from the specified relative path of a web resource.protected PaginationPage
fromPage(String page)
Computes thePaginationPage
according to the given asked page data.protected org.silverpeas.kernel.bundle.LocalizationBundle
getBundle()
Gets the bundle to use.protected String
getBundleLocation()
Gets the location of the bundle to use.SilverpeasRole
getHighestUserRole()
Gets the highest role of the user behind the service call.HttpRequest
getHttpRequest()
Gets the HTTP request mapped with the execution context of this web service.javax.servlet.http.HttpServletRequest
getHttpServletRequest()
Gets the HTTP servlet request mapped with the execution context of this web service.javax.servlet.http.HttpServletResponse
getHttpServletResponse()
Gets the HTTP servlet response mapped with the execution context of this web service.protected OrganizationController
getOrganisationController()
Gets the organization controller.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 bySilverpeasWebResource.getBasePath()
.RESTRequestContext
getSilverpeasContext()
Gets the context of Silverpeas linked to the current request.WebResourceUri
getUri()
Gets the URI targeted by the current HTTP request in the form of aWebResourceUri
.protected User
getUser()
Gets the detail about the user that has called this web service.protected UserPreferences
getUserPreferences()
Gets the preference of the user that requested the resource backed by this web service.protected Collection<SilverpeasRole>
getUserRoles()
Gets roles of the authenticated user.protected URI
identifiedBy(String... id)
Convenient method to build a URI from the request's absolute path and the specified identifiers.protected URI
identifiedBy(javax.ws.rs.core.UriBuilder base, String... id)
Convenient method to build a URI from the base URI represented by the specifiedUriBuilder
and from the specified identifiers.protected void
initContext()
protected WebResourceUri
initWebResourceUri()
Default initialization ofWebResourceUri
instance for all WEB services extendingRESTWebService
class.protected boolean
isUserDefined()
Is the user behind the request is well-defined in Silverpeas?protected <R> RESTWebService.WebProcess<R>
process(RESTWebService.WebTreatment<R> webTreatment)
This method permits to start the setting of aRESTWebService.WebTreatment
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.silverpeas.core.web.rs.ProtectedWebResource
validateUserAuthorization
-
Methods inherited from interface org.silverpeas.core.web.SilverpeasWebResource
getComponentId
-
Methods inherited from interface org.silverpeas.core.web.rs.WebAuthenticationValidation
validateUserAuthentication
-
-
-
-
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
-
-
Method Detail
-
initContext
@PostConstruct protected void initContext()
-
getSilverpeasContext
public RESTRequestContext getSilverpeasContext()
Description copied from interface:WebAuthenticationValidation
Gets the context of Silverpeas linked to the current request. This context must be initialized before the functional request processing.- Specified by:
getSilverpeasContext
in interfaceWebAuthenticationValidation
- Specified by:
getSilverpeasContext
in interfaceWebAuthorizationValidation
- Returns:
SilverpeasRequestContext
instance.
-
getUri
public WebResourceUri getUri()
Description copied from interface:SilverpeasWebResource
Gets the URI targeted by the current HTTP request in the form of aWebResourceUri
.- Specified by:
getUri
in interfaceSilverpeasWebResource
- Returns:
- the
WebResourceUri
initialized with the URI request.
-
initWebResourceUri
protected WebResourceUri initWebResourceUri()
Default initialization ofWebResourceUri
instance for all WEB services extendingRESTWebService
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 bygetUri()
method.- Returns:
- a
WebResourceUri
instance.
-
createWebResourceUri
protected WebResourceUri createWebResourceUri(String webResourcePath)
Creates aWebResourceUri
instance from the specified relative path of a web resource. It is dedicated to be used byinitWebResourceUri()
but it can be used to create a customWebResourceUri
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 bySilverpeasWebResource.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.
-
getHttpRequest
public HttpRequest getHttpRequest()
Gets the HTTP request mapped with the execution context of this web service.- Specified by:
getHttpRequest
in interfaceSilverpeasWebResource
- Returns:
- the HTTP 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 aRESTWebService.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 specifiedUriBuilder
and from the specified identifiers. Each identifier will be added to the base URI as a path node in the returned URI.- Parameters:
base
- aUriBuilder
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 thePaginationPage
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
.
-
-