Skip to content

Commit e8e4f86

Browse files
fixed #276
1 parent 108ee94 commit e8e4f86

File tree

3 files changed

+74
-15
lines changed

3 files changed

+74
-15
lines changed

src/main/java/org/woehlke/twitterwall/backend/service/remote/impl/TwitterApiServiceImpl.java

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.slf4j.LoggerFactory;
55
import org.springframework.beans.factory.annotation.Autowired;
66
import org.springframework.core.env.Environment;
7+
import org.springframework.social.ApiException;
78
import org.springframework.social.RateLimitExceededException;
89
import org.springframework.social.ResourceNotFoundException;
910
import org.springframework.social.twitter.api.*;
@@ -36,7 +37,7 @@ public List<Tweet> findTweetsForSearchQuery() {
3637
fetchedTweets = getTwitterProxy().searchOperations().search(twitterProperties.getSearchQuery(), twitterProperties.getPageSize()).getTweets();
3738
msg += " result: ";
3839
if (fetchedTweets.size() == 0) {
39-
log.error(msg + " result.size: 0");
40+
log.warn(msg + " result.size: 0");
4041
return new ArrayList<>();
4142
} else {
4243
log.debug(msg + " result.size: " + fetchedTweets.size());
@@ -45,6 +46,8 @@ public List<Tweet> findTweetsForSearchQuery() {
4546
} catch (RateLimitExceededException e) {
4647
log.warn(msg + " Rate Limit Exceeded : ");
4748
waitLongerForApi();
49+
} catch (ApiException apiEx){
50+
log.warn(msg + " Api Exception : " + apiEx.getMessage());
4851
} catch (Exception e) {
4952
log.error(msg + e.getMessage());
5053
return new ArrayList<>();
@@ -68,6 +71,11 @@ public Tweet findOneTweetById(long tweetTwitterId) {
6871
} catch (RateLimitExceededException e) {
6972
log.warn(msg + " Rate Limit Exceeded ");
7073
waitLongerForApi();
74+
} catch (ResourceNotFoundException ex){
75+
log.warn(msg + ex.getMessage());
76+
waitForApi();
77+
} catch (ApiException apiEx){
78+
log.warn(msg + " Api Exception : " + apiEx.getMessage());
7179
} catch (Exception e) {
7280
log.error(msg + e.getMessage());
7381
e.printStackTrace();
@@ -86,7 +94,7 @@ public List<Tweet> getHomeTimeline() {
8694
fetchedTweets = getTwitterProxy().timelineOperations().getHomeTimeline(twitterProperties.getPageSize());
8795
msg += " result: ";
8896
if (fetchedTweets.size() == 0) {
89-
log.error(msg + " result.size: 0");
97+
log.warn(msg + " result.size: 0");
9098
return new ArrayList<>();
9199
} else {
92100
log.debug(msg + " result.size: " + fetchedTweets.size());
@@ -95,6 +103,8 @@ public List<Tweet> getHomeTimeline() {
95103
} catch (RateLimitExceededException e) {
96104
log.warn(msg + " Rate Limit Exceeded : ");
97105
waitLongerForApi();
106+
} catch (ApiException apiEx){
107+
log.warn(msg + " Api Exception : " + apiEx.getMessage());
98108
} catch (Exception e) {
99109
log.error(msg + e.getMessage());
100110
return new ArrayList<>();
@@ -112,7 +122,7 @@ public List<Tweet> getUserTimeline() {
112122
fetchedTweets = getTwitterProxy().timelineOperations().getUserTimeline(twitterProperties.getPageSize());
113123
msg += " result: ";
114124
if (fetchedTweets.size() == 0) {
115-
log.error(msg + " result.size: 0");
125+
log.warn(msg + " result.size: 0");
116126
//TODO: Why?
117127
return new ArrayList<>();
118128
} else {
@@ -122,6 +132,8 @@ public List<Tweet> getUserTimeline() {
122132
} catch (RateLimitExceededException e) {
123133
log.warn(msg + " Rate Limit Exceeded : ");
124134
waitLongerForApi();
135+
} catch (ApiException apiEx){
136+
log.warn(msg + " Api Exception : " + apiEx.getMessage());
125137
} catch (Exception e) {
126138
log.error(msg + e.getMessage());
127139
return new ArrayList<>();
@@ -139,7 +151,7 @@ public List<Tweet> getMentions() {
139151
fetchedTweets = getTwitterProxy().timelineOperations().getMentions(twitterProperties.getPageSize());
140152
msg += " result: ";
141153
if (fetchedTweets.size() == 0) {
142-
log.error(msg + " result.size: 0");
154+
log.warn(msg + " result.size: 0");
143155
return new ArrayList<>();
144156
} else {
145157
log.debug(msg + " result.size: " + fetchedTweets.size());
@@ -148,6 +160,9 @@ public List<Tweet> getMentions() {
148160
} catch (RateLimitExceededException e) {
149161
log.warn(msg + " Rate Limit Exceeded : ");
150162
waitLongerForApi();
163+
} catch (ApiException apiEx){
164+
log.warn(msg + " Api Exception : " + apiEx.getMessage());
165+
waitLongerForApi();
151166
} catch (Exception e) {
152167
log.error(msg + e.getMessage());
153168
return new ArrayList<>();
@@ -165,7 +180,7 @@ public List<Tweet> getFavorites() {
165180
fetchedTweets = getTwitterProxy().timelineOperations().getFavorites(twitterProperties.getPageSize());
166181
msg += " result: ";
167182
if (fetchedTweets.size() == 0) {
168-
log.error(msg + " result.size: 0");
183+
log.warn(msg + " result.size: 0");
169184
return new ArrayList<>();
170185
} else {
171186
log.debug(msg + " result.size: " + fetchedTweets.size());
@@ -174,6 +189,9 @@ public List<Tweet> getFavorites() {
174189
} catch (RateLimitExceededException e) {
175190
log.warn(msg + " Rate Limit Exceeded : ");
176191
waitLongerForApi();
192+
} catch (ApiException apiEx){
193+
log.warn(msg + " Api Exception : " + apiEx.getMessage());
194+
waitLongerForApi();
177195
} catch (Exception e) {
178196
log.error(msg + e.getMessage());
179197
return new ArrayList<>();
@@ -200,6 +218,9 @@ public List<Tweet> getRetweetsOfMe(){
200218
} catch (RateLimitExceededException e) {
201219
log.warn(msg + " Rate Limit Exceeded : ");
202220
waitLongerForApi();
221+
} catch (ApiException apiEx){
222+
log.warn(msg + " Api Exception : " + apiEx.getMessage());
223+
waitLongerForApi();
203224
} catch (Exception e) {
204225
log.error(msg + e.getMessage());
205226
return new ArrayList<>();
@@ -222,8 +243,11 @@ public User2UserList getLists(){
222243
} catch (RateLimitExceededException e) {
223244
log.warn(msg + " Rate Limit Exceeded : " + exceptionMsg1);
224245
waitLongerForApi();
246+
} catch (ApiException apiEx){
247+
log.warn(msg + " Api Exception : " + apiEx.getMessage());
248+
waitLongerForApi();
225249
} catch (Exception e) {
226-
log.warn(msg + "Exception at: " + exceptionMsg1 + e.getMessage());
250+
log.error(msg + "Exception at: " + exceptionMsg1 + e.getMessage());
227251
}
228252
}
229253
return null;
@@ -252,8 +276,14 @@ public User2UserList getUserListForUser(long idTwitterOfListOwningUser){
252276
} catch (RateLimitExceededException e) {
253277
log.warn(msg + " Rate Limit Exceeded : "+exceptionMsg1);
254278
waitLongerForApi();
279+
} catch (ResourceNotFoundException ex){
280+
log.warn(msg + ex.getMessage());
281+
waitForApi();
282+
} catch (ApiException apiEx){
283+
log.warn(msg + " Api Exception : " + apiEx.getMessage());
284+
waitLongerForApi();
255285
} catch (Exception e) {
256-
log.warn(msg + "Exception at: "+exceptionMsg1+ e.getMessage());
286+
log.error(msg + "Exception at: "+exceptionMsg1+ e.getMessage());
257287
}
258288
}
259289
doTheJob = true;
@@ -268,8 +298,14 @@ public User2UserList getUserListForUser(long idTwitterOfListOwningUser){
268298
} catch (RateLimitExceededException e) {
269299
log.warn(msg + " Rate Limit Exceeded : "+exceptionMsg2);
270300
waitLongerForApi();
271-
} catch (Exception e) {
272-
log.warn(msg + "Exception at: "+exceptionMsg2+ e.getMessage());
301+
} catch (ResourceNotFoundException ex){
302+
log.warn(msg + ex.getMessage());
303+
waitForApi();
304+
} catch (ApiException apiEx){
305+
log.warn(msg + " Api Exception : " + apiEx.getMessage());
306+
waitLongerForApi();
307+
} catch (Exception e) {
308+
log.error(msg + "Exception at: "+exceptionMsg2+ e.getMessage());
273309
}
274310
}
275311
doTheJob = true;
@@ -284,8 +320,14 @@ public User2UserList getUserListForUser(long idTwitterOfListOwningUser){
284320
} catch (RateLimitExceededException e) {
285321
log.warn(msg + " Rate Limit Exceeded : "+exceptionMsg3);
286322
waitLongerForApi();
323+
} catch (ResourceNotFoundException ex){
324+
log.warn(msg + ex.getMessage());
325+
waitForApi();
326+
} catch (ApiException apiEx){
327+
log.warn(msg + " Api Exception : " + apiEx.getMessage());
328+
waitLongerForApi();
287329
} catch (Exception e) {
288-
log.warn(msg + "Exception at: "+exceptionMsg3+ e.getMessage());
330+
log.error(msg + "Exception at: "+exceptionMsg3+ e.getMessage());
289331
}
290332
}
291333
User2UserList result = new User2UserList();
@@ -316,6 +358,9 @@ public TwitterProfile getUserProfileForTwitterId(long userProfileTwitterId) {
316358
} catch (ResourceNotFoundException e) {
317359
log.warn(msg + " User not found : " + userProfileTwitterId);
318360
return null;
361+
} catch (ApiException apiEx){
362+
log.warn(msg + " Api Exception : " + apiEx.getMessage());
363+
waitLongerForApi();
319364
} catch (Exception e) {
320365
log.error(msg + e.getMessage());
321366
return null;
@@ -342,6 +387,9 @@ public TwitterProfile getUserProfileForScreenName(String screenName) {
342387
} catch (ResourceNotFoundException e) {
343388
log.warn(msg + " User not found : " + screenName);
344389
return null;
390+
} catch (ApiException apiEx){
391+
log.warn(msg + " Api Exception : " + apiEx.getMessage());
392+
waitLongerForApi();
345393
} catch (Exception e) {
346394
log.error(msg + e.getMessage());
347395
return null;
@@ -362,6 +410,12 @@ public List<TwitterProfile> findUsersFromDefinedList(String screenNameOfTheListO
362410
} catch (RateLimitExceededException e) {
363411
log.warn(msg + " Rate Limit Exceeded : ");
364412
waitLongerForApi();
413+
} catch (ResourceNotFoundException ex){
414+
log.warn(msg + ex.getMessage());
415+
waitForApi();
416+
} catch (ApiException apiEx){
417+
log.warn(msg + " Api Exception : " + apiEx.getMessage());
418+
waitLongerForApi();
365419
} catch (Exception e) {
366420
log.error(msg + e.getMessage());
367421
return new ArrayList<>();
@@ -382,6 +436,9 @@ public CursoredList<Long> getFollowerIds() {
382436
} catch (RateLimitExceededException e) {
383437
log.warn(msg + " Rate Limit Exceeded : ");
384438
waitLongerForApi();
439+
} catch (ApiException apiEx){
440+
log.warn(msg + " Api Exception : " + apiEx.getMessage());
441+
waitLongerForApi();
385442
} catch (Exception e) {
386443
log.error(msg + e.getMessage());
387444
return new CursoredList<>(new ArrayList<>(), 0L, 0L);
@@ -402,6 +459,9 @@ public CursoredList<Long> getFriendIds() {
402459
} catch (RateLimitExceededException e) {
403460
log.warn(msg + " Rate Limit Exceeded : ");
404461
waitLongerForApi();
462+
} catch (ApiException apiEx){
463+
log.warn(msg + " Api Exception : " + apiEx.getMessage());
464+
waitLongerForApi();
405465
} catch (Exception e) {
406466
log.error(msg + e.getMessage());
407467
return new CursoredList<>(new ArrayList<>(), 0L, 0L);

src/test/java/org/woehlke/twitterwall/AlphaTopLevelSuiteIT.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@
5050
UserControllerTest.class,
5151
UserListControllerTest.class,
5252

53-
/*
54-
TwitterUrlServiceTest.class,
53+
//TwitterUrlServiceTest.class,
5554

56-
TaskStartFireAndForgetTestImpl.class,
57-
TaskStartTestImpl.class,
58-
*/
55+
//TaskStartFireAndForgetTestImpl.class,
56+
//TaskStartTestImpl.class,
5957

6058
CronJobsTest.class
6159
})

src/test/resources/logback.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<logger name="org.woehlke.twitterwall.backend.service.persist" level="INFO" />
1919
<logger name="org.woehlke.twitterwall.backend.service.persist.impl" level="ERROR" />
2020
<logger name="org.woehlke.twitterwall.backend.service.transform" level="INFO" />
21+
<logger name="org.woehlke.twitterwall.backend.service.remote.impl" level="ERROR" />
2122
<logger name="org.woehlke.twitterwall" level="WARN" />
2223
<logger name="org.apache.http" level="WARN" />
2324
<logger name="org.apache.tomcat" level="WARN" />

0 commit comments

Comments
 (0)