import eu.etaxonomy.cdm.persistence.hibernate.permission.voter.TaxonBaseVoter;\r
import eu.etaxonomy.cdm.persistence.hibernate.permission.voter.TaxonNodeVoter;\r
import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;\r
-import eu.etaxonomy.taxeditor.service.CachedCommonServiceImpl;\r
import eu.etaxonomy.taxeditor.service.AuthenticatingHttpInvokerRequestExecutor;\r
+import eu.etaxonomy.taxeditor.service.CachedCommonServiceImpl;\r
import eu.etaxonomy.taxeditor.service.ICachedCommonService;\r
import eu.etaxonomy.taxeditor.service.RemoteInvocationTermCacher;\r
import eu.etaxonomy.taxeditor.session.CdmEntitySessionManager;\r
// TODO split into CdmRepository and proper @Configuration class\r
public class CdmApplicationRemoteConfiguration implements ICdmRepository, ApplicationContextAware {\r
\r
- private static final int HTTP_READ_TIMEOUT = 0;\r
+ /**\r
+ * Timeout for service lookup etc. This timeout should me more\r
+ * strict than {@link #HTTP_READ_TIMEOUT} to avoid connecting to\r
+ * cdm servers when the network quality is too bad.\r
+ */\r
+ public static final int HTTP_READ_TIMEOUT_MIN = 300;\r
+ /**\r
+ * Timeout for normal operation\r
+ */\r
+ public static final int HTTP_READ_TIMEOUT = 0;\r
\r
@SuppressWarnings("unused")\r
private static final Logger logger = Logger.getLogger(CdmApplicationRemoteConfiguration.class);\r
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpParams;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
+import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteConfiguration;
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.config.CdmSourceException;
import eu.etaxonomy.cdm.config.ConfigFileUtil;
public final static int NULL_PORT = -1;
public final static String NULL_PORT_STRING = "N/A";
- public static final int TIME_OUT = 7000;
-
private static final String CDM_REMOTE_SERVERS_CONFIG_FILE = "cdm_remote_servers.json";
}
private String getResponse(String url) throws CDMServerException {
- DefaultHttpClient client = new DefaultHttpClient();
- // client = HttpClientBuilder.create().build();
- // client.getParams();
- HttpParams params = client.getParams();
- HttpConnectionParams.setConnectionTimeout(params, TIME_OUT);
- HttpConnectionParams.setSoTimeout(params, TIME_OUT);
+ RequestConfig.Builder requestBuilder = RequestConfig.custom();
+ requestBuilder.setConnectTimeout(CdmApplicationRemoteConfiguration.HTTP_READ_TIMEOUT_MIN);
+ requestBuilder.setConnectionRequestTimeout(CdmApplicationRemoteConfiguration.HTTP_READ_TIMEOUT_MIN);
+ requestBuilder.setSocketTimeout(CdmApplicationRemoteConfiguration.HTTP_READ_TIMEOUT_MIN);
+ CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestBuilder.build()).build();
HttpGet httpGet = new HttpGet(url);
responseBody = client.execute(httpGet, responseHandler);
} catch (ClientProtocolException e) {
throw new CDMServerException(e);
- } catch (IOException e) {
+ } catch (IOException e) { // java.net.ConnectException: Connection refused, java.net.SocketTimeoutException: Read timed out
throw new CDMServerException(e);
} finally{
- client.close();
+ try {
+ client.close();
+ client = null;
+ } catch (IOException e) {
+ // IGNORE //
+ }
}
return responseBody;
}
return true;
}
Socket s = new Socket();
- s.connect(new InetSocketAddress(server, port), TIME_OUT);
+ s.connect(new InetSocketAddress(server, port), CdmApplicationRemoteConfiguration.HTTP_READ_TIMEOUT_MIN);
s.close();
logger.info("[CDM-Server] Available @ " + server + ":" + port );
updateInfo();