Example usage for com.liferay.portal.util PropsValues RSS_CONNECTION_TIMEOUT

List of usage examples for com.liferay.portal.util PropsValues RSS_CONNECTION_TIMEOUT

Introduction

In this page you can find the example usage for com.liferay.portal.util PropsValues RSS_CONNECTION_TIMEOUT.

Prototype

int RSS_CONNECTION_TIMEOUT

To view the source code for com.liferay.portal.util PropsValues RSS_CONNECTION_TIMEOUT.

Click Source Link

Usage

From source file:com.liferay.portlet.rss.util.RSSWebCacheItem.java

License:Open Source License

public Object convert(String key) throws WebCacheException {
    SyndFeed feed = null;// ww  w .  j  a  v a2 s.  c  o  m

    try {

        // com.liferay.portal.kernel.util.HttpUtil will break the connection
        // if it spends more than 5 seconds looking up a location. However,
        // German umlauts do not get encoded correctly. This may be a bug
        // with commons-httpclient or with how FeedParser uses
        // java.io.Reader.

        // Use http://xml.newsisfree.com/feeds/29/629.xml and
        // http://test.domosoft.com/up/RSS to test if German umlauts show
        // up correctly.

        /*Reader reader = new StringReader(
           new String(HttpUtil.URLtoByteArray(_url)));
                
        channel = FeedParser.parse(builder, reader);*/

        HttpImpl httpImpl = (HttpImpl) HttpUtil.getHttp();

        HostConfiguration hostConfiguration = httpImpl.getHostConfiguration(_url);

        HttpClient httpClient = httpImpl.getClient(hostConfiguration);

        httpImpl.proxifyState(httpClient.getState(), hostConfiguration);

        HttpClientParams httpClientParams = httpClient.getParams();

        httpClientParams.setConnectionManagerTimeout(PropsValues.RSS_CONNECTION_TIMEOUT);
        httpClientParams.setSoTimeout(PropsValues.RSS_CONNECTION_TIMEOUT);

        GetMethod getMethod = new GetMethod(_url);

        httpClient.executeMethod(hostConfiguration, getMethod);

        SyndFeedInput input = new SyndFeedInput();

        feed = input.build(new XmlReader(getMethod.getResponseBodyAsStream()));
    } catch (Exception e) {
        throw new WebCacheException(_url + " " + e.toString());
    }

    return feed;
}

From source file:com.liferay.rss.web.internal.util.RSSWebCacheItem.java

License:Open Source License

private InputStream _readURL() throws IOException {
    URL url = new URL(_url);

    if ("file".equals(url.getProtocol())) {
        return url.openStream();
    }/*from   w  w  w  . j  a v  a2 s .  co  m*/

    Http.Options options = new Http.Options();

    options.setLocation(_url);
    options.setTimeout(PropsValues.RSS_CONNECTION_TIMEOUT);

    return HttpUtil.URLtoInputStream(options);
}