Class SlingClient.InternalBuilder<T extends SlingClient>
- Type Parameters:
T
- type extending SlingClient
- Direct Known Subclasses:
SlingClient.Builder
- Enclosing class:
SlingClient
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
:
Of course, the Clients and InternalBuilder are extensible on several levels, so MyClient.InternalBuilder can be further extended.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; }
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal SlingClient.InternalBuilder<T>
addInterceptorFirst
(org.apache.http.HttpRequestInterceptor itcp) Adds this protocol interceptor to the head of the protocol processing list.final SlingClient.InternalBuilder<T>
addInterceptorFirst
(org.apache.http.HttpResponseInterceptor itcp) final SlingClient.InternalBuilder<T>
Adds this protocol interceptor to the head of the protocol processing list for both requests and responsesfinal SlingClient.InternalBuilder<T>
addInterceptorLast
(org.apache.http.HttpRequestInterceptor itcp) Adds this protocol interceptor to the tail of the protocol processing list.final SlingClient.InternalBuilder<T>
addInterceptorLast
(org.apache.http.HttpResponseInterceptor itcp) Adds this protocol interceptor to the tail of the protocol processing list.final SlingClient.InternalBuilder<T>
Adds this protocol interceptor to the tail of the protocol processing list for both requests and responsesabstract T
build()
protected org.apache.http.impl.client.CloseableHttpClient
protected SlingClientConfig
final SlingClient.InternalBuilder<T>
Disables automatic redirect handling.org.apache.http.impl.client.HttpClientBuilder
setCookieStore
(org.apache.http.client.CookieStore cs) setCredentialsProvider
(org.apache.http.client.CredentialsProvider cp) setPassword
(String password) setPreemptiveAuth
(boolean isPreemptiveAuth) final SlingClient.InternalBuilder<T>
setRedirectStrategy
(org.apache.http.client.RedirectStrategy redirectStrategy) AssignsRedirectStrategy
instance.
-
Constructor Details
-
InternalBuilder
-
-
Method Details
-
setUrl
-
setUser
-
setPassword
-
setCredentialsProvider
public SlingClient.InternalBuilder<T> setCredentialsProvider(org.apache.http.client.CredentialsProvider cp) -
setPreemptiveAuth
-
setCookieStore
-
httpClientBuilder
public org.apache.http.impl.client.HttpClientBuilder httpClientBuilder() -
build
- Throws:
ClientException
-
buildHttpClient
protected org.apache.http.impl.client.CloseableHttpClient buildHttpClient() -
buildSlingClientConfig
- Throws:
ClientException
-
addInterceptorFirst
public final SlingClient.InternalBuilder<T> addInterceptorFirst(org.apache.http.HttpResponseInterceptor itcp) -
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 responsesPlease 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
Adds this protocol interceptor to the tail of the protocol processing list for both requests and responsesPlease 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) AssignsRedirectStrategy
instance.Please note this value can be overridden by the
disableRedirectHandling()
method.- Parameters:
redirectStrategy
- custom redirect strategy- Returns:
- this
-
disableRedirectHandling
Disables automatic redirect handling.- Returns:
- this
-