author | dadubrow |
Wed, 16 Dec 2009 10:28:34 -0600 | |
changeset 688 | ae5ff180a61d |
parent 433 | 93ea4941aeb5 |
permissions | -rw-r--r-- |
83
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
1 |
/* |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
3 |
* All rights reserved. |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
8 |
* |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
9 |
* Initial Contributors: |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
10 |
* Nokia Corporation - initial contribution. |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
11 |
* |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
12 |
* Contributors: |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
13 |
* |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
14 |
* Description: |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
15 |
* |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
16 |
*/ |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
17 |
|
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
18 |
package com.nokia.carbide.cpp.internal.news.reader.feed; |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
19 |
|
417
f902e026d524
Updated news reader to use proxy data provided by Eclipse when creating http connections; fix for Bug 9564.
stechong
parents:
83
diff
changeset
|
20 |
import java.io.IOException; |
433
93ea4941aeb5
Updated news reader to use ProxyUtils class from com.nokia.cpp.utils.core plugin to retrieve proxy data.
stechong
parents:
417
diff
changeset
|
21 |
import java.net.URISyntaxException; |
417
f902e026d524
Updated news reader to use proxy data provided by Eclipse when creating http connections; fix for Bug 9564.
stechong
parents:
83
diff
changeset
|
22 |
import java.net.URL; |
83
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
23 |
import java.net.URLConnection; |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
24 |
|
417
f902e026d524
Updated news reader to use proxy data provided by Eclipse when creating http connections; fix for Bug 9564.
stechong
parents:
83
diff
changeset
|
25 |
import org.eclipse.core.net.proxy.IProxyData; |
f902e026d524
Updated news reader to use proxy data provided by Eclipse when creating http connections; fix for Bug 9564.
stechong
parents:
83
diff
changeset
|
26 |
|
f902e026d524
Updated news reader to use proxy data provided by Eclipse when creating http connections; fix for Bug 9564.
stechong
parents:
83
diff
changeset
|
27 |
import com.nokia.carbide.cpp.internal.news.reader.CarbideNewsReaderPlugin; |
433
93ea4941aeb5
Updated news reader to use ProxyUtils class from com.nokia.cpp.utils.core plugin to retrieve proxy data.
stechong
parents:
417
diff
changeset
|
28 |
import com.nokia.cpp.internal.api.utils.core.ProxyUtils; |
417
f902e026d524
Updated news reader to use proxy data provided by Eclipse when creating http connections; fix for Bug 9564.
stechong
parents:
83
diff
changeset
|
29 |
import com.sun.syndication.feed.synd.SyndFeed; |
f902e026d524
Updated news reader to use proxy data provided by Eclipse when creating http connections; fix for Bug 9564.
stechong
parents:
83
diff
changeset
|
30 |
import com.sun.syndication.fetcher.FetcherException; |
83
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
31 |
import com.sun.syndication.fetcher.impl.FeedFetcherCache; |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
32 |
import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher; |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
33 |
import com.sun.syndication.fetcher.impl.SyndFeedInfo; |
417
f902e026d524
Updated news reader to use proxy data provided by Eclipse when creating http connections; fix for Bug 9564.
stechong
parents:
83
diff
changeset
|
34 |
import com.sun.syndication.io.FeedException; |
83
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
35 |
|
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
36 |
/** |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
37 |
* A class to retrieve feed via HTTP connection. |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
38 |
* |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
39 |
*/ |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
40 |
public class CarbideFeedFetcher extends HttpURLFeedFetcher { |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
41 |
|
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
42 |
/** |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
43 |
* Constructor to enable CarbideFeedFetcher without caching feeds. |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
44 |
*/ |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
45 |
public CarbideFeedFetcher() { |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
46 |
super(); |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
47 |
} |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
48 |
|
417
f902e026d524
Updated news reader to use proxy data provided by Eclipse when creating http connections; fix for Bug 9564.
stechong
parents:
83
diff
changeset
|
49 |
/* |
f902e026d524
Updated news reader to use proxy data provided by Eclipse when creating http connections; fix for Bug 9564.
stechong
parents:
83
diff
changeset
|
50 |
* (non-Javadoc) |
f902e026d524
Updated news reader to use proxy data provided by Eclipse when creating http connections; fix for Bug 9564.
stechong
parents:
83
diff
changeset
|
51 |
* @see com.sun.syndication.fetcher.impl.HttpURLFeedFetcher#retrieveFeed(java.net.URL) |
f902e026d524
Updated news reader to use proxy data provided by Eclipse when creating http connections; fix for Bug 9564.
stechong
parents:
83
diff
changeset
|
52 |
*/ |
f902e026d524
Updated news reader to use proxy data provided by Eclipse when creating http connections; fix for Bug 9564.
stechong
parents:
83
diff
changeset
|
53 |
public SyndFeed retrieveFeed(URL feedUrl) throws IllegalArgumentException, IOException, FeedException, FetcherException { |
433
93ea4941aeb5
Updated news reader to use ProxyUtils class from com.nokia.cpp.utils.core plugin to retrieve proxy data.
stechong
parents:
417
diff
changeset
|
54 |
try { |
93ea4941aeb5
Updated news reader to use ProxyUtils class from com.nokia.cpp.utils.core plugin to retrieve proxy data.
stechong
parents:
417
diff
changeset
|
55 |
IProxyData data = ProxyUtils.getProxyData(feedUrl.toURI()); |
93ea4941aeb5
Updated news reader to use ProxyUtils class from com.nokia.cpp.utils.core plugin to retrieve proxy data.
stechong
parents:
417
diff
changeset
|
56 |
if (data != null) { |
93ea4941aeb5
Updated news reader to use ProxyUtils class from com.nokia.cpp.utils.core plugin to retrieve proxy data.
stechong
parents:
417
diff
changeset
|
57 |
System.setProperty("http.proxyHost", data.getHost()); |
93ea4941aeb5
Updated news reader to use ProxyUtils class from com.nokia.cpp.utils.core plugin to retrieve proxy data.
stechong
parents:
417
diff
changeset
|
58 |
System.setProperty("http.proxyPort", Integer.toString(data.getPort())); |
93ea4941aeb5
Updated news reader to use ProxyUtils class from com.nokia.cpp.utils.core plugin to retrieve proxy data.
stechong
parents:
417
diff
changeset
|
59 |
} |
93ea4941aeb5
Updated news reader to use ProxyUtils class from com.nokia.cpp.utils.core plugin to retrieve proxy data.
stechong
parents:
417
diff
changeset
|
60 |
} catch (URISyntaxException e) { |
93ea4941aeb5
Updated news reader to use ProxyUtils class from com.nokia.cpp.utils.core plugin to retrieve proxy data.
stechong
parents:
417
diff
changeset
|
61 |
CarbideNewsReaderPlugin.log(e); |
417
f902e026d524
Updated news reader to use proxy data provided by Eclipse when creating http connections; fix for Bug 9564.
stechong
parents:
83
diff
changeset
|
62 |
} |
f902e026d524
Updated news reader to use proxy data provided by Eclipse when creating http connections; fix for Bug 9564.
stechong
parents:
83
diff
changeset
|
63 |
return super.retrieveFeed(feedUrl); |
f902e026d524
Updated news reader to use proxy data provided by Eclipse when creating http connections; fix for Bug 9564.
stechong
parents:
83
diff
changeset
|
64 |
} |
f902e026d524
Updated news reader to use proxy data provided by Eclipse when creating http connections; fix for Bug 9564.
stechong
parents:
83
diff
changeset
|
65 |
|
83
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
66 |
/** |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
67 |
* Constructor to enable CarbideFeedFetcher to cache feeds |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
68 |
* @param feedCache - an instance of the FeedFetcherCache interface |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
69 |
*/ |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
70 |
public CarbideFeedFetcher(FeedFetcherCache feedInfoCache) { |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
71 |
super(feedInfoCache); |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
72 |
} |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
73 |
|
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
74 |
/* |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
75 |
* (non-Javadoc) |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
76 |
* @see com.sun.syndication.fetcher.impl.HttpURLFeedFetcher#setRequestHeaders(java.net.URLConnection, com.sun.syndication.fetcher.impl.SyndFeedInfo) |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
77 |
*/ |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
78 |
protected void setRequestHeaders(URLConnection connection, SyndFeedInfo syndFeedInfo) { |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
79 |
super.setRequestHeaders(connection, syndFeedInfo); |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
80 |
// specify acceptable content types |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
81 |
connection.setRequestProperty("Accept", "*/xml"); |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
82 |
} |
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
83 |
|
6c6d4b0c9171
Specifies acceptable content types in connection request header; fix for Bug 8775.
stechong
parents:
diff
changeset
|
84 |
} |