diff --git a/pom.xml b/pom.xml
index f2affa1..e53434e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
org.gcube.resources.discovery
ic-client
- 1.1.0-SNAPSHOT
+ 1.0.5-SNAPSHOT
Information Collector Client
Client API for the Information Collector service
diff --git a/src/main/java/org/gcube/resources/discovery/icclient/ICClient.java b/src/main/java/org/gcube/resources/discovery/icclient/ICClient.java
index 3cb60a3..60e27a7 100644
--- a/src/main/java/org/gcube/resources/discovery/icclient/ICClient.java
+++ b/src/main/java/org/gcube/resources/discovery/icclient/ICClient.java
@@ -1,8 +1,8 @@
package org.gcube.resources.discovery.icclient;
-import static org.gcube.common.authorization.client.Constants.authorizationService;
-import static org.gcube.common.clients.stubs.jaxws.StubFactory.*;
-import static org.gcube.resources.discovery.icclient.stubs.CollectorConstants.*;
+import static org.gcube.common.clients.stubs.jaxws.StubFactory.stubFor;
+import static org.gcube.resources.discovery.icclient.stubs.CollectorConstants.collector;
+import static org.gcube.resources.discovery.icclient.stubs.CollectorConstants.localname;
import java.net.URI;
import java.util.ArrayList;
@@ -12,11 +12,7 @@ import java.util.regex.Pattern;
import javax.xml.ws.soap.SOAPFaultException;
-import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
-import org.gcube.common.authorization.library.AuthorizationEntry;
-import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.clients.stubs.jaxws.JAXWSUtils;
-import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.api.ServiceMap;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.api.DiscoveryException;
@@ -75,7 +71,7 @@ public class ICClient implements DiscoveryClient {
//helper
private CollectorStub getStub() {
-
+ /*
ServiceMap serviceMap = null;
if (SecurityTokenProvider.instance.get()!=null) {
@@ -86,9 +82,9 @@ public class ICClient implements DiscoveryClient {
} catch (Throwable e) {
throw new IllegalArgumentException(e);
}
- }
+ }*/
- if (serviceMap ==null) serviceMap = ServiceMap.instance;
+ ServiceMap serviceMap = ServiceMap.instance;
String address = serviceMap.endpoint(localname);
log.info("connecting to {}",address);
if (serviceMap.version().equals("2.0.0"))
diff --git a/src/main/java/org/gcube/resources/discovery/icclient/stubs/CollectorStubRestImpl.java b/src/main/java/org/gcube/resources/discovery/icclient/stubs/CollectorStubRestImpl.java
index 96d617c..dc94024 100644
--- a/src/main/java/org/gcube/resources/discovery/icclient/stubs/CollectorStubRestImpl.java
+++ b/src/main/java/org/gcube/resources/discovery/icclient/stubs/CollectorStubRestImpl.java
@@ -16,14 +16,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CollectorStubRestImpl implements CollectorStub {
-
+
private static Logger log = LoggerFactory.getLogger(CollectorStubRestImpl.class);
-
+
public static final String TOKEN_HEADER_ENTRY = "gcube-token";
public static final String SCOPE_HEADER_ENTRY = "gcube-scope";
private String endopoint;
-
-
+
+
public CollectorStubRestImpl(String endopoint) {
super();
this.endopoint = endopoint;
@@ -33,25 +33,32 @@ public class CollectorStubRestImpl implements CollectorStub {
public String execute(String query) throws MalformedQueryException {
//final String methodPath = "/search/";
final String queryParameter = "query";
-
+
try {
StringBuilder callUrl = new StringBuilder(endopoint).append("?").append(queryParameter).append("=").append(URLEncoder.encode(query, StandardCharsets.UTF_8.toString()));
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "GET", false);
connection.setDoInput(true);
if (connection.getResponseCode()!=200){
- log.info("response code is not 200");
- throw new Exception("error executing query");
+ try(BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)connection.getErrorStream()))){
+ StringBuilder error = new StringBuilder();
+ String line;
+ while((line = reader.readLine()) != null)
+ error.append(line);
+ throw new Exception("error executing query: "+error.toString());
+ }
+
+ } else {
+ String toReturn;
+ try(BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)connection.getContent()))){
+ StringBuilder result = new StringBuilder();
+ String line;
+ while((line = reader.readLine()) != null)
+ result.append(line);
+ toReturn = result.toString();
+ }
+ return toReturn;
}
- String toReturn;
- try(BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)connection.getContent()))){
- StringBuilder result = new StringBuilder();
- String line;
- while((line = reader.readLine()) != null)
- result.append(line);
- toReturn = result.toString();
- }
- return toReturn;
}catch (Exception e) {
log.error("error executing query",e);
throw new MalformedQueryException(e.getMessage());
@@ -74,5 +81,5 @@ public class CollectorStubRestImpl implements CollectorStub {
connection.setRequestMethod(method);
return connection;
}
-
+
}
diff --git a/src/test/java/org/acme/APIClient.java b/src/test/java/org/acme/APIClient.java
index 07c230a..e09c192 100644
--- a/src/test/java/org/acme/APIClient.java
+++ b/src/test/java/org/acme/APIClient.java
@@ -13,6 +13,7 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
+import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.common.resources.gcore.HostingNode;
@@ -60,7 +61,8 @@ public class APIClient {
@Test
public void testThredds() throws Exception{
- ScopeProvider.instance.set("/gcube/devNext/NextNext");
+ //ScopeProvider.instance.set("/gcube/devNext/NextNext");
+ SecurityTokenProvider.instance.set("52b59669-ccde-46d2-a4da-108b9e941f7c-98187548");
SimpleQuery query = queryFor(GCoreEndpoint.class);
query.addCondition("$resource/Profile/ServiceClass/string() eq 'DataAccess' ");
query.setResult("$resource/Profile/ServiceName/text()");