Skip to content

Commit 9b4e459

Browse files
basic retry functions
1 parent 2e54bb7 commit 9b4e459

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>apereo</groupId>
77
<artifactId>data-loader-library</artifactId>
8-
<version>1.0.3</version>
8+
<version>1.0.4</version>
99
<packaging>jar</packaging>
1010

1111
<name>apereo-data-loader-library</name>

src/main/java/unicon/matthews/dataloader/MatthewsClient.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,16 @@ public void postEnrollment(Enrollment enrollment) {
124124
String path = "/api/classes/{classSourcedId}/enrollments";
125125
String url = this.baseUrl + StringUtils.replace(path, "{classSourcedId}", enrollment.getKlass().getSourcedId());
126126

127-
restTemplate
128-
.exchange(url, HttpMethod.POST, he, JsonObject.class);
127+
ResponseEntity<JsonObject> response =
128+
restTemplate
129+
.exchange(url, HttpMethod.POST, he, JsonObject.class);
130+
131+
if (response != null && response.getStatusCode() == HttpStatus.UNAUTHORIZED) {
132+
httpHeaders.add("Authorization", "Bearer "+ getToken());
133+
restTemplate
134+
.exchange(url, HttpMethod.POST, he, JsonObject.class);
135+
}
136+
129137
}
130138

131139
public void postUser(User user) {
@@ -139,7 +147,7 @@ public void postUser(User user) {
139147
.exchange(url, HttpMethod.POST, he, JsonObject.class);
140148

141149

142-
if (response != null && response.getStatusCode() == HttpStatus.FORBIDDEN) {
150+
if (response != null && response.getStatusCode() == HttpStatus.UNAUTHORIZED) {
143151
httpHeaders.add("Authorization", "Bearer "+ getToken());
144152
restTemplate
145153
.exchange(url, HttpMethod.POST, he, JsonObject.class);
@@ -153,9 +161,16 @@ public void postUserMapping(UserMapping userMapping) {
153161
String path = "/api/users/mapping";
154162
String url = this.baseUrl + path;
155163

156-
restTemplate
164+
ResponseEntity<JsonObject> response =
165+
restTemplate
157166
.exchange(url, HttpMethod.POST, he, JsonObject.class);
158167

168+
if (response != null && response.getStatusCode() == HttpStatus.UNAUTHORIZED) {
169+
httpHeaders.add("Authorization", "Bearer "+ getToken());
170+
restTemplate
171+
.exchange(url, HttpMethod.POST, he, JsonObject.class);
172+
}
173+
159174
}
160175

161176
public void postLineItem(LineItem lineItem) {

0 commit comments

Comments
 (0)