diff --git a/src/main/java/com/commafeed/backend/HttpGetter.java b/src/main/java/com/commafeed/backend/HttpGetter.java index 0455049e..474c080a 100644 --- a/src/main/java/com/commafeed/backend/HttpGetter.java +++ b/src/main/java/com/commafeed/backend/HttpGetter.java @@ -1,7 +1,10 @@ package com.commafeed.backend; +import java.io.IOException; + import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.params.CookiePolicy; @@ -18,7 +21,8 @@ public class HttpGetter { return new String(getBinary(url), "UTF-8"); } - public byte[] getBinary(String url) throws Exception { + public byte[] getBinary(String url) throws ClientProtocolException, + IOException { byte[] content = null; HttpClient httpclient = new DefaultHttpClient(); diff --git a/src/main/java/com/commafeed/backend/feeds/FeedFetcher.java b/src/main/java/com/commafeed/backend/feeds/FeedFetcher.java index 99535ff2..811952f1 100644 --- a/src/main/java/com/commafeed/backend/feeds/FeedFetcher.java +++ b/src/main/java/com/commafeed/backend/feeds/FeedFetcher.java @@ -1,7 +1,11 @@ package com.commafeed.backend.feeds; +import java.io.IOException; + import javax.inject.Inject; +import org.apache.commons.codec.binary.StringUtils; +import org.apache.http.client.ClientProtocolException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; @@ -22,21 +26,19 @@ public class FeedFetcher { @Inject HttpGetter getter; - public Feed fetch(String feedUrl) throws FeedException { + public Feed fetch(String feedUrl) throws FeedException, + ClientProtocolException, IOException { log.debug("Fetching feed {}", feedUrl); Feed feed = null; - try { - byte[] content = getter.getBinary(feedUrl); - String extractedUrl = extractFeedUrl(new String(content, "UTF-8")); - if (extractedUrl != null) { - content = getter.getBinary(extractedUrl); - feedUrl = extractedUrl; - } - feed = parser.parse(feedUrl, content); - } catch (Exception e) { - throw new FeedException(e.getMessage(), e); + byte[] content = getter.getBinary(feedUrl); + String extractedUrl = extractFeedUrl(StringUtils.newStringUtf8(content)); + if (extractedUrl != null) { + content = getter.getBinary(extractedUrl); + feedUrl = extractedUrl; } + feed = parser.parse(feedUrl, content); + return feed; } diff --git a/src/main/java/com/commafeed/frontend/rest/resources/SubscriptionsREST.java b/src/main/java/com/commafeed/frontend/rest/resources/SubscriptionsREST.java index ed6b734a..43f7ea55 100644 --- a/src/main/java/com/commafeed/frontend/rest/resources/SubscriptionsREST.java +++ b/src/main/java/com/commafeed/frontend/rest/resources/SubscriptionsREST.java @@ -30,7 +30,6 @@ import com.commafeed.frontend.model.Subscription; import com.commafeed.frontend.model.SubscriptionRequest; import com.commafeed.frontend.rest.resources.EntriesREST.Type; import com.google.common.base.Preconditions; -import com.sun.syndication.io.FeedException; @Path("subscriptions") public class SubscriptionsREST extends AbstractREST { @@ -44,7 +43,7 @@ public class SubscriptionsREST extends AbstractREST { Feed feed = null; try { feed = feedFetcher.fetch(url); - } catch (FeedException e) { + } catch (Exception e) { throw new WebApplicationException(e, Response .status(Status.INTERNAL_SERVER_ERROR) .entity(e.getMessage()).build());