Changeset 7266
- Timestamp:
- 01/05/22 22:26:59 (2 years ago)
- Location:
- SRUClient/trunk/src/main/java/eu/clarin/sru/client
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUAbstractRequest.java
r6938 r7266 81 81 82 82 83 enum SRUOperation {84 EXPLAIN, SCAN, SEARCH_RETRIEVE85 } // enum SRUOperation86 87 88 83 protected static class URIHelper { 89 84 private final URIBuilder uriBuilder; … … 477 472 * @return a operation constant for this request 478 473 */ 479 abstract SRUOperation getOperation();474 public abstract SRUOperation getOperation(); 480 475 481 476 -
SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUClientConfig.java
r7194 r7266 39 39 private final CloseableHttpClient httpClient; 40 40 private final HttpClientContext httpContext; 41 private final SRURequestAuthenticator requestAuthenticator; 41 42 private final int threadCount; 42 43 private final List<SRURecordDataParser> recordParsers; … … 83 84 public CloseableHttpClient getCustomizedHttpClient() { 84 85 return httpClient; 86 } 87 88 89 /** 90 * Get the request authenticator 91 * 92 * @return the configured request authenticator or <code>null</code> 93 */ 94 public SRURequestAuthenticator getRequestAuthenticator() { 95 return requestAuthenticator; 85 96 } 86 97 … … 142 153 this.httpContext = null; 143 154 } 155 this.requestAuthenticator = builder.requestAuthenticator; 144 156 this.threadCount = builder.threadCount; 145 157 if (builder.recordParsers != null) { … … 170 182 private CloseableHttpClient httpClient = null; 171 183 private HttpClientContext httpContext = null; 184 private SRURequestAuthenticator requestAuthenticator; 172 185 private int threadCount = 173 186 Runtime.getRuntime().availableProcessors() * 2; … … 271 284 272 285 286 public Builder setRequestAuthenticator( 287 SRURequestAuthenticator requestAuthenticator) { 288 this.requestAuthenticator = requestAuthenticator; 289 return this; 290 } 291 292 273 293 /** 274 294 * Set the number of worker threads. This value is only relevant for the -
SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUExplainRequest.java
r6938 r7266 105 105 106 106 @Override 107 SRUOperation getOperation() {107 public SRUOperation getOperation() { 108 108 return SRUOperation.EXPLAIN; 109 109 } -
SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUScanRequest.java
r6938 r7266 152 152 153 153 @Override 154 SRUOperation getOperation() {154 public SRUOperation getOperation() { 155 155 return SRUOperation.SCAN; 156 156 } -
SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUSearchRetrieveRequest.java
r6938 r7266 313 313 314 314 @Override 315 SRUOperation getOperation() {315 public SRUOperation getOperation() { 316 316 return SRUOperation.SEARCH_RETRIEVE; 317 317 } -
SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUSimpleClient.java
r7191 r7266 85 85 private final CloseableHttpClient httpClient; 86 86 private final HttpContext httpContext; 87 private final SRURequestAuthenticator requestAuthenticator; 87 88 private final XmlStreamReaderProxy proxy = new XmlStreamReaderProxy(); 88 89 private final SRUExplainRecordDataParser explainRecordParser = … … 124 125 } 125 126 } 126 127 127 final CloseableHttpClient client = config.getCustomizedHttpClient(); 128 128 if (client != null) { … … 136 136 httpContext = null; 137 137 } 138 this.requestAuthenticator = config.getRequestAuthenticator(); 138 139 } 139 140 … … 168 169 // create URI and perform request 169 170 final URI uri = request.makeURI(defaultVersion); 170 CloseableHttpResponse response = executeRequest(uri );171 CloseableHttpResponse response = executeRequest(uri, request); 171 172 InputStream stream = null; 172 173 SRUXMLStreamReader reader = null; … … 258 259 // create URI and perform request 259 260 final URI uri = request.makeURI(defaultVersion); 260 CloseableHttpResponse response = executeRequest(uri );261 CloseableHttpResponse response = executeRequest(uri, request); 261 262 InputStream stream = null; 262 263 SRUXMLStreamReader reader = null; … … 347 348 // create URI and perform request 348 349 final URI uri = request.makeURI(defaultVersion); 349 CloseableHttpResponse response = executeRequest(uri );350 CloseableHttpResponse response = executeRequest(uri, request); 350 351 InputStream stream = null; 351 352 SRUXMLStreamReader reader = null; … … 407 408 408 409 409 private CloseableHttpResponse executeRequest(URI uri)410 throws SRUClientException {410 private CloseableHttpResponse executeRequest(URI requestUri, 411 SRUAbstractRequest sruRequest) throws SRUClientException { 411 412 CloseableHttpResponse response = null; 412 413 boolean forceClose = true; 413 414 try { 414 logger.debug("submitting HTTP request: {}", uri.toString());415 415 try { 416 HttpGet request = new HttpGet(uri); 416 HttpGet request = new HttpGet(requestUri); 417 if (requestAuthenticator != null) { 418 String value = requestAuthenticator.createAuthenticationHeaderValue( 419 sruRequest.getOperation(), 420 sruRequest.getBaseURI().toString()); 421 if (value != null) { 422 value = value.trim(); 423 if (!value.isEmpty()) { 424 logger.debug("adding HTTP authentication header with value: {}", value); 425 request.addHeader("Authentication", value); 426 } else { 427 logger.error("request authenticator returned an empty header value!"); 428 } 429 } 430 } 431 logger.debug("submitting HTTP request: {}", requestUri.toString()); 417 432 response = httpClient.execute(request, httpContext); 418 433 StatusLine status = response.getStatusLine(); 419 434 if (status.getStatusCode() != HttpStatus.SC_OK) { 420 435 if (status.getStatusCode() == HttpStatus.SC_NOT_FOUND) { 421 throw new SRUClientException("not found: " + uri);436 throw new SRUClientException("not found: " + requestUri); 422 437 } else { 423 438 throw new SRUClientException("unexpected status: " + … … 431 446 } catch (UnknownHostException e) { 432 447 throw new SRUClientException( 433 "unknown host: " + uri.getHost(), e);448 "unknown host: " + requestUri.getHost(), e); 434 449 } catch (IOException e) { 435 450 String msg = null; … … 1279 1294 (diagnostics == null), strictMode)) != null) { 1280 1295 if (diagnostics == null) { 1281 diagnostics = new ArrayList< SRUDiagnostic>();1296 diagnostics = new ArrayList<>(); 1282 1297 } 1283 1298 diagnostics.add(diagnostic);
Note: See TracChangeset
for help on using the changeset viewer.