Creating Trunk Branch
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-client@130463 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
commit
55cf7dd702
|
@ -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>
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>resource-registry-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>
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1,4 @@
|
||||||
|
activeProfiles=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
resolveWorkspaceProjects=true
|
||||||
|
version=1
|
|
@ -0,0 +1,113 @@
|
||||||
|
<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>
|
||||||
|
<groupId>org.gcube.tools</groupId>
|
||||||
|
<artifactId>maven-parent</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
<groupId>org.gcube.information-system</groupId>
|
||||||
|
<artifactId>resource-registry-client</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<name>Resource Registry Client</name>
|
||||||
|
<description>Contains Idempotent API for Resource Registry</description>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.distribution</groupId>
|
||||||
|
<artifactId>gcube-bom</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.core</groupId>
|
||||||
|
<artifactId>common-generic-clients</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.core</groupId>
|
||||||
|
<artifactId>common-gcube-calls</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.core</groupId>
|
||||||
|
<artifactId>common-fw-clients</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.information-system</groupId>
|
||||||
|
<artifactId>resource-registry-api</artifactId>
|
||||||
|
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Test 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>
|
||||||
|
</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>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<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>
|
|
@ -0,0 +1,33 @@
|
||||||
|
package org.gcube.informationsystem.resourceregistry.client.plugin;
|
||||||
|
|
||||||
|
import org.gcube.common.clients.Plugin;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.Constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||||
|
*
|
||||||
|
* @param <S>
|
||||||
|
* @param <P>
|
||||||
|
*/
|
||||||
|
public abstract class AbstractPlugin<S, P> implements Plugin<S, P> {
|
||||||
|
|
||||||
|
public final String name;
|
||||||
|
|
||||||
|
public AbstractPlugin(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String serviceClass() {
|
||||||
|
return Constants.SERVICE_CLASS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String serviceName() {
|
||||||
|
return Constants.SERVICE_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.informationsystem.resourceregistry.client.plugin;
|
||||||
|
|
||||||
|
import org.gcube.common.clients.GCubeEndpoint;
|
||||||
|
import org.gcube.common.clients.config.ProxyConfig;
|
||||||
|
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.client.proxy.ResourceRegistryClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ResourceRegistryClientPlugin extends AbstractPlugin<GCubeEndpoint, ResourceRegistryClient>{
|
||||||
|
|
||||||
|
public ResourceRegistryClientPlugin(){
|
||||||
|
super(ResourceRegistryClientPlugin.class.getSimpleName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String namespace() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Exception convert(Exception fault, ProxyConfig<?, ?> config) {
|
||||||
|
// The Jersey client wraps the exception. So we need to get the wrapped
|
||||||
|
// exception thrown by ResourceRegistry Service.
|
||||||
|
|
||||||
|
Throwable throwable = fault.getCause();
|
||||||
|
if(throwable != null && throwable instanceof ResourceRegistryException){
|
||||||
|
return (Exception) throwable;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fault;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GCubeEndpoint resolve(GCubeEndpoint address, ProxyConfig<?, ?> config)
|
||||||
|
throws Exception {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceRegistryClient newProxy(
|
||||||
|
ProxyDelegate<GCubeEndpoint> delegate) {
|
||||||
|
return new ResourceRegistryClient(delegate);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,114 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.informationsystem.resourceregistry.client.proxy;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.client.Constants;
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.common.clients.Call;
|
||||||
|
import org.gcube.common.clients.GCubeEndpoint;
|
||||||
|
import org.gcube.common.clients.delegates.AsyncProxyDelegate;
|
||||||
|
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||||
|
import org.gcube.common.clients.exceptions.ServiceException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.AccessRESTPath;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.InvalidQueryException;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||||
|
*/
|
||||||
|
public class ResourceRegistryClient {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory
|
||||||
|
.getLogger(ResourceRegistryClient.class);
|
||||||
|
|
||||||
|
private final AsyncProxyDelegate<GCubeEndpoint> delegate;
|
||||||
|
|
||||||
|
public ResourceRegistryClient(ProxyDelegate<GCubeEndpoint> config) {
|
||||||
|
this.delegate = new AsyncProxyDelegate<GCubeEndpoint>(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected HttpURLConnection makeRequest(URL url, String method,
|
||||||
|
boolean includeTokenInHeader) throws Exception {
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
if (includeTokenInHeader) {
|
||||||
|
connection.setRequestProperty(Constants.TOKEN_HEADER_ENTRY,
|
||||||
|
SecurityTokenProvider.instance.get());
|
||||||
|
}
|
||||||
|
connection.setRequestMethod(method);
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void appendQueryParameter(StringBuilder builder, String name,
|
||||||
|
String value) throws UnsupportedEncodingException {
|
||||||
|
builder.append(name).append("=");
|
||||||
|
String encodedValue = URLEncoder.encode(value, "UTF-8");
|
||||||
|
builder.append(encodedValue).append("&");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String query(final String query, final String fetchPlan)
|
||||||
|
throws InvalidQueryException {
|
||||||
|
|
||||||
|
Call<GCubeEndpoint, String> call = new Call<GCubeEndpoint, String>() {
|
||||||
|
|
||||||
|
public String call(GCubeEndpoint endpoint) throws Exception {
|
||||||
|
|
||||||
|
StringBuilder callUrl = new StringBuilder(endpoint.getAddress());
|
||||||
|
callUrl.append("/").append(AccessRESTPath.ACCESS_PATH_PART)
|
||||||
|
.append("/");
|
||||||
|
|
||||||
|
appendQueryParameter(callUrl, AccessRESTPath.QUERY_PARAM, query);
|
||||||
|
|
||||||
|
if (fetchPlan != null) {
|
||||||
|
appendQueryParameter(callUrl,
|
||||||
|
AccessRESTPath.FETCH_PLAN_PARAM, fetchPlan);
|
||||||
|
}
|
||||||
|
|
||||||
|
URL url = new URL(callUrl.toString());
|
||||||
|
HttpURLConnection connection = makeRequest(url, "GET", false);
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
connection.setDoInput(false);
|
||||||
|
connection.setRequestProperty("Content-type", "text/plain");
|
||||||
|
|
||||||
|
logger.debug("Response code for {} is {} : {}",
|
||||||
|
callUrl.toString(), connection.getResponseCode(),
|
||||||
|
connection.getResponseMessage());
|
||||||
|
|
||||||
|
if (connection.getResponseCode() != 200) {
|
||||||
|
throw new Exception(
|
||||||
|
"Error Querying Resource Registry Service");
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
try (BufferedReader reader = new BufferedReader(
|
||||||
|
new InputStreamReader(
|
||||||
|
(InputStream) connection.getContent()))) {
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
result.append(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.toString();
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
return delegate.make(call);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ServiceException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue