Skip to content

Commit bb5c91e

Browse files
committed
- allows for client builder extensibility so the service library can extend it
1 parent cb7f915 commit bb5c91e

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

‎src/main/java/com/microsoft/graph/core/BaseClient.java‎

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ public static Builder<OkHttpClient> builder() {
111111
/**
112112
* Builder to help configure the Graph service client
113113
*/
114-
public static final class Builder<httpClientType> {
114+
public static class Builder<httpClientType> {
115115
private ISerializer serializer;
116116
private IHttpProvider httpProvider;
117117
private ILogger logger;
118118
private httpClientType httpClient;
119119
private ICoreAuthenticationProvider auth;
120120

121-
private ICoreAuthenticationProvider getAuth() {
121+
private ICoreAuthenticationProvider getAuthenticationProvider() {
122122
if(auth == null) {
123123
throw new NullPointerException("auth"); // TODO initialize to default once moved to core
124124
} else {
@@ -142,7 +142,7 @@ private ISerializer getSerializer() {
142142
@SuppressWarnings("unchecked")
143143
private httpClientType getHttpClient() {
144144
if(httpClient == null) {
145-
return (httpClientType)HttpClients.createDefault(getAuth());
145+
return (httpClientType)HttpClients.createDefault(getAuthenticationProvider());
146146
} else {
147147
return httpClient;
148148
}
@@ -224,6 +224,24 @@ public Builder<httpClientType> authenticationProvider(@Nonnull final ICoreAuthen
224224
return this;
225225
}
226226

227+
/**
228+
* Builds and returns the Graph service client.
229+
*
230+
* @param instance the instance to set the information for
231+
* @param <ClientType> the type of the client to return
232+
* @return the Graph service client object
233+
* @throws ClientException
234+
* if there was an exception creating the client
235+
*/
236+
@Nonnull
237+
protected <ClientType extends BaseClient> ClientType buildClient(ClientType instance) throws ClientException {
238+
instance.setHttpProvider(this.getHttpProvider());
239+
instance.setLogger(this.getLogger());
240+
instance.setSerializer(this.getSerializer());
241+
instance.validate();
242+
return instance;
243+
}
244+
227245
/**
228246
* Builds and returns the Graph service client.
229247
*
@@ -233,12 +251,7 @@ public Builder<httpClientType> authenticationProvider(@Nonnull final ICoreAuthen
233251
*/
234252
@Nonnull
235253
public IBaseClient buildClient() throws ClientException {
236-
BaseClient client = new BaseClient();
237-
client.setHttpProvider(this.getHttpProvider());
238-
client.setLogger(this.getLogger());
239-
client.setSerializer(this.getSerializer());
240-
client.validate();
241-
return client;
254+
return buildClient(new BaseClient());
242255
}
243256
}
244257

0 commit comments

Comments
 (0)