- Timestamp:
- 11/10/15 10:52:04 (9 years ago)
- Location:
- SRUServer/trunk/src/main/java/eu/clarin/sru/server
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRURequestImpl.java
r6779 r6787 206 206 */ 207 207 boolean checkParameters() { 208 /*209 * FIXME: those parameters must be inject from "outside" (probably210 * by the appropriate Servlet instance)211 */212 208 final SRUVersion minVersion = config.getMinVersion(); 213 209 final SRUVersion maxVersion = config.getMaxVersion(); 210 211 /* 212 * generally assume, we will also allow processing of SRU 1.1 or 1.2 213 */ 214 boolean processSruOld = true; 214 215 215 216 /* … … 220 221 if (maxVersion.compareTo(SRUVersion.VERSION_2_0) >= 0) { 221 222 if (getParameter(PARAM_VERSION, false, false) == null) { 223 /* 224 * Ok, we're committed to SRU 2.0 now, so don't allow processing 225 * of SRU 1.1 and 1.2 ... 226 */ 227 processSruOld = false; 228 222 229 logger.debug("handling request as SRU 2.0, because no '{}' " + 223 230 "parameter was found in the request", PARAM_VERSION); … … 246 253 if (op != null) { 247 254 /* 248 * XXX: if operation is searchRetrive an operation parameter, 249 * is also searchRetrieve, the server may ignore it 255 * XXX: if operation is searchRetrive and the 'operation' 256 * parameter is also searchRetrieve, should the server just 257 * ignore it? 250 258 */ 251 259 if (!(operation == SRUOperation.SEARCH_RETRIEVE) && 252 260 op.equals(OP_SEARCH_RETRIEVE)) { 253 261 addDiagnostic(SRUConstants.SRU_UNSUPPORTED_PARAMETER, 254 PARAM_OPERATION, "Parameter '" +262 PARAM_OPERATION, "Parameter \"" + 255 263 PARAM_OPERATION + 256 " 'is not valid for SRU version 2.0");264 "\" is not valid for SRU version 2.0"); 257 265 } 258 266 } … … 260 268 logger.debug("handling request as legacy SRU, because found " + 261 269 "parameter '{}' in request", PARAM_VERSION); 262 263 // parse mandatory operation parameter 264 final String op = getParameter(PARAM_OPERATION, false, false); 265 if (op != null) { 266 if (!op.isEmpty()) { 267 if (op.equals(OP_EXPLAIN)) { 268 this.operation = SRUOperation.EXPLAIN; 269 } else if (op.equals(OP_SCAN)) { 270 this.operation = SRUOperation.SCAN; 271 } else if (op.equals(OP_SEARCH_RETRIEVE)) { 272 this.operation = SRUOperation.SEARCH_RETRIEVE; 273 } else { 274 addDiagnostic(SRUConstants.SRU_UNSUPPORTED_OPERATION, 275 null, "Operation \"" + op + "\" is not supported."); 276 } 270 } 271 } 272 273 if (processSruOld) { 274 // parse mandatory operation parameter 275 final String op = getParameter(PARAM_OPERATION, false, false); 276 if (op != null) { 277 if (!op.isEmpty()) { 278 if (op.equals(OP_EXPLAIN)) { 279 operation = SRUOperation.EXPLAIN; 280 } else if (op.equals(OP_SCAN)) { 281 operation = SRUOperation.SCAN; 282 } else if (op.equals(OP_SEARCH_RETRIEVE)) { 283 operation = SRUOperation.SEARCH_RETRIEVE; 277 284 } else { 278 285 addDiagnostic(SRUConstants.SRU_UNSUPPORTED_OPERATION, 279 null, "An empty parameter \"" + 280 PARAM_OPERATION + 281 "\" is not supported."); 286 null, "Operation \"" + op + "\" is not supported."); 282 287 } 283 284 // parse and check version285 version = parseAndCheckVersionParameter(operation);286 288 } else { 287 /* 288 * absent parameter should be interpreted as "explain" 289 */ 290 operation = SRUOperation.EXPLAIN; 291 292 // parse and check version 293 version = parseAndCheckVersionParameter(operation); 289 addDiagnostic(SRUConstants.SRU_UNSUPPORTED_OPERATION, 290 null, "An empty parameter \"" + 291 PARAM_OPERATION + 292 "\" is not supported."); 294 293 } 295 } 296 } 297 298 if ((version == null) || (operation == null)) { 299 logger.error("internal error!!!!1elf"); 300 } 301 302 if (minVersion.compareTo(version) < 0) { 303 addDiagnostic(SRUConstants.SRU_UNSUPPORTED_VERSION, 304 version.getVersionString(), "Version '{}' is not supported by this endpoint"); 305 } 306 return checkParameters2(); 307 } 308 309 310 boolean checkParameters2() { 311 294 295 // parse and check version 296 version = parseAndCheckVersionParameter(operation); 297 } else { 298 /* 299 * absent parameter should be interpreted as "explain" 300 */ 301 operation = SRUOperation.EXPLAIN; 302 303 // parse and check version 304 version = parseAndCheckVersionParameter(operation); 305 } 306 } 307 308 309 /* 310 * sanity check 311 */ 312 if ((version != null) && (operation != null)) { 313 logger.debug("min = {}, min? = {}, max = {}, max? = {}, version = {}", 314 minVersion, 315 version.compareTo(minVersion), 316 maxVersion, 317 version.compareTo(maxVersion), 318 version); 319 if ((version.compareTo(minVersion) >= 0) && 320 (version.compareTo(maxVersion) <= 0)) { 321 /* 322 * FIXME: re-factor to make this nicer ... 323 */ 324 this.version = version; 325 this.operation = operation; 326 return checkParameters2(); 327 } else { 328 addDiagnostic(SRUConstants.SRU_UNSUPPORTED_VERSION, 329 maxVersion.getVersionString(), 330 "Version \"" + version.getVersionString() + 331 "\" is not supported by this endpoint."); 332 } 333 } 334 logger.debug("bailed"); 335 return false; 336 } 337 338 339 private boolean checkParameters2() { 312 340 if (diagnostics == null) { 313 341 // check mandatory/optional parameters for operation … … 457 485 } 458 486 459 // diagnostics != null -> consider as success 487 /* 488 * diagnostics == null -> consider as success 489 * FIXME: this should ne done nicer! 490 */ 460 491 return (diagnostics == null); 461 492 } -
SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRUServer.java
r6779 r6787 1141 1141 /* FALL-THROUGH */ 1142 1142 case VERSION_1_2: 1143 return NAMESPACES_LEGACY; 1143 switch (config.getLegacyNamespaceMode()) { 1144 case LOC: 1145 return NAMESPACES_LEGACY_LOC; 1146 case OASIS: 1147 return NAMESPACES_1_2_OASIS; 1148 default: 1149 // FIXME: better exception? 1150 throw new IllegalAccessError("invalid legacy mode: " + version); 1151 } // switch 1144 1152 case VERSION_2_0: 1145 1153 return NAMESPACES_2_0; … … 1153 1161 1154 1162 1155 private static final SRUNamespaces NAMESPACES_LEGACY = new SRUNamespaces() {1163 private static final SRUNamespaces NAMESPACES_LEGACY_LOC = new SRUNamespaces() { 1156 1164 private static final String SRU_NS = 1157 1165 "http://www.loc.gov/zing/srw/"; … … 1191 1199 public String getScanPrefix() { 1192 1200 return SRU_PREFIX; 1201 } 1202 1203 1204 @Override 1205 public String getDiagnosticNS() { 1206 return SRU_DIAGNOSIC_NS; 1207 } 1208 1209 1210 @Override 1211 public String getDiagnosticPrefix() { 1212 return SRU_DIAGNOSTIC_PREFIX; 1213 } 1214 1215 1216 @Override 1217 public String getExplainNS() { 1218 return SRU_EXPLAIN_NS; 1219 } 1220 1221 1222 @Override 1223 public String getExplainPrefix() { 1224 return SRU_EXPLAIN_PREFIX; 1225 } 1226 1227 1228 @Override 1229 public String getXcqlNS() { 1230 return SRU_XCQL_NS; 1231 } 1232 }; 1233 1234 1235 private static final SRUNamespaces NAMESPACES_1_2_OASIS = new SRUNamespaces() { 1236 private static final String SRU_RESPONSE_NS = 1237 "http://docs.oasis-open.org/ns/search-ws/sruResponse"; 1238 private static final String SRU_RESPONSE_PREFIX = 1239 "sruResponse"; 1240 private static final String SRU_SCAN_NS = 1241 "http://docs.oasis-open.org/ns/search-ws/scan"; 1242 private static final String SRU_SCAN_PREFIX = 1243 "scan"; 1244 private static final String SRU_DIAGNOSIC_NS = 1245 "http://docs.oasis-open.org/ns/search-ws/diagnostic"; 1246 private static final String SRU_DIAGNOSTIC_PREFIX = 1247 "diag"; 1248 private static final String SRU_EXPLAIN_NS = 1249 "http://explain.z3950.org/dtd/2.0/"; 1250 private static final String SRU_EXPLAIN_PREFIX = 1251 "zr"; 1252 private static final String SRU_XCQL_NS = 1253 "http://docs.oasis-open.org/ns/search-ws/xcql"; 1254 1255 1256 @Override 1257 public String getResponseNS() { 1258 return SRU_RESPONSE_NS; 1259 } 1260 1261 1262 @Override 1263 public String getResponsePrefix() { 1264 return SRU_RESPONSE_PREFIX; 1265 } 1266 1267 1268 @Override 1269 public String getScanNS() { 1270 return SRU_SCAN_NS; 1271 } 1272 1273 1274 @Override 1275 public String getScanPrefix() { 1276 return SRU_SCAN_PREFIX; 1193 1277 } 1194 1278 -
SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRUServerConfig.java
r6780 r6787 89 89 * Valid values: "<code>1.1</code>", "<code>1.2</code>" or " 90 90 * <code>2.0</code>" (without quotation marks) 91 * < p>91 * </p> 92 92 */ 93 93 public static final String SRU_SUPPORTED_VERSION_MIN = … … 99 99 * Valid values: "<code>1.1</code>", "<code>1.2</code>" or " 100 100 * <code>2.0</code>" (without quotation marks) 101 * < p>101 * </p> 102 102 */ 103 103 public static final String SRU_SUPPORTED_VERSION_MAX = … … 112 112 * Valid values: "<code>1.1</code>", "<code>1.2</code>" or " 113 113 * <code>2.0</code>" (without quotation marks) 114 * < p>114 * </p> 115 115 */ 116 116 public static final String SRU_SUPPORTED_VERSION_DEFAULT = 117 117 "eu.clarin.sru.server.sruSupportedVersionDefault"; 118 /** 119 * Parameter constant for setting the namespace URIs for SRU 1.1 and SRU 120 * 1.2. 121 * <p> 122 * Valid values: "<code>loc"</code> for Library Of Congress URI or " 123 * <code>oasis</code> for OASIS URIs (without quotation marks). 124 * </p> 125 */ 126 public static final String SRU_LEGACY_NAMESPACE_MODE = 127 "eu.clarin.sru.server.legacyNamespaceMode"; 118 128 /** 119 129 * Parameter constant for configuring the transports for this SRU server. … … 268 278 private static final SRUVersion DEFAULT_SRU_VERSION_MAX = 269 279 SRUVersion.VERSION_1_2; 280 private static final LegacyNamespaceMode DEFAULT_LEGACY_NAMESPACE_MODE = 281 LegacyNamespaceMode.LOC; 270 282 private static final int DEFAULT_NUMBER_OF_RECORDS = 100; 271 283 private static final int DEFAULT_MAXIMUM_RECORDS = 250; … … 277 289 private static final String CONFIG_FILE_SCHEMA_URL = 278 290 "META-INF/sru-server-config.xsd"; 291 public static enum LegacyNamespaceMode { 292 LOC, OASIS 293 } // enum LegacyNamespaceMode 279 294 280 295 public static final class LocalizedString { … … 603 618 private final SRUVersion maxVersion; 604 619 private final SRUVersion defaultVersion; 620 private final LegacyNamespaceMode legacyNamespaceMode; 605 621 private final String transport; 606 622 private final String host; … … 623 639 624 640 625 private SRUServerConfig(SRUVersion minVersion, SRUVersion maxVersion, 626 SRUVersion defaultVersion, String transport, String host, int port, 627 String database, int numberOfRecords, int maximumRecords, 628 int numberOfTerms, int maximumTerms, boolean echoRequests, 629 int indentResponse, int responseBufferSize, 641 private SRUServerConfig(SRUVersion minVersion, 642 SRUVersion maxVersion, 643 SRUVersion defaultVersion, 644 LegacyNamespaceMode legacyNamespaceMode, 645 String transport, 646 String host, 647 int port, 648 String database, 649 int numberOfRecords, 650 int maximumRecords, 651 int numberOfTerms, 652 int maximumTerms, 653 boolean echoRequests, 654 int indentResponse, 655 int responseBufferSize, 630 656 boolean allowOverrideMaximumRecords, 631 657 boolean allowOverrideMaximumTerms, 632 boolean allowOverrideIndentResponse, DatabaseInfo databaseinfo, 633 IndexInfo indexInfo, List<SchemaInfo> schemaInfo) { 658 boolean allowOverrideIndentResponse, 659 DatabaseInfo databaseinfo, 660 IndexInfo indexInfo, 661 List<SchemaInfo> schemaInfo) { 634 662 this.minVersion = minVersion; 635 663 this.maxVersion = maxVersion; 636 664 this.defaultVersion = defaultVersion; 665 this.legacyNamespaceMode = legacyNamespaceMode; 637 666 this.transport = transport; 638 667 this.host = host; … … 683 712 684 713 714 public LegacyNamespaceMode getLegacyNamespaceMode() { 715 return legacyNamespaceMode; 716 } 717 718 685 719 public SRURecordPacking getDefaultRecordPacking() { 686 720 return SRURecordPacking.XML; … … 952 986 SRU_SUPPORTED_VERSION_MAX + "\" (" + 953 987 maxVersion.getVersionString() + ")"); 988 } 989 990 LegacyNamespaceMode legacyNamespaceMode = 991 DEFAULT_LEGACY_NAMESPACE_MODE; 992 String mode = params.get(SRU_LEGACY_NAMESPACE_MODE); 993 if ((mode != null) && !mode.isEmpty()) { 994 if ("loc".equals(mode)) { 995 legacyNamespaceMode = LegacyNamespaceMode.LOC; 996 } else if ("oasis".equals(mode)) { 997 legacyNamespaceMode = LegacyNamespaceMode.OASIS; 998 } else { 999 throw new SRUConfigException( 1000 "invalid value for parameter \"" + 1001 SRU_LEGACY_NAMESPACE_MODE + "\": " + mode); 1002 } 954 1003 } 955 1004 … … 1026 1075 DEFAULT_RESPONSE_BUFFER_SIZE, 0, -1); 1027 1076 1028 return new SRUServerConfig(minVersion, maxVersion, defaultVersion, 1029 transport, host, port, database, numberOfRecords, 1030 maximumRecords, numberOfTerms, maximumTerms, echoRequests, 1031 indentResponse, responseBufferSize, 1032 allowOverrideMaximumRecords, allowOverrideMaximumTerms, 1033 allowOverrideIndentResponse, databaseInfo, indexInfo, 1077 return new SRUServerConfig(minVersion, 1078 maxVersion, 1079 defaultVersion, 1080 legacyNamespaceMode, 1081 transport, 1082 host, 1083 port, 1084 database, 1085 numberOfRecords, 1086 maximumRecords, 1087 numberOfTerms, 1088 maximumTerms, 1089 echoRequests, 1090 indentResponse, 1091 responseBufferSize, 1092 allowOverrideMaximumRecords, 1093 allowOverrideMaximumTerms, 1094 allowOverrideIndentResponse, 1095 databaseInfo, 1096 indexInfo, 1034 1097 schemaInfo); 1035 1098 } catch (IOException e) {
Note: See TracChangeset
for help on using the changeset viewer.