Class SlingClient.InternalBuilder<T extends SlingClient>

  • Type Parameters:
    T - type extending SlingClient
    Direct Known Subclasses:
    SlingClient.Builder
    Enclosing class:
    SlingClient

    public abstract static class SlingClient.InternalBuilder<T extends SlingClient>
    extends Object

    Extensible InternalBuilder for SlingClient. Can be used by calling: SlingClient.builder().create(...).build(). Between create() and build(), any number of set methods can be called to customize the client.
    It also exposes the underling httpClientBuilder through httpClientBuilder() which can be used to customize the client at http level.

    The InternalBuilder is created to be easily extensible. A class, e.g. MyClient extends SlingClient, can have its own InternalBuilder. This is worth creating if MyClient has fields that need to be initialized. The Skeleton of such InternalBuilder (created inside MyClient) is:

     
     public static abstract class InternalBuilder<T extends MyClient> extends SlingClient.InternalBuilder<T> {
         private String additionalField;
    
         public InternalBuilder(URI url, String user, String password) { super(url, user, password); }
    
         public InternalBuilder<T> setAdditionalField(String s) { additionalField = s; }
     }
     
     

    Besides this, two more methods need to be implemented directly inside MyClient:

     
     public static InternalBuilder<?> builder(URI url, String user, String password) {
         return new InternalBuilder<MyClient>(url, user, password) {
             {@literal @}Override
             public MyClient build() throws ClientException { return new MyClient(this); }
         };
     }
    
     protected MyClient(InternalBuilder<MyClient> builder) throws ClientException {
       super(builder);
       additionalField = builder.additionalField;
     }
     
     
    Of course, the Clients and InternalBuilder are extensible on several levels, so MyClient.InternalBuilder can be further extended.
    • Constructor Detail

      • InternalBuilder

        protected InternalBuilder​(URI url,
                                  String user,
                                  String password)
    • Method Detail

      • httpClientBuilder

        public org.apache.http.impl.client.HttpClientBuilder httpClientBuilder()
      • buildHttpClient

        protected org.apache.http.impl.client.CloseableHttpClient buildHttpClient()
      • addInterceptorLast

        public final SlingClient.InternalBuilder<T> addInterceptorLast​(org.apache.http.HttpResponseInterceptor itcp)
        Adds this protocol interceptor to the tail of the protocol processing list.

        Please note this value can be overridden by the HttpClientBuilder.setHttpProcessor( org.apache.http.protocol.HttpProcessor) method.

        Parameters:
        itcp - the interceptor
        Returns:
        this
      • addInterceptorFirst

        public final SlingClient.InternalBuilder<T> addInterceptorFirst​(org.apache.http.HttpRequestInterceptor itcp)
        Adds this protocol interceptor to the head of the protocol processing list.

        Please note this value can be overridden by the HttpClientBuilder.setHttpProcessor( org.apache.http.protocol.HttpProcessor) method.

        Parameters:
        itcp - the interceptor
        Returns:
        this
      • addInterceptorLast

        public final SlingClient.InternalBuilder<T> addInterceptorLast​(org.apache.http.HttpRequestInterceptor itcp)
        Adds this protocol interceptor to the tail of the protocol processing list.

        Please note this value can be overridden by the HttpClientBuilder.setHttpProcessor( org.apache.http.protocol.HttpProcessor) method.

        Parameters:
        itcp - the interceptor
        Returns:
        this
      • addInterceptorFirst

        public final SlingClient.InternalBuilder<T> addInterceptorFirst​(HttpRequestResponseInterceptor itcp)
        Adds this protocol interceptor to the head of the protocol processing list for both requests and responses

        Please note this value can be overridden by the HttpClientBuilder.setHttpProcessor( org.apache.http.protocol.HttpProcessor) method.

        Parameters:
        itcp - the request and response interceptor
        Returns:
        this
      • addInterceptorLast

        public final SlingClient.InternalBuilder<T> addInterceptorLast​(HttpRequestResponseInterceptor itcp)
        Adds this protocol interceptor to the tail of the protocol processing list for both requests and responses

        Please note this value can be overridden by the HttpClientBuilder.setHttpProcessor( org.apache.http.protocol.HttpProcessor) method.

        Parameters:
        itcp - the request and response interceptor
        Returns:
        this
      • setRedirectStrategy

        public final SlingClient.InternalBuilder<T> setRedirectStrategy​(org.apache.http.client.RedirectStrategy redirectStrategy)
        Assigns RedirectStrategy instance.

        Please note this value can be overridden by the disableRedirectHandling() method.

        Parameters:
        redirectStrategy - custom redirect strategy
        Returns:
        this
      • disableRedirectHandling

        public final SlingClient.InternalBuilder<T> disableRedirectHandling()
        Disables automatic redirect handling.
        Returns:
        this