fix wrong number of records requested in present operation

This commit is contained in:
Jörg Prante 2023-03-29 16:27:10 +02:00
parent e03dac53ef
commit 9a3035098a
3 changed files with 17 additions and 12 deletions

View file

@ -1,5 +1,5 @@
group = org.xbib group = org.xbib
name = z3950 name = z3950
version = 5.1.0 version = 5.1.1
org.gradle.warning.mode = ALL org.gradle.warning.mode = ALL

View file

@ -100,10 +100,6 @@ public class JDKZClient implements Client, Closeable {
// Z39.50 present bails out when offset = 0 // Z39.50 present bails out when offset = 0
offset = 1; offset = 1;
} }
if (length > searchOperation.getCount()) {
// avoid condition 13 "Present request out-of-range"
length = searchOperation.getCount();
}
present.execute(offset, length, searchOperation.getCount(), searchListener, recordListener); present.execute(offset, length, searchOperation.getCount(), searchListener, recordListener);
} }
} }

View file

@ -62,7 +62,11 @@ public class PresentOperation extends AbstractOperation<PresentResponse, Present
presentRequest.resultSetId.value = new InternationalString(); presentRequest.resultSetId.value = new InternationalString();
presentRequest.resultSetId.value.value = new ASN1GeneralString(resultSetName); presentRequest.resultSetId.value.value = new ASN1GeneralString(resultSetName);
presentRequest.resultSetStartPoint = new ASN1Integer(offset); presentRequest.resultSetStartPoint = new ASN1Integer(offset);
presentRequest.numberOfRecordsRequested = new ASN1Integer(length); int numberOfRecordsRequested = length;
if ((offset - 1) + length > total) {
numberOfRecordsRequested = total - offset + 1;
}
presentRequest.numberOfRecordsRequested = new ASN1Integer(numberOfRecordsRequested);
if (elementSetName != null) { if (elementSetName != null) {
presentRequest.recordComposition = new PresentRequestRecordComposition(); presentRequest.recordComposition = new PresentRequestRecordComposition();
presentRequest.recordComposition.simple = new ElementSetNames(); presentRequest.recordComposition.simple = new ElementSetNames();
@ -126,21 +130,26 @@ public class PresentOperation extends AbstractOperation<PresentResponse, Present
private ZException createZExceptionFrom(int status, int nReturned, PresentResponse response) { private ZException createZExceptionFrom(int status, int nReturned, PresentResponse response) {
String message; String message;
switch (status) { switch (status) {
case 1: case 1 -> {
message = "Some records were not returned (request was terminated by access control)"; message = "Some records were not returned (request was terminated by access control)";
return new NoRecordsReturnedException(message, status); return new NoRecordsReturnedException(message, status);
case 2: }
case 2 -> {
message = "Some records were not returned (message size is too small)"; message = "Some records were not returned (message size is too small)";
return new MessageSizeTooSmallException(message, status, nReturned); return new MessageSizeTooSmallException(message, status, nReturned);
case 3: }
case 3 -> {
message = "Some records were not returned (request was terminated by control, at origin request)"; message = "Some records were not returned (request was terminated by control, at origin request)";
return new RequestTerminatedByAccessControlException(message, status, nReturned); return new RequestTerminatedByAccessControlException(message, status, nReturned);
case 4: }
case 4 -> {
message = "Some records were not returned (request was terminated by control, by the target)"; message = "Some records were not returned (request was terminated by control, by the target)";
return new RequestTerminatedException(message, status, nReturned); return new RequestTerminatedException(message, status, nReturned);
case 5: }
case 5 -> {
return new NoRecordsReturnedException(response.toString(), status); return new NoRecordsReturnedException(response.toString(), status);
} }
}
return new ZException(response.toString(), status, nReturned); return new ZException(response.toString(), status, nReturned);
} }
} }