propagate exception message

This commit is contained in:
Athou
2013-07-03 07:56:52 +02:00
parent 4565a7c43f
commit e759d095ed
4 changed files with 17 additions and 16 deletions

View File

@@ -110,7 +110,7 @@ public class HttpGetter {
response = client.execute(httpget);
int code = response.getStatusLine().getStatusCode();
if (code == HttpStatus.SC_NOT_MODIFIED) {
throw new NotModifiedException();
throw new NotModifiedException("304 http code");
} else if (code >= 300) {
throw new HttpResponseException(code,
"Server returned HTTP error code " + code);
@@ -118,7 +118,7 @@ public class HttpGetter {
} catch (HttpResponseException e) {
if (e.getStatusCode() == HttpStatus.SC_NOT_MODIFIED) {
throw new NotModifiedException();
throw new NotModifiedException("304 http code");
} else {
throw e;
}
@@ -131,13 +131,13 @@ public class HttpGetter {
: lastModifiedHeader.getValue();
if (lastModified != null
&& StringUtils.equals(lastModified, lastModifiedResponse)) {
throw new NotModifiedException();
throw new NotModifiedException("lastModifiedHeader is the same");
}
String eTagResponse = eTagHeader == null ? null : eTagHeader
.getValue();
if (eTag != null && StringUtils.equals(eTag, eTagResponse)) {
throw new NotModifiedException();
throw new NotModifiedException("eTagHeader is the same");
}
HttpEntity entity = response.getEntity();
@@ -217,6 +217,10 @@ public class HttpGetter {
public static class NotModifiedException extends Exception {
private static final long serialVersionUID = 1L;
public NotModifiedException(String message){
super(message);
}
}

View File

@@ -57,7 +57,7 @@ public class FeedFetcher {
if (lastContentHash != null && hash != null
&& lastContentHash.equals(hash)) {
log.debug("content hash not modified: {}", feedUrl);
throw new NotModifiedException();
throw new NotModifiedException("content hash not modified");
}
fetchedFeed = parser.parse(feedUrl, content);
@@ -67,7 +67,7 @@ public class FeedFetcher {
&& lastPublishedDate.getTime() == fetchedFeed.getFeed()
.getLastPublishedDate().getTime()) {
log.debug("publishedDate not modified: {}", feedUrl);
throw new NotModifiedException();
throw new NotModifiedException("publishedDate not modified");
}
Feed feed = fetchedFeed.getFeed();

View File

@@ -93,7 +93,7 @@ public class FeedParser {
entry.setUrl(FeedUtils.truncate(
FeedUtils.toAbsoluteUrl(item.getLink(), feed.getLink()),
2048));
entry.setUpdated(validateDate(getEntryUpdateDate(item)));
entry.setUpdated(validateDate(getEntryUpdateDate(item), true));
entry.setAuthor(item.getAuthor());
FeedEntryContent content = new FeedEntryContent();
@@ -111,7 +111,7 @@ public class FeedParser {
entries.add(entry);
}
Date lastEntryDate = null;
Date publishedDate = validateDate(rss.getPublishedDate());
Date publishedDate = validateDate(rss.getPublishedDate(), false);
if (!entries.isEmpty()) {
List<Long> sortedTimestamps = FeedUtils
.getSortedTimestamps(entries);
@@ -119,7 +119,7 @@ public class FeedParser {
lastEntryDate = new Date(timestamp);
publishedDate = getFeedPublishedDate(publishedDate, entries);
}
feed.setLastPublishedDate(publishedDate);
feed.setLastPublishedDate(validateDate(publishedDate, true));
feed.setAverageEntryInterval(FeedUtils
.averageTimeBetweenEntries(entries));
feed.setLastEntryDate(lastEntryDate);
@@ -160,12 +160,9 @@ public class FeedParser {
private Date getFeedPublishedDate(Date publishedDate,
List<FeedEntry> entries) {
if (publishedDate == null) {
return null;
}
for (FeedEntry entry : entries) {
if (entry.getUpdated().getTime() > publishedDate.getTime()) {
if (publishedDate == null || entry.getUpdated().getTime() > publishedDate.getTime()) {
publishedDate = entry.getUpdated();
}
}
@@ -183,10 +180,10 @@ public class FeedParser {
return date;
}
private Date validateDate(Date date) {
private Date validateDate(Date date, boolean nullToNow) {
Date now = new Date();
if (date == null) {
return now;
return nullToNow ? now : null;
}
if (date.before(START) || date.after(END)) {
return now;

View File

@@ -125,7 +125,7 @@ public class FeedRefreshWorker {
feedRefreshUpdater.updateFeed(feed, entries);
} catch (NotModifiedException e) {
log.debug("Feed not modified (304) : " + feed.getUrl());
log.debug("Feed not modified : {} - {}", feed.getUrl(), e.getMessage());
Date disabledUntil = null;
if (applicationSettingsService.get().isHeavyLoad()) {