Skip to content

Commit a069135

Browse files
author
Nakul Sabharwal
committed
Added request level middleware options, renamed to CoreHttpProvider
1 parent bba70e7 commit a069135

File tree

10 files changed

+524
-44
lines changed

10 files changed

+524
-44
lines changed

src/main/java/com/microsoft/graph/core/DefaultClientConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import com.microsoft.graph.authentication.IAuthenticationProvider;
2626
import com.microsoft.graph.concurrency.DefaultExecutors;
2727
import com.microsoft.graph.concurrency.IExecutors;
28+
import com.microsoft.graph.http.CoreHttpProvider;
2829
import com.microsoft.graph.http.IHttpProvider;
29-
import com.microsoft.graph.http.OkHttpProvider;
3030
import com.microsoft.graph.logger.DefaultLogger;
3131
import com.microsoft.graph.logger.ILogger;
3232
import com.microsoft.graph.serializer.DefaultSerializer;
@@ -98,7 +98,7 @@ public IAuthenticationProvider getAuthenticationProvider() {
9898
@Override
9999
public IHttpProvider getHttpProvider() {
100100
if (httpProvider == null) {
101-
httpProvider = new OkHttpProvider(getSerializer(),
101+
httpProvider = new CoreHttpProvider(getSerializer(),
102102
getAuthenticationProvider(),
103103
getExecutors(),
104104
getLogger());

src/main/java/com/microsoft/graph/http/BaseCollectionRequest.java

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@
2222

2323
package com.microsoft.graph.http;
2424

25+
import java.net.URL;
26+
import java.util.List;
27+
2528
import com.microsoft.graph.core.ClientException;
2629
import com.microsoft.graph.core.IBaseClient;
30+
import com.microsoft.graph.httpcore.middlewareoption.IShouldRedirect;
31+
import com.microsoft.graph.httpcore.middlewareoption.IShouldRetry;
2732
import com.microsoft.graph.options.FunctionOption;
2833
import com.microsoft.graph.options.HeaderOption;
2934
import com.microsoft.graph.options.Option;
3035
import com.microsoft.graph.options.QueryOption;
3136

32-
import java.net.URL;
33-
import java.util.List;
34-
3537
/**
3638
* A request against a collection
3739
*
@@ -205,4 +207,94 @@ protected BaseRequest getBaseRequest() {
205207
public Class<T2> getCollectionPageClass() {
206208
return collectionPageClass;
207209
}
210+
211+
/**
212+
* Sets the max redirects
213+
*
214+
* @param maxRedirects Max redirects that a request can take
215+
*/
216+
public void setMaxRedirects(int maxRedirects) {
217+
baseRequest.setMaxRedirects(maxRedirects);
218+
}
219+
220+
/**
221+
* Gets the max redirects
222+
*
223+
* @return Max redirects that a request can take
224+
*/
225+
public int getMaxRedirects() {
226+
return baseRequest.getMaxRedirects();
227+
}
228+
229+
/**
230+
* Sets the should redirect callback
231+
*
232+
* @param shouldRedirect Callback called before doing a redirect
233+
*/
234+
public void setShouldRedirect(IShouldRedirect shouldRedirect) {
235+
baseRequest.setShouldRedirect(shouldRedirect);
236+
}
237+
238+
/**
239+
* Gets the should redirect callback
240+
*
241+
* @return Callback which is called before redirect
242+
*/
243+
public IShouldRedirect getShouldRedirect() {
244+
return baseRequest.getShouldRedirect();
245+
}
246+
247+
/**
248+
* Sets the should retry callback
249+
*
250+
* @param shouldretry The callback called before retry
251+
*/
252+
public void setShouldRetry(IShouldRetry shouldretry) {
253+
baseRequest.setShouldRetry(shouldretry);
254+
}
255+
256+
/**
257+
* Gets the should retry callback
258+
*
259+
* @return Callback called before retry
260+
*/
261+
public IShouldRetry getShouldRetry() {
262+
return baseRequest.getShouldRetry();
263+
}
264+
265+
/**
266+
* Sets the max retries
267+
*
268+
* @param maxRetries Max retries for a request
269+
*/
270+
public void setMaxRetries(int maxRetries) {
271+
baseRequest.setMaxRedirects(maxRetries);
272+
}
273+
274+
/**
275+
* Gets max retries
276+
*
277+
* @return Max retries for a request
278+
*/
279+
public int getMaxRetries() {
280+
return baseRequest.getMaxRetries();
281+
}
282+
283+
/**
284+
* Sets the delay in seconds between retires
285+
*
286+
* @param delay Delay in seconds between retries
287+
*/
288+
public void setDelay(long delay) {
289+
baseRequest.setDelay(delay);
290+
}
291+
292+
/**
293+
* Gets delay between retries
294+
*
295+
* @return Delay between retries in seconds
296+
*/
297+
public long getDelay() {
298+
return baseRequest.getDelay();
299+
}
208300
}

src/main/java/com/microsoft/graph/http/BaseRequest.java

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727

2828
import com.microsoft.graph.concurrency.ICallback;
2929
import com.microsoft.graph.core.IBaseClient;
30+
import com.microsoft.graph.httpcore.middlewareoption.IShouldRedirect;
31+
import com.microsoft.graph.httpcore.middlewareoption.IShouldRetry;
32+
import com.microsoft.graph.httpcore.middlewareoption.RedirectOptions;
33+
import com.microsoft.graph.httpcore.middlewareoption.RetryOptions;
3034
import com.microsoft.graph.options.FunctionOption;
3135
import com.microsoft.graph.options.QueryOption;
3236
import com.microsoft.graph.core.ClientException;
@@ -95,6 +99,31 @@ public abstract class BaseRequest implements IHttpRequest {
9599
* Value to pass to setUseCaches in connection
96100
*/
97101
private boolean useCaches;
102+
103+
/**
104+
* MaxRedirects of every request
105+
*/
106+
private int maxRedirects = RedirectOptions.DEFAULT_MAX_REDIRECTS;
107+
108+
/**
109+
* ShouldRedirect callback for every request
110+
*/
111+
private IShouldRedirect shouldRedirect = RedirectOptions.DEFAULT_SHOULD_REDIRECT;
112+
113+
/**
114+
* Max redirects for every request
115+
*/
116+
private int maxRetries = RetryOptions.DEFAULT_MAX_RETRIES;
117+
118+
/**
119+
* Delay in seconds for every request
120+
*/
121+
private long delay = RetryOptions.DEFAULT_DELAY;
122+
123+
/**
124+
* Callback before doing a retry
125+
*/
126+
private IShouldRetry shouldRetry = RetryOptions.DEFAULT_SHOULD_RETRY;
98127

99128
/**
100129
* Creates the request
@@ -351,5 +380,95 @@ public IBaseClient getClient() {
351380
*/
352381
public Class<?> getResponseType() {
353382
return responseClass;
383+
}
384+
385+
/**
386+
* Sets the max redirects
387+
*
388+
* @param maxRedirects Max redirects that a request can take
389+
*/
390+
public void setMaxRedirects(int maxRedirects) {
391+
this.maxRedirects = maxRedirects;
392+
}
393+
394+
/**
395+
* Gets the max redirects
396+
*
397+
* @return Max redirects that a request can take
398+
*/
399+
public int getMaxRedirects() {
400+
return maxRedirects;
401+
}
402+
403+
/**
404+
* Sets the should redirect callback
405+
*
406+
* @param shouldRedirect Callback called before doing a redirect
407+
*/
408+
public void setShouldRedirect(IShouldRedirect shouldRedirect) {
409+
this.shouldRedirect = shouldRedirect;
410+
}
411+
412+
/**
413+
* Gets the should redirect callback
414+
*
415+
* @return Callback which is called before redirect
416+
*/
417+
public IShouldRedirect getShouldRedirect() {
418+
return shouldRedirect;
419+
}
420+
421+
/**
422+
* Sets the should retry callback
423+
*
424+
* @param shouldretry The callback called before retry
425+
*/
426+
public void setShouldRetry(IShouldRetry shouldretry) {
427+
this.shouldRetry = shouldretry;
428+
}
429+
430+
/**
431+
* Gets the should retry callback
432+
*
433+
* @return Callback called before retry
434+
*/
435+
public IShouldRetry getShouldRetry() {
436+
return shouldRetry;
437+
}
438+
439+
/**
440+
* Sets the max retries
441+
*
442+
* @param maxRetries Max retries for a request
443+
*/
444+
public void setMaxRetries(int maxRetries) {
445+
this.maxRedirects = maxRedirects;
446+
}
447+
448+
/**
449+
* Gets max retries
450+
*
451+
* @return Max retries for a request
452+
*/
453+
public int getMaxRetries() {
454+
return maxRetries;
455+
}
456+
457+
/**
458+
* Sets the delay in seconds between retires
459+
*
460+
* @param delay Delay in seconds between retries
461+
*/
462+
public void setDelay(long delay) {
463+
this.delay = delay;
464+
}
465+
466+
/**
467+
* Gets delay between retries
468+
*
469+
* @return Delay between retries in seconds
470+
*/
471+
public long getDelay() {
472+
return delay;
354473
}
355474
}

src/main/java/com/microsoft/graph/http/BaseStreamRequest.java

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import com.microsoft.graph.core.IBaseClient;
2828
import com.microsoft.graph.httpcore.middlewareoption.IShouldRedirect;
2929
import com.microsoft.graph.httpcore.middlewareoption.IShouldRetry;
30+
import com.microsoft.graph.httpcore.middlewareoption.RedirectOptions;
31+
import com.microsoft.graph.httpcore.middlewareoption.RetryOptions;
3032
import com.microsoft.graph.options.HeaderOption;
3133
import com.microsoft.graph.options.Option;
3234

@@ -178,4 +180,94 @@ public List<Option> getOptions() {
178180
return baseRequest.getOptions();
179181
}
180182

183+
/**
184+
* Sets the max redirects
185+
*
186+
* @param maxRedirects Max redirects that a request can take
187+
*/
188+
public void setMaxRedirects(int maxRedirects) {
189+
baseRequest.setMaxRedirects(maxRedirects);
190+
}
191+
192+
/**
193+
* Gets the max redirects
194+
*
195+
* @return Max redirects that a request can take
196+
*/
197+
public int getMaxRedirects() {
198+
return baseRequest.getMaxRedirects();
199+
}
200+
201+
/**
202+
* Sets the should redirect callback
203+
*
204+
* @param shouldRedirect Callback called before doing a redirect
205+
*/
206+
public void setShouldRedirect(IShouldRedirect shouldRedirect) {
207+
baseRequest.setShouldRedirect(shouldRedirect);
208+
}
209+
210+
/**
211+
* Gets the should redirect callback
212+
*
213+
* @return Callback which is called before redirect
214+
*/
215+
public IShouldRedirect getShouldRedirect() {
216+
return baseRequest.getShouldRedirect();
217+
}
218+
219+
/**
220+
* Sets the should retry callback
221+
*
222+
* @param shouldretry The callback called before retry
223+
*/
224+
public void setShouldRetry(IShouldRetry shouldretry) {
225+
baseRequest.setShouldRetry(shouldretry);
226+
}
227+
228+
/**
229+
* Gets the should retry callback
230+
*
231+
* @return Callback called before retry
232+
*/
233+
public IShouldRetry getShouldRetry() {
234+
return baseRequest.getShouldRetry();
235+
}
236+
237+
/**
238+
* Sets the max retries
239+
*
240+
* @param maxRetries Max retries for a request
241+
*/
242+
public void setMaxRetries(int maxRetries) {
243+
baseRequest.setMaxRetries(maxRetries);
244+
}
245+
246+
/**
247+
* Gets max retries
248+
*
249+
* @return Max retries for a request
250+
*/
251+
public int getMaxRetries() {
252+
return baseRequest.getMaxRetries();
253+
}
254+
255+
/**
256+
* Sets the delay in seconds between retires
257+
*
258+
* @param delay Delay in seconds between retries
259+
*/
260+
public void setDelay(long delay) {
261+
baseRequest.setDelay(delay);
262+
}
263+
264+
/**
265+
* Gets delay between retries
266+
*
267+
* @return Delay between retries in seconds
268+
*/
269+
public long getDelay() {
270+
return baseRequest.getDelay();
271+
}
272+
181273
}

0 commit comments

Comments
 (0)