Updated news reader to use proxy data provided by Eclipse when creating http connections; fix for Bug 9564.
--- a/core/com.nokia.carbide.cpp.news.reader/META-INF/MANIFEST.MF Tue Aug 11 14:22:33 2009 -0500
+++ b/core/com.nokia.carbide.cpp.news.reader/META-INF/MANIFEST.MF Tue Aug 11 15:01:16 2009 -0500
@@ -5,7 +5,8 @@
Bundle-Version: 1.4.0.qualifier
Bundle-Activator: com.nokia.carbide.cpp.internal.news.reader.CarbideNewsReaderPlugin
Bundle-Vendor: Nokia
-Require-Bundle: org.eclipse.core.resources,
+Require-Bundle: org.eclipse.core.net,
+ org.eclipse.core.resources,
org.eclipse.core.runtime,
org.eclipse.emf.ecore,
org.eclipse.emf.ecore.xmi,
--- a/core/com.nokia.carbide.cpp.news.reader/src/com/nokia/carbide/cpp/internal/news/reader/CarbideNewsReaderPlugin.java Tue Aug 11 14:22:33 2009 -0500
+++ b/core/com.nokia.carbide.cpp.news.reader/src/com/nokia/carbide/cpp/internal/news/reader/CarbideNewsReaderPlugin.java Tue Aug 11 15:01:16 2009 -0500
@@ -18,8 +18,11 @@
package com.nokia.carbide.cpp.internal.news.reader;
import java.io.IOException;
+import java.net.URISyntaxException;
import java.net.URL;
+import org.eclipse.core.net.proxy.IProxyData;
+import org.eclipse.core.net.proxy.IProxyService;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -34,6 +37,7 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
import com.nokia.carbide.cpp.internal.news.reader.editor.NewsEditor;
import com.nokia.carbide.cpp.internal.news.reader.feed.FeedManager;
@@ -121,6 +125,32 @@
}
/**
+ * Retrieve proxy data for a given URL.
+ * @param url - URL in question
+ * @return proxy data associated with the URL if one is available, null otherwise
+ */
+ public static IProxyData getProxyData(URL url) {
+ BundleContext context = getDefault().getBundle().getBundleContext();
+ if (context != null) {
+ ServiceReference reference = context.getServiceReference(IProxyService.class.getName());
+ if (reference != null) {
+ IProxyService proxyService = (IProxyService) context.getService(reference);
+ if (proxyService != null) {
+ try {
+ IProxyData[] proxyData = proxyService.select(url.toURI());
+ if (proxyData != null && proxyData.length > 0) {
+ return proxyData[0];
+ }
+ } catch (URISyntaxException e) {
+ return null;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
* Launch the Carbide.c++ news page.
*/
public static void launchNewsPage() {
--- a/core/com.nokia.carbide.cpp.news.reader/src/com/nokia/carbide/cpp/internal/news/reader/feed/CarbideFeedFetcher.java Tue Aug 11 14:22:33 2009 -0500
+++ b/core/com.nokia.carbide.cpp.news.reader/src/com/nokia/carbide/cpp/internal/news/reader/feed/CarbideFeedFetcher.java Tue Aug 11 15:01:16 2009 -0500
@@ -17,11 +17,19 @@
package com.nokia.carbide.cpp.internal.news.reader.feed;
+import java.io.IOException;
+import java.net.URL;
import java.net.URLConnection;
+import org.eclipse.core.net.proxy.IProxyData;
+
+import com.nokia.carbide.cpp.internal.news.reader.CarbideNewsReaderPlugin;
+import com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.fetcher.FetcherException;
import com.sun.syndication.fetcher.impl.FeedFetcherCache;
import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher;
import com.sun.syndication.fetcher.impl.SyndFeedInfo;
+import com.sun.syndication.io.FeedException;
/**
* A class to retrieve feed via HTTP connection.
@@ -36,6 +44,19 @@
super();
}
+ /*
+ * (non-Javadoc)
+ * @see com.sun.syndication.fetcher.impl.HttpURLFeedFetcher#retrieveFeed(java.net.URL)
+ */
+ public SyndFeed retrieveFeed(URL feedUrl) throws IllegalArgumentException, IOException, FeedException, FetcherException {
+ IProxyData data = CarbideNewsReaderPlugin.getProxyData(feedUrl);
+ if (data != null) {
+ System.setProperty("http.proxyHost", data.getHost());
+ System.setProperty("http.proxyPort", Integer.toString(data.getPort()));
+ }
+ return super.retrieveFeed(feedUrl);
+ }
+
/**
* Constructor to enable CarbideFeedFetcher to cache feeds
* @param feedCache - an instance of the FeedFetcherCache interface
--- a/core/com.nokia.carbide.cpp.news.reader/src/com/nokia/carbide/cpp/internal/news/reader/gen/FeedInfo/FeedInfoManager.java Tue Aug 11 14:22:33 2009 -0500
+++ b/core/com.nokia.carbide.cpp.news.reader/src/com/nokia/carbide/cpp/internal/news/reader/gen/FeedInfo/FeedInfoManager.java Tue Aug 11 15:01:16 2009 -0500
@@ -21,10 +21,14 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.SocketAddress;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
+import org.eclipse.core.net.proxy.IProxyData;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
@@ -133,7 +137,20 @@
HttpURLConnection connection = null;
InputStream inputStream = null;
try {
- connection = (HttpURLConnection) fileUrl.openConnection();
+ Proxy proxy = null;
+ IProxyData data = CarbideNewsReaderPlugin.getProxyData(fileUrl);
+ if (data != null) {
+ String host = data.getHost();
+ int port = data.getPort();
+ SocketAddress address = new InetSocketAddress(host, port);
+ proxy = new Proxy(Proxy.Type.HTTP, address);
+ }
+ if (proxy != null) {
+ connection = (HttpURLConnection) fileUrl.openConnection(proxy);
+ }
+ else {
+ connection = (HttpURLConnection) fileUrl.openConnection();
+ }
setRequestHeaders(connection);
connection.setUseCaches(false);
connection.connect();