forked from Archives/Athou_commafeed
handle pushpress errors
This commit is contained in:
@@ -7,12 +7,11 @@ import java.util.Date;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.apache.commons.lang.mutable.MutableBoolean;
|
import org.apache.commons.lang.mutable.MutableBoolean;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.commafeed.backend.MetricsBean;
|
|
||||||
import com.commafeed.backend.HttpGetter.NotModifiedException;
|
import com.commafeed.backend.HttpGetter.NotModifiedException;
|
||||||
|
import com.commafeed.backend.MetricsBean;
|
||||||
import com.commafeed.backend.model.Feed;
|
import com.commafeed.backend.model.Feed;
|
||||||
import com.commafeed.backend.model.FeedEntry;
|
import com.commafeed.backend.model.FeedEntry;
|
||||||
import com.commafeed.backend.model.FeedPushInfo;
|
import com.commafeed.backend.model.FeedPushInfo;
|
||||||
@@ -143,13 +142,6 @@ public class FeedRefreshWorker {
|
|||||||
if (info == null) {
|
if (info == null) {
|
||||||
info = feedPushInfoService.findOrCreate(feed, hub, topic);
|
info = feedPushInfoService.findOrCreate(feed, hub, topic);
|
||||||
}
|
}
|
||||||
if (!StringUtils.equals(hub, info.getHub())
|
|
||||||
|| !StringUtils.equals(topic, info.getTopic())) {
|
|
||||||
info.setHub(hub);
|
|
||||||
info.setTopic(topic);
|
|
||||||
info.setFeed(feed);
|
|
||||||
info.setActive(false);
|
|
||||||
}
|
|
||||||
feed.setPushInfo(info);
|
feed.setPushInfo(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.http.HttpHeaders;
|
import org.apache.http.HttpHeaders;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.NameValuePair;
|
import org.apache.http.NameValuePair;
|
||||||
@@ -17,6 +18,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.commafeed.backend.HttpGetter;
|
import com.commafeed.backend.HttpGetter;
|
||||||
|
import com.commafeed.backend.dao.FeedPushInfoDAO;
|
||||||
import com.commafeed.backend.model.Feed;
|
import com.commafeed.backend.model.Feed;
|
||||||
import com.commafeed.backend.model.FeedPushInfo;
|
import com.commafeed.backend.model.FeedPushInfo;
|
||||||
import com.commafeed.backend.services.ApplicationSettingsService;
|
import com.commafeed.backend.services.ApplicationSettingsService;
|
||||||
@@ -30,6 +32,9 @@ public class SubscriptionHandler {
|
|||||||
@Inject
|
@Inject
|
||||||
ApplicationSettingsService applicationSettingsService;
|
ApplicationSettingsService applicationSettingsService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FeedPushInfoDAO feedPushInfoDAO;
|
||||||
|
|
||||||
public void subscribe(Feed feed) {
|
public void subscribe(Feed feed) {
|
||||||
FeedPushInfo info = feed.getPushInfo();
|
FeedPushInfo info = feed.getPushInfo();
|
||||||
String hub = info.getHub();
|
String hub = info.getHub();
|
||||||
@@ -63,9 +68,20 @@ public class SubscriptionHandler {
|
|||||||
|
|
||||||
int code = response.getStatusLine().getStatusCode();
|
int code = response.getStatusLine().getStatusCode();
|
||||||
if (code != 204 && code != 202 && code != 200) {
|
if (code != 204 && code != 202 && code != 200) {
|
||||||
throw new Exception("Unexpected response code: " + code + " "
|
String message = EntityUtils.toString(response.getEntity());
|
||||||
+ response.getStatusLine().getReasonPhrase() + " - "
|
String pushpressError = " is value is not allowed. You may only subscribe to";
|
||||||
+ EntityUtils.toString(response.getEntity()));
|
if (code == 400
|
||||||
|
&& StringUtils.contains(message, pushpressError)) {
|
||||||
|
String[] tokens = message.split(" ");
|
||||||
|
info.setTopic(tokens[tokens.length - 1]);
|
||||||
|
feedPushInfoDAO.update(info);
|
||||||
|
log.debug("handled pushpress subfeed {} : {}", topic,
|
||||||
|
info.getTopic());
|
||||||
|
} else {
|
||||||
|
throw new Exception("Unexpected response code: " + code
|
||||||
|
+ " " + response.getStatusLine().getReasonPhrase()
|
||||||
|
+ " - " + message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log.debug("subscribed to {} for {}", hub, topic);
|
log.debug("subscribed to {} for {}", hub, topic);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user