Class SlingClient.InternalBuilder<T extends SlingClient>
- java.lang.Object
-
- org.apache.sling.testing.clients.SlingClient.InternalBuilder<T>
-
- Type Parameters:
T- type extending SlingClient
- Direct Known Subclasses:
SlingClient.Builder
- Enclosing class:
- SlingClient
public abstract static class SlingClient.InternalBuilder<T extends SlingClient> extends java.lang.ObjectExtensible 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 throughhttpClientBuilder()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
Constructors Modifier Constructor Description protectedInternalBuilder(java.net.URI url, java.lang.String user, java.lang.String password)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description SlingClient.InternalBuilder<T>addInterceptorFirst(org.apache.http.HttpRequestInterceptor itcp)Adds this protocol interceptor to the head of the protocol processing list.SlingClient.InternalBuilder<T>addInterceptorFirst(org.apache.http.HttpResponseInterceptor itcp)SlingClient.InternalBuilder<T>addInterceptorLast(org.apache.http.HttpRequestInterceptor itcp)Adds this protocol interceptor to the tail of the protocol processing list.SlingClient.InternalBuilder<T>addInterceptorLast(org.apache.http.HttpResponseInterceptor itcp)Adds this protocol interceptor to the tail of the protocol processing list.abstract Tbuild()protected org.apache.http.impl.client.CloseableHttpClientbuildHttpClient()protected SlingClientConfigbuildSlingClientConfig()SlingClient.InternalBuilder<T>disableRedirectHandling()Disables automatic redirect handling.org.apache.http.impl.client.HttpClientBuilderhttpClientBuilder()SlingClient.InternalBuilder<T>setCookieStore(org.apache.http.client.CookieStore cs)SlingClient.InternalBuilder<T>setCredentialsProvider(org.apache.http.client.CredentialsProvider cp)SlingClient.InternalBuilder<T>setPassword(java.lang.String password)SlingClient.InternalBuilder<T>setPreemptiveAuth(boolean isPreemptiveAuth)SlingClient.InternalBuilder<T>setRedirectStrategy(org.apache.http.client.RedirectStrategy redirectStrategy)AssignsRedirectStrategyinstance.SlingClient.InternalBuilder<T>setUrl(java.net.URI url)SlingClient.InternalBuilder<T>setUser(java.lang.String user)
-
-
-
Method Detail
-
setUrl
public SlingClient.InternalBuilder<T> setUrl(java.net.URI url)
-
setUser
public SlingClient.InternalBuilder<T> setUser(java.lang.String user)
-
setPassword
public SlingClient.InternalBuilder<T> setPassword(java.lang.String password)
-
setCredentialsProvider
public SlingClient.InternalBuilder<T> setCredentialsProvider(org.apache.http.client.CredentialsProvider cp)
-
setPreemptiveAuth
public SlingClient.InternalBuilder<T> setPreemptiveAuth(boolean isPreemptiveAuth)
-
setCookieStore
public SlingClient.InternalBuilder<T> setCookieStore(org.apache.http.client.CookieStore cs)
-
httpClientBuilder
public org.apache.http.impl.client.HttpClientBuilder httpClientBuilder()
-
build
public abstract T build() throws ClientException
- Throws:
ClientException
-
buildHttpClient
protected org.apache.http.impl.client.CloseableHttpClient buildHttpClient()
-
buildSlingClientConfig
protected SlingClientConfig buildSlingClientConfig() throws ClientException
- 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
-
setRedirectStrategy
public final SlingClient.InternalBuilder<T> setRedirectStrategy(org.apache.http.client.RedirectStrategy redirectStrategy)
AssignsRedirectStrategyinstance.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
-
-