mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
tweak feed fetching
This commit is contained in:
@@ -1,14 +1,6 @@
|
||||
package com.commafeed.backend.feeds;
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.ejb.AccessTimeout;
|
||||
import javax.ejb.AsyncResult;
|
||||
import javax.ejb.Asynchronous;
|
||||
import javax.ejb.Lock;
|
||||
import javax.ejb.LockType;
|
||||
import javax.ejb.Singleton;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
@@ -16,14 +8,16 @@ import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.params.HttpConnectionParams;
|
||||
import org.apache.http.params.HttpProtocolParams;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.sun.syndication.io.FeedException;
|
||||
|
||||
@Singleton
|
||||
@Stateless
|
||||
public class FeedFetcher {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(FeedFetcher.class);
|
||||
@@ -31,15 +25,15 @@ public class FeedFetcher {
|
||||
@Inject
|
||||
FeedParser parser;
|
||||
|
||||
@Asynchronous
|
||||
@Lock(LockType.READ)
|
||||
@AccessTimeout(value = 15, unit = TimeUnit.SECONDS)
|
||||
public Future<Feed> fetch(String feedUrl) {
|
||||
public Feed fetch(String feedUrl) throws FeedException {
|
||||
log.debug("Fetching feed {}", feedUrl);
|
||||
Feed feed = null;
|
||||
|
||||
HttpClient httpclient = new DefaultHttpClient();
|
||||
HttpProtocolParams.setContentCharset(httpclient.getParams(), "UTF-8");
|
||||
HttpConnectionParams
|
||||
.setConnectionTimeout(httpclient.getParams(), 15000);
|
||||
HttpConnectionParams.setSoTimeout(httpclient.getParams(), 15000);
|
||||
|
||||
try {
|
||||
HttpGet httpget = new HttpGet(feedUrl);
|
||||
@@ -48,11 +42,11 @@ public class FeedFetcher {
|
||||
String content = EntityUtils.toString(entity, "UTF-8");
|
||||
feed = parser.parse(feedUrl, content);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
throw new FeedException(e.getMessage(), e);
|
||||
} finally {
|
||||
httpclient.getConnectionManager().shutdown();
|
||||
}
|
||||
return new AsyncResult<Feed>(feed);
|
||||
return feed;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user