24 |
24 |
import org.apache.http.HttpResponse;
|
25 |
25 |
import org.apache.http.client.ClientProtocolException;
|
26 |
26 |
import org.apache.http.client.ResponseHandler;
|
|
27 |
import org.apache.http.client.config.RequestConfig;
|
27 |
28 |
import org.apache.http.client.methods.HttpGet;
|
28 |
|
import org.apache.http.impl.client.DefaultHttpClient;
|
29 |
|
import org.apache.http.params.HttpConnectionParams;
|
30 |
|
import org.apache.http.params.HttpParams;
|
|
29 |
import org.apache.http.impl.client.CloseableHttpClient;
|
|
30 |
import org.apache.http.impl.client.HttpClientBuilder;
|
31 |
31 |
import org.apache.http.util.EntityUtils;
|
32 |
32 |
import org.apache.log4j.Logger;
|
33 |
33 |
import org.json.JSONArray;
|
... | ... | |
37 |
37 |
import com.fasterxml.jackson.core.type.TypeReference;
|
38 |
38 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
39 |
39 |
|
|
40 |
import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteConfiguration;
|
40 |
41 |
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
41 |
42 |
import eu.etaxonomy.cdm.config.CdmSourceException;
|
42 |
43 |
import eu.etaxonomy.cdm.config.ConfigFileUtil;
|
... | ... | |
73 |
74 |
public final static int NULL_PORT = -1;
|
74 |
75 |
public final static String NULL_PORT_STRING = "N/A";
|
75 |
76 |
|
76 |
|
public static final int TIME_OUT = 7000;
|
77 |
|
|
78 |
77 |
private static final String CDM_REMOTE_SERVERS_CONFIG_FILE = "cdm_remote_servers.json";
|
79 |
78 |
|
80 |
79 |
|
... | ... | |
186 |
185 |
}
|
187 |
186 |
|
188 |
187 |
private String getResponse(String url) throws CDMServerException {
|
189 |
|
DefaultHttpClient client = new DefaultHttpClient();
|
190 |
|
// client = HttpClientBuilder.create().build();
|
191 |
|
// client.getParams();
|
192 |
|
HttpParams params = client.getParams();
|
193 |
188 |
|
194 |
|
HttpConnectionParams.setConnectionTimeout(params, TIME_OUT);
|
195 |
|
HttpConnectionParams.setSoTimeout(params, TIME_OUT);
|
|
189 |
RequestConfig.Builder requestBuilder = RequestConfig.custom();
|
|
190 |
requestBuilder.setConnectTimeout(CdmApplicationRemoteConfiguration.HTTP_READ_TIMEOUT_MIN);
|
|
191 |
requestBuilder.setConnectionRequestTimeout(CdmApplicationRemoteConfiguration.HTTP_READ_TIMEOUT_MIN);
|
|
192 |
requestBuilder.setSocketTimeout(CdmApplicationRemoteConfiguration.HTTP_READ_TIMEOUT_MIN);
|
|
193 |
CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestBuilder.build()).build();
|
196 |
194 |
|
197 |
195 |
HttpGet httpGet = new HttpGet(url);
|
198 |
196 |
|
... | ... | |
219 |
217 |
responseBody = client.execute(httpGet, responseHandler);
|
220 |
218 |
} catch (ClientProtocolException e) {
|
221 |
219 |
throw new CDMServerException(e);
|
222 |
|
} catch (IOException e) {
|
|
220 |
} catch (IOException e) { // java.net.ConnectException: Connection refused, java.net.SocketTimeoutException: Read timed out
|
223 |
221 |
throw new CDMServerException(e);
|
224 |
222 |
} finally{
|
225 |
|
client.close();
|
|
223 |
try {
|
|
224 |
client.close();
|
|
225 |
client = null;
|
|
226 |
} catch (IOException e) {
|
|
227 |
// IGNORE //
|
|
228 |
}
|
226 |
229 |
}
|
227 |
230 |
return responseBody;
|
228 |
231 |
}
|
... | ... | |
268 |
271 |
return true;
|
269 |
272 |
}
|
270 |
273 |
Socket s = new Socket();
|
271 |
|
s.connect(new InetSocketAddress(server, port), TIME_OUT);
|
|
274 |
s.connect(new InetSocketAddress(server, port), CdmApplicationRemoteConfiguration.HTTP_READ_TIMEOUT_MIN);
|
272 |
275 |
s.close();
|
273 |
276 |
logger.info("[CDM-Server] Available @ " + server + ":" + port );
|
274 |
277 |
updateInfo();
|
ref #8812 replacing deprecated usage of apache HttpClient by new classes