branch for release 3.10.1

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/data-analysis/RConnectorClient/2.0@125433 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Lucio Lelii 2016-03-16 11:24:25 +00:00
commit 0192d2be46
25 changed files with 860 additions and 0 deletions

36
.classpath Normal file
View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

23
.project Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>r-connector-client</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,6 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View File

@ -0,0 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

4
distro/LICENSE Normal file
View File

@ -0,0 +1,4 @@
gCube System - License
------------------------------------------------------------
${gcube.license}

66
distro/README Normal file
View File

@ -0,0 +1,66 @@
The gCube System - ${name}
--------------------------------------------------
${description}
${gcube.description}
${gcube.funding}
Version
--------------------------------------------------
${version} (${buildDate})
Please see the file named "changelog.xml" in this directory for the release notes.
Authors
--------------------------------------------------
* Lucio Lelii (lucio.lelii@isti.cnr.it), CNR, Italy
Maintainers
-----------
* Lucio Lelii (lucio.lelii@isti.cnr.it), CNR, Italy
Download information
--------------------------------------------------
Source code is available from SVN:
${scm.url}
Binaries can be downloaded from the gCube website:
${gcube.website}
Installation
--------------------------------------------------
Installation documentation is available on-line in the gCube Wiki:
${gcube.wikiRoot}/RConnector
Documentation
--------------------------------------------------
Documentation is available on-line in the gCube Wiki:
${gcube.wikiRoot}/RConnector
Support
--------------------------------------------------
Bugs and support requests can be reported in the gCube issue tracking tool:
${gcube.issueTracking}
Licensing
--------------------------------------------------
This software is licensed under the terms you may find in the file named "LICENSE" in this directory.

9
distro/changelog.xml Normal file
View File

@ -0,0 +1,9 @@
<ReleaseNotes>
<Changeset component="r-connector-client-1.0.0" date="2013-02-11">
<Change>First Release</Change>
</Changeset>
<Changeset component="r-connector-client-2.0.0" date="2016-03-15">
<Change>Added the method connect with empty arguments</Change>
<Change>Readme file changed</Change>
</Changeset>
</ReleaseNotes>

32
distro/descriptor.xml Normal file
View File

@ -0,0 +1,32 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>changelog.xml</include>
<include>profile.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
</fileSets>
<files>
<file>
<source>target/${build.finalName}.${project.packaging}</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
</files>
</assembly>

26
distro/profile.xml Normal file
View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID />
<Type>Service</Type>
<Profile>
<Description>${description}</Description>
<Class>DataAnalysis</Class>
<Name>${artifactId}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Name>${artifactId}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</MavenCoordinates>
<Files>
<File>${build.finalName}.jar</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

114
pom.xml Normal file
View File

@ -0,0 +1,114 @@
<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>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.0.0</version>
</parent>
<groupId>org.gcube.data.analysis</groupId>
<artifactId>r-connector-client</artifactId>
<version>2.0.0-SNAPSHOT</version>
<name>r-connector-client</name>
<description>r connector client</description>
<properties>
<distroDirectory>distro</distroDirectory>
</properties>
<dependencies>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-generic-clients</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-gcube-calls</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.13</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-profile</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target</outputDirectory>
<resources>
<resource>
<directory>${distroDirectory}</directory>
<filtering>true</filtering>
<includes>
<include>profile.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<descriptors>
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,33 @@
package org.gcube.data.analysis.rconnector.client;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.client.WebTarget;
import javax.xml.namespace.QName;
import org.gcube.common.clients.ProxyBuilder;
import org.gcube.common.clients.ProxyBuilderImpl;
import org.gcube.data.analysis.rconnector.client.plugin.ConnectorPlugin;
import org.gcube.data.analysis.rconnector.client.proxy.ConnectorProxy;
public class Constants {
/** Service name. */
public static final String SERVICE_NAME = "RConnector";
/** Service class. */
public static final String SERVICE_CLASS = "DataAnalysis";
public static final String CONTEXT_SERVICE_NAME="r-connector";
public static final int DEFAULT_TIMEOUT= (int) TimeUnit.SECONDS.toMillis(10);
private static final String TNS = "http://gcube-system.org/";
public static final QName CONNECTOR_QNAME = new QName(TNS, "connector");
public static ProxyBuilder<ConnectorProxy> rConnector() {
return new ProxyBuilderImpl<WebTarget,ConnectorProxy>(new ConnectorPlugin());
}
}

View File

@ -0,0 +1,38 @@
package org.gcube.data.analysis.rconnector.client;
import javax.xml.namespace.QName;
import org.gcube.common.calls.Call;
import org.gcube.data.analysis.rconnector.client.GcubeServiceBuilderDSL.NameClause;
public class GcubeService {
private final QName name;
private String path;
private final Call call = new Call();
/**
* Starts the bulding process for a {@link GcubeService}.
* @return the service
*/
public static NameClause service() {
return new GcubeServiceBuilder();
}
public GcubeService(QName name, String path) {
this.name=name;
this.path = path;
}
public String path() {
return path;
}
public QName name() {
return name;
}
public Call call() {
return call;
}
}

View File

@ -0,0 +1,41 @@
package org.gcube.data.analysis.rconnector.client;
import javax.xml.namespace.QName;
import org.gcube.data.analysis.rconnector.client.GcubeServiceBuilderDSL.NameClause;
import org.gcube.data.analysis.rconnector.client.GcubeServiceBuilderDSL.StubClause;
import static org.gcube.data.analysis.rconnector.client.Utils.*;
/**
* Builds {@link GCoreService} instances.
*
* @author Fabio Simeoni
*
*/
public class GcubeServiceBuilder implements NameClause, StubClause {
private QName name;
@Override
public StubClause withName(QName name) {
notNull("service name", name);
this.name=name;
return this;
}
@Override
public GcubeService andPath(String path) {
return new GcubeService(name, path);
}
@Override
public GcubeService useRootPath() {
return new GcubeService(name, "/");
}
}

View File

@ -0,0 +1,48 @@
package org.gcube.data.analysis.rconnector.client;
import javax.xml.namespace.QName;
/**
* The clauses of a simple DSL to build {@link GCoreService}.
*
* @author Fabio Simeoni
*
*/
public interface GcubeServiceBuilderDSL {
/**
* The clause that sets the name of the target service.
*
* @author Fabio Simeoni
*
*/
static interface NameClause {
/**
* Sets the qualified name of the target service.
*
* @param name the qualified name of the target service
* @return the next clause
*/
StubClause withName(QName name);
}
/**
* The clause that sets the stub interface of the target service.
*
* @author Fabio Simeoni
*
*/
static interface StubClause {
/**
* Sets the stub interface of the target service.
* @param type the interface
* @return the {@link GCoreService} that described the target service.
*/
GcubeService useRootPath();
GcubeService andPath(String path);
}
}

View File

@ -0,0 +1,60 @@
package org.gcube.data.analysis.rconnector.client;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.ws.EndpointReference;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
public class JaxRSEndpointReference {
private static final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
private static final String addressLocalName = "Address";
//private static final String keyLocalName = "ResourceKey";
String address;
//Element key;
static {
factory.setNamespaceAware(true);
}
JaxRSEndpointReference(EndpointReference reference) {
this(serialise(reference));
}
JaxRSEndpointReference(String reference) {
try {
Document document = factory.newDocumentBuilder().parse(new InputSource(new StringReader(reference)));
NodeList addresses = document.getElementsByTagNameNS("*", addressLocalName);
if (addresses.getLength() == 0)
throw new RuntimeException("reference does not contain an address");
address = addresses.item(0).getTextContent();
} catch (Exception e) {
throw new IllegalArgumentException("reference is not a gCore reference", e);
}
}
@Override
public String toString() {
return address;
}
// helper
private static String serialise(EndpointReference reference) {
StringWriter writer = new StringWriter();
reference.writeTo(new StreamResult(writer));
return writer.toString();
}
}

View File

@ -0,0 +1,35 @@
package org.gcube.data.analysis.rconnector.client;
import java.io.IOException;
import java.util.Collections;
import java.util.Map.Entry;
import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientRequestFilter;
import org.gcube.common.calls.Interceptors;
import org.gcube.common.calls.Request;
import org.gcube.common.scope.api.ScopeProvider;
public class JaxRSRequestFilter implements ClientRequestFilter {
private GcubeService service;
public JaxRSRequestFilter(GcubeService service) {
super();
this.service = service;
}
@Override
public void filter(final ClientRequestContext rc) throws IOException {
System.out.println("request intercepted");
if (ScopeProvider.instance.get()!=null){
Request requestContext = Interceptors.executeRequestChain(service.call());
for (Entry<String, String> entry: requestContext.getHeaders()){
System.out.println("setting "+entry.getKey()+" "+entry.getValue());
rc.getHeaders().put(entry.getKey(), Collections.singletonList((Object)entry.getValue()));
}
}
}
}

View File

@ -0,0 +1,62 @@
package org.gcube.data.analysis.rconnector.client;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.xml.ws.EndpointReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TargetFactory implements TargetFactoryDSL.AtClause{
private static Logger log = LoggerFactory.getLogger(TargetFactory.class);
private GcubeService target;
public static TargetFactory stubFor(GcubeService target){
return new TargetFactory(target);
}
private TargetFactory(GcubeService target) {
this.target = target;
}
public WebTarget at(String address) {
try{
Client client = ClientBuilder.newClient();
String resourceAddress = address.substring(0, address.indexOf("/service"));
WebTarget resourcetarget = client.target(resourceAddress).path("/resource/");
int status = resourcetarget.request().get().getStatus();
if (status!=200)
throw new Exception();
WebTarget webTarget = client.target(address);
webTarget.path(target.path());
webTarget.register(new JaxRSRequestFilter(target));
return webTarget;
}catch (Exception e) {
log.error("error building service",e);
throw new RuntimeException("error building service",e);
}
}
public WebTarget at(EndpointReference endpoint){
return at(new JaxRSEndpointReference(endpoint).address);
}
}

View File

@ -0,0 +1,34 @@
package org.gcube.data.analysis.rconnector.client;
import javax.ws.rs.client.WebTarget;
import org.gcube.common.clients.stubs.jaxws.StubFactory;
/**
* Simple DSL for the {@link StubFactory}
*
* @author Fabio Simeoni
*
*/
public interface TargetFactoryDSL {
/**
* Selects the address of the service endpoint or service instance.
*
* @author Fabio Simeoni
*
* @param <T>
*/
interface AtClause {
/**
* Returns a stub for a service endpoint at a given address.
* @param address the address
* @return the stub
*/
WebTarget at(String address);
}
}

View File

@ -0,0 +1,9 @@
package org.gcube.data.analysis.rconnector.client;
public class Utils {
static void notNull(String message,Object o) {
if (o==null)
throw new IllegalArgumentException(o+" cannot be null");
}
}

View File

@ -0,0 +1,37 @@
package org.gcube.data.analysis.rconnector.client.plugin;
import org.gcube.common.clients.Plugin;
import org.gcube.data.analysis.rconnector.client.Constants;
public abstract class AbstractPlugin<S,P> implements Plugin<S,P> {
public final String name;
public AbstractPlugin(String name) {
this.name=name;
}
@Override
public String serviceClass() {
return Constants.SERVICE_CLASS;
}
@Override
public String serviceName() {
return Constants.SERVICE_NAME;
}
@Override
public String name() {
return name;
}
@Override
public String namespace() {
return "";
}
}

View File

@ -0,0 +1,40 @@
package org.gcube.data.analysis.rconnector.client.plugin;
import static org.gcube.data.analysis.rconnector.client.GcubeService.service;
import static org.gcube.data.analysis.rconnector.client.TargetFactory.stubFor;
import javax.ws.rs.client.WebTarget;
import javax.xml.ws.EndpointReference;
import org.gcube.common.clients.config.ProxyConfig;
import org.gcube.common.clients.delegates.ProxyDelegate;
import org.gcube.data.analysis.rconnector.client.Constants;
import org.gcube.data.analysis.rconnector.client.GcubeService;
import org.gcube.data.analysis.rconnector.client.proxy.ConnectorProxy;
import org.gcube.data.analysis.rconnector.client.proxy.DefaultConnectorProxy;
public class ConnectorPlugin extends AbstractPlugin<WebTarget, ConnectorProxy>{
public ConnectorPlugin() {
super("r-connector/gcube/service");
}
@Override
public Exception convert(Exception fault, ProxyConfig<?, ?> config) {
return fault;
}
@Override
public WebTarget resolve(EndpointReference address, ProxyConfig<?, ?> config)
throws Exception {
GcubeService service = service().withName(Constants.CONNECTOR_QNAME).useRootPath();
return stubFor(service).at(address);
}
@Override
public ConnectorProxy newProxy(ProxyDelegate<WebTarget> delegate) {
return new DefaultConnectorProxy(delegate);
}
}

View File

@ -0,0 +1,11 @@
package org.gcube.data.analysis.rconnector.client.proxy;
import java.net.URI;
public interface ConnectorProxy {
URI connect(Long tabularResourceId);
URI connect();
}

View File

@ -0,0 +1,54 @@
package org.gcube.data.analysis.rconnector.client.proxy;
import static org.gcube.common.clients.exceptions.FaultDSL.again;
import java.net.URI;
import javax.ws.rs.client.WebTarget;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.clients.Call;
import org.gcube.common.clients.delegates.ProxyDelegate;
public class DefaultConnectorProxy implements ConnectorProxy {
private final ProxyDelegate<WebTarget> delegate;
public DefaultConnectorProxy(ProxyDelegate<WebTarget> config){
this.delegate = config;
}
@Override
public URI connect(final Long trId) {
Call<WebTarget, URI> call = new Call<WebTarget, URI>() {
@Override
public URI call(WebTarget endpoint) throws Exception {
return endpoint.path("connect/").path(trId.toString()).queryParam("gcube-token", SecurityTokenProvider.instance.get())
.getUri();
}
};
try {
return delegate.make(call);
} catch (Exception e) {
throw again(e).asServiceException();
}
}
@Override
public URI connect() {
Call<WebTarget, URI> call = new Call<WebTarget, URI>() {
@Override
public URI call(WebTarget endpoint) throws Exception {
return endpoint.path("connect").queryParam("gcube-token", SecurityTokenProvider.instance.get()).getUri();
}
};
try {
return delegate.make(call);
} catch (Exception e) {
throw again(e).asServiceException();
}
}
}

View File

@ -0,0 +1,33 @@
package org.gcube.data.analysis.tconnector.test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.junit.Test;
import static org.gcube.data.analysis.rconnector.client.Constants.*;
public class TESTConnection {
@Test
public void connect(){
ScopeProvider.instance.set("/gcube/devsec");
SecurityTokenProvider.instance.set("df75336d-0944-4324-b444-c711d21f705b");
System.out.println(rConnector().build().connect());
}
@Test
public void testte(){
Pattern pattern = Pattern.compile("[^/]*//([^:]*)[^/]*/(.*)");
Matcher m = pattern.matcher("jdbc:postgresql://node7.d.d4science.research-infrastructures.eu:5432/tabulardata");
m.find();
System.out.println(m.group(1));
System.out.println(m.group(2));
}
}