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