Class HalClient


  • @ProviderType
    public final class HalClient
    extends Object
    Factory for HAL specific JsonPipelineActions.
    • Constructor Detail

      • HalClient

        public HalClient​(String serviceId,
                         io.wcm.caravan.pipeline.cache.CacheStrategy cacheStrategy)
        Parameters:
        serviceId - Service ID
        cacheStrategy - default cache strategy to use for all actions that fetch additional resources
      • HalClient

        public HalClient​(String serviceId,
                         io.wcm.caravan.pipeline.cache.CacheStrategy cacheStrategy,
                         Map<String,​String> contextProperties)
        Parameters:
        serviceId - Service ID
        cacheStrategy - default cache strategy to use for all actions that fetch additional resources
        contextProperties - a Map of properties to pass on to JsonPipelineFactory.create(CaravanHttpRequest, Map)
      • HalClient

        public HalClient​(io.wcm.caravan.io.http.request.CaravanHttpRequest entryPointRequest,
                         io.wcm.caravan.pipeline.cache.CacheStrategy cacheStrategy,
                         Map<String,​String> contextProperties)
        Parameters:
        entryPointRequest - the request to be executed to fetch the HAL entry point
        cacheStrategy - default cache strategy to use for all actions that fetch additional resources
        contextProperties - a Map of properties to pass on to JsonPipelineFactory.create(CaravanHttpRequest, Map)
      • HalClient

        public HalClient​(io.wcm.caravan.io.http.request.CaravanHttpRequest entryPointRequest,
                         ServiceIdExtractor serviceIdExtractor,
                         io.wcm.caravan.pipeline.cache.CacheStrategy cacheStrategy,
                         Map<String,​String> contextProperties)
        Parameters:
        entryPointRequest - the request to be executed to fetch the HAL entry point
        serviceIdExtractor - Service ID extractor
        cacheStrategy - default cache strategy to use for all actions that fetch additional resources
        contextProperties - a Map of properties to pass on to JsonPipelineFactory.create(CaravanHttpRequest, Map)
    • Method Detail

      • addExceptionHandler

        public HalClient addExceptionHandler​(io.wcm.caravan.pipeline.JsonPipelineExceptionHandler newExceptionHandler)
        Adds an exception handler for the pipeline actions.
        Parameters:
        newExceptionHandler - The exceptionHandler to set.
        Returns:
        This HAL client
      • setLogger

        public HalClient setLogger​(org.slf4j.Logger value)
        Sets the logger for the pipeline actions.
        Parameters:
        value - Logger to set.
        Returns:
        This HAL client
      • setServiceIdExtractor

        public HalClient setServiceIdExtractor​(ServiceIdExtractor extractor)
        Replaces the default service id extractor (that uses the same serviceId for all requests) with a custom logic
        Parameters:
        extractor - the ServiceIdExtractor to use
        Returns:
        this hal client
      • getEntryPoint

        public io.wcm.caravan.pipeline.JsonPipeline getEntryPoint​(io.wcm.caravan.pipeline.JsonPipelineFactory factory)
        Creates a JsonPipeline that will fetch the entry point of the HAL service
        Parameters:
        factory - the factory to use to create the pipeline
        Returns:
        the pipeline
      • createEntryPoint

        @Deprecated
        public io.wcm.caravan.pipeline.JsonPipeline createEntryPoint​(io.wcm.caravan.pipeline.JsonPipelineFactory factory)
        Deprecated.
        Creates a JSON pipeline for a service entry point.
        Parameters:
        factory - Pipeline factory
        Returns:
        JSON pipeline
      • create

        @Deprecated
        public io.wcm.caravan.pipeline.JsonPipeline create​(io.wcm.caravan.pipeline.JsonPipelineFactory factory,
                                                           String url)
        Deprecated.
        specify the entry point in the constructor and use getEntryPoint(JsonPipelineFactory) instead
        Creates a JSON pipeline for a service and URL.
        Parameters:
        factory - Pipeline factory
        url - URL to start
        Returns:
        JSON pipeline
      • create

        @Deprecated
        public io.wcm.caravan.pipeline.JsonPipeline create​(io.wcm.caravan.pipeline.JsonPipelineFactory factory,
                                                           io.wcm.caravan.io.http.request.CaravanHttpRequest request)
        Deprecated.
        specify the entry point in the constructor and use getEntryPoint(JsonPipelineFactory) instead
        Creates a JSON pipeline for a HTTP request.
        Parameters:
        factory - Pipeline factory
        request - Pre-configured HTTP request
        Returns:
        JSON pipeline
      • follow

        public FollowLink follow​(String relation)
        Creates a follow link action for the first relation specific link
        Parameters:
        relation - Link relation
        Returns:
        Follow link action
      • follow

        public FollowLink follow​(String relation,
                                 Map<String,​Object> parameters)
        Creates a follow link action for the first relation specific link with the given URL parameters.
        Parameters:
        relation - Link relation
        parameters - URL parameters
        Returns:
        Follow link action
      • follow

        public FollowLink follow​(String relation,
                                 int index)
        Creates a follow link action for the index specified link.
        Parameters:
        relation - Link relation
        index - Link index
        Returns:
        Follow link action
      • follow

        public FollowLink follow​(String relation,
                                 Map<String,​Object> parameters,
                                 int index)
        Creates a follow link action for the index specified link with the given URL parameters.
        Parameters:
        relation - Link relation
        parameters - URL parameters
        index - Link index
        Returns:
        Follow link action
      • follow

        public FollowLink follow​(String relation,
                                 Map<String,​Object> parameters,
                                 String name)
        Creates a follow link action for the forst link with the given relation and name
        Parameters:
        relation - Link relation
        parameters - URL parameters
        name - of the link to follow
        Returns:
        Follow link action
      • embed

        public EmbedLinks embed​(String relation)
        Creates an embed links action for all relation specific links.
        Parameters:
        relation - Link relation
        Returns:
        Embed links action
      • embed

        public EmbedLinks embed​(String relation,
                                Map<String,​Object> parameters)
        Creates an embed links action for all relation specific links with the given URL parameters.
        Parameters:
        relation - Link relation
        parameters - URL parameters
        Returns:
        Embed links action
      • embed

        public EmbedLink embed​(String relation,
                               int index)
        Creates an embed link action for the index specified link.
        Parameters:
        relation - Link relation
        index - Link index
        Returns:
        Embed links action
      • embed

        public EmbedLink embed​(String relation,
                               Map<String,​Object> parameters,
                               int index)
        Creates an embed link action for the index specified link with the given URL parameters.
        Parameters:
        relation - Link relation
        parameters - URL parameters
        index - Link index
        Returns:
        Embed links action
      • deepEmbed

        public DeepEmbedLinks deepEmbed​(String relation)
        Fetches the content of all links with the given relation in a HAL resource and all embedded resources, and replaces the links with the corresponding embedded resources.
        Parameters:
        relation - Link relation
        Returns:
        Deep Embed links action
      • deepEmbed

        public DeepEmbedLinks deepEmbed​(String relation,
                                        Map<String,​Object> parameters)
        Fetches the content of all links with the given relation in a HAL resource and all embedded resources, and replaces the links with the corresponding embedded resources.
        Parameters:
        relation - Link relation
        parameters - URL parameters
        Returns:
        Deep Embed links action
      • buildResource

        @Deprecated
        public BuildResource buildResource​(String selfHref,
                                           rx.functions.Func2<io.wcm.caravan.hal.resource.HalResource,​io.wcm.caravan.hal.resource.util.HalBuilder,​io.wcm.caravan.hal.resource.HalResource> buildFunc)
        Deprecated.
        use createResource instead
        Allows to create a BuildResource action by specifying the output href and a lambda
        Parameters:
        selfHref - the path of the output resource to be used for the self helf
        buildFunc - the lambda that gets the previous step's output and a HalBuilder with the specified self-link
        Returns:
        the action that executes the lambda build function
      • createResource

        public CreateResource createResource​(String selfHref,
                                             Function<io.wcm.caravan.hal.resource.HalResource,​io.wcm.caravan.hal.resource.HalResource> buildFunc)
        Allows to create a CreateResource action by specifying the output href and a lambda. The CreateResource action will automatically generated a cache-key based on the given href, and also set the self-link of the resource returned by the lambda
        Parameters:
        selfHref - the path of the output resource to be used for the self helf
        buildFunc - the lambda that gets the previous step's output and should return a new HalResource
        Returns:
        the action that executes the lambda build function
      • modifyResource

        public ModifyResource modifyResource​(String selfHref,
                                             rx.functions.Action1<io.wcm.caravan.hal.resource.HalResource> modifyFunc)
        Allows to create a ModifyResource action by specifying the output href and a lambda
        Parameters:
        selfHref - the path of the output resource to be used for the self helf
        modifyFunc - the lambda that gets a HalResource with the previous step's output and the specified self-link
        Returns:
        the action that executes the lambda build function
      • load

        public LoadLink load​(io.wcm.caravan.hal.resource.Link link)
        Creates a LoadLink action for the given link.
        Parameters:
        link - Link to load
        Returns:
        Load link action
      • load

        public LoadLink load​(io.wcm.caravan.hal.resource.Link link,
                             Map<String,​Object> parameters)
        Creates a LoadLink action for the given link and URI parameters.
        Parameters:
        link - Link to load
        parameters - URI parameters
        Returns:
        Load link action