fix logging issues, update to xbib cql 1.1.1

This commit is contained in:
Jörg Prante 2018-02-06 16:31:17 +01:00
parent d8972929bb
commit d19450e2e1
6 changed files with 70 additions and 67 deletions

View file

@ -1,6 +1,6 @@
plugins {
id "org.sonarqube" version '2.5'
id "io.codearte.nexus-staging" version "0.7.0"
id "org.sonarqube" version '2.6.1'
id "io.codearte.nexus-staging" version "0.11.0"
}
printf "Host: %s\nOS: %s %s %s\nJVM: %s %s %s %s\nGroovy: %s\nGradle: %s\n" +
@ -36,7 +36,7 @@ subprojects {
dependencies {
testCompile 'junit:junit:4.12'
wagon 'org.apache.maven.wagon:wagon-ssh:2.12'
wagon 'org.apache.maven.wagon:wagon-ssh:3.0.0'
}
sourceCompatibility = JavaVersion.VERSION_1_8

View file

@ -1,5 +1,5 @@
group = org.xbib
name = z3950
version = 1.0.1
version = 1.0.2
xbib-cql.version = 1.1.0
xbib-cql.version = 1.1.1

Binary file not shown.

View file

@ -1,6 +1,6 @@
#Mon Oct 09 13:24:07 CEST 2017
#Tue Jan 16 10:22:51 CET 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-all.zip

View file

@ -18,7 +18,6 @@ import org.xbib.io.iso23950.v3.RPNQuery;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.UncheckedIOException;
import java.net.InetSocketAddress;
@ -26,7 +25,6 @@ import java.net.Socket;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -103,89 +101,38 @@ public class ZClient implements AutoCloseable {
}
}
public static ZClient newZClient(String name) throws IOException {
return newZClient(getProperties(name));
}
public static Properties getProperties(String name) throws IOException {
Properties properties = new Properties();
try (InputStream inputStream =
ZClient.class.getResourceAsStream("/org/xbib/io/iso23950/service/" + name + ".properties")) {
properties.load(inputStream);
}
return properties;
}
public static ZClient newZClient(Properties properties) throws IOException {
Builder builder = builder();
if (properties.containsKey("host")) {
builder.setHost(properties.getProperty("host"));
}
if (properties.containsKey("port")) {
builder.setPort(Integer.parseInt(properties.getProperty("port")));
}
if (properties.containsKey("user")) {
builder.setUser(properties.getProperty("user"));
}
if (properties.containsKey("pass")) {
builder.setPass(properties.getProperty("pass"));
}
if (properties.containsKey("database")) {
builder.setDatabases(Collections.singletonList(properties.getProperty("database")));
}
if (properties.containsKey("elementsetname")) {
builder.setElementSetName(properties.getProperty("elementsetname"));
}
if (properties.containsKey("preferredrecordsyntax")) {
builder.setPreferredRecordSyntax(properties.getProperty("preferredrecordsyntax"));
}
if (properties.containsKey("resultsetname")) {
builder.setResultSetName(properties.getProperty("resultsetname"));
}
if (properties.containsKey("encoding")) {
builder.setEncoding(properties.getProperty("encoding"));
}
if (properties.containsKey("format")) {
builder.setFormat(properties.getProperty("format"));
}
if (properties.containsKey("type")) {
builder.setType(properties.getProperty("type"));
}
return builder.build();
}
public boolean isConnected() {
return socket != null && socket.isConnected();
}
@Override
public void close() throws IOException {
public void close() {
if (isConnected()) {
try {
sendClose(0);
} catch (IOException e) {
logger.log(Level.WARNING, "while attempting to close connection: {}", e.getMessage());
logger.log(Level.WARNING, "while attempting to send close for close connection: " + e.getMessage(), e);
}
try {
if (src != null) {
src.close();
}
} catch (IOException e) {
logger.log(Level.WARNING, "error attempting to close connection: {}", e.getMessage());
logger.log(Level.WARNING, "error attempting to close src: " + e.getMessage(), e);
}
try {
if (dest != null) {
dest.close();
}
} catch (IOException e) {
logger.log(Level.WARNING, "error attempting to close connection: {}", e.getMessage());
logger.log(Level.WARNING, "error attempting to close dest: " + e.getMessage(), e);
}
try {
if (socket != null) {
socket.close();
}
} catch (IOException e) {
logger.log(Level.WARNING, "error attempting to close connection: {}", e.getMessage());
logger.log(Level.WARNING, "error attempting to close socket: " + e.getMessage(), e);
}
}
}

View file

@ -2,8 +2,12 @@ package org.xbib.io.iso23950;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -20,7 +24,7 @@ public class ZClientTest {
String query = "bib.identifierISSN = 00280836";
int from = 1;
int size = 10;
try (ZClient client = ZClient.newZClient(serviceName)) {
try (ZClient client = newZClient(serviceName)) {
logger.log(Level.INFO, "executing CQL " + serviceName);
int count = client.executeCQL(query, from, size,
(status, total, returned, elapsedMillis) ->
@ -39,7 +43,7 @@ public class ZClientTest {
String query = "@attr 1=8 \"00280836\"";
int from = 1;
int size = 10;
try (ZClient client = ZClient.newZClient(serviceName)) {
try (ZClient client = newZClient(serviceName)) {
logger.log(Level.INFO, "executing PQF " + serviceName);
int count = client.executePQF(query, from, size,
(status, total, returned, elapsedMillis) ->
@ -51,4 +55,56 @@ public class ZClientTest {
}
}
}
private static ZClient newZClient(String name) throws IOException {
return newZClient(getProperties(name));
}
private static Properties getProperties(String name) throws IOException {
Properties properties = new Properties();
try (InputStream inputStream =
ZClient.class.getResourceAsStream("/org/xbib/io/iso23950/service/" + name + ".properties")) {
properties.load(inputStream);
}
return properties;
}
private static ZClient newZClient(Properties properties) {
ZClient.Builder builder = ZClient.builder();
if (properties.containsKey("host")) {
builder.setHost(properties.getProperty("host"));
}
if (properties.containsKey("port")) {
builder.setPort(Integer.parseInt(properties.getProperty("port")));
}
if (properties.containsKey("user")) {
builder.setUser(properties.getProperty("user"));
}
if (properties.containsKey("pass")) {
builder.setPass(properties.getProperty("pass"));
}
if (properties.containsKey("database")) {
builder.setDatabases(Collections.singletonList(properties.getProperty("database")));
}
if (properties.containsKey("elementsetname")) {
builder.setElementSetName(properties.getProperty("elementsetname"));
}
if (properties.containsKey("preferredrecordsyntax")) {
builder.setPreferredRecordSyntax(properties.getProperty("preferredrecordsyntax"));
}
if (properties.containsKey("resultsetname")) {
builder.setResultSetName(properties.getProperty("resultsetname"));
}
if (properties.containsKey("encoding")) {
builder.setEncoding(properties.getProperty("encoding"));
}
if (properties.containsKey("format")) {
builder.setFormat(properties.getProperty("format"));
}
if (properties.containsKey("type")) {
builder.setType(properties.getProperty("type"));
}
return builder.build();
}
}