Skip to content

Commit 1bf60ec

Browse files
Add middleware options at client level in config file
1 parent 7472381 commit 1bf60ec

File tree

7 files changed

+736
-522
lines changed

7 files changed

+736
-522
lines changed

build.gradle

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ repositories {
2020
// You can declare any Maven/Ivy/file repository here.
2121
jcenter()
2222
mavenCentral()
23-
jcenter{
24-
url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
25-
}
2623
}
2724

2825
dependencies {
@@ -40,7 +37,7 @@ dependencies {
4037
compile 'com.sun.jersey:jersey-server:1.19.4'
4138

4239
// Core Http library
43-
compile('com.microsoft.graph:microsoft-graph-core:0.1.0-SNAPSHOT')
40+
compile('com.microsoft.graph:microsoft-graph-core:1.0.0')
4441
}
4542

4643
def pomConfig = {

src/main/java/com/microsoft/graph/concurrency/ChunkedUploadResponseHandler.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ public ChunkedUploadResponseHandler(final Class<UploadType> uploadType) {
6868
public void configConnection(final IConnection connection) {
6969
return;
7070
}
71+
72+
/**
73+
* Do nothing before getting the response
74+
*
75+
* @param response The response
76+
*/
77+
@Override
78+
public void configConnection(final Response response) {
79+
return;
80+
}
7181

7282
/**
7383
* Generate the chunked upload response result

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

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222

2323
package com.microsoft.graph.core;
2424

25+
import com.microsoft.graph.httpcore.middlewareoption.IShouldRedirect;
26+
import com.microsoft.graph.httpcore.middlewareoption.IShouldRetry;
27+
import com.microsoft.graph.httpcore.middlewareoption.RedirectOptions;
28+
import com.microsoft.graph.httpcore.middlewareoption.RetryOptions;
29+
2530
public class DefaultConnectionConfig implements IConnectionConfig{
2631

2732
/**
@@ -34,6 +39,31 @@ public class DefaultConnectionConfig implements IConnectionConfig{
3439
*/
3540
private static int DEFAULT_READ_TIMEOUT_MS = 30_000;
3641

42+
/**
43+
* MaxRedirects of every request
44+
*/
45+
private static int maxRedirects = RedirectOptions.DEFAULT_MAX_REDIRECTS;
46+
47+
/**
48+
* ShouldRedirect callback for every request
49+
*/
50+
private static IShouldRedirect shouldRedirect = RedirectOptions.DEFAULT_SHOULD_REDIRECT;
51+
52+
/**
53+
* Max redirects for every request
54+
*/
55+
private static int maxRetries = RetryOptions.DEFAULT_MAX_RETRIES;
56+
57+
/**
58+
* Delay in seconds for every request
59+
*/
60+
private static long delay = RetryOptions.DEFAULT_DELAY;
61+
62+
/**
63+
*
64+
*/
65+
private static IShouldRetry shouldRetry = RetryOptions.DEFAULT_SHOULD_RETRY;
66+
3767
/**
3868
* Gets the connect timeout
3969
*
@@ -73,5 +103,95 @@ public int getReadTimeout() {
73103
public void setReadTimeout(int readTimeoutValue) {
74104
DEFAULT_READ_TIMEOUT_MS = readTimeoutValue;
75105
}
106+
107+
/**
108+
* Sets the max redirects
109+
*
110+
* @param maxRedirects Max redirects that a request can take
111+
*/
112+
public void setMaxRedirects(int maxRedirects) {
113+
this.maxRedirects = maxRedirects;
114+
}
115+
116+
/**
117+
* Gets the max redirects
118+
*
119+
* @return Max redirects that a request can take
120+
*/
121+
public int getMaxRedirects() {
122+
return maxRedirects;
123+
}
124+
125+
/**
126+
* Sets the should redirect callback
127+
*
128+
* @param shouldRedirect Callback called before doing a redirect
129+
*/
130+
public void setShouldRedirect(IShouldRedirect shouldRedirect) {
131+
this.shouldRedirect = shouldRedirect;
132+
}
133+
134+
/**
135+
* Gets the should redirect callback
136+
*
137+
* @return Callback which is called before redirect
138+
*/
139+
public IShouldRedirect getShouldRedirect() {
140+
return shouldRedirect;
141+
}
142+
143+
/**
144+
* Sets the should retry callback
145+
*
146+
* @param shouldretry The callback called before retry
147+
*/
148+
public void setShouldRetry(IShouldRetry shouldretry) {
149+
this.shouldRetry = shouldretry;
150+
}
151+
152+
/**
153+
* Gets the should retry callback
154+
*
155+
* @return Callback called before retry
156+
*/
157+
public IShouldRetry getShouldRetry() {
158+
return shouldRetry;
159+
}
160+
161+
/**
162+
* Sets the max retries
163+
*
164+
* @param Max retries for a request
165+
*/
166+
public void setMaxRetries(int maxRetries) {
167+
this.maxRedirects = maxRedirects;
168+
}
169+
170+
/**
171+
* Gets max retries
172+
*
173+
* @return Max retries for a request
174+
*/
175+
public int getMaxRetries() {
176+
return maxRetries;
177+
}
178+
179+
/**
180+
* Sets the delay in seconds between retires
181+
*
182+
* @param delay Delay in seconds between retries
183+
*/
184+
public void setDelay(long delay) {
185+
this.delay = delay;
186+
}
187+
188+
/**
189+
* Gets delay between retries
190+
*
191+
* @return Delay between retries in seconds
192+
*/
193+
public long getDelay() {
194+
return delay;
195+
}
76196

77197
}

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
package com.microsoft.graph.core;
2424

25+
import com.microsoft.graph.httpcore.middlewareoption.IShouldRedirect;
26+
import com.microsoft.graph.httpcore.middlewareoption.IShouldRetry;
27+
2528
public interface IConnectionConfig {
2629

2730
/**
@@ -51,4 +54,75 @@ public interface IConnectionConfig {
5154
* @param readTimeoutValue Read timeout in milliseconds to be set to.
5255
*/
5356
void setReadTimeout(int readTimeoutValue);
57+
58+
/**
59+
* Sets the max redirects
60+
*
61+
* @param maxRedirects Max redirects that a request can take
62+
*/
63+
void setMaxRedirects(int maxRedirects);
64+
65+
/**
66+
* Gets the max redirects
67+
*
68+
* @return Max redirects that a request can take
69+
*/
70+
int getMaxRedirects();
71+
72+
/**
73+
* Sets the should redirect callback
74+
*
75+
* @param shouldRedirect Callback called before doing a redirect
76+
*/
77+
void setShouldRedirect(IShouldRedirect shouldRedirect);
78+
79+
/**
80+
* Gets the should redirect callback
81+
*
82+
* @return Callback which is called before redirect
83+
*/
84+
IShouldRedirect getShouldRedirect();
85+
86+
/**
87+
* Sets the should retry callback
88+
*
89+
* @param shouldretry The callback called before retry
90+
*/
91+
void setShouldRetry(IShouldRetry shouldretry);
92+
93+
/**
94+
* Gets the should retry callback
95+
*
96+
* @return Callback called before retry
97+
*/
98+
IShouldRetry getShouldRetry();
99+
100+
/**
101+
* Sets the max retries
102+
*
103+
* @param Max retries for a request
104+
*/
105+
void setMaxRetries(int maxRetries);
106+
107+
/**
108+
* Gets max retries
109+
*
110+
* @return Max retries for a request
111+
*/
112+
int getMaxRetries();
113+
114+
/**
115+
* Sets the delay in seconds between retires
116+
*
117+
* @param delay Delay in seconds between retries
118+
*/
119+
void setDelay(long delay);
120+
121+
/**
122+
* Gets delay between retries
123+
*
124+
* @return Delay between retries in seconds
125+
*/
126+
long getDelay();
127+
54128
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.google.gson.Gson;
3232
import com.google.gson.GsonBuilder;
3333
import com.microsoft.graph.core.ClientException;
34+
import com.microsoft.graph.core.GraphErrorCodes;
3435
import com.microsoft.graph.logger.ILogger;
3536
import com.microsoft.graph.logger.LoggerLevel;
3637
import com.microsoft.graph.options.HeaderOption;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ public interface IStatefulResponseHandler<ResultType, DeserializedType> {
4343
* @param connection the HTTP connection
4444
*/
4545
void configConnection(final IConnection connection);
46+
47+
/**
48+
* Configure the response
49+
*
50+
* @param response the HTTP response
51+
*/
52+
void configConnection(final Response connection);
4653

4754
/**
4855
* Generate result after receiving response

0 commit comments

Comments
 (0)