Replaced / removed deprecated code

This commit is contained in:
Patrick Gotthard 2014-04-12 21:38:12 +02:00
parent 279642a53d
commit 6fa6b2aec5

View file

@ -28,6 +28,7 @@ import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpClientParams;
import org.rometools.fetcher.FetcherEvent;
@ -157,23 +158,24 @@ public class HttpClientFeedFetcher extends AbstractFeedFetcher {
*/
@Override
public SyndFeed retrieveFeed(final String userAgent, final URL feedUrl) throws IllegalArgumentException, IOException, FeedException, FetcherException {
if (feedUrl == null) {
throw new IllegalArgumentException("null is not a valid URL");
}
// TODO Fix this
// System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
final HttpClient client = new HttpClient(httpClientParams);
if (getCredentialSupplier() != null) {
client.getState().setAuthenticationPreemptive(true);
// TODO what should realm be here?
final Credentials credentials = getCredentialSupplier().getCredentials(null, feedUrl.getHost());
client.getParams().setAuthenticationPreemptive(true);
final String host = feedUrl.getHost();
final Credentials credentials = getCredentialSupplier().getCredentials(null, host);
if (credentials != null) {
client.getState().setCredentials(null, feedUrl.getHost(), credentials);
final AuthScope authScope = new AuthScope(host, -1);
client.getState().setCredentials(authScope, credentials);
}
}
System.setProperty("httpclient.useragent", userAgent);
@ -229,7 +231,6 @@ public class HttpClientFeedFetcher extends AbstractFeedFetcher {
return feed;
} finally {
method.releaseConnection();
method.recycle();
}
} else {
// cache is not in use
@ -241,16 +242,15 @@ public class HttpClientFeedFetcher extends AbstractFeedFetcher {
return getFeed(null, urlStr, method, statusCode);
} finally {
method.releaseConnection();
method.recycle();
}
}
}
private SyndFeed getFeed(final SyndFeedInfo syndFeedInfo, final String urlStr, final HttpMethod method, final int statusCode) throws IOException,
HttpException, FetcherException, FeedException {
if (statusCode == HttpURLConnection.HTTP_NOT_MODIFIED && syndFeedInfo != null) {
fireEvent(FetcherEvent.EVENT_TYPE_FEED_UNCHANGED, urlStr);
return syndFeedInfo.getSyndFeed();
}
@ -270,6 +270,7 @@ public class HttpClientFeedFetcher extends AbstractFeedFetcher {
*/
private SyndFeedInfo buildSyndFeedInfo(final URL feedUrl, final String urlStr, final HttpMethod method, SyndFeed feed, final int statusCode)
throws MalformedURLException {
SyndFeedInfo syndFeedInfo;
syndFeedInfo = new SyndFeedInfo();
@ -324,6 +325,7 @@ public class HttpClientFeedFetcher extends AbstractFeedFetcher {
* @throws FeedException
*/
private SyndFeed retrieveFeed(final String urlStr, final HttpMethod method) throws IOException, HttpException, FetcherException, FeedException {
InputStream stream = null;
if (method.getResponseHeader("Content-Encoding") != null && "gzip".equalsIgnoreCase(method.getResponseHeader("Content-Encoding").getValue())) {
@ -365,4 +367,5 @@ public class HttpClientFeedFetcher extends AbstractFeedFetcher {
*/
public void afterHttpClientMethodCreate(HttpMethod method);
}
}