rest collector call added

This commit is contained in:
lucio 2019-10-23 17:19:44 +02:00
parent 61b3f1c140
commit 4dc045bdee
2 changed files with 28 additions and 33 deletions

View File

@ -6,20 +6,11 @@
<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"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
@ -27,7 +18,7 @@
<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">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>

View File

@ -17,6 +17,7 @@ import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.api.DiscoveryException;
import org.gcube.resources.discovery.client.queries.api.Query;
import org.gcube.resources.discovery.icclient.stubs.CollectorStub;
import org.gcube.resources.discovery.icclient.stubs.CollectorStubRestImpl;
import org.gcube.resources.discovery.icclient.stubs.MalformedQueryException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -31,10 +32,10 @@ public class ICClient implements DiscoveryClient<String> {
//result split pattern
private static final Pattern pattern = Pattern.compile("<Record>(.*?)</Record>", Pattern.DOTALL);
public List<String> submit(Query query) throws DiscoveryException {
try {
CollectorStub stub = getStub();
String results = callService(query, stub);
@ -46,44 +47,47 @@ public class ICClient implements DiscoveryClient<String> {
catch(SOAPFaultException e) {
throw new RuntimeException(JAXWSUtils.remoteCause(e));
}
}
//helper
private String callService(Query query, CollectorStub stub) {
String expression = query.expression();
log.info("executing query {}",expression);
long time = System.currentTimeMillis();
String submittedExpression = Helper.queryAddAuthenticationControl(expression);
String response = stub.execute(submittedExpression);
log.info("executed query {} in {} ms",expression,System.currentTimeMillis()-time);
return response;
}
//helper
private CollectorStub getStub() {
ServiceMap serviceMap = ServiceMap.instance;
String address = serviceMap.endpoint(localname);
log.info("connecting to {}",address);
if (serviceMap.version().equals("2.0.0"))
return new CollectorStubRestImpl(address);
else
return stubFor(collector).at(URI.create(address));
//find endpoint address in service map currently in scope
String address = ServiceMap.instance.endpoint(localname);
log.info("connectinfg to "+address);
//obtain a JAXWS stub configured for gCube calls
return stubFor(collector).at(URI.create(address));
}
//helper
private List<String> splitIntoList(String response) {
List<String> results = new ArrayList<String>();
Matcher m = pattern.matcher(response);
while (m.find())
results.add(m.group(1).trim());