Changeset 2121
- Timestamp:
- 08/20/12 20:15:37 (12 years ago)
- Location:
- SRUClient/trunk/src/main/java/eu/clarin/sru/client
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUAbstractRequest.java
r2088 r2121 46 46 private static final String PARAM_EXTENSION_PREFIX = "x-"; 47 47 /** for end-point conformance testing only. never use in production. */ 48 public static final String X_MALFORMED_OPERATION = 49 "x-malformed-operation"; 50 /** for end-point conformance testing only. never use in production. */ 48 51 public static final String X_MALFORMED_VERSION = 49 52 "x-malformed-version"; 50 53 /** for end-point conformance testing only. never use in production. */ 51 public static final String X_MALFORMED_OPERATION =52 "x-maformed-operation";53 /** for end-point conformance testing only. never use in production. */54 54 public static final String MALFORMED_OMIT = "omit"; 55 private static final String MALFORMED_KEY_PREFIX = "x-malformed"; 55 56 56 57 … … 59 60 } // enum SRUOperation 60 61 61 62 62 63 class URIBuilder { 63 64 private final StringBuilder sb; … … 68 69 } 69 70 70 71 71 72 public URIBuilder append(String name, String value) { 72 73 if (name == null) { … … 93 94 } 94 95 95 96 96 97 public URIBuilder append(String name, int value) { 97 98 return append(name, Integer.toString(value)); … … 122 123 /** 123 124 * Get the endpoint URI. 124 * 125 * 125 126 * @return the endpoiunt URI 126 127 */ … … 132 133 /** 133 134 * Set the version for this request. 134 * 135 * 135 136 * @param version a version of <code>null</code> for client default 136 137 */ … … 142 143 /** 143 144 * Get the version for this request. 144 * 145 * 145 146 * @return version for this request or <code>null</code> of client default 146 147 * is used … … 153 154 /** 154 155 * Set an extra request parameter for this request. 155 * 156 * 156 157 * @param name 157 158 * the name for the extra request data parameter … … 191 192 /** 192 193 * Set the value of extra request parameter for this request. 193 * 194 * 194 195 * @param name 195 196 * the name for the extra request data parameter … … 225 226 } 226 227 227 228 228 229 final URI makeURI(SRUVersion defaultVersion) 229 230 throws SRUClientException { … … 236 237 * append operation parameter 237 238 * 238 * NB: Setting "x- operation-version" as an extra request parameter makes239 * the client to send invalid requests. This is intended to use for240 * testing endpoints for protocol conformance (i.e. provoke an error)241 * and SHOULD NEVER be used in production!239 * NB: Setting "x-malformed-operation" as an extra request parameter 240 * makes the client to send invalid requests. This is intended to use 241 * for testing endpoints for protocol conformance (i.e. provoke an 242 * error) and SHOULD NEVER be used in production! 242 243 */ 243 244 final String malformedOperation = … … 301 302 extraRequestData.entrySet()) { 302 303 String key = entry.getKey(); 303 if (key.equals(X_MALFORMED_OPERATION) || 304 key.equals(X_MALFORMED_VERSION)) { 304 if (key.startsWith(MALFORMED_KEY_PREFIX)) { 305 305 continue; 306 306 } -
SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUScanRequest.java
r2088 r2121 29 29 */ 30 30 public final class SRUScanRequest extends SRUAbstractRequest { 31 /** for end-point conformance testing only. never use in production. */ 32 public static final String X_MALFORMED_SCAN_CLAUSE = 33 "x-malformed-scanClause"; 34 /** for end-point conformance testing only. never use in production. */ 35 public static final String X_MALFORMED_RESPONSE_POSITION = 36 "x-malformed-responsePosition"; 37 /** for end-point conformance testing only. never use in production. */ 38 public static final String X_MALFORMED_MAXIMUM_TERMS = 39 "x-malformed-maximumTerms"; 31 40 private String scanClause; 32 41 private int responsePosition = -1; … … 138 147 void addParametersToURI(URIBuilder uriBuilder) throws SRUClientException { 139 148 // scanClause 140 if ((scanClause == null) || scanClause.isEmpty()) { 141 throw new SRUClientException( 142 "mandatory argument 'scanClause' not set or empty"); 149 final String malformedScan = 150 getExtraRequestData(X_MALFORMED_SCAN_CLAUSE); 151 if (malformedScan == null) { 152 if ((scanClause == null) || scanClause.isEmpty()) { 153 throw new SRUClientException( 154 "mandatory argument 'scanClause' not set or empty"); 155 } 156 uriBuilder.append(PARAM_SCAN_CLAUSE, scanClause); 157 } else { 158 if (!malformedScan.equalsIgnoreCase(MALFORMED_OMIT)) { 159 uriBuilder.append(PARAM_VERSION, malformedScan); 160 } 143 161 } 144 uriBuilder.append(PARAM_SCAN_CLAUSE, scanClause);145 162 146 163 // responsePosition 147 if (responsePosition > -1) { 148 uriBuilder.append(PARAM_RESPONSE_POSITION, responsePosition); 164 final String malformedResponsePosition = 165 getExtraRequestData(X_MALFORMED_RESPONSE_POSITION); 166 if (malformedResponsePosition == null) { 167 if (responsePosition > -1) { 168 uriBuilder.append(PARAM_RESPONSE_POSITION, responsePosition); 169 } 170 } else { 171 if (!malformedResponsePosition.equalsIgnoreCase(MALFORMED_OMIT)) { 172 uriBuilder.append(PARAM_RESPONSE_POSITION, 173 malformedResponsePosition); 174 } 149 175 } 150 176 151 177 // maximumTerms 152 if (maximumTerms > -1) { 153 uriBuilder.append(PARAM_MAXIMUM_TERMS, maximumTerms); 178 final String malformedMaximumTerms = 179 getExtraRequestData(X_MALFORMED_MAXIMUM_TERMS); 180 if (malformedMaximumTerms == null) { 181 if (maximumTerms > -1) { 182 uriBuilder.append(PARAM_MAXIMUM_TERMS, maximumTerms); 183 } 184 } else { 185 if (!malformedMaximumTerms.equalsIgnoreCase(MALFORMED_OMIT)) { 186 uriBuilder.append(PARAM_MAXIMUM_TERMS, malformedMaximumTerms); 187 } 154 188 } 155 189 } -
SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUSearchRetrieveRequest.java
r2088 r2121 25 25 * <li><em>query</em></li> 26 26 * </ul> 27 * 27 * 28 28 * @see SRUSearchRetrieveHandler 29 29 * @see <a href="http://www.loc.gov/standards/sru/specs/search-retrieve.html"> … … 31 31 */ 32 32 public final class SRUSearchRetrieveRequest extends SRUAbstractRequest { 33 /** for end-point conformance testing only. never use in production. */ 34 public static final String X_MALFORMED_QUERY = 35 "x-malformed-query"; 36 /** for end-point conformance testing only. never use in production. */ 37 public static final String X_MALFORMED_START_RECORD = 38 "x-malformed-startRecord"; 39 /** for end-point conformance testing only. never use in production. */ 40 public static final String X_MALFORMED_MAXIMUM_RECORDS = 41 "x-malformed-maximumRecords"; 42 /** for end-point conformance testing only. never use in production. */ 43 public static final String X_MALFORMED_RECORD_PACKING = 44 "x-malformed-recordPacking"; 33 45 private String query; 34 46 private int startRecord = -1; … … 41 53 /** 42 54 * Constructor. 43 * 55 * 44 56 * @param baseURI 45 57 * the baseURI of the endpoint … … 52 64 /** 53 65 * Get the value of the <em>query</em> argument for this request. 54 * 66 * 55 67 * @return the value for the <em>query</em> argument or <code>null</code> of 56 68 * none was set … … 63 75 /** 64 76 * Set the value of the <em>query</em> argument for this request. 65 * 77 * 66 78 * @param query 67 79 * the value for the <em>query</em> argument … … 84 96 /** 85 97 * Get the value of the <em>startRecord</em> argument for this request. 86 * 98 * 87 99 * @return the value for the <em>startRecord</em> argument or 88 100 * <code>-1</code> of none was set … … 95 107 /** 96 108 * Set the value of the <em>startRecord</em> argument for this request. 97 * 109 * 98 110 * @param startRecord 99 111 * the value for the <em>startRecord</em> argument … … 111 123 /** 112 124 * Get the value of the <em>maximumRecords</em> argument for this request. 113 * 125 * 114 126 * @return the value for the <em>maximumRecords</em> argument or 115 127 * <code>-1</code> of none was set … … 122 134 /** 123 135 * Set the value of the <em>maximumRecords</em> argument for this request. 124 * 136 * 125 137 * @param maximumRecords 126 138 * the value for the <em>maximumRecords</em> argument … … 138 150 /** 139 151 * Get the value of the <em>recordSchema</em> argument for this request. 140 * 152 * 141 153 * @return the value for the <em>recordSchema</em> argument or 142 154 * <code>null</code> of none was set … … 149 161 /** 150 162 * Set the value of the <em>recordSchema</em> argument for this request. 151 * 163 * 152 164 * @param recordSchema 153 165 * the value for the <em>recordSchema</em> argument … … 164 176 /** 165 177 * Get the value of the <em>recordSchema</em> argument for this request. 166 * 178 * 167 179 * @return the value for the <em>recordSchema</em> argument or 168 180 * <code>null</code> of none was set … … 175 187 /** 176 188 * Set the value of the <em>recordPacking</em> argument for this request. 177 * 189 * 178 190 * @param recordPacking 179 191 * the value for the <em>recordPacking</em> argument … … 191 203 /** 192 204 * Get the value of the <em>resultSetTTL</em> argument for this request. 193 * 205 * 194 206 * @return the value for the <em>resultSetTTL</em> argument or 195 207 * <code>-1</code> of none was set … … 202 214 /** 203 215 * Set the value of the <em>resultSetTTL</em> argument for this request. 204 * 216 * 205 217 * @param resultSetTTL 206 218 * the value for the <em>resultSetTTL</em> argument … … 221 233 @Override 222 234 void addParametersToURI(URIBuilder uriBuilder) throws SRUClientException { 223 // query 224 if ((query == null) || query.isEmpty()) { 225 throw new SRUClientException( 226 "mandatory argument 'query' not set or empty"); 227 } 228 uriBuilder.append(PARAM_QUERY, query); 229 230 // startRecord 231 if (startRecord > 0) { 232 uriBuilder.append(PARAM_START_RECORD, startRecord); 233 } 234 235 // maximumRecords 236 if (maximumRecords > -1) { 237 uriBuilder.append(PARAM_MAXIMUM_RECORDS, maximumRecords); 238 } 239 240 // recordPacking 241 if (recordPacking != null) { 242 switch (recordPacking) { 243 case XML: 244 uriBuilder.append(PARAM_RECORD_PACKING, RECORD_PACKING_XML); 245 break; 246 case STRING: 247 uriBuilder.append(PARAM_RECORD_PACKING, RECORD_PACKING_STRING); 248 break; 249 default: 250 throw new SRUClientException("unsupported record packing: " + 251 recordPacking); 252 } // switch 253 } 254 255 // recordSchema 235 /* 236 * append query argument (mandatory) 237 * 238 * NB: Setting "x-malformed-query" as an extra request parameter makes 239 * the client to send invalid requests. This is intended to use for 240 * testing endpoints for protocol conformance (i.e. provoke an error) 241 * and SHOULD NEVER be used in production! 242 */ 243 final String malformedQuery = getExtraRequestData(X_MALFORMED_QUERY); 244 if (malformedQuery == null) { 245 if ((query == null) || query.isEmpty()) { 246 throw new SRUClientException( 247 "mandatory argument 'query' not set or empty"); 248 } 249 uriBuilder.append(PARAM_QUERY, query); 250 } else { 251 if (!malformedQuery.equalsIgnoreCase(MALFORMED_OMIT)) { 252 uriBuilder.append(PARAM_QUERY, malformedQuery); 253 } 254 } 255 256 /* 257 * append startRecord argument (optional) 258 * 259 * NB: Setting "x-malformed-startRecord" as an extra request parameter 260 * makes the client to send invalid requests. This is intended to use 261 * for testing endpoints for protocol conformance (i.e. provoke an 262 * error) and SHOULD NEVER be used in production! 263 */ 264 final String malformedStartRecord = 265 getExtraRequestData(X_MALFORMED_START_RECORD); 266 if (malformedStartRecord == null) { 267 if (startRecord > 0) { 268 uriBuilder.append(PARAM_START_RECORD, startRecord); 269 } 270 } else { 271 if (!malformedStartRecord.equalsIgnoreCase(MALFORMED_OMIT)) { 272 uriBuilder.append(PARAM_START_RECORD, malformedStartRecord); 273 } 274 } 275 276 /* 277 * append maximumRecords argument (optional) 278 * 279 * NB: Setting "x-malformed-maximumRecords" as an extra request 280 * parameter makes the client to send invalid requests. This is 281 * intended to use for testing endpoints for protocol conformance 282 * (i.e. provoke an error) and SHOULD NEVER be used in production! 283 */ 284 final String malformedMaxiumRecords = 285 getExtraRequestData(X_MALFORMED_MAXIMUM_RECORDS); 286 if (malformedMaxiumRecords == null) { 287 if (maximumRecords > -1) { 288 uriBuilder.append(PARAM_MAXIMUM_RECORDS, maximumRecords); 289 } 290 } else { 291 if (!malformedMaxiumRecords.equalsIgnoreCase(MALFORMED_OMIT)) { 292 uriBuilder.append(PARAM_MAXIMUM_RECORDS, 293 malformedMaxiumRecords); 294 } 295 } 296 297 /* 298 * append recordPacking argument (optional) 299 * 300 * NB: Setting "x-malformed-recordPacking" as an extra request 301 * parameter makes the client to send invalid requests. This is 302 * intended to use for testing endpoints for protocol conformance 303 * (i.e. provoke an error) and SHOULD NEVER be used in production! 304 */ 305 final String malformedRecordPacking = 306 getExtraRequestData(X_MALFORMED_RECORD_PACKING); 307 if (malformedRecordPacking == null) { 308 if (recordPacking != null) { 309 switch (recordPacking) { 310 case XML: 311 uriBuilder.append(PARAM_RECORD_PACKING, RECORD_PACKING_XML); 312 break; 313 case STRING: 314 uriBuilder.append(PARAM_RECORD_PACKING, 315 RECORD_PACKING_STRING); 316 break; 317 default: 318 throw new SRUClientException( 319 "unsupported record packing: " + recordPacking); 320 } // switch 321 } 322 } else { 323 if (!malformedRecordPacking.equalsIgnoreCase(MALFORMED_OMIT)) { 324 uriBuilder.append(PARAM_RECORD_PACKING, malformedRecordPacking); 325 } 326 } 327 328 /* 329 * append recordSchema argument (optional) 330 */ 256 331 if (recordSchema != null) { 257 332 uriBuilder.append(PARAM_RECORD_SCHEMA, recordSchema); 258 333 } 259 334 260 // resultSetTTL 335 /* 336 * append resultSetTTL argument (optional) 337 */ 261 338 if (resultSetTTL > -1) { 262 339 uriBuilder.append(PARAM_RESULT_SET_TTL, resultSetTTL);
Note: See TracChangeset
for help on using the changeset viewer.