moved to jakarta and SG4

This commit is contained in:
lucio 2024-10-01 17:09:01 +02:00
parent a6552698f8
commit 8544191e4e
8 changed files with 134 additions and 108 deletions

30
pom.xml
View File

@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
@ -9,20 +10,27 @@
</parent>
<groupId>org.gcube.core</groupId>
<artifactId>common-clients</artifactId>
<version>3.0.0</version>
<version>3.0.0-SNAPSHOT</version>
<name>Common Clients</name>
<description>A framework for client APIs</description>
<scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
<connection>
scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
<developerConnection>
scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
</scm>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>3.0.1-SNAPSHOT</version>
<version>4.0.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -38,8 +46,12 @@
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
@ -59,5 +71,9 @@
<version>1.6.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-security</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -5,8 +5,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
import javax.xml.ws.wsaddressing.W3CEndpointReference;
import org.gcube.common.clients.cache.EndpointCache;
import org.gcube.common.clients.config.DiscoveryConfig;
import org.gcube.common.clients.config.EndpointConfig;
@ -17,6 +15,8 @@ import org.gcube.common.clients.delegates.ProxyDelegate;
import org.gcube.common.clients.delegates.ProxyPlugin;
import org.gcube.common.clients.queries.Query;
import jakarta.xml.ws.wsaddressing.W3CEndpointReference;
/**
* Partial implementation of proxy builders.
*
@ -26,105 +26,111 @@ import org.gcube.common.clients.queries.Query;
* @param <S> the type of service stubs
* @param <P> the type of service proxies
*/
public abstract class AbstractBuilder<A,S,P> {
public abstract class AbstractBuilder<A, S, P> {
/**
* Default proxy timeout.
*/
public static final int defaultTimeout = (int)TimeUnit.SECONDS.toMillis(10);
private final ProxyPlugin<A,S,P> plugin;
public static final int defaultTimeout = (int) TimeUnit.SECONDS.toMillis(10);
private final ProxyPlugin<A, S, P> plugin;
private Query<A> query;
private W3CEndpointReference address;
private final EndpointCache<A> cache;
private final Map<String,Object> properties = new HashMap<String, Object>();
private final Map<String, Object> properties = new HashMap<String, Object>();
/**
* Constructs an instance with a given {@link ProxyPlugin}, and {@link EndpointCache}, and zero or more default {@link Property}s.
* @param plugin the plugin
* @param cache the cache
* Constructs an instance with a given {@link ProxyPlugin}, and
* {@link EndpointCache}, and zero or more default {@link Property}s.
*
* @param plugin the plugin
* @param cache the cache
* @param properties the properties
*/
protected AbstractBuilder(ProxyPlugin<A,S,P> plugin,EndpointCache<A> cache,Property<?> ... properties) {
this.plugin=plugin;
this.cache=cache;
//sets default timeout, may be overridden by custom properties below
protected AbstractBuilder(ProxyPlugin<A, S, P> plugin, EndpointCache<A> cache, Property<?>... properties) {
this.plugin = plugin;
this.cache = cache;
// sets default timeout, may be overridden by custom properties below
setTimeout(defaultTimeout);
//add custom properties
// add custom properties
for (Property<?> property : properties)
addProperty(property);
}
/**
* Returns the {@link ProxyPlugin}.
* @return the plugin
*/
protected ProxyPlugin<A,S,P> plugin() {
/**
* Returns the {@link ProxyPlugin}.
*
* @return the plugin
*/
protected ProxyPlugin<A, S, P> plugin() {
return plugin;
}
/**
* Sets the query.
* @param query the query
*/
protected void setQuery(Query<A> query) {
/**
* Sets the query.
*
* @param query the query
*/
protected void setQuery(Query<A> query) {
this.query = query;
}
/**
* Sets the timeout.
* @param timeout the timout
*/
protected void setTimeout(int timeout) {
addProperty(Property.timeout(timeout));
}
/**
* Sets the address.
* @param address the address
*/
protected void setAddress(W3CEndpointReference address) {
this.address=address;
}
/**
* Adds a custom property.
* @param property the property
*/
protected void addProperty(Property<?> property) {
properties.put(property.name(),property.value());
}
//shared among subclasses
public P build() {
ProxyDelegate<S> delegate = null;
if (address==null) {
DiscoveryConfig<A,S> config =
new DiscoveryConfig<A,S>(plugin,query,cache);
for (Entry<String,Object> prop : properties.entrySet())
config.addProperty(prop.getKey(),prop.getValue());
delegate = new DiscoveryDelegate<A,S>(config);
/**
* Sets the timeout.
*
* @param timeout the timout
*/
protected void setTimeout(int timeout) {
addProperty(Property.timeout(timeout));
}
/**
* Sets the address.
*
* @param address the address
*/
protected void setAddress(W3CEndpointReference address) {
this.address = address;
}
/**
* Adds a custom property.
*
* @param property the property
*/
protected void addProperty(Property<?> property) {
properties.put(property.name(), property.value());
}
// shared among subclasses
public P build() {
ProxyDelegate<S> delegate = null;
if (address == null) {
DiscoveryConfig<A, S> config = new DiscoveryConfig<A, S>(plugin, query, cache);
for (Entry<String, Object> prop : properties.entrySet())
config.addProperty(prop.getKey(), prop.getValue());
delegate = new DiscoveryDelegate<A, S>(config);
} else {
EndpointConfig<A, S> config = new EndpointConfig<A, S>(plugin, convertAddress(address));
for (Entry<String, Object> prop : properties.entrySet())
config.addProperty(prop.getKey(), prop.getValue());
delegate = new DirectDelegate<A, S>(config);
}
else {
EndpointConfig<A,S> config = new EndpointConfig<A,S>(plugin,convertAddress(address));
for (Entry<String,Object> prop : properties.entrySet())
config.addProperty(prop.getKey(),prop.getValue());
delegate = new DirectDelegate<A,S>(config);
}
return plugin.newProxy(delegate);
}
/**
* Converts a {@link W3CEndpointReference} in a service address.
* @param address the address as a {@link W3CEndpointReference}
* @return the converted address
*/
protected abstract A convertAddress(W3CEndpointReference address);
}
protected abstract String contextPath();
/**
* Converts a {@link W3CEndpointReference} in a service address.
*
* @param address the address as a {@link W3CEndpointReference}
* @return the converted address
*/
protected abstract A convertAddress(W3CEndpointReference address);
protected abstract String contextPath();
}

View File

@ -4,8 +4,6 @@ import java.net.URI;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import javax.xml.ws.wsaddressing.W3CEndpointReference;
import org.gcube.common.clients.builders.StatefulBuilderAPI.Builder;
import org.gcube.common.clients.builders.StatefulBuilderAPI.FinalClause;
import org.gcube.common.clients.builders.StatefulBuilderAPI.SecondClause;
@ -14,6 +12,8 @@ import org.gcube.common.clients.config.Property;
import org.gcube.common.clients.delegates.ProxyPlugin;
import org.gcube.common.clients.queries.Query;
import jakarta.xml.ws.wsaddressing.W3CEndpointReference;
/**
* Partial implementation of proxy builders for stateful services.
*

View File

@ -4,12 +4,13 @@ import java.net.URI;
import java.net.URL;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.ws.wsaddressing.W3CEndpointReference;
import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import jakarta.xml.ws.wsaddressing.W3CEndpointReference;
import jakarta.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
/**
* Factory methods for addresses of service endpoints and service instances.
*

View File

@ -4,11 +4,11 @@ import java.net.URI;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import javax.xml.ws.wsaddressing.W3CEndpointReference;
import org.gcube.common.clients.config.Property;
import org.gcube.common.clients.queries.Query;
import jakarta.xml.ws.wsaddressing.W3CEndpointReference;
/**
* Defines a DSL for proxy builders of stateful services.
*

View File

@ -1,6 +1,6 @@
package org.gcube.common.clients;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import java.io.StringReader;
import java.io.StringWriter;
@ -8,7 +8,6 @@ import java.net.URI;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.ws.wsaddressing.W3CEndpointReference;
import org.gcube.common.clients.builders.AddressingUtils;
import org.junit.BeforeClass;
@ -17,6 +16,8 @@ import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import jakarta.xml.ws.wsaddressing.W3CEndpointReference;
public class AddressingUtilsTest {
private static final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

View File

@ -109,12 +109,6 @@ public class AsyncDelegateTest {
SecretManagerProvider.set(new Secret() {
@Override
public boolean isExpired() {
// TODO Auto-generated method stub
return false;
}
@Override
public Owner getOwner() {
// TODO Auto-generated method stub
@ -131,6 +125,12 @@ public class AsyncDelegateTest {
public String getContext() {
return scope;
}
@Override
public boolean isValid() {
// TODO Auto-generated method stub
return true;
}
});
//stage call
@ -175,7 +175,7 @@ public class AsyncDelegateTest {
@Override
public boolean isExpired() {
public boolean isValid() {
// TODO Auto-generated method stub
return false;
}

View File

@ -1,16 +1,16 @@
package org.gcube.common.clients;
import static java.util.concurrent.TimeUnit.*;
import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;
import java.io.StringWriter;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import javax.xml.transform.stream.StreamResult;
import javax.xml.ws.wsaddressing.W3CEndpointReference;
import org.gcube.common.clients.builders.AbstractBuilder;
import org.gcube.common.clients.builders.AbstractStatefulBuilder;
@ -37,6 +37,8 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import jakarta.xml.ws.wsaddressing.W3CEndpointReference;
@RunWith(MockitoJUnitRunner.class)
public class BuildersTest {