Skip to content

Commit

Permalink
uPortal-ProjectGH-163 added timeout for http calls to ensure that it …
Browse files Browse the repository at this point in the history
…doesn't wait for a non-connecting site
  • Loading branch information
j-crawford committed Apr 25, 2019
1 parent fe18023 commit a09a53c
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketTimeoutException;
import java.util.Set;
import javax.portlet.PortletRequest;
import net.fortuna.ical4j.model.component.VEvent;
import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;
import org.apache.commons.httpclient.ConnectTimeoutException;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
Expand All @@ -37,6 +39,7 @@
import org.apache.commons.io.input.BOMInputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.params.CoreConnectionPNames;
import org.jasig.portlet.calendar.CalendarConfiguration;
import org.jasig.portlet.calendar.caching.DefaultCacheKeyGeneratorImpl;
import org.jasig.portlet.calendar.caching.ICacheKeyGenerator;
Expand Down Expand Up @@ -260,7 +263,14 @@ protected String getIntervalSpecificCacheKey(String baseKey, Interval interval)
protected InputStream retrieveCalendarHttp(String url, Credentials credentials)
throws CalendarException {

final int TIMEOUT_MS = 3 * 1000;
final HttpClient client = new HttpClient();

//fixing where broken https links never connect. just keeps retrying.
client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, TIMEOUT_MS );
client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, TIMEOUT_MS);
client.getParams().setParameter("http.connection-manager.timeout", new Long(TIMEOUT_MS));

if (null != credentials) {
client.getState().setCredentials(AuthScope.ANY, credentials);
}
Expand Down Expand Up @@ -294,6 +304,12 @@ protected InputStream retrieveCalendarHttp(String url, Credentials credentials)
throw new CalendarException(
"Non-successful status code retrieving url '" + url + "'; status code: " + rc);
}
} catch(ConnectTimeoutException e) {
log.warn("Error fetching iCalendar feed for "+ url, e);
throw new CalendarException("Error fetching iCalendar feed for "+ url, e);
} catch(SocketTimeoutException e){
log.warn("Error fetching iCalendar feed for "+ url, e);
throw new CalendarException("Error fetching iCalendar feed for "+ url, e);
} catch (HttpException e) {
log.warn("Error fetching iCalendar feed", e);
throw new CalendarException("Error fetching iCalendar feed", e);
Expand Down

0 comments on commit a09a53c

Please sign in to comment.