ISLookUp client

This commit is contained in:
Michele Artini 2021-06-14 11:10:57 +02:00
parent 743b68096b
commit b9b29e2b2c
6 changed files with 115 additions and 13 deletions

View File

@ -1,11 +1,15 @@
package eu.dnetlib.openaire.directindex;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import eu.dnetlib.common.app.AbstractDnetApp;
import eu.dnetlib.common.clients.ISLookupClientFactory;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
@ -18,6 +22,9 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableScheduling
public class DirectIndexApplication extends AbstractDnetApp {
@Value("${openaire.service.islookup.wsdl}")
private String isLookupUrl;
public static void main(final String[] args) {
SpringApplication.run(DirectIndexApplication.class, args);
}
@ -38,4 +45,9 @@ public class DirectIndexApplication extends AbstractDnetApp {
.build());
}
@Bean
public ISLookUpService lookupServiceStub() {
return ISLookupClientFactory.getLookUpService(isLookupUrl);
}
}

View File

@ -8,10 +8,13 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
import eu.dnetlib.openaire.directindex.DirectIndexApiException;
import eu.dnetlib.openaire.directindex.input.DatasourceEntry;
@ -20,6 +23,9 @@ public class ISLookupClient {
private static final Log log = LogFactory.getLog(ISLookupClient.class);
@Autowired
private ISLookUpService lookupService;
@Cacheable("indexDsInfo")
public IndexDsInfo currentIndexDsInfo() {
try {
@ -99,14 +105,22 @@ public class ISLookupClient {
log.info("Evicting indexDsInfo cache");
}
public String findOne(final String query) {
// TODO Auto-generated method stub
return null;
public String findOne(final String query) throws DirectIndexApiException {
try {
return lookupService.getResourceProfileByQuery(query);
} catch (final ISLookUpException e) {
log.error("Error executing xquery: " + query, e);
throw new DirectIndexApiException("Error executing xquery: " + query, e);
}
}
public List<String> find(final String query) {
// TODO Auto-generated method stub
return null;
public List<String> find(final String query) throws DirectIndexApiException {
try {
return lookupService.quickSearchProfile(query);
} catch (final ISLookUpException e) {
log.error("Error executing xquery: " + query, e);
throw new DirectIndexApiException("Error executing xquery: " + query, e);
}
}
}

View File

@ -28,6 +28,7 @@ spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.use_sql_comments=false
spring.jpa.properties.hibernate.format_sql=false
openaire.api.community=http://XXXXXX/openaire/community/
oaf.schema.location=https://www.openaire.eu/schema/1.0/oaf-1.0.xsd
directindex.scheduling.enabled = false
openaire.api.community = http://..../openaire/community/
oaf.schema.location = https://www.openaire.eu/schema/1.0/oaf-1.0.xsd
openaire.service.islookup.wsdl = http://beta.services.openaire.eu:8280/is/services/isLookUp?wsdl

View File

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>eu.dnetlib.dhp</groupId>
@ -23,7 +25,7 @@
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- for /metrics and /health controllers -->
<dependency>
<groupId>org.springframework.boot</groupId>
@ -76,6 +78,15 @@
<artifactId>simpleclient_spring_web</artifactId>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>cnr-rmi-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.1.5</version>
</dependency>
<!-- JUNIT -->
<dependency>

View File

@ -0,0 +1,55 @@
package eu.dnetlib.common.clients;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
public class ISLookupClientFactory {
private static final Logger log = LoggerFactory.getLogger(ISLookupClientFactory.class);
private static final int requestTimeout = 60000 * 10;
private static final int connectTimeout = 60000 * 10;
public static ISLookUpService getLookUpService(final String isLookupUrl) {
return getServiceStub(ISLookUpService.class, isLookupUrl);
}
@SuppressWarnings("unchecked")
private static <T> T getServiceStub(final Class<T> clazz, final String endpoint) {
log.info(String.format("creating %s stub from %s", clazz.getName(), endpoint));
final JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean();
jaxWsProxyFactory.setServiceClass(clazz);
jaxWsProxyFactory.setAddress(endpoint);
final T service = (T) jaxWsProxyFactory.create();
Client client = ClientProxy.getClient(service);
if (client != null) {
HTTPConduit conduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
log
.info(
String
.format(
"setting connectTimeout to %s, requestTimeout to %s for service %s",
connectTimeout,
requestTimeout,
clazz.getCanonicalName()));
policy.setConnectionTimeout(connectTimeout);
policy.setReceiveTimeout(requestTimeout);
conduit.setClient(policy);
}
return service;
}
}

15
pom.xml
View File

@ -1,4 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
@ -146,13 +148,19 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</exclusions>
</dependency>
<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>cnr-rmi-api</artifactId>
<version>${cnr-rmi-api.version}</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.4</version>
<version>1.4</version>
</dependency>
<dependency>
@ -361,6 +369,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.plugin.version>3.6.0</maven.compiler.plugin.version>
<java.version>1.8</java.version>
<cnr-rmi-api.version>2.6.1</cnr-rmi-api.version>
<dhp-schemas-version>2.3.6</dhp-schemas-version>
<apache.solr.version>7.1.0</apache.solr.version>
<mongodb.driver.version>3.4.2</mongodb.driver.version>