avoid class cast when Z server return a Close instead of a SearchResponse (timeout)

This commit is contained in:
Jörg Prante 2021-07-30 16:28:24 +02:00
parent 1a0ff7d6c8
commit 7bcc85b223
3 changed files with 41 additions and 34 deletions

View file

@ -1,6 +1,6 @@
group = org.xbib group = org.xbib
name = z3950 name = z3950
version = 2.3.1 version = 2.3.2
gradle.wrapper.version = 6.6.1 gradle.wrapper.version = 6.6.1
netty.version = 4.1.65.Final netty.version = 4.1.65.Final

View file

@ -120,6 +120,7 @@ public class AbstractOperation<IN extends ASN1Any, OUT extends ASN1Any> {
if (ber.getTagType() != BEREncoding.CONTEXT_SPECIFIC_TAG) { if (ber.getTagType() != BEREncoding.CONTEXT_SPECIFIC_TAG) {
throw new ASN1Exception("bad BER encoding: choice not matched"); throw new ASN1Exception("bad BER encoding: choice not matched");
} }
try {
switch (ber.getTag()) { switch (ber.getTag()) {
case 20: case 20:
return (IN) new InitializeRequest(ber, false); return (IN) new InitializeRequest(ber, false);
@ -154,6 +155,10 @@ public class AbstractOperation<IN extends ASN1Any, OUT extends ASN1Any> {
case 48: case 48:
return (IN) new Close(ber, false); return (IN) new Close(ber, false);
} }
} catch (Exception e) {
// class cast exception if Close is returned, ignore
return null;
}
throw new ASN1Exception("bad BER encoding: choice not matched"); throw new ASN1Exception("bad BER encoding: choice not matched");
} }

View file

@ -133,6 +133,8 @@ public class SearchOperation extends AbstractOperation<SearchResponse, SearchReq
} }
} }
} }
} else {
logger.log(Level.WARNING, "no search response returned for host " + host + " " + databases);
} }
} catch (IOException e) { } catch (IOException e) {
// add host in IOException message // add host in IOException message