Changeset 7263
- Timestamp:
- 12/21/21 11:35:46 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/FCSEndpointTester.java
r7197 r7263 55 55 import eu.clarin.sru.client.SRUClient; 56 56 import eu.clarin.sru.client.SRUClientException; 57 import eu.clarin.sru.client.SRUExplainRequest; 58 import eu.clarin.sru.client.SRUExplainResponse; 59 import eu.clarin.sru.client.SRUVersion; 60 import eu.clarin.sru.client.fcs.ClarinFCSClientBuilder; 61 import eu.clarin.sru.client.fcs.ClarinFCSConstants; 62 import eu.clarin.sru.client.fcs.ClarinFCSEndpointDescription; 63 import eu.clarin.sru.client.fcs.ClarinFCSEndpointDescriptionParser; 57 import eu.clarin.sru.client.fcs.utils.ClarinFCSEndpointVersionAutodetector; 58 import eu.clarin.sru.client.fcs.utils.ClarinFCSEndpointVersionAutodetector.AutodetectedFCSVersion; 64 59 65 60 … … 85 80 new FCSLoggingHandler(); 86 81 private final ExecutorService executor = Executors.newCachedThreadPool(); 82 private final ClarinFCSEndpointVersionAutodetector versionAutodetector = 83 new ClarinFCSEndpointVersionAutodetector(); 87 84 private static final FCSEndpointTester INSTANCE = new FCSEndpointTester(); 88 85 … … 199 196 listener.updateProgress("Detecting CLARIN-FCS profile ..."); 200 197 201 FCSTestProfile profile = null; 202 203 SRUClient client = new ClarinFCSClientBuilder() 204 .addDefaultDataViewParsers() 205 .setDefaultSRUVersion(SRUVersion.VERSION_2_0) 206 .unknownDataViewAsString() 207 .enableLegacySupport() 208 .registerExtraResponseDataParser( 209 new ClarinFCSEndpointDescriptionParser()) 210 .buildClient(); 211 198 AutodetectedFCSVersion version = null; 212 199 try { 213 SRUExplainRequest request = new SRUExplainRequest(endpointURI); 214 request.setStrictMode(false); 215 request.setVersion(SRUVersion.VERSION_1_2); 216 request.setExtraRequestData(ClarinFCSConstants.X_FCS_ENDPOINT_DESCRIPTION, 217 ClarinFCSConstants.TRUE); 218 request.setParseRecordDataEnabled(true); 219 SRUExplainResponse response = client.explain(request); 220 221 ClarinFCSEndpointDescription ed = 222 response.getFirstExtraResponseData(ClarinFCSEndpointDescription.class); 223 if (ed != null) { 224 if (ed.getVersion() == 1) { 225 profile = FCSTestProfile.CLARIN_FCS_1_0; 226 } 227 } else { 228 logger.debug("assume legacy"); 229 profile = FCSTestProfile.CLARIN_FCS_LEGACY; 230 } 231 232 if (profile == null) { 233 request = new SRUExplainRequest(endpointURI); 234 request.setStrictMode(false); 235 request.setVersion(SRUVersion.VERSION_2_0); 236 request.setExtraRequestData( 237 ClarinFCSConstants.X_FCS_ENDPOINT_DESCRIPTION, 238 ClarinFCSConstants.TRUE); 239 request.setParseRecordDataEnabled(true); 240 try { 241 response = client.explain(request); 242 243 ed = response.getFirstExtraResponseData( 244 ClarinFCSEndpointDescription.class); 245 if (ed != null) { 246 if (ed.getVersion() == 2) { 247 profile = FCSTestProfile.CLARIN_FCS_2_0; 248 } 249 } 250 } catch (SRUClientException e) { 251 if ((e.getMessage() != null) && (e.getMessage() 252 .contains("responded with different version"))) { 253 throw new SRUClientException( 254 "Seriously broken Endpoint: when trying to " + 255 "detect FCS 2.0 the Endpoint illegally " + 256 "responded with a SRU 1.2 reponse to a " + 257 "SRU 2.0 request!"); 258 } else { 259 throw e; 260 } 261 } 262 } 263 if (profile != null) { 264 final FCSTestContext context = 265 new FCSTestContext(profile, 266 endpointURI, 267 searchTerm, 268 strictMode, 269 connectTimeout, 270 socketTimeout); 271 return context; 272 } 200 version = versionAutodetector.autodetectVersion(endpointURI); 273 201 } catch (SRUClientException e) { 274 202 logger.error("error", e); … … 276 204 "auto-detecting CLARIN-FCS version", e); 277 205 } 278 throw new SRUClientException("Unable to auto-detect CLARIN-FCS version!"); 206 207 logger.debug("auto-detected endpoint version = {}", version); 208 209 FCSTestProfile profile = null; 210 switch (version) { 211 case FCS_LEGACY: 212 profile = FCSTestProfile.CLARIN_FCS_LEGACY; 213 break; 214 case FCS_1_0: 215 profile = FCSTestProfile.CLARIN_FCS_1_0; 216 break; 217 case FCS_2_0: 218 profile = FCSTestProfile.CLARIN_FCS_2_0; 219 break; 220 case UNKNOWN: 221 /* $FALL-THROUGH$ */ 222 default: 223 throw new SRUClientException("Unable to auto-detect CLARIN-FCS version!"); 224 } 225 return new FCSTestContext(profile, 226 endpointURI, 227 searchTerm, 228 strictMode, 229 connectTimeout, 230 socketTimeout); 279 231 } 280 232 … … 301 253 302 254 303 List<FCSTest> tests = new ArrayList< FCSTest>();255 List<FCSTest> tests = new ArrayList<>(); 304 256 for (FCSTest test : TESTS) { 305 257 final FCSTestCase tc = … … 318 270 for (FCSTest test : tests) { 319 271 if (results == null) { 320 results = new LinkedList< FCSTestResult>();272 results = new LinkedList<>(); 321 273 } 322 274 logger.debug("running test {}:{}", num, test.getName()); … … 414 366 reflections.getTypesAnnotatedWith(FCSTestCase.class); 415 367 if ((annotations != null) && !annotations.isEmpty()) { 416 List<Class<?>> classes = new ArrayList< Class<?>>(368 List<Class<?>> classes = new ArrayList<>( 417 369 annotations.size()); 418 370 for (Class<?> clazz : annotations) { … … 432 384 for (Class<?> clazz : classes) { 433 385 if (tests == null) { 434 tests = new ArrayList< FCSTest>(classes.size());386 tests = new ArrayList<>(classes.size()); 435 387 } 436 388 tests.add((FCSTest) clazz.newInstance());
Note: See TracChangeset
for help on using the changeset viewer.