release 4.3
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/common/common-jaxrs-client/1.0@142025 82a268e6-3cf1-43bd-a215-b396298e98cfsmartgears_4
commit
d6ff780ccf
@ -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.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<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="output" path="target/classes"/>
|
||||
</classpath>
|
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>common-jaxrs-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 @@
|
||||
${gcube.license}
|
@ -0,0 +1,61 @@
|
||||
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,6 @@
|
||||
<ReleaseNotes>
|
||||
<Changeset component="org.gcube.common.jaxrs-calls.1-0-0" date="2017-02-01">
|
||||
<Change>first release</Change>
|
||||
</Changeset>
|
||||
|
||||
</ReleaseNotes>
|
@ -0,0 +1,31 @@
|
||||
<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>profile.xml</include>
|
||||
<include>changelog.xml</include>
|
||||
</includes>
|
||||
<fileMode>755</fileMode>
|
||||
<filtered>true</filtered>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
<files>
|
||||
<file>
|
||||
<source>target/${build.finalName}.jar</source>
|
||||
<outputDirectory>/${artifactId}</outputDirectory>
|
||||
</file>
|
||||
</files>
|
||||
</assembly>
|
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Resource>
|
||||
<ID></ID>
|
||||
<Type>Service</Type>
|
||||
<Profile>
|
||||
<Description>${description}</Description>
|
||||
<Class>Common</Class>
|
||||
<Name>${artifactId}</Name>
|
||||
<Version>1.0.0</Version>
|
||||
<Packages>
|
||||
<Software>
|
||||
<Description>${description}</Description>
|
||||
<Name>${artifactId}</Name>
|
||||
<Version>${version}</Version>
|
||||
<MavenCoordinates>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${artifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
</MavenCoordinates>
|
||||
<Type>library</Type>
|
||||
<Files>
|
||||
<File>${build.finalName}.jar</File>
|
||||
</Files>
|
||||
</Software>
|
||||
</Packages>
|
||||
</Profile>
|
||||
</Resource>
|
||||
|
@ -0,0 +1,40 @@
|
||||
<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.common</groupId>
|
||||
<artifactId>common-jaxrs-client</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>gcube-jaxrs-client</name>
|
||||
|
||||
<parent>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-scope</artifactId>
|
||||
<version>[1.1.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>org.glassfish.jersey.core</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
<version>2.24.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>javax.ws.rs-api</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
@ -0,0 +1,38 @@
|
||||
package org.gcube.common.calls.jaxrs;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.gcube.common.calls.Call;
|
||||
import org.gcube.common.calls.jaxrs.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;
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package org.gcube.common.calls.jaxrs;
|
||||
|
||||
import static org.gcube.common.calls.jaxrs.Utils.notNull;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.gcube.common.calls.jaxrs.GcubeServiceBuilderDSL.NameClause;
|
||||
import org.gcube.common.calls.jaxrs.GcubeServiceBuilderDSL.StubClause;
|
||||
|
||||
|
||||
/**
|
||||
* Builds {@link GCoreService} instances.
|
||||
*
|
||||
* @author Fabio Simeoni
|
||||
*
|
||||
*/
|
||||
public class GcubeServiceBuilder implements NameClause, StubClause {
|
||||
|
||||
private QName name;
|
||||
|
||||
public StubClause withName(QName name) {
|
||||
|
||||
notNull("service name", name);
|
||||
|
||||
this.name=name;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public GcubeService andPath(String path) {
|
||||
return new GcubeService(name, path);
|
||||
}
|
||||
|
||||
public GcubeService useRootPath() {
|
||||
return new GcubeService(name, "/");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package org.gcube.common.calls.jaxrs;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package org.gcube.common.calls.jaxrs;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package org.gcube.common.calls.jaxrs;
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package org.gcube.common.calls.jaxrs;
|
||||
|
||||
public class Utils {
|
||||
|
||||
static void notNull(String message,Object o) {
|
||||
if (o==null)
|
||||
throw new IllegalArgumentException(o+" cannot be null");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue