Class ClientSession

  • All Implemented Interfaces:
    JcmsRestConstants

    public class ClientSession
    extends java.lang.Object
    implements JcmsRestConstants
    Represents a HTTP client session for calling JCMS through its REST Open API.
    Since:
    JCMS-6.0
    Author:
    dissert
    • Field Detail

      • DEFAULT_MAX_REDIRECT

        public static int DEFAULT_MAX_REDIRECT
      • NOFOLLOWREDIRECT_MAX_REDIRECT

        public static int NOFOLLOWREDIRECT_MAX_REDIRECT
    • Constructor Detail

      • ClientSession

        public ClientSession​(java.lang.String baseUrl)
    • Method Detail

      • getClient

        public org.restlet.Client getClient()
        Retrieve the underlying Restlet Client instance used for remote communication. Modify with care.
        Returns:
        the underlying Client instance, never return null
        Since:
        JCMS-2334
      • getDefaultMediaType

        public org.restlet.data.MediaType getDefaultMediaType()
        Returns:
        the default media type manipulated in this session.
      • setDefaultMediaType

        public void setDefaultMediaType​(org.restlet.data.MediaType defaultMediaType)
        Modify the default media type manipulated in this session
        Parameters:
        defaultMediaType -
      • setAuthentication

        public void setAuthentication​(Authentication authentication)
        Add an authentication to the session
        Parameters:
        authentication - the authentication to be added
      • removeAuthentication

        public Authentication removeAuthentication()
        Removes and returns the current authentication (null if none was added). Important : also remove any cookies that may have been set or retrieved in a previous request of this client session.
        Returns:
        the current authentication
      • storeCookies

        public void storeCookies​(org.restlet.util.Series<org.restlet.data.CookieSetting> cookiesSettings)
        Cookies management : store cookies relative to the current client. Differienciation between session and stored cookies is done with the cookie max age.
        Parameters:
        cookiesSettings -
      • setCookies

        public void setCookies​(org.restlet.data.Request request)
        Cookies management : set cookies relative to the current client in the given request.
        Parameters:
        request -
      • getReference

        public org.restlet.data.Reference getReference​(java.lang.String uriRelativePath)
        Parameters:
        uriRelativePath - The uriRelativePath as given genericaly in OpenAPI, without the context path and the "rest" prefix
        Returns:
        the Reference corresponding to the complete uri with the context path and the "rest" prefix.
      • setAcceptLanguage

        public void setAcceptLanguage​(java.lang.String acceptLanguage)
      • sendRequest

        public org.restlet.data.Response sendRequest​(org.restlet.data.Request request,
                                                     org.restlet.data.MediaType[] mediaTypes,
                                                     Authentication forcedAuthentication,
                                                     int maxRedirect)
        In the context of a client session (same cookies, same authentication), send request to the server, including authentication and managing cookies.
        Parameters:
        request - the request to send (without authentication and cookies)
        mediaTypes - accepted media type.
        forcedAuthentication - the authentication for this request only
        maxRedirect - the number of maximum redirection made if -1, redirect is not followed
        Returns:
        The final response (after redirection)
      • sendRequest

        public org.restlet.data.Response sendRequest​(org.restlet.data.Request request,
                                                     org.restlet.data.MediaType mediaType,
                                                     Authentication forcedAuthentication,
                                                     int maxRedirect)
      • sendRequest

        public org.restlet.data.Response sendRequest​(org.restlet.data.Request request,
                                                     org.restlet.data.MediaType[] mediaTypes,
                                                     Authentication forcedAuthentication)
      • sendRequest

        public org.restlet.data.Response sendRequest​(org.restlet.data.Request request,
                                                     org.restlet.data.MediaType mediaType,
                                                     Authentication forcedAuthentication)
      • sendRequest

        public org.restlet.data.Response sendRequest​(org.restlet.data.Request request,
                                                     Authentication forcedAuthentication)
      • sendRequest

        public org.restlet.data.Response sendRequest​(org.restlet.data.Reference reference,
                                                     org.restlet.data.Method method,
                                                     Authentication forcedAuthentication)
      • sendRequest

        public org.restlet.data.Response sendRequest​(org.restlet.data.Request request,
                                                     org.restlet.data.MediaType[] mediaTypes,
                                                     Authentication forcedAuthentication,
                                                     boolean noFollowRedirect)
      • sendRequest

        public org.restlet.data.Response sendRequest​(org.restlet.data.Request request,
                                                     org.restlet.data.MediaType mediaType,
                                                     Authentication forcedAuthentication,
                                                     boolean noFollowRedirect)
      • getRequest

        public org.restlet.data.Request getRequest​(org.restlet.data.Reference reference,
                                                   org.restlet.data.Method method)
      • getFormMultipartRequest

        public org.restlet.data.Request getFormMultipartRequest​(org.restlet.data.Reference reference,
                                                                java.util.List<MultipartParameter> multipartContent)
        Create a Request with Content-Type form-multipart and entity body compliant to form-multipart specification, with content in the Map multipartContent. Values may be String or File.
        Parameters:
        reference - The reference of the request
        multipartContent - the content of the form-multipart entity body
        Returns:
        the Restlet request
      • getBaseUrl

        public java.lang.String getBaseUrl()
      • findResource

        public JcmsResource findResource​(org.restlet.data.Reference resourceRef)
      • createQuery

        public RestQuery createQuery​(java.lang.String resourcePath)
      • createQuery

        public RestQuery createQuery​(org.restlet.data.Reference reference)
      • getCreatedDataRef

        public org.restlet.data.Reference getCreatedDataRef​(JcmsResource response)
        When a data is created (while using createData), the URI of the new data is given in the HTTP response header "Location". This method returns the given URI encapsulated in a Reference.
        Parameters:
        response - the response of the the createData request
        Returns:
        the URI of the new data.
      • getUserAgent

        public java.lang.String getUserAgent()
      • setUserAgent

        public void setUserAgent​(java.lang.String userAgent)