update to netty 4.1.89, avoid class casting execption in case of broken PQF

This commit is contained in:
Jörg Prante 2023-03-10 17:12:43 +01:00
parent 4565e8834f
commit ba048d872a
5 changed files with 58 additions and 6 deletions

View file

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

View file

@ -5,7 +5,7 @@ dependencyResolutionManagement {
version('groovy', '4.0.7')
version('junit', '5.9.2')
version('junit4', '4.13.2')
version('netty', '4.1.87.Final')
version('netty', '4.1.89.Final')
library('junit-jupiter-api', 'org.junit.jupiter', 'junit-jupiter-api').versionRef('junit')
library('junit-jupiter-params', 'org.junit.jupiter', 'junit-jupiter-params').versionRef('junit')
library('junit-jupiter-engine', 'org.junit.jupiter', 'junit-jupiter-engine').versionRef('junit')

View file

@ -0,0 +1,46 @@
package org.xbib.z3950.client.jdk.test;
import org.junit.jupiter.api.Test;
import org.xbib.z3950.client.jdk.JDKZClient;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.logging.Level;
import java.util.logging.Logger;
class LVIZClientTest {
private static final Logger logger = Logger.getLogger(LVIZClientTest.class.getName());
@Test
void testLVI() {
String query = "@attr 1=4 linux";
int from = 1;
int size = 10;
try (JDKZClient client = newZClient()) {
logger.log(Level.INFO, "executing PQF " + query);
int count = client.searchPQF(query, from, size,
(status, total, returned, elapsedMillis) ->
logger.log(Level.INFO, "total results = " + total + " millis = " + elapsedMillis),
record -> logger.log(Level.INFO, "record = " + record.toString(StandardCharsets.UTF_8)),
() -> logger.log(Level.WARNING, "timeout"));
logger.log(Level.INFO, "record count = " + count);
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
}
private JDKZClient newZClient() {
JDKZClient.Builder builder = JDKZClient.builder();
builder.setHost("sru.hbz-nrw.de");
builder.setPort(210);
builder.setDatabases(Collections.singletonList("LVI"));
builder.setElementSetName(null);
builder.setPreferredRecordSyntax("xml");
builder.setResultSetName("default");
builder.setEncoding("utf-8");
builder.setFormat("Marc21");
builder.setType("Bibliographic");
return builder.build();
}
}

View file

@ -17,12 +17,16 @@ import org.xbib.z3950.common.v3.RPNStructure;
import org.xbib.z3950.common.v3.RPNStructureRpnRpnOp;
import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* PQF abstract syntax tree.
*/
public class PQFRPNGenerator implements Visitor {
private static final Logger logger = Logger.getLogger(PQFRPNGenerator.class.getName());
private final Stack<ASN1Any> result;
private RPNQuery rpnQuery;
@ -39,7 +43,12 @@ public class PQFRPNGenerator implements Visitor {
public void visit(PQF pqf) {
if (!result.isEmpty()) {
this.rpnQuery = new RPNQuery();
rpnQuery.rpn = (RPNStructure) result.pop();
ASN1Any any = result.pop();
if (any instanceof RPNStructure) {
rpnQuery.rpn = (RPNStructure) any;
} else if (any instanceof ASN1OctetString) {
logger.log(Level.INFO, "found ASN1OctetString = " + ((ASN1OctetString) any).get());
}
if (pqf.getAttrSet() == null) {
// Z39.50 BIB-1: urn:oid:1.2.840.10003.3.1
rpnQuery.attributeSetId = new AttributeSetId();

View file

@ -13,9 +13,6 @@ import java.util.logging.Logger;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
*
*/
class PQFParserTest {
private static final Logger logger = Logger.getLogger(PQFParserTest.class.getName());