Browse Source
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/information-system/icproxy/1.1@132336 82a268e6-3cf1-43bd-a215-b396298e98cfFeature/21584
commit
586d2e666c
19 changed files with 806 additions and 0 deletions
@ -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,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<projectDescription> |
||||
<name>icproxy</name> |
||||
<comment></comment> |
||||
<projects> |
||||
</projects> |
||||
<buildSpec> |
||||
<buildCommand> |
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name> |
||||
<arguments> |
||||
</arguments> |
||||
</buildCommand> |
||||
<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> |
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature> |
||||
</natures> |
||||
</projectDescription> |
@ -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,62 @@
|
||||
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-AT-isti.cnr.it), CNR, Italy |
||||
|
||||
Maintainers |
||||
-------------------------------------------------- |
||||
|
||||
* Lucio Lelii (lucio.lelii-AT-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} |
||||
|
||||
Documentation |
||||
-------------------------------------------------- |
||||
|
||||
Documentation is available on-line in the gCube Wiki: |
||||
${gcube.wikiRoot} |
||||
|
||||
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. |
@ -0,0 +1,8 @@
|
||||
<ReleaseNotes> |
||||
<Changeset component="org.gcube.information-system.icproxy.1-0-0" date="2015-04-28"> |
||||
<Change>First Release</Change> |
||||
</Changeset> |
||||
<Changeset component="org.gcube.information-system.icproxy.1-1-0" date="2016-10-3-"> |
||||
<Change>Porting to auth2</Change> |
||||
</Changeset> |
||||
</ReleaseNotes> |
@ -0,0 +1,35 @@
|
||||
<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> |
||||
</includes> |
||||
<fileMode>755</fileMode> |
||||
<filtered>true</filtered> |
||||
</fileSet> |
||||
</fileSets> |
||||
<files> |
||||
<file> |
||||
<source>${distroDirectory}/profile.xml</source> |
||||
<outputDirectory>/</outputDirectory> |
||||
<filtered>true</filtered> |
||||
</file> |
||||
<file> |
||||
<source>target/${build.finalName}.war</source> |
||||
<outputDirectory>/${artifactId}</outputDirectory> |
||||
</file> |
||||
</files> |
||||
</assembly> |
@ -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>InformationSystem</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> |
||||
|
@ -0,0 +1,162 @@
|
||||
<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> |
||||
<groupId>org.gcube.information-system</groupId> |
||||
<artifactId>icproxy</artifactId> |
||||
<version>1.1.0-SNAPSHOT</version> |
||||
<name>ICProxy</name> |
||||
|
||||
<packaging>war</packaging> |
||||
|
||||
<!-- <properties> <distroDirectory>distro</distroDirectory> </properties> --> |
||||
|
||||
<scm> |
||||
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/icproxy</url> |
||||
</scm> |
||||
|
||||
<properties> |
||||
<distroDirectory>distro</distroDirectory> |
||||
</properties> |
||||
|
||||
<dependencyManagement> |
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.gcube.distribution</groupId> |
||||
<artifactId>maven-smartgears-bom</artifactId> |
||||
<version>2.0.0-SNAPSHOT</version> |
||||
<type>pom</type> |
||||
<scope>import</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.glassfish.jersey</groupId> |
||||
<artifactId>jersey-bom</artifactId> |
||||
<version>2.23.2</version> |
||||
<type>pom</type> |
||||
<scope>import</scope> |
||||
</dependency> |
||||
</dependencies> |
||||
</dependencyManagement> |
||||
|
||||
<dependencies> |
||||
|
||||
|
||||
<!-- smartgears --> |
||||
<dependency> |
||||
<groupId>org.gcube.core</groupId> |
||||
<artifactId>common-smartgears</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.gcube.core</groupId> |
||||
<artifactId>common-smartgears-app</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.gcube.resources.discovery</groupId> |
||||
<artifactId>discovery-client</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.gcube.resources.discovery</groupId> |
||||
<artifactId>ic-client</artifactId> |
||||
</dependency> |
||||
|
||||
<!-- jersey --> |
||||
|
||||
<dependency> |
||||
<groupId>org.glassfish.jersey.containers</groupId> |
||||
<artifactId>jersey-container-servlet-core</artifactId> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.glassfish.jersey.containers</groupId> |
||||
<!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core" --> |
||||
<artifactId>jersey-container-servlet</artifactId> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>javax.servlet</groupId> |
||||
<artifactId>javax.servlet-api</artifactId> |
||||
<version>3.0.1</version> |
||||
<scope>provided</scope> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.slf4j</groupId> |
||||
<artifactId>slf4j-api</artifactId> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>ch.qos.logback</groupId> |
||||
<artifactId>logback-classic</artifactId> |
||||
<version>1.0.13</version> |
||||
</dependency> |
||||
|
||||
|
||||
|
||||
<!-- lombok --> |
||||
<dependency> |
||||
<groupId>org.projectlombok</groupId> |
||||
<artifactId>lombok</artifactId> |
||||
<version>0.11.6</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.glassfish.jersey.test-framework</groupId> |
||||
<artifactId>jersey-test-framework-util</artifactId> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.glassfish.jersey.test-framework.providers</groupId> |
||||
<artifactId>jersey-test-framework-provider-simple</artifactId> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>junit</groupId> |
||||
<artifactId>junit</artifactId> |
||||
<version>4.12</version> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
<build> |
||||
<finalName>${artifactId}</finalName> |
||||
<plugins> |
||||
<plugin> |
||||
<artifactId>maven-compiler-plugin</artifactId> |
||||
<version>2.3.2</version> |
||||
<configuration> |
||||
<source>1.7</source> |
||||
<target>1.7</target> |
||||
</configuration> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-war-plugin</artifactId> |
||||
<version>2.4</version> |
||||
<configuration> |
||||
<warName>icproxy</warName> |
||||
<failOnMissingWebXml>false</failOnMissingWebXml> |
||||
</configuration> |
||||
</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,14 @@
|
||||
package org.gcube.informationsystem.icproxy; |
||||
|
||||
import javax.ws.rs.ApplicationPath; |
||||
|
||||
import org.glassfish.jersey.server.ResourceConfig; |
||||
|
||||
@ApplicationPath("/gcube/service/") |
||||
public class ICProxy extends ResourceConfig { |
||||
|
||||
public ICProxy() { |
||||
packages("org.gcube.informationsystem.icproxy.resources"); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,77 @@
|
||||
package org.gcube.informationsystem.icproxy.resources; |
||||
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.client; |
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; |
||||
|
||||
import java.util.List; |
||||
|
||||
import javax.validation.constraints.NotNull; |
||||
import javax.ws.rs.GET; |
||||
import javax.ws.rs.Path; |
||||
import javax.ws.rs.PathParam; |
||||
import javax.ws.rs.Produces; |
||||
import javax.ws.rs.QueryParam; |
||||
import javax.ws.rs.WebApplicationException; |
||||
import javax.ws.rs.core.MediaType; |
||||
import javax.ws.rs.core.Response; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import org.gcube.common.resources.gcore.GCoreEndpoint; |
||||
import org.gcube.common.scope.api.ScopeProvider; |
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient; |
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery; |
||||
|
||||
|
||||
@Path("GCoreEndpoint") |
||||
@Slf4j |
||||
public class GCoreEndpointResource { |
||||
|
||||
|
||||
@GET |
||||
@Path("/{class}{name:(/[^/?$]+)?}") |
||||
@Produces(MediaType.TEXT_XML) |
||||
public String retrieveCustom(@NotNull @PathParam("class") String serviceClass, |
||||
@PathParam("name") String serviceName, @QueryParam("result") String resultXPath) { |
||||
try{ |
||||
String scope = ScopeProvider.instance.get(); |
||||
log.info("gcoreendpoint wuth result called with serviceclass {} and servicename {} and result {} in scope {}",serviceClass, serviceName, resultXPath, scope); |
||||
|
||||
|
||||
SimpleQuery query = createClassQuery(serviceClass); |
||||
if (serviceName!=null && !serviceName.isEmpty() ){ |
||||
serviceName = serviceName.replace("/", ""); |
||||
query.addCondition(String.format("$resource/Profile/ServiceName/text() eq '%s'",serviceName)); |
||||
} |
||||
|
||||
if (resultXPath!=null && !resultXPath.isEmpty()) |
||||
if (resultXPath.startsWith("/")) |
||||
query.setResult("$resource"+resultXPath); |
||||
else |
||||
query.setResult("$resource/"+resultXPath); |
||||
|
||||
DiscoveryClient<String> client = client(); |
||||
List<String> endpoints = client.submit(query); |
||||
StringBuilder builder = new StringBuilder("<Results>"); |
||||
for (String single: endpoints) |
||||
builder.append("<Result>").append(single.replaceAll("\n", "")).append("</Result>"); |
||||
|
||||
builder.append("</Results>"); |
||||
|
||||
log.debug("retrieved resources are "+endpoints.size()); |
||||
return builder.toString(); |
||||
}catch(Exception e){ |
||||
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST) |
||||
.entity("Error : "+e.getMessage()).type(MediaType.TEXT_PLAIN).build()); |
||||
} |
||||
} |
||||
|
||||
SimpleQuery createClassQuery(String serviceClass){ |
||||
SimpleQuery query = queryFor(GCoreEndpoint.class); |
||||
query.addCondition(String.format("$resource/Profile/ServiceClass/text() eq '%s'",serviceClass)); |
||||
query.addCondition("$resource/Profile/DeploymentData/Status/text() eq 'ready'"); |
||||
return query; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,63 @@
|
||||
package org.gcube.informationsystem.icproxy.resources; |
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; |
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; |
||||
|
||||
import java.util.List; |
||||
|
||||
import javax.validation.constraints.NotNull; |
||||
import javax.ws.rs.GET; |
||||
import javax.ws.rs.Path; |
||||
import javax.ws.rs.PathParam; |
||||
import javax.ws.rs.Produces; |
||||
import javax.ws.rs.core.MediaType; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import org.gcube.common.resources.gcore.GenericResource; |
||||
import org.gcube.common.scope.api.ScopeProvider; |
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient; |
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery; |
||||
|
||||
@Path("GenericResource") |
||||
@Slf4j |
||||
public class GenericResourceResource { |
||||
|
||||
|
||||
@GET |
||||
@Path("/{secondaryType}/{name}") |
||||
@Produces(MediaType.APPLICATION_XML) |
||||
public List<GenericResource> retrieveByTypeAndName(@NotNull @PathParam("secondaryType") String secondaryType, |
||||
@NotNull @PathParam("name") String resourceName) { |
||||
|
||||
String scope = ScopeProvider.instance.get(); |
||||
log.info("genericResource called with secondaryType {} and name {} in scope {}",secondaryType, resourceName, scope); |
||||
SimpleQuery query = createSecondaryTypeQuery(secondaryType) |
||||
.addCondition(String.format("$resource/Profile/Name/text() eq '%s'",resourceName)); |
||||
DiscoveryClient<GenericResource> client = clientFor(GenericResource.class); |
||||
List<GenericResource> endpoints = client.submit(query); |
||||
log.debug("retrieved resources are "+endpoints.size()); |
||||
return endpoints; |
||||
} |
||||
|
||||
@GET |
||||
@Path("/{secondaryType}") |
||||
@Produces(MediaType.APPLICATION_XML) |
||||
public List<GenericResource> retrieveByType(@NotNull @PathParam("secondaryType") String secondaryType, |
||||
@NotNull @PathParam("name") String resourceName) { |
||||
String scope = ScopeProvider.instance.get(); |
||||
log.info("genericResource called with secondaryType {} in scope {}",secondaryType, scope); |
||||
SimpleQuery query = createSecondaryTypeQuery(secondaryType); |
||||
DiscoveryClient<GenericResource> client = clientFor(GenericResource.class); |
||||
List<GenericResource> endpoints = client.submit(query); |
||||
log.debug("retrieved resources are "+endpoints.size()); |
||||
return endpoints; |
||||
} |
||||
|
||||
SimpleQuery createSecondaryTypeQuery(String secondaryTpe){ |
||||
SimpleQuery query = queryFor(GenericResource.class); |
||||
query.addCondition(String.format("$resource/Profile/SecondaryType/text() eq '%s'",secondaryTpe)); |
||||
return query; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,77 @@
|
||||
package org.gcube.informationsystem.icproxy.resources; |
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.client; |
||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; |
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; |
||||
|
||||
import java.util.List; |
||||
|
||||
import javax.validation.constraints.NotNull; |
||||
import javax.ws.rs.GET; |
||||
import javax.ws.rs.Path; |
||||
import javax.ws.rs.PathParam; |
||||
import javax.ws.rs.Produces; |
||||
import javax.ws.rs.QueryParam; |
||||
import javax.ws.rs.core.MediaType; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import org.gcube.common.resources.gcore.GCoreEndpoint; |
||||
import org.gcube.common.resources.gcore.HostingNode; |
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient; |
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery; |
||||
|
||||
@Slf4j |
||||
@Path("HostingNode") |
||||
public class HostingNodeResource { |
||||
|
||||
@GET |
||||
@Produces(MediaType.APPLICATION_XML) |
||||
public List<HostingNode> retrieve() { |
||||
SimpleQuery query = queryFor(HostingNode.class); |
||||
query.addCondition("$resource/Profile/GHNDescription/Status/text() eq \"certified\""); |
||||
DiscoveryClient<HostingNode> client = clientFor(HostingNode.class); |
||||
List<HostingNode> endpoints = client.submit(query); |
||||
log.debug("retrieved resources are "+endpoints.size()); |
||||
return endpoints; |
||||
} |
||||
|
||||
@GET |
||||
@Path("/{id}/GCoreEnpoints") |
||||
@Produces(MediaType.APPLICATION_XML) |
||||
public List<GCoreEndpoint> retrieveGcoreEnpoints(@NotNull @PathParam("id") String id) { |
||||
log.info("hostingnode called for GCoreEndpoint running on HostingNode with id {}",id); |
||||
SimpleQuery query = queryFor(GCoreEndpoint.class); |
||||
query.addCondition(String.format("$resource/Profile/GHN/@UniqueID/string() eq '%s'",id)); |
||||
DiscoveryClient<GCoreEndpoint> client = clientFor(GCoreEndpoint.class); |
||||
List<GCoreEndpoint> endpoints = client.submit(query); |
||||
log.debug("retrieved resources are "+endpoints.size()); |
||||
return endpoints; |
||||
} |
||||
|
||||
@GET |
||||
@Path("/CustomQuery") |
||||
@Produces(MediaType.TEXT_XML) |
||||
public String retrieve(@NotNull @QueryParam("result") String resultXPath) { |
||||
log.info("hostingnode called (with result {}) ", resultXPath); |
||||
|
||||
SimpleQuery query = queryFor(HostingNode.class); |
||||
|
||||
if (resultXPath!=null && !resultXPath.isEmpty()) |
||||
if (resultXPath.startsWith("/")) |
||||
query.setResult("$resource"+resultXPath); |
||||
else |
||||
query.setResult("$resource/"+resultXPath); |
||||
|
||||
query.addCondition("$resource/Profile/GHNDescription/Status/text() eq \"certified\""); |
||||
DiscoveryClient<String> client = client(); |
||||
List<String> endpoints = client.submit(query); |
||||
StringBuilder builder = new StringBuilder("<Results>"); |
||||
for (String single: endpoints) |
||||
builder.append("<Result>").append(single.replaceAll("\n", "")).append("</Result>"); |
||||
builder.append("</Results>"); |
||||
log.debug("retrieved resources are "+endpoints.size()); |
||||
return builder.toString(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,42 @@
|
||||
package org.gcube.informationsystem.icproxy.resources; |
||||
|
||||
import java.util.List; |
||||
|
||||
import javax.validation.constraints.NotNull; |
||||
import javax.ws.rs.GET; |
||||
import javax.ws.rs.Path; |
||||
import javax.ws.rs.PathParam; |
||||
import javax.ws.rs.Produces; |
||||
import javax.ws.rs.WebApplicationException; |
||||
import javax.ws.rs.core.MediaType; |
||||
import javax.ws.rs.core.Response; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient; |
||||
import org.gcube.resources.discovery.client.queries.api.Query; |
||||
import org.gcube.resources.discovery.client.queries.impl.QueryBox; |
||||
import org.gcube.resources.discovery.icclient.ICFactory; |
||||
|
||||
@Path("/") |
||||
@Slf4j |
||||
public class ICResource { |
||||
|
||||
@GET |
||||
@Path("/{id}") |
||||
@Produces(MediaType.TEXT_PLAIN) |
||||
public String getById(@NotNull @PathParam("id") String id){ |
||||
log.info("resource request with id ",id); |
||||
|
||||
Query q = new QueryBox(String.format("declare namespace ic = 'http://gcube-system.org/namespaces/informationsystem/registry'; " + |
||||
"for $resource in collection('/db/Profiles')//Document/Data/ic:Profile/Resource " + |
||||
"where ($resource/ID/text() eq '%s') return $resource", id)); |
||||
DiscoveryClient<String> client = ICFactory.client(); |
||||
List<String> resources = client.submit(q); |
||||
if (resources.size()>0) |
||||
return resources.get(0); |
||||
else throw new WebApplicationException("id "+id+" not found",Response.Status.NOT_FOUND); |
||||
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,75 @@
|
||||
package org.gcube.informationsystem.icproxy.resources; |
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.client; |
||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; |
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; |
||||
|
||||
import java.util.List; |
||||
|
||||
import javax.validation.constraints.NotNull; |
||||
import javax.ws.rs.GET; |
||||
import javax.ws.rs.Path; |
||||
import javax.ws.rs.PathParam; |
||||
import javax.ws.rs.Produces; |
||||
import javax.ws.rs.core.MediaType; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint; |
||||
import org.gcube.common.scope.api.ScopeProvider; |
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient; |
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery; |
||||
|
||||
@Slf4j |
||||
@Path("ServiceEndpoint") |
||||
public class ServiceEndpointResource { |
||||
|
||||
@GET |
||||
@Path("/{category}/{name}") |
||||
@Produces(MediaType.APPLICATION_XML) |
||||
public List<ServiceEndpoint> retrieve(@NotNull @PathParam("name") String resourceName, |
||||
@NotNull @PathParam("category") String resourceCategory) { |
||||
log.info("ServiceEndpoint called with category {} and name {} in scope {}",resourceCategory, resourceName, ScopeProvider.instance.get()); |
||||
|
||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class); |
||||
|
||||
List<ServiceEndpoint> endpoints = client.submit(getQuery(resourceName, resourceCategory)); |
||||
log.debug("retrieved resources are "+endpoints.size()); |
||||
return endpoints; |
||||
} |
||||
|
||||
@GET |
||||
@Path("/{category}/{name}/Result/{result:([^$\\?]+)}") |
||||
@Produces(MediaType.TEXT_XML) |
||||
public String retrieveCustom(@NotNull @PathParam("name") String resourceName, |
||||
@NotNull @PathParam("category") String resourceCategory, @NotNull @PathParam("result") String resultXPath) { |
||||
log.info("ServiceEndpoint called with category {} and name {} and result {} in scope {}" |
||||
,resourceCategory, resourceName, resultXPath, ScopeProvider.instance.get()); |
||||
|
||||
SimpleQuery query = getQuery(resourceName, resourceCategory); |
||||
|
||||
if (resultXPath.startsWith("/")) |
||||
query.setResult("$resource"+resultXPath); |
||||
else |
||||
query.setResult("$resource/"+resultXPath); |
||||
|
||||
DiscoveryClient<String> client = client(); |
||||
List<String> endpoints = client.submit(query); |
||||
StringBuilder builder = new StringBuilder("<Results>"); |
||||
for (String single: endpoints) |
||||
builder.append("<Result>").append(single.replaceAll("\n", "")).append("</Result>"); |
||||
|
||||
builder.append("</Results>"); |
||||
|
||||
log.debug("retrieved resources are "+endpoints.size()); |
||||
return builder.toString(); |
||||
} |
||||
|
||||
private SimpleQuery getQuery(String resourceName, String resourceCategory){ |
||||
SimpleQuery query = queryFor(ServiceEndpoint.class); |
||||
query.addCondition(String.format("$resource/Profile/Name/text() eq '%s'",resourceName)); |
||||
query.addCondition(String.format("$resource/Profile/Category/text() eq '%s'",resourceCategory)); |
||||
return query; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,12 @@
|
||||
<application mode='online'> |
||||
<name>ICProxy</name> |
||||
<group>DataAccess</group> |
||||
<version>1.0.0-SNAPSHOT</version> |
||||
<description>icproxy webapp</description> |
||||
<!-- <servlets> |
||||
<servlet name="org.gcube.data.analysis.rconnector.RConnector" entryPointName="connector"/> |
||||
</servlets> --> |
||||
<local-persistence location='target' /> |
||||
<exclude>/ServiceEndpoint/*</exclude> |
||||
</application> |
||||
|
@ -0,0 +1,9 @@
|
||||
<web-app> |
||||
<servlet> |
||||
<servlet-name>org.gcube.informationsystem.icproxy.ICProxy</servlet-name> |
||||
</servlet> |
||||
<servlet-mapping> |
||||
<servlet-name>org.gcube.informationsystem.icproxy.ICProxy</servlet-name> |
||||
<url-pattern>/gcube/service/*</url-pattern> |
||||
</servlet-mapping> |
||||
</web-app> |
@ -0,0 +1,69 @@
|
||||
package org.gcube.informationsystem.icproxy; |
||||
|
||||
import javax.ws.rs.core.Application; |
||||
|
||||
import org.gcube.informationsystem.icproxy.resources.GCoreEndpointResource; |
||||
import org.gcube.informationsystem.icproxy.resources.GenericResourceResource; |
||||
import org.gcube.informationsystem.icproxy.resources.HostingNodeResource; |
||||
import org.gcube.informationsystem.icproxy.resources.ICResource; |
||||
import org.gcube.informationsystem.icproxy.resources.ServiceEndpointResource; |
||||
import org.glassfish.jersey.server.ResourceConfig; |
||||
import org.glassfish.jersey.test.JerseyTest; |
||||
import org.junit.Test; |
||||
|
||||
public class TestCall extends JerseyTest{ |
||||
|
||||
@Override |
||||
protected Application configure() { |
||||
return new ResourceConfig(ICResource.class,GCoreEndpointResource.class, ServiceEndpointResource.class, HostingNodeResource.class, GenericResourceResource.class); |
||||
} |
||||
|
||||
@Test |
||||
public void gcoreEndpoint() { |
||||
final String ret = target("GCoreEndpoint").path("DataAnalysis").queryParam("scope", "/gcube/devsec").request().get(String.class); |
||||
System.out.println("return is "+ret); |
||||
} |
||||
|
||||
@Test |
||||
public void gcoreEndpointWithServicename() { |
||||
final String ret = target("GCoreEndpoint").path("DataAnalysis").path("RConnector") |
||||
.queryParam("scope", "/gcube/devsec") |
||||
.request().get(String.class); |
||||
System.out.println(ret); |
||||
} |
||||
|
||||
@Test |
||||
public void gcoreEndpointWithResult() { |
||||
|
||||
|
||||
final String ret = target("GCoreEndpoint").path("DataAnalysis") |
||||
.queryParam("result","/Profile/AccessPoint/RunningInstanceInterfaces//Endpoint[@EntryName/string() eq \"querymanager\"]") |
||||
.queryParam("scope", "/gcube/devsec").request().get(String.class); |
||||
System.out.println(ret); |
||||
} |
||||
|
||||
@Test |
||||
public void serviceEndpoint() { |
||||
final String ret = target("ServiceEndpoint").path("BiodiversityRepository").path("CatalogueOfLife").queryParam("scope", "/gcube/devsec").request().get(String.class); |
||||
System.out.println(ret); |
||||
} |
||||
|
||||
@Test |
||||
public void hostingNode() { |
||||
final String ret = target("HostingNode").queryParam("scope", "/gcube/devsec").request().get(String.class); |
||||
System.out.println(ret); |
||||
} |
||||
|
||||
@Test |
||||
public void gCoreEnpointsForHostingNode() { |
||||
final String ret = target("HostingNode").path("92ee1020-5604-11e3-8182-e7053f61b8fe").path("GCoreEnpoints").queryParam("scope", "/gcube/devsec").request().get(String.class); |
||||
System.out.println(ret); |
||||
} |
||||
|
||||
@Test |
||||
public void getById() { |
||||
final String ret = target("/").path("92ee1020-5604-11e3-8182-e7053f61b8fe").queryParam("scope", "/gcube/devsec").request().get(String.class); |
||||
System.out.println(ret); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue