branched for 1.x releases
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/common/common-jaxws-calls/1.0@83991 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
commit
889b5e06ab
|
@ -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.6">
|
||||||
|
<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>common-jaxws-calls</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,7 @@
|
||||||
|
#Wed Oct 09 11:35:27 CEST 2013
|
||||||
|
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,6 @@
|
||||||
|
#Tue Sep 17 11:10:21 CEST 2013
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||||
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.source=1.6
|
|
@ -0,0 +1,5 @@
|
||||||
|
#Mon Sep 16 15:19:47 CEST 2013
|
||||||
|
activeProfiles=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
resolveWorkspaceProjects=true
|
||||||
|
version=1
|
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
gCube System - License
|
||||||
|
------------------------------------------------------------
|
||||||
|
|
||||||
|
The gCube/gCore software is licensed as Free Open Source software conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
|
||||||
|
The software and documentation is provided by its authors/distributors "as is" and no expressed or
|
||||||
|
implied warranty is given for its use, quality or fitness for a particular case.
|
|
@ -0,0 +1,2 @@
|
||||||
|
* Lucio Lelii (lucio.lelii@isti.cnr.it), CNR, Italy
|
||||||
|
* Fabio Simeoni (fabio.simeoni@fao.org), FAO of the UN, Italy
|
|
@ -0,0 +1,39 @@
|
||||||
|
The gCube System - ${name}
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
This work has been partially supported by the following European projects: DILIGENT (FP6-2003-IST-2), D4Science (FP7-INFRA-2007-1.2.2),
|
||||||
|
D4Science-II (FP7-INFRA-2008-1.2.2), iMarine (FP7-INFRASTRUCTURES-2011-2), and EUBrazilOpenBio (FP7-ICT-2011-EU-Brazil).
|
||||||
|
|
||||||
|
Authors
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Lucio Lelii (lucio.lelii@isti.cnr.it), CNR, Italy
|
||||||
|
* Fabio Simeoni (fabio.simeoni@fao.org), FAO of the UN, Italy
|
||||||
|
|
||||||
|
Version and Release Date
|
||||||
|
------------------------
|
||||||
|
${version}
|
||||||
|
|
||||||
|
Description
|
||||||
|
-----------
|
||||||
|
${description}
|
||||||
|
|
||||||
|
Download information
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
Source code is available from SVN:
|
||||||
|
${scm.url}
|
||||||
|
|
||||||
|
Binaries can be downloaded from:
|
||||||
|
|
||||||
|
|
||||||
|
Documentation
|
||||||
|
-------------
|
||||||
|
Documentation is available on-line from the Projects Documentation Wiki:
|
||||||
|
https://gcube.wiki.gcube-system.org/gcube/index.php/....
|
||||||
|
|
||||||
|
|
||||||
|
Licensing
|
||||||
|
---------
|
||||||
|
|
||||||
|
This software is licensed under the terms you may find in the file named "LICENSE" in this directory.
|
|
@ -0,0 +1,5 @@
|
||||||
|
<ReleaseNotes>
|
||||||
|
<Changeset component="${build.finalName}" date="2013-10-24">
|
||||||
|
<Change>First Release</Change>
|
||||||
|
</Changeset>
|
||||||
|
</ReleaseNotes>
|
|
@ -0,0 +1,42 @@
|
||||||
|
<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>INSTALL</include>
|
||||||
|
<include>MAINTAINERS</include>
|
||||||
|
<include>changelog.xml</include>
|
||||||
|
</includes>
|
||||||
|
<fileMode>755</fileMode>
|
||||||
|
<filtered>true</filtered>
|
||||||
|
</fileSet>
|
||||||
|
</fileSets>
|
||||||
|
<files>
|
||||||
|
<file>
|
||||||
|
<source>${distroDirectory}/profile.xml</source>
|
||||||
|
<outputDirectory>/etc</outputDirectory>
|
||||||
|
<filtered>true</filtered>
|
||||||
|
</file>
|
||||||
|
<file>
|
||||||
|
<source>target/${build.finalName}.jar</source>
|
||||||
|
<outputDirectory>/${artifactId}</outputDirectory>
|
||||||
|
</file>
|
||||||
|
<file>
|
||||||
|
<source>${distroDirectory}/svnpath.txt</source>
|
||||||
|
<outputDirectory>/${artifactId}</outputDirectory>
|
||||||
|
<filtered>true</filtered>
|
||||||
|
</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>Common</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 @@
|
||||||
|
${scm.url}
|
|
@ -0,0 +1,98 @@
|
||||||
|
<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.core</groupId>
|
||||||
|
<artifactId>common-jaxws-calls</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<distroDirectory>distro</distroDirectory>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<scm>
|
||||||
|
<connection>scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId}</connection>
|
||||||
|
<developerConnection>scm:svn:https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId}</developerConnection>
|
||||||
|
<url>http://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId}</url>
|
||||||
|
</scm>
|
||||||
|
|
||||||
|
<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</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>1.7.5</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>
|
||||||
|
<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,9 @@
|
||||||
|
package org.gcube.common.calls.jaxws;
|
||||||
|
|
||||||
|
public class Constants {
|
||||||
|
|
||||||
|
public static final String QNAME_KEY="qname";
|
||||||
|
|
||||||
|
public static final String TYPE_KEY="type";
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package org.gcube.common.calls.jaxws;
|
||||||
|
|
||||||
|
import javax.xml.namespace.QName;
|
||||||
|
|
||||||
|
import org.gcube.common.calls.Call;
|
||||||
|
import org.gcube.common.calls.jaxws.GcubeServiceBuilderDSL.NameClause;
|
||||||
|
|
||||||
|
public class GcubeService<T> {
|
||||||
|
|
||||||
|
private final QName name;
|
||||||
|
private final Class<T> type;
|
||||||
|
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, Class<T> type) {
|
||||||
|
this.name=name;
|
||||||
|
this.type=type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QName name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<T> type() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Call call() {
|
||||||
|
return call;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
package org.gcube.common.calls.jaxws;
|
||||||
|
|
||||||
|
import static org.gcube.common.calls.jaxws.JAXWSUtils.*;
|
||||||
|
|
||||||
|
import javax.xml.namespace.QName;
|
||||||
|
|
||||||
|
import org.gcube.common.calls.jaxws.GcubeServiceBuilderDSL.NameClause;
|
||||||
|
import org.gcube.common.calls.jaxws.GcubeServiceBuilderDSL.StubClause;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 <T> GcubeService<T> andInterface(Class<T> type) {
|
||||||
|
|
||||||
|
notNull("service interface", type);
|
||||||
|
|
||||||
|
return new GcubeService<T>(name, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package org.gcube.common.calls.jaxws;
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
<T> GcubeService<T> andInterface(Class<T> type);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package org.gcube.common.calls.jaxws;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Library-wide utilities.
|
||||||
|
*
|
||||||
|
* @author Fabio Simeoni
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class JAXWSUtils {
|
||||||
|
|
||||||
|
@XmlRootElement
|
||||||
|
public static class Empty{}
|
||||||
|
|
||||||
|
public static final Empty empty = new Empty();
|
||||||
|
|
||||||
|
static void notNull(String message,Object o) {
|
||||||
|
if (o==null)
|
||||||
|
throw new IllegalArgumentException(o+" cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
package org.gcube.common.calls.jaxws;
|
||||||
|
|
||||||
|
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 JaxWSEndpointReference {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
JaxWSEndpointReference(EndpointReference reference) {
|
||||||
|
this(serialise(reference));
|
||||||
|
}
|
||||||
|
|
||||||
|
JaxWSEndpointReference(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();
|
||||||
|
|
||||||
|
/*NodeList keys = document.getElementsByTagNameNS("*", keyLocalName);
|
||||||
|
|
||||||
|
if (keys.getLength() >1)
|
||||||
|
throw new RuntimeException("reference contains " + keys.getLength() + " resource key(s)");
|
||||||
|
|
||||||
|
if (keys.getLength()==1)
|
||||||
|
key = (Element) keys.item(0);
|
||||||
|
*/
|
||||||
|
} 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,81 @@
|
||||||
|
package org.gcube.common.calls.jaxws;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.xml.ws.Binding;
|
||||||
|
import javax.xml.ws.BindingProvider;
|
||||||
|
import javax.xml.ws.EndpointReference;
|
||||||
|
import javax.xml.ws.Service;
|
||||||
|
import javax.xml.ws.handler.Handler;
|
||||||
|
|
||||||
|
import org.gcube.common.calls.jaxws.handlers.JaxWSHandler;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class StubFactory<T> implements StubFactoryDSL.AtClause<T>{
|
||||||
|
|
||||||
|
private static Logger log = LoggerFactory.getLogger(StubFactory.class);
|
||||||
|
|
||||||
|
private GcubeService<T> target;
|
||||||
|
|
||||||
|
public static <T> StubFactory<T> stubFor(GcubeService<T> target){
|
||||||
|
return new StubFactory<T>(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private StubFactory(GcubeService<T> target) {
|
||||||
|
this.target = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public T at(String address) {
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
String endpointAddress = address+"?wsdl";
|
||||||
|
|
||||||
|
log.debug("contcting endpoint "+endpointAddress);
|
||||||
|
|
||||||
|
// get JAXWS service from endpoint address
|
||||||
|
Service service = Service.create(new URL(endpointAddress), target.name());
|
||||||
|
|
||||||
|
// get JAXWS stub
|
||||||
|
T stub = service.getPort(target.type());
|
||||||
|
|
||||||
|
BindingProvider provider = (BindingProvider) stub;
|
||||||
|
|
||||||
|
// configure stub for gCube calls
|
||||||
|
registerHandler(provider, target);
|
||||||
|
|
||||||
|
return stub;
|
||||||
|
|
||||||
|
}catch (Exception e) {
|
||||||
|
log.error("error building service",e);
|
||||||
|
throw new RuntimeException("error building service",e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public T at(EndpointReference endpoint){
|
||||||
|
return at(new JaxWSEndpointReference(endpoint).address);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// helper
|
||||||
|
private void registerHandler(BindingProvider provider, GcubeService<?> context) {
|
||||||
|
|
||||||
|
Binding binding = provider.getBinding();
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
List<Handler> currentChain = binding.getHandlerChain();
|
||||||
|
|
||||||
|
JaxWSHandler handler = new JaxWSHandler(context);
|
||||||
|
|
||||||
|
currentChain.add(handler);
|
||||||
|
|
||||||
|
binding.setHandlerChain(currentChain);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package org.gcube.common.calls.jaxws;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple DSL for the {@link StubFactory}
|
||||||
|
*
|
||||||
|
* @author Fabio Simeoni
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface StubFactoryDSL {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selects the address of the service endpoint or service instance.
|
||||||
|
*
|
||||||
|
* @author Fabio Simeoni
|
||||||
|
*
|
||||||
|
* @param <T>
|
||||||
|
*/
|
||||||
|
interface AtClause<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a stub for a service endpoint at a given address.
|
||||||
|
* @param address the address
|
||||||
|
* @return the stub
|
||||||
|
*/
|
||||||
|
T at(String address);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package org.gcube.common.calls.jaxws.handlers;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
import javax.xml.namespace.QName;
|
||||||
|
import javax.xml.ws.handler.MessageContext;
|
||||||
|
import javax.xml.ws.handler.soap.SOAPHandler;
|
||||||
|
import javax.xml.ws.handler.soap.SOAPMessageContext;
|
||||||
|
|
||||||
|
import org.gcube.common.calls.Interceptors;
|
||||||
|
import org.gcube.common.calls.Request;
|
||||||
|
import org.gcube.common.calls.jaxws.GcubeService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class JaxWSHandler implements SOAPHandler<SOAPMessageContext>{
|
||||||
|
|
||||||
|
private Logger logger = LoggerFactory.getLogger(JaxWSHandler.class);
|
||||||
|
|
||||||
|
protected GcubeService<?> context;
|
||||||
|
|
||||||
|
public JaxWSHandler(GcubeService<?> context) {
|
||||||
|
super();
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close(MessageContext arg0) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handleFault(SOAPMessageContext arg0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handleMessage(SOAPMessageContext messageContext) {
|
||||||
|
Boolean outbound = (Boolean) messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
|
||||||
|
|
||||||
|
logger.trace("handling message");
|
||||||
|
|
||||||
|
if (outbound){
|
||||||
|
Request requestContext = Interceptors.executeRequestChain(context.call());
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, List<String>> headers = (Map<String, List<String>>) messageContext.get(MessageContext.HTTP_REQUEST_HEADERS);
|
||||||
|
|
||||||
|
if (headers==null)
|
||||||
|
headers = new HashMap<String, List<String>>();
|
||||||
|
|
||||||
|
for (Entry<String, String> entry: requestContext.getHeaders())
|
||||||
|
headers.put(entry.getKey(), Collections.singletonList(entry.getValue()));
|
||||||
|
|
||||||
|
messageContext.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
|
||||||
|
}
|
||||||
|
/*else{
|
||||||
|
Response context = Interceptors.executeResponseChain();
|
||||||
|
}*/
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<QName> getHeaders() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue