Revision d60221b5
Added by Andreas Müller almost 4 years ago
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmServerInfo.java | ||
---|---|---|
44 | 44 |
import eu.etaxonomy.cdm.database.CdmPersistentDataSource; |
45 | 45 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
46 | 46 |
import eu.etaxonomy.cdm.model.metadata.CdmMetaData; |
47 |
import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
|
|
48 |
import eu.etaxonomy.taxeditor.remoting.server.CDMServerUtils;
|
|
47 |
import eu.etaxonomy.taxeditor.remoting.server.CdmServerException;
|
|
48 |
import eu.etaxonomy.taxeditor.remoting.server.CdmServerUtils;
|
|
49 | 49 |
|
50 | 50 |
/** |
51 | 51 |
* @author cmathew |
... | ... | |
125 | 125 |
return cdmlibServicesLastModified; |
126 | 126 |
} |
127 | 127 |
|
128 |
public void refreshInstances() throws CDMServerException {
|
|
128 |
public void refreshInstances() throws CdmServerException {
|
|
129 | 129 |
instances.clear(); |
130 | 130 |
if(isLocalhostMgd()) { |
131 | 131 |
addInstancesFromDataSourcesConfig(); |
... | ... | |
141 | 141 |
}); |
142 | 142 |
} |
143 | 143 |
|
144 |
public void updateInfo() throws CDMServerException {
|
|
144 |
public void updateInfo() throws CdmServerException {
|
|
145 | 145 |
|
146 | 146 |
String url = guessProtocol() + "://" + server + ":" + String.valueOf(port) + "/" + prefix + "info.jsp"; |
147 | 147 |
String responseBody = getResponse(url); |
... | ... | |
151 | 151 |
cdmlibServicesVersion = info.getString("cdmlibServicesVersion"); |
152 | 152 |
cdmlibServicesLastModified = info.getString("cdmlibServicesLastModified"); |
153 | 153 |
} catch (JSONException e) { |
154 |
throw new CDMServerException(e);
|
|
154 |
throw new CdmServerException(e);
|
|
155 | 155 |
} |
156 | 156 |
} |
157 | 157 |
} |
... | ... | |
160 | 160 |
return port == 443 ? "https" : "http"; |
161 | 161 |
} |
162 | 162 |
|
163 |
public void addInstancesViaHttp() throws CDMServerException {
|
|
163 |
public void addInstancesViaHttp() throws CdmServerException {
|
|
164 | 164 |
updateInfo(); |
165 | 165 |
String url = guessProtocol() + "://" + server + ":" + String.valueOf(port) + "/" + prefix + "instances.jsp"; |
166 | 166 |
String responseBody = getResponse(url); |
... | ... | |
182 | 182 |
} |
183 | 183 |
} |
184 | 184 |
} catch (JSONException e) { |
185 |
throw new CDMServerException(e);
|
|
185 |
throw new CdmServerException(e);
|
|
186 | 186 |
} |
187 | 187 |
} |
188 | 188 |
} |
189 | 189 |
|
190 |
private String getResponse(String url) throws CDMServerException {
|
|
190 |
private String getResponse(String url) throws CdmServerException {
|
|
191 | 191 |
|
192 | 192 |
RequestConfig.Builder requestBuilder = RequestConfig.custom(); |
193 | 193 |
requestBuilder.setConnectTimeout(CdmApplicationRemoteConfiguration.HTTP_READ_TIMEOUT_MIN); |
... | ... | |
219 | 219 |
try { |
220 | 220 |
responseBody = client.execute(httpGet, responseHandler); |
221 | 221 |
} catch (ClientProtocolException e) { |
222 |
throw new CDMServerException(e);
|
|
222 |
throw new CdmServerException(e);
|
|
223 | 223 |
} catch (IOException e) { // java.net.ConnectException: Connection refused, java.net.SocketTimeoutException: Read timed out |
224 |
throw new CDMServerException(e);
|
|
224 |
throw new CdmServerException(e);
|
|
225 | 225 |
} finally{ |
226 | 226 |
try { |
227 | 227 |
client.close(); |
... | ... | |
235 | 235 |
|
236 | 236 |
public void addInstancesFromDataSourcesConfig() { |
237 | 237 |
for(ICdmDataSource dataSource : CdmPersistentDataSource.getAllDataSources()){ |
238 |
String datasourceNCName = CDMServerUtils.xmlNCNamefrom(dataSource.getName());
|
|
238 |
String datasourceNCName = CdmServerUtils.xmlNCNamefrom(dataSource.getName());
|
|
239 | 239 |
logger.info("Adding local instance " + dataSource.getName() + " as " + datasourceNCName); |
240 | 240 |
addInstance(datasourceNCName, datasourceNCName); |
241 | 241 |
} |
... | ... | |
269 | 269 |
return null; |
270 | 270 |
} |
271 | 271 |
|
272 |
public boolean pingServer() throws CDMServerException, IOException {
|
|
272 |
public boolean pingServer() throws CdmServerException, IOException {
|
|
273 | 273 |
if(isLocalhostMgd()) { |
274 | 274 |
return true; |
275 | 275 |
} |
... | ... | |
281 | 281 |
return true; |
282 | 282 |
} |
283 | 283 |
|
284 |
public boolean pingInstance(CdmInstanceInfo instance, int port) throws CDMServerException {
|
|
285 |
ICdmRemoteSource crs = getCdmRemoteSource(instance, port);
|
|
284 |
public boolean pingInstance(CdmInstanceInfo instance, int port) throws CdmServerException {
|
|
285 |
ICdmRemoteSource cdmRemoteSource = getCdmRemoteSource(instance, port);
|
|
286 | 286 |
try { |
287 |
if(crs != null && crs.checkConnection()) {
|
|
287 |
if(cdmRemoteSource != null && cdmRemoteSource.checkConnection()) {
|
|
288 | 288 |
logger.info("[CDM-Server] Running @ " + server + ":" + port + " for instance " + instance); |
289 | 289 |
return true; |
290 | 290 |
} |
291 | 291 |
} catch (CdmSourceException e) { |
292 | 292 |
logger.error(e.getMessage(), e); |
293 |
throw new CDMServerException(e);
|
|
293 |
throw new CdmServerException(e);
|
|
294 | 294 |
} |
295 | 295 |
|
296 | 296 |
return false; |
297 | 297 |
} |
298 | 298 |
|
299 |
public int compareDbSchemaVersion(CdmInstanceInfo instance, int port) throws CDMServerException {
|
|
299 |
public int compareDbSchemaVersion(CdmInstanceInfo instance, int port) throws CdmServerException {
|
|
300 | 300 |
|
301 | 301 |
ICdmRemoteSource crs = getCdmRemoteSource(instance, port); |
302 | 302 |
String dbSchemaVersion; |
303 | 303 |
try { |
304 | 304 |
dbSchemaVersion = crs.getDbSchemaVersion(); |
305 | 305 |
} catch (CdmSourceException e) { |
306 |
throw new CDMServerException(e);
|
|
306 |
throw new CdmServerException(e);
|
|
307 | 307 |
} |
308 | 308 |
|
309 | 309 |
|
310 | 310 |
if(dbSchemaVersion != null) { |
311 | 311 |
return CdmMetaData.compareVersion(dbSchemaVersion, CdmMetaData.getDbSchemaVersion(), 3, null); |
312 | 312 |
} else { |
313 |
throw new CDMServerException("Cannot determine editor db. schema version");
|
|
313 |
throw new CdmServerException("Cannot determine editor db. schema version");
|
|
314 | 314 |
} |
315 | 315 |
} |
316 | 316 |
|
... | ... | |
444 | 444 |
this.port = port; |
445 | 445 |
} |
446 | 446 |
|
447 |
public List<CdmInstanceInfo> getInstances() throws CDMServerException {
|
|
447 |
public List<CdmInstanceInfo> getInstances() throws CdmServerException {
|
|
448 | 448 |
if(instances.isEmpty()) { |
449 | 449 |
refreshInstances(); |
450 | 450 |
} |
... | ... | |
465 | 465 |
logger.info("Will connect local development cdm instance: at port " + devPort); |
466 | 466 |
return devCii.getCdmRemoteSource(devInstance, devPort); |
467 | 467 |
} |
468 |
} catch (CDMServerException e) {
|
|
468 |
} catch (CdmServerException e) {
|
|
469 | 469 |
logger.error("Can not connect to local development cdm instance at port " + devPort + ". " |
470 | 470 |
+ "Make sure the cdm instance is running and that the Spring profile \"remoting\" is " |
471 | 471 |
+ "activated (-Dspring.profiles.active=remoting)", e); |
Also available in: Unified diff
rename CdmServerUtils, CdmServerException and CdmEmbeddedServerException